Setting fontWeight/fontStyle/lineSpacing doesn't work

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

Setting fontWeight/fontStyle/lineSpacing doesn't work

Post by Airon65 »

Here is my code:

Code: Select all

	Magick::Image image( Magick::Geometry( 700, 700 ), Magick::Color( "white" ) );
	
	image.font( "verdana" );
	image.fontPointsize( 70 );
	
	image.fontWeight( 900 );
	image.fontStyle( Magick::ItalicStyle );
	image.textInterlineSpacing( 0.1f );
	
	image.textGravity( MagickCore::CenterGravity );
	image.draw( Magick::DrawableText( 0, 0, "Hello\nworld!" ) );
	
	image.write( "images/testImage.png" );
And that's my output:
Image
As you can see there are no any weight, style affect. And there's no also any interlineSpacing effect. Why does it work like this?

Version: ImageMagick 7.0.5-4 Q16 x86_64 2017-03-25 http://www.imagemagick.org
macOS 10.12.3
Last edited by Airon65 on 2017-04-28T21:32:08-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Setting fontWeight/fontStyle/lineSpacing doesn't work

Post by snibgo »

For drawing text, as opposed to other methods, I suppose you should use methods on http://www.imagemagick.org/Magick++/Drawable.html such as DrawableFont.
snibgo's IM pages: im.snibgo.com
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

Re: Setting fontWeight/fontStyle/lineSpacing doesn't work

Post by Airon65 »

snibgo wrote: 2017-04-28T20:46:23-07:00 For drawing text, as opposed to other methods, I suppose you should use methods on http://www.imagemagick.org/Magick++/Drawable.html such as DrawableFont.
Well maybe. But for what purposes developers created those methods such as fontStyle(), fontWeight(), textInterlineSpacing()? :)
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

Re: Setting fontWeight/fontStyle/lineSpacing doesn't work

Post by Airon65 »

Code: Select all

Magick::Image image( Magick::Geometry( 300, 300 ), Magick::Color( "white" ) );
	
std::vector < Magick::Drawable > textArr;
	
textArr.push_back( Magick::DrawablePointSize( 70 ) );
textArr.push_back( Magick::DrawableTextInterlineSpacing( 0.1f ) );
textArr.push_back( Magick::DrawableGravity( MagickCore::CenterGravity ) );
textArr.push_back( Magick::DrawableFont( "verdana", Magick::ItalicStyle, 900, Magick::NormalStretch ) );
textArr.push_back( Magick::DrawableText( 0, 0, "Hello\nworld!" ) );
	
image.draw( textArr );
	
image.write( "images/testImage.png" );
The same output as listed above...
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

Re: Setting fontWeight/fontStyle/lineSpacing doesn't work

Post by Airon65 »

Code: Select all

$ convert -size 230x130 xc:lightblue -font verdana -pointsize 25 -style italic -draw "gravity NorthWest fill black text 0,0 'The quick red fox jumped over the lazy brown dog'" font1.png
Image
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

Re: Setting fontWeight/fontStyle/lineSpacing doesn't work

Post by Airon65 »

Well I can use another ttf file for setting italic style of setting new font weight but what to do with the TextInterlineSpacing? It doesn't work in both cases...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Setting fontWeight/fontStyle/lineSpacing doesn't work

Post by fmw42 »

There is no -style. But in command line, you can use -interline-spacing. See http://www.imagemagick.org/Usage/text/# ... ne-spacing. That should autowrap with caption, but with label:, -annotate, and -draw, you likely need to put in newline character (\n) where you want it to wrap.;
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Setting fontWeight/fontStyle/lineSpacing doesn't work

Post by snibgo »

Interline spacing of zero means "no change". A value of 0.1 will increase it by 0.1 pixels, which I can't see. Try:

Code: Select all

image.textInterlineSpacing( 50.0f );
snibgo's IM pages: im.snibgo.com
jeroenooms
Posts: 4
Joined: 2017-07-24T01:26:54-07:00
Authentication code: 1151

Re: Setting fontWeight/fontStyle/lineSpacing doesn't work

Post by jeroenooms »

I ran into this as well. In my case it was because imagemagick on osx homebrew is built without fontconfig. Therefore it is unable to find the italic/boldface fonts.

The problem was fixed after: brew reinstall imagemagick --with-fontconfig
Post Reply