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 » 2017-04-28T19:59:45-07:00

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: 9404
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 » 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.
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 » 2017-04-28T21:10:14-07:00

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 » 2017-04-28T21:22:45-07:00

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 » 2017-04-28T21:33:47-07:00

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 » 2017-04-28T21:38:33-07:00

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: 22109
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

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

Post by fmw42 » 2017-04-28T22:06:13-07:00

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: 9404
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 » 2017-04-29T08:55:25-07:00

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 » 2017-07-25T14:17:20-07:00

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