Strokes in Pango vs. Complex scripts in IM

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?".
Bob Pickle
Posts: 20
Joined: 2013-11-11T08:52:56-07:00
Authentication code: 6789

Strokes in Pango vs. Complex scripts in IM

Post by Bob Pickle »

Hi.

I have a need to use complex scripts, such as Arabic and Devangari, and thus need to use Pango since IM can't combine and rearrange the letters properly, as made clear on other threads.

But I also want to be able to produce outlined text, and cannot see any way to set stroke color and width in Pango, whether using markup or -define.

A workaround I tried was to superimpose multiple copies of the result from Pango, behind that result, using a different color. This worked great, except that the edges weren't rounded enough, because I couldn't offset these copies by a fraction of a pixel.The edge of a curve looks stair stepped if the offsetting is limited to integer values.

Is there any possible way to add the ability to set stroke width and color to the integration of Pango? Or is that something that is only available in connection with Pango when using Cairo? Or could IM be improved so that it can combine images that are offset by fractions of a pixel?

Any suggestions?

Bob
Version: ImageMagick 6.7.6-3 2012-04-28 Q16
Bob Pickle
Posts: 20
Joined: 2013-11-11T08:52:56-07:00
Authentication code: 6789

Re: Strokes in Pango vs. Complex scripts in IM

Post by Bob Pickle »

Another feature of IM that appears to be unavailable in IM's implementation of Pango is line spacing. Shouldn't there be a way to define a line height for Pango?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Strokes in Pango vs. Complex scripts in IM

Post by magick »

Use the Pango markup language, see http://www.imagemagick.org/Usage/text/#pango_markup.
Bob Pickle
Posts: 20
Joined: 2013-11-11T08:52:56-07:00
Authentication code: 6789

Re: Strokes in Pango vs. Complex scripts in IM

Post by Bob Pickle »

magick,
Bob Pickle wrote:But I also want to be able to produce outlined text, and cannot see any way to set stroke color and width in Pango, whether using markup or -define.
My point is that I cannot see any way to use Pango's markup language to control stroke color, stroke width, or line spacing. Am I missing something?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Strokes in Pango vs. Complex scripts in IM

Post by fmw42 »

But I also want to be able to produce outlined text
Use an outline font or apply an edge operator afterwards to a normal font and colorize the edges

See -morphology edge/edgein/edgeout
http://www.imagemagick.org/Usage/morphology/#difference
Bob Pickle
Posts: 20
Joined: 2013-11-11T08:52:56-07:00
Authentication code: 6789

Re: Strokes in Pango vs. Complex scripts in IM

Post by Bob Pickle »

Any suggestions on line spacing?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Strokes in Pango vs. Complex scripts in IM

Post by fmw42 »

All I can suggest is use Pango for each line of text and then composite all the lines with appropriate offsets. Otherwise, can you explain further why caption: does not do what you want?

As for PANGO, that is not under the control of Imagemagick. It is a delegate library. So you would need to contact the PANGO developers to get an enhancements. Does Pango already support those features? If so, the I suppose they could be made available in IM. But I am not a developer.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Strokes in Pango vs. Complex scripts in IM

Post by snibgo »

Bob Pickle wrote:Or could IM be improved so that it can combine images that are offset by fractions of a pixel?
It can, by using "-distort SRT" and fractional values of NewX and NewY. See http://www.imagemagick.org/script/comma ... hp#distort

I don't use Pango as it isn't included in the Windows binary. An alternative you might want to explore is using SVG, with Inkscape as the delegate.
snibgo's IM pages: im.snibgo.com
Bob Pickle
Posts: 20
Joined: 2013-11-11T08:52:56-07:00
Authentication code: 6789

Re: Strokes in Pango vs. Complex scripts in IM

Post by Bob Pickle »

fmw42 wrote:Otherwise, can you explain further why caption: does not do what you want?
Gladly. Caption and label do not handle these complex scripts correctly. Based on the position of the letter in a word, and what characters are near it, different glyphs are supposed to be used. The substitution of the correct glyph for the standalone glyph is done by the application, not the font. All caption and label return are the standalone glyphs, regardless of the position of the letter in the word, and regardless of what characters are next to the letter

