[R] CairoPDF and greek letter spacing

James Cloos cloos at jhcloos.com
Wed Jan 18 22:06:01 CET 2012


>>>>> "RT" == Rolf Turner <rolf.turner at xtra.co.nz> writes:

RT> Compare:

RT>     require(lattice)
RT>     cairo_pdf(file="mung.pdf")
RT>     print(xyplot(y~x,data=data.frame(x=1:10,y=1:10),main=expression(Length==mu*m)))
RT>     dev.off()
RT> and
RT>     pdf(file="gorp.pdf")
RT>     print(xyplot(y~x,data=data.frame(x=1:10,y=1:10),main=expression(Length==mu*m)))
RT>     dev.off()

After using qpdf(1) to uncompress the pdfs, the latter produces:

BT
/F6 1 Tf 14.00 0.00 -0.00 14.00 270.63 487.95 Tm (m) Tj
ET
BT
/F2 1 Tf 14.00 0.00 -0.00 14.00 278.69 487.95 Tm (m) Tj
ET

where /F6 is /Symbol and /F2 is /Helvetica.

The former produces:

14.399414 0 0 14.399414 209.167969 487.277344 Tm
% (Length =) elided
/f-2-0 1 Tf
0.786979 -0.00461173 Td
<b5>Tj
/f-0-0 1 Tf
0.625025 -0.0124788 Td
(m)Tj

where /f-2-0 is /DQHRIK+Symbol and f-0-0 is /OJZLOW+NimbusSanL-Regu.

In gorp, (m)’s start point is 8.06 units right of (μ)’s start point.

In mung, (m)’s start point is 0.161954 units right of (μ)’s end point.

The version of /DQHRIK+Symbol has a /mu with a width of 576 font units
and a 1000 unit em.  At 14.4pt that is a width of 8.294 pdf points.

Gorp does not have embedded fonts, but Adobe’s AFM file for /Symbol
also specified 576 font units for /mu’s width.  That line of text,
though is set at 14pt rather than 14.4pt, so a width of 8.064 pts.

It looks like all of the text in gorp is set tighter than in mung.

Perhaps using utf8 would look better:

  require(lattice)
  cairo_pdf(file="mung8.pdf", family="serif")
  print(xyplot(y~x,data=data.frame(x=1:10,y=1:10),main="Length = µm"))
  dev.off()

It certainly looks better here, with sans, serif or any font which has
latin and greek glyphs.  To do that with Latin Modern Roman, though, I
had to use U+00B5 MICRO SIGN (µ) rather than U+03BC GREEK SMALL LETTER MU.
(The snippet above uses MICRO SIGN.)

I think the takeaway is that cairo works better with a utf8 workflow.

-JimC
-- 
James Cloos <cloos at jhcloos.com>         OpenPGP: 1024D/ED7DAEA6



More information about the R-help mailing list