Skip to content

PDF fonts problem

4 messages · Mihalicza Péter, Paul Murrell

#
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):

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

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")

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

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

-- 
Peter Mihalicza
economist

National Institute for Strategic Health Research
6-8. Arany J?nos utca, Budapest-1051, Hungary
www.eski.hu

Tel.: +36-1-354-5320
E-mail: mihalicza.peter at eski.hu
#
Hi
Mihalicza P?ter wrote:
Thanks for the clear example.  A couple of changes, fixes, and
explanations included below ...
On Linux, that needs to be something like ...

Sys.setlocale(category="LC_CTYPE", locale="hu_HU.utf8")
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.
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

  
    
#
Dear Dr. Murrel,

Thank you for all the clarifications!

Paul Murrell ?rta:
This solved my problem, so I am really very grateful! I am not too 
familiar with font protocols.
Just for the sake of knowledge: if my embedFonts specification should 
not have made any difference, why did the output pdf differed from the 
one before embedding?

Thanks again,
Peter
2 days later
#
Hi
Mihalicza P?ter wrote:
Your embedFonts() specification (especially your 'fontpaths' argument)
*did* make a difference.  This function calls ghostscript to perform the
embedding and if ghostscript cannot find the PFB files it cannot embed
the font.  If the PDF file does not have embedded fonts, the PDF reader
will use (substitute) its own fonts and the result can look awful.

Paul