.
snibgo wrote:
Bob Pickle wrote:Or could IM be improved so that it can combine images that are offset by fractions of a pixel?
It can, by using "-distort SRT" and fractional values of NewX and NewY. See http://www.imagemagick.org/script/comma ... hp#distort

I don't use Pango as it isn't included in the Windows binary. An alternative you might want to explore is using SVG, with Inkscape as the delegate.
Thanks for the tip, and I'll explore using SVG.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Strokes in Pango vs. Complex scripts in IM

Post by snibgo »

Another possibility is to put the text in a PDF document. IM will delegate the resterising to Ghostscript, which might (or might not) use the correct glyphs.

If you find a good solution, do mention it here as it might help someone else.
snibgo's IM pages: im.snibgo.com
Bob Pickle
Posts: 20
Joined: 2013-11-11T08:52:56-07:00
Authentication code: 6789

Re: Strokes in Pango vs. Complex scripts in IM

Post by Bob Pickle »

snibgo wrote:Another possibility is to put the text in a PDF document. IM will delegate the resterising to Ghostscript, which might (or might not) use the correct glyphs.

If you find a good solution, do mention it here as it might help someone else.
LaTeX vs. XeTeX/LuaLaTeX has the same issue as IM vs. Pango: The former has the bells and whistles of formatting/graphic abilities, and the latter works well with complex scripts. So if I used LuaLaTeX to create the PDF, the PDF should contain the correct glyphs. Sounds like a lot of work, but I'll think about it.

It seems to me that the only way SVG would work is if the RSVG library can handle complex scripts.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Strokes in Pango vs. Complex scripts in IM

Post by fmw42 »

It seems to me that the only way SVG would work is if the RSVG library can handle complex scripts.
I do not work much with SVG, but I hear that Inkscape is more flexible than RSVG. Snibgo might know more about that, but check out Inkscape. If installed, IM will use that over RSVG.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Strokes in Pango vs. Complex scripts in IM

Post by snibgo »

Yes, Inkscape is usually better than RSVG.

@Bob: if you can put some Arabic or whatever text up, perhaps encoded in UTF-8, ideally with an image of what it should look like, and an image of the wrong output, I can see what Inkscape produces. You can put files somewhere like dropbox.com and paste the URLs here.
snibgo's IM pages: im.snibgo.com
Bob Pickle
Posts: 20
Joined: 2013-11-11T08:52:56-07:00
Authentication code: 6789

Re: Strokes in Pango vs. Complex scripts in IM

Post by Bob Pickle »

This is the Arabic from the template for CS4 Photoshop.

مرحبا

Is that what you need? You'd like to see the Arabic as it should be, and the above gives you that, since your browser should handle the character substitution correctly.

There are five characters there, and they read from right to left. The five characters are:

م رح ب ا

They appear as standalone characters because I put a space between each one. IM puts them in reverse order, unless you use -direction right-to-left. So, try the following, substituting whatever font you have or wish:

Code: Select all

convert -direction right-to-left -size 320x -font Simplified-Arabic-Regular -pointsize 32 caption:'مرحبا' caption_test.gif

convert -direction right-to-left -size 320x -font Simplified-Arabic-Regular -pointsize 32 label:'مرحبا' label_test.gif

convert -font Simplified-Arabic-Regular -pointsize 32 pango:'<span font="Simplified Arabic Regular">مرحبا</span>' pango_test.gif
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Strokes in Pango vs. Complex scripts in IM

Post by snibgo »

Thanks. On Windows 7 I used Notepad to create a file called arabic3.svg, coded as UTF-8.

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   width="400"
   height="100"
   version="1.1">
    <text
       xml:space="preserve"
       style="font-size:50px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
       x="10" y="90"
         ><tspan>مرحبا</tspan>
    </text>
</svg>
Then this command:

Code: Select all

convert -verbose arabic3.svg arabic3.png
Here is arabic3.png:
Image
I think it is exactly as you want.

This is with IM v6.8.7-0 using Inkscape 0.48 as delegate. MSVG gives the wrong result. I don't have RSVG.

http://www.w3.org/TR/SVG/text.html contains the SVG 1.1 text attributes. Inkscape can also deal with SVG 1.2 flowing text, http://www.w3.org/TR/2004/WD-SVG12-20041027/flow.html .
snibgo's IM pages: im.snibgo.com
Post Reply