On 31/03/2010, at 6:58 AM, Behdad Esfahbod wrote:
PDF stores the exact glyph locations. The layout is not done during therendering but when the PDF is produced.
Right, so a PDF preview trades device independence for suboptimal render quality.
Obviously, the SVG renderer is doing something different [to get the same results rendering English text across platforms].Sure, you can try turning metrics hinting off. That should give you fairlyrobust results.
Good to know. At first, I thought this causes layout to use the real glyph metrics, not the nominal ones altered by glyph hinting, that being sufficient to decouple layout from the device. The logical width of a rendered line of text would be accurate to within a device pixel, at the cost of not attempting to absorb into the layout some of the error inflicted by the device's lower precision. However, the cairo documentation states "hinting font metrics means quantizing them so that they are integer values in device space". This suggests I'm wrong and that layout remains device dependent. I have tested this using the attached C program on OS X 10.4, Debian Linux (lenny), and Win32, using the same MS arial.ttf font file. OS X and Linux get identical logical extents, but win32 differs (see below for details - in fact it doesn't appear to honour the option). If I understand metrics hinting, this last is a bug, and I can rely on the others to remain equal, plus or minus a pixel? If so, can I expect this to hold for other scripts?
Lastly, if anyone has any pointers on how to layout text for UML-like diagrams using cairo (via pango or something else) such that at least English text can be guaranteed to stay within its box across platforms, I'd really appreciate them - even if it's to say 'my friend, you're a madman; that's crazy talk'.What do you my by "its box"? If you have a presized box, you can rescale text to fit within it. That's an application-side algorithm you can easily implement.
Unfortunately the size of the diagram box depends on the size of the laid-out text it contains. Lacking a platform invariant layout (or, at least, lacking a guaranteed maximum layout size under reasonableassumptions), the necessary box size is platform specific. Scaling leads to platform-specific text size, and could result in mixed-font-size diagrams when viewing a diagram that was edited across platforms, or unexpected changes to the box size when editing its text. I'm don't know that it would be unacceptably ugly but it is more work than flicking a few switches like metrics hinting if that
is a viable option. Many thanks for your help, Richard.
Attachment:
textsize.c
Description: Binary data
Linux lotus.internal 2.6.26-2-686 #1 SMP Tue Mar 9 17:35:51 UTC 2010 i686 GNU/Linux
Cairo version: 1.6.4 Pango version: 1.20.5 Hint metrics set to: OFF Font: 'arial 12px'Layout text: 'The origin of thinking is some perplexity, confusion or doubt.'
Ink extents: (0,0) 319x13 Logical extents: (0,0) 320x14 <--Darwin orchid.internal 8.11.0 Darwin Kernel Version 8.11.0: Wed Oct 10 18:26:00 PDT 2007; root:xnu-792.24.17~1/RELEASE_PPC Power Macintosh powerpc
Cairo version: 1.8.8 Pango version: 1.24.5 Hint metrics set to: OFF Font: 'arial 12px'Layout text: 'The origin of thinking is some perplexity, confusion or doubt.'
Ink extents: (0,2) 319x12 Logical extents: (0,0) 320x14 <-- MINGW32_NT-5.0 LOTUS 1.0.11(0.46/3/2) 2009-07-11 17:46 i686 Msys Cairo version: 1.8.8 Pango version: 1.24.5 Hint metrics set to: OFF Font: 'arial 12px'Layout text: 'The origin of thinking is some perplexity, confusion or doubt.'
Ink extents: (0,3) 326x11 Logical extents: (0,0) 327x15 <-- same size as when metrics ON (ditto with pango 1.26.2) MINGW32_NT-5.0 LOTUS 1.0.11(0.46/3/2) 2009-07-11 17:46 i686 Msys Cairo version: 1.8.8 Pango version: 1.24.5 Hint metrics set to: ON Font: 'arial 12px'Layout text: 'The origin of thinking is some perplexity, confusion or doubt.'
Ink extents: (0,3) 326x11 Logical extents: (0,0) 327x15 <-- same size as when metrics OFF (ditto with pango 1.26.2) To compile: $ gcc textsize.c `pkg-config --cflags --libs pangocairo` -o textsize(pango 1.20.5 requires -DPANGO_ENABLE_BACKEND to pick up the pango_context_new() call)
Notes: The same Windows 2000 arial*.ttf files were used in all runs. I used the FontBook application to disable the system arial on OS X. On linux, I copied the files into the /usr/share/fonts/truetype/ms-arial directory, re-ran fc-cache,
and verified it was using the file by using fc-cat.