Merge pull request #327 from leiyangyou/master

create/text: adding linespacing support
This commit is contained in:
John Cupitt 2015-09-20 10:54:12 +01:00
commit 1cdeefe955
1 changed files with 13 additions and 2 deletions

View File

@ -64,6 +64,7 @@ typedef struct _VipsText {
char *text; char *text;
char *font; char *font;
int width; int width;
int linespacing;
VipsAlign align; VipsAlign align;
int dpi; int dpi;
@ -103,7 +104,7 @@ vips_text_dispose( GObject *gobject )
static PangoLayout * static PangoLayout *
text_layout_new( PangoContext *context, text_layout_new( PangoContext *context,
const char *text, const char *font, int width, const char *text, const char *font, int width, int linespacing,
VipsAlign align, int dpi ) VipsAlign align, int dpi )
{ {
PangoLayout *layout; PangoLayout *layout;
@ -120,6 +121,9 @@ text_layout_new( PangoContext *context,
if( width > 0 ) if( width > 0 )
pango_layout_set_width( layout, width * PANGO_SCALE ); pango_layout_set_width( layout, width * PANGO_SCALE );
if (linespacing > 0)
pango_layout_set_spacing( layout, linespacing * PANGO_SCALE);
switch( align ) { switch( align ) {
case VIPS_ALIGN_LOW: case VIPS_ALIGN_LOW:
palign = PANGO_ALIGN_LEFT; palign = PANGO_ALIGN_LEFT;
@ -180,7 +184,7 @@ vips_text_build( VipsObject *object )
if( !(text->layout = text_layout_new( text->context, if( !(text->layout = text_layout_new( text->context,
text->text, text->font, text->text, text->font,
text->width, text->align, text->dpi )) ) { text->width, text->linespacing, text->align, text->dpi )) ) {
g_mutex_unlock( vips_text_lock ); g_mutex_unlock( vips_text_lock );
return( -1 ); return( -1 );
} }
@ -308,6 +312,13 @@ vips_text_class_init( VipsTextClass *class )
G_STRUCT_OFFSET( VipsText, dpi ), G_STRUCT_OFFSET( VipsText, dpi ),
1, 1000000, 72 ); 1, 1000000, 72 );
VIPS_ARG_INT( class, "linespacing", 4,
_( "Line Spacing" ),
_( "Line Spacing to render at" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsText, linespacing ),
0, 1000000, 0 );
} }
static void static void