possible bug with pango: and & or & in text string

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

possible bug with pango: and & or & in text string

Post by fmw42 »

see viewtopic.php?f=1&t=31723&p=144873#p144873

This fails:

Code: Select all

convert -size 100x100 -font arial -gravity center pango:"&åß∂ƒ©" tmp.png
as does

Code: Select all

convert -size 100x100 -font arial -gravity center pango:"&åß∂ƒ©" tmp.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug with pango: and & or & in text string

Post by fmw42 »

Here is a workaround. Escape the ; as \;

Code: Select all

convert -size 100x100 -font arial -gravity center pango:"&amp\;åß∂ƒ©" tmp.png
It seems to work for me.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: possible bug with pango: and & or & in text string

Post by snibgo »

Other workarounds:

1. Prefix with backslash, eg

Code: Select all

convert -size 100x100 -font arial -gravity center pango:"hello \& world" t.png
Yes, this works on Windows, where backslash isn't the escape.

2. Put the pango string in a file, at @ it, eg put

Code: Select all

Hello & world
... into pangoamp.txt, then:

Code: Select all

convert -size 100x100 -font arial -gravity center pango:@pangoamp.txt t.png

This is the problem cause:

pango.c function ReadPANGOImage() takes the string after "pango:", which is a kind-of filename.

It parses that string with property.c InterpretImageProperties(). This translates "\n" into newline, and other translations, including "&" to "&".

So a string with "&" will passed to pango with a naked "&".

That's the problem. I don't know the most appropriate cure.
snibgo's IM pages: im.snibgo.com
krukid
Posts: 2
Joined: 2019-09-02T18:15:43-07:00
Authentication code: 1152

Re: possible bug with pango: and & or & in text string

Post by krukid »

note that to avoid the weird handling of html entities and backslashes you can also pipe the text via stdin:

Code: Select all

echo -n "& text" | magick -define pango:markup=false pango:@- tmp.png
Post Reply