add a fontfile option to text
use @fontfile to give a font to load ... note that this just loads the font, you'll need to set it with @font as well see https://github.com/jcupitt/libvips/issues/950
This commit is contained in:
parent
6ee7789095
commit
4d683559aa
@ -19,6 +19,7 @@
|
|||||||
- jpegload adds a jpeg-chroma-subsample field with eg. 4:4:4 for no
|
- jpegload adds a jpeg-chroma-subsample field with eg. 4:4:4 for no
|
||||||
chrominance subsampling.
|
chrominance subsampling.
|
||||||
- tiffload, pdfload, magickload set VIPS_META_N_PAGES "n-pages" metadata item
|
- tiffload, pdfload, magickload set VIPS_META_N_PAGES "n-pages" metadata item
|
||||||
|
- add fontfile option to vips_text() [fangqiao]
|
||||||
|
|
||||||
12/3/18 started 8.6.4
|
12/3/18 started 8.6.4
|
||||||
- better fitting of fonts with overhanging edges [Adrià]
|
- better fitting of fonts with overhanging edges [Adrià]
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
* - implement auto fitting of text inside bounds
|
* - implement auto fitting of text inside bounds
|
||||||
* 12/3/18
|
* 12/3/18
|
||||||
* - better fitting of fonts with overhanging edges, thanks Adrià
|
* - better fitting of fonts with overhanging edges, thanks Adrià
|
||||||
|
* 26/4/18 fangqiao
|
||||||
|
* - add fontfile option
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -80,6 +82,7 @@ typedef struct _VipsText {
|
|||||||
int spacing;
|
int spacing;
|
||||||
VipsAlign align;
|
VipsAlign align;
|
||||||
int dpi;
|
int dpi;
|
||||||
|
char *fontfile;
|
||||||
|
|
||||||
FT_Bitmap bitmap;
|
FT_Bitmap bitmap;
|
||||||
PangoContext *context;
|
PangoContext *context;
|
||||||
@ -337,6 +340,15 @@ vips_text_build( VipsObject *object )
|
|||||||
if( !vips_text_fontmap )
|
if( !vips_text_fontmap )
|
||||||
vips_text_fontmap = pango_ft2_font_map_new();
|
vips_text_fontmap = pango_ft2_font_map_new();
|
||||||
|
|
||||||
|
if( text->fontfile &&
|
||||||
|
!FcConfigAppFontAddFile( NULL,
|
||||||
|
(const FcChar8 *) text->fontfile ) ) {
|
||||||
|
vips_error( class->nickname,
|
||||||
|
_( "unable to load font \"%s\"" ), text->fontfile );
|
||||||
|
g_mutex_unlock( vips_text_lock );
|
||||||
|
return( -1 );
|
||||||
|
}
|
||||||
|
|
||||||
/* If our caller set height and not dpi, we adjust dpi until
|
/* If our caller set height and not dpi, we adjust dpi until
|
||||||
* we get a fit.
|
* we get a fit.
|
||||||
*/
|
*/
|
||||||
@ -477,6 +489,13 @@ vips_text_class_init( VipsTextClass *class )
|
|||||||
G_STRUCT_OFFSET( VipsText, spacing ),
|
G_STRUCT_OFFSET( VipsText, spacing ),
|
||||||
0, 1000000, 0 );
|
0, 1000000, 0 );
|
||||||
|
|
||||||
|
VIPS_ARG_STRING( class, "fontfile", 12,
|
||||||
|
_( "Font file" ),
|
||||||
|
_( "Load this font file" ),
|
||||||
|
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||||
|
G_STRUCT_OFFSET( VipsText, fontfile ),
|
||||||
|
NULL );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -499,6 +518,7 @@ vips_text_init( VipsText *text )
|
|||||||
* Optional arguments:
|
* Optional arguments:
|
||||||
*
|
*
|
||||||
* * @font: %gchararray, font to render with
|
* * @font: %gchararray, font to render with
|
||||||
|
* * @fontfile: %gchararray, load this font file
|
||||||
* * @width: %gint, image should be no wider than this many pixels
|
* * @width: %gint, image should be no wider than this many pixels
|
||||||
* * @height: %gint, image should be no higher than this many pixels
|
* * @height: %gint, image should be no higher than this many pixels
|
||||||
* * @align: #VipsAlign, left/centre/right alignment
|
* * @align: #VipsAlign, left/centre/right alignment
|
||||||
@ -516,6 +536,9 @@ vips_text_init( VipsText *text )
|
|||||||
* @font is the font to render with, as a fontconfig name. Examples might be
|
* @font is the font to render with, as a fontconfig name. Examples might be
|
||||||
* "sans 12" or perhaps "bitstream charter bold 10".
|
* "sans 12" or perhaps "bitstream charter bold 10".
|
||||||
*
|
*
|
||||||
|
* You can specify a font to load with @fontfile. You'll need to also set the
|
||||||
|
* name of the font with @font.
|
||||||
|
*
|
||||||
* @width is the number of pixels to word-wrap at. Lines of text wider than
|
* @width is the number of pixels to word-wrap at. Lines of text wider than
|
||||||
* this will be broken at word bounaries.
|
* this will be broken at word bounaries.
|
||||||
* @align can be used to set the alignment style for multi-line
|
* @align can be used to set the alignment style for multi-line
|
||||||
@ -532,7 +555,7 @@ vips_text_init( VipsText *text )
|
|||||||
* @dpi sets the resolution to render at. "sans 12" at 72 dpi draws characters
|
* @dpi sets the resolution to render at. "sans 12" at 72 dpi draws characters
|
||||||
* approximately 12 pixels high.
|
* approximately 12 pixels high.
|
||||||
*
|
*
|
||||||
* @spacing sets the line spacing, in points. It would typicallly be something
|
* @spacing sets the line spacing, in points. It would typically be something
|
||||||
* like font size times 1.2.
|
* like font size times 1.2.
|
||||||
*
|
*
|
||||||
* See also: vips_xyz(), vips_text(), vips_gaussnoise().
|
* See also: vips_xyz(), vips_text(), vips_gaussnoise().
|
||||||
|
Loading…
Reference in New Issue
Block a user