[R] PDF fonts problem

Paul Murrell p.murrell at auckland.ac.nz
Thu Sep 18 23:21:18 CEST 2008


Hi


Mihalicza Péter wrote:
> Dear List,
> 
> I am writing a paper in Hungarian, that I Sweave and than pdfLaTeX. 
> Everything is fine, except for two accented letters in the graphs that 
> behave strange, though on the screen and in eps exports they look 
> perfect. The problem is that I need pdf graphs, since I would like to 
> have a PDF after LaTeX-ing.
> For the example below I downloaded the following two font sets:
> 1. Latin Modern from http://www.ctan.org/get/fonts/lm.zip
> 2. Computer Moder Super from 
> http://www.ctan.org/get/fonts/ps-type1/cm-super.zip
> Both are specifically made for Eastern European languages (among many 
> other).
> 
> The example is (I hope it is fully reproducible):


Thanks for the clear example.  A couple of changes, fixes, and
explanations included below ...


> Sys.setlocale(category="LC_CTYPE", locale="hungarian")


On Linux, that needs to be something like ...

Sys.setlocale(category="LC_CTYPE", locale="hu_HU.utf8")


> LM <- Type1Font("LM", paste("lm/fonts/afm/public/lm/", c("lmb10.afm", 
> "lmbx10.afm", "lmbo10.afm", "lmbxo10.afm"), sep=""))
> pdfFonts(LM=LM)
> postscriptFonts(LM=LM)
> 
> CMS <- Type1Font("CMS", paste("cm-super/afm/", c("sfrm1000.afm", 
> "sfrb1000.afm", "sfti1000.afm", "sfsl1000.afm"), sep=""))
> pdfFonts(CMS=CMS)
> postscriptFonts(CMS=CMS)
> 
> #Default
> pdf("tryfont-default.pdf")
> grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
> dev.off()
> #The u151 and the u171 characters "slips into" the characters following 
> them ("h" and "l")


For me, with Adobe Reader, on Linux, u151 and u171 are just missing, but 
the root problem is probably the same;  the PDF reader is probably 
substituting a font and not using the default font because the real font 
is not embedded in the file.  The "slippage" you are seeing is probably 
due to the fact that the metrics (size of each character) are completely 
wrong in the substituted font so the characters are drawn in the wrong 
positions.


> postscript("tryfont-default.eps")
> grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
> dev.off()
> #everything is perfect
> 
> #CMS
> pdf("tryfont-cms.pdf", family="CMS")
> grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
> dev.off()
> #u151 and u171 doesn't show, though the other accented ones do
> 
> embedFonts("tryfont-cms.pdf",
> outfile="tryfont-cms-embed.pdf",
> fontpaths="/cm-super/afm/")
> #after embedding the same "slipping" occurs


The 'fontpaths' argument describes where the PFB files are, not where 
the AFM files are.  So this is probably failing to embed the fonts 
because it can't find the fonts.  Does it work if you change to 
something like ...

  embedFonts("tryfont-cms.pdf",
            outfile="tryfont-cms-embed.pdf",
            fontpaths="cm-super/pfb/")

In your PDF reader, see if you can find a "document properties" or 
something similar;  that should tell you whether the fonts have been 
embedded or whether the reader is substituting a different font.

On Linux, you can use pdffonts to find out.  For example, for me (look 
at the 'emb' column) ...

$ pdffonts tryfont-cms.pdf
name                                 type         emb sub uni object ID
------------------------------------ ------------ --- --- --- ---------
SFRM1000                             Type 1       no  no  no       9  0


$ pdffonts tryfont-cms-embed.pdf
name                                 type         emb sub uni object ID
------------------------------------ ------------ --- --- --- ---------
PPLABU+Times-Roman?                  Type 1C      yes yes no      10  0


Paul


> postscript("tryfont-cms.eps", family="CMS")
> grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
> dev.off()
> #everything is perfect
> 
> #LM
> pdf("tryfont-lm.pdf", family="LM")
> grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
> dev.off()
> #same as CMS
> 
> embedFonts("tryfont-lm.pdf",
> outfile="tryfont-lm-embed.pdf",
> fontpaths="lm/fonts/afm/public/lm/")
> #same as CMS
> 
> postscript("tryfont-LM.eps", family="LM")
> grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
> dev.off()
> #same as CMS
> 
> After trying all this, I am out of ideas.
> Could anyone suggest a solution?
> 
>  > sessionInfo()
> R version 2.7.2 (2008-08-25)
> i386-pc-mingw32
> 
> locale:
> LC_COLLATE=Hungarian_Hungary.1250;LC_CTYPE=Hungarian_Hungary.1250;LC_MONETARY=Hungarian_Hungary.1250;LC_NUMERIC=C;LC_TIME=Hungarian_Hungary.1250
> 
> attached base packages:
> [1] datasets  utils     stats     graphics  grDevices splines   grid    
> [8] methods   base    
> 
> other attached packages:
> [1] ggplot2_0.6        colorspace_0.95    RColorBrewer_1.0-2 
> MASS_7.2-44      
> [5] proto_0.3-8        reshape_0.8.0      Hmisc_3.4-3      
> 
> loaded via a namespace (and not attached):
> [1] cluster_1.11.11 lattice_0.17-13
> 
> 
> Thank you,
> Peter
> 

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



More information about the R-help mailing list