Setting interline-spacing with Pango?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
firebird
Posts: 1
Joined: 2014-04-02T21:40:43-07:00
Authentication code: 6789

Setting interline-spacing with Pango?

Post by firebird »

I'm trying to set the -interline-spacing with Pango, with no success. Here are my test commands:

Code: Select all

convert -font courier -density 72x72 -interline-spacing 50  -pointsize 20  -size 150  -background white pango:'This is text for my test paragraph. Here is some more text for my test paragraph.' test-pango.jpg

convert -font courier -density 72x72 -interline-spacing 50  -pointsize 20  -size 150  -background white caption:'This is text for my test paragraph. Here is some more text for my test paragraph.' test-caption.jpg
When using "caption:" the line height is adjusted as expected, but Pango completely ignores the setting. I've also been unable to find a -define pango:* equivalent or a Pango markup equivalent.

Is there a way to use Pango and to control the line height at the same time?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Setting interline-spacing with Pango?

Post by fmw42 »

I'm trying to set the -interline-spacing with Pango, with no success
Not that I know. I could not find it either in the Pango docs as per https://developer.gnome.org/pango/stabl ... ormat.html

It does seem odd that they have ignored that option.
krukid
Posts: 2
Joined: 2019-09-02T18:15:43-07:00
Authentication code: 1152

Re: Setting interline-spacing with Pango?

Post by krukid »

Pango itself supports various layout options as you can see here: https://developer.gnome.org/pango/stabl ... jects.html

Unfortunately, ImageMagick Pango "coder" is a pretty basic wrapper around Pango library. For any use of Pango that is beyond trivial, line spacing is essential so I had to patch it in by hand and rebuild IM from source.

Git checkout ImageMagick 7.0.8-61, copy the following patch to /coders/ and run git apply pango-spacing.patch. Then build IM and you'll be able to use -define pango:spacing=30, same as you -define pango:indent=30.

(I assume anyone interested in this already knows how to build IM from source with Pango support)

pango-spacing.patch

Code: Select all

diff --git a/pango.c b/pango.c
index 5f91187..f8df397 100755
--- a/pango.c
+++ b/pango.c
@@ -309,6 +309,13 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
       if (LocaleCompare(option,"word-char") == 0)
         pango_layout_set_wrap(layout,PANGO_WRAP_WORD_CHAR);
     }
+  option=GetImageOption(image_info,"pango:spacing");
+  if (option != (const char *) NULL)
+    {
+      pango_layout_set_spacing(layout,(int) ((StringToLong(option)*
+        (image->resolution.x == 0.0 ? DefaultSVGDensity : image->resolution.x)*
+        PANGO_SCALE+DefaultSVGDensity/2)/DefaultSVGDensity+0.5));
+    }
   option=GetImageOption(image_info,"pango:indent");
   if (option != (const char *) NULL)
     pango_layout_set_indent(layout,(int) ((StringToLong(option)*
PS: If you know C, you'll notice the mechanism IM uses to infer various Pango options like font, alignment, etc from image context, so I guess the better way would be to create a mapper from -interline-spacing.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Setting interline-spacing with Pango?

Post by fmw42 »

Perhaps the IM developers will add these patches to the Pango ImageMagick coder?
Post Reply