Skip to content

pdf font embedding --- again

7 messages · ivo_welch-rstat8303@mailblocks.com, Brian Ripley, Paul Murrell

#
dear R wizards---  I would like to do some book-on-demand printing at a 
popular printer named lulu, but lulu requires inclusion even of the 
basic postscript fonts.  Interestingly, my book itself does not need 
the 14 base acrobat fonts, only the embedded R figures do.  Of course, 
I really would like to get pdftex to embed the fonts, but how to do 
this is not obvious either.  [This method seems to be what the R help 
page is indicating...  The software including the PostScript plot file 
should either embed the font outlines (usually from '.pfb' or '.pfa' 
files) or use DSC comments to instruct the print spooler to do so.)

So, I would really, really like to embed the necessary fonts with the R 
figures.  I first reread the discussion in this mailing list about 
(eps) font embedding earlier this year.  This was ultimately not very 
helpful.  First, I do not  know how to instruct my embedding program to 
include the fonts that R figures want.  Second, I already start with 
the pdf device, so distilling eps files is not a good option--and it 
would seem a bit crazy to first use the wrong output device 
(postscript), then ship my files over to a windows machine somewhere 
that has distiller installed, run distiller by hand, then ftp them back 
to my linux machine---just for getting the fonts embedded.

Is it impossible to get R to embed the necessary fonts in its pdf 
output?

help appreciated.

regards, /iaw
---
ivo welch
#
On Mon, 22 Aug 2005 ivo_welch-rstat8303 at mailblocks.com wrote:

            
Why not use the fonts your book does use in the figures?  (That's how
my books are done.)
Yes, as it has no access to them.  They are not Open Source.  You may be 
able to use URW clones, depending on their licensing conditions.
#
Thank you---as always.

still, I remain font-desparate.

I would love to use the fonts from my book, but [a] I cannot figure out 
how to do this yet even in the R postscript device; and [b] I am using 
the R pdf device, not the postscript device.  I guess if I can solve 
[a], then I can rewrite all my graphics creations now into the 
postscript device, and replace the dev.off() with something that 
follows it with ps2pdf.  The following attempt, however, does not work:

   afmfiles <- c("lbr.afm", "lbd.afm", "lbi.afm", "lbdi.afm", 
"lbms.afm");
  Lucida <- postscriptFont("Lucida", metrics=afmfiles);
  postscript(file="test.ps", family=Lucida);
  l<- 40:80;
  plot(l,l,pch=l);
  dev.off();

By the way, if I try  " postscript(family=afmfiles);" then I do not get 
an R error, but R 2.1.0 segfaults, which is probably not desirable.  
This occurs even if there is no .afm file in the current directory.


Can I make a suggestion to the R team?    It would be nice if I could 
specify a pdf() device parameter that says "choose font settings to 
embed all fonts" (i.e., do not use fonts that cannot be embedded, 
either).  Something that guarantees me that I get a figure that I can 
give to someone that is fully specified.   Right now, accomplishing 
this is not easy to figure out, and perhaps not even possible.  Yes, in 
the list of font families that R recognizes are some fonts that do not 
seem among the 13 standard fonts (such as URWbookman).  moreover, if I 
choose it as my pdf font family, it is smart enough to use a different 
symbol file ('StandardSymL'), which I hope is also open and not adobe.  
If so, they could be used in principle.  How do I get R to embed 
URWbookman?  ZapfDingbats always seems to be included, so I hope this 
is open and embeddable.

more help would be highly appreciated.

Regards,

/iaw
---
ivo welch

-----Original Message-----
From: Prof Brian Ripley <ripley at stats.ox.ac.uk>
To: ivo_welch-rstat8303 at mailblocks.com
Cc: r-help at stat.math.ethz.ch
Sent: Mon, 22 Aug 2005 17:07:14 +0100 (BST)
Subject: Re: [R] pdf font embedding --- again
On Mon, 22 Aug 2005 ivo_welch-rstat8303 at mailblocks.com wrote:
>
  > dear R wizards--- I would like to do some book-on-demand printing at 
a
 > popular printer named lulu, but lulu requires inclusion even of the
 > basic postscript fonts. Interestingly, my book itself does not need
  > the 14 base acrobat fonts, only the embedded R figures do. Of 
course,
 > I really would like to get pdftex to embed the fonts, but how to do
 > this is not obvious either. [This method seems to be what the R help
  > page is indicating... The software including the PostScript plot 
file
 > should either embed the font outlines (usually from '.pfb' or '.pfa'
 > files) or use DSC comments to instruct the print spooler to do so.)

 Why not use the fonts your book does use in the figures? (That's how
 my books are done.)

  > So, I would really, really like to embed the necessary fonts with 
the R
 > figures. I first reread the discussion in this mailing list about
 > (eps) font embedding earlier this year. This was ultimately not very
  > helpful. First, I do not know how to instruct my embedding program 
to
 > include the fonts that R figures want. Second, I already start with
 > the pdf device, so distilling eps files is not a good option--and it
 > would seem a bit crazy to first use the wrong output device
 > (postscript), then ship my files over to a windows machine somewhere
  > that has distiller installed, run distiller by hand, then ftp them 
back
 > to my linux machine---just for getting the fonts embedded.
 >
 > Is it impossible to get R to embed the necessary fonts in its pdf
 > output?

  Yes, as it has no access to them. They are not Open Source. You may be 
able to use URW clones, depending on their licensing conditions.

 -- Brian D. Ripley, ripley at stats.ox.ac.uk
 Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel: +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UK Fax: +44 1865 272595
7 days later
#
Hi

I think there are two problems:

(i)  You are specifying the font incorrectly.  Try ...

# You might need to specify full paths to these
afmfiles <- c("lbr.afm", "lbd.afm", "lbi.afm", "lbdi.afm", "lbms.afm");
# Set up the mapping for "lucida" font family
postscriptFonts(lucida=postscriptFont("Lucida", metrics=afmfiles))
# Specify that the "lucida" font is to be used
postscript(file="test.ps", family="lucida");
l<- 40:80;
plot(l,l,pch=l);
dev.off();

Should work for pdf() too.

This should put a reference to the appropriate font in the PostScript or 
  PDF file that R creates.

(ii)  R does not embed font information.  But you can, for example, use 
ghostscript to do it, as long as you tell ghostscript about the font 
too.  You might have to set up a file 'FontMap' which looks something 
like ...

/Lucida   (PATH_TO/lb___.pfb);

... (assuming that lb___.pfb is the name of the .pfb file for the Lucida 
font).  Then try something like (NOTE that you have to specify 
GS_FONTPATH to tell ghostscript where your FontMap file is) ...

GS_FONTPATH=PATH_TO_FontMap gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite 
-sPAPERSIZE=a4 -sOutputFile=testembed.pdf test.pdf

This should give you a file with the font info embedded and then you 
should be able to include that in a LaTeX document.

Paul

p.s. Thanks for the segfault report.  I will look at why that is happening.
ivo_welch-rstat8303 at mailblocks.com wrote:

  
    
#
Hi
Paul Murrell wrote:
Thanks to Brian Ripley for pointing out that that should be ...

postscript(file="test.ps", fonts="lucida");

  
    
#
Dear Paul:

Thank you for responding.  I had thought I had imposed too much, and 
did not want to be a bother any more.  In any case, this does not seem 
to work for me.
# snipped a lot of fonts
$lucida
$lucida$family
[1] "Lucida"

$lucida$metrics
[1] "lbr.afm"  "lbd.afm"  "lbi.afm"  "lbdi.afm" "lbms.afm"

$lucida$encoding
[1] "default"
Error in postscript(file = "test.ps", fonts = "Lucida") :
        Failed to initialise additional PostScript fonts
In addition: Warning message:
Font encoding not found in PostScript font database
to make sure I have all the files accessible, I symbolically linked 
them into the current directory, too:

$ file *
lbd.afm:  symbolic link to 
`/usr/share/texmf/fonts/afm/yandy/lubright/lbd.afm'
lbd.pfb:  symbolic link to 
`/usr/local/share/texmf/fonts/type1/yandy/lbd.pfb'
lbdi.afm: symbolic link to 
`/usr/share/texmf/fonts/afm/yandy/lubright/lbdi.afm'
lbdi.pfb: symbolic link to 
`/usr/local/share/texmf/fonts/type1/yandy/lbdi.pfb'
lbi.afm:  symbolic link to 
`/usr/share/texmf/fonts/afm/yandy/lubright/lbi.afm'
lbi.pfb:  symbolic link to 
`/usr/local/share/texmf/fonts/type1/yandy/lbi.pfb'
lbms.afm: symbolic link to 
`/usr/share/texmf/fonts/afm/yandy/lumath/lbms.afm'
lbms.pfb: symbolic link to 
`/usr/local/share/texmf/fonts/type1/yandy/lbms.pfb'
lbr.afm:  symbolic link to 
`/usr/share/texmf/fonts/afm/yandy/lubright/lbr.afm'
lbr.pfb:  symbolic link to 
`/usr/local/share/texmf/fonts/type1/yandy/lbr.pfb'

the links are live, and the files are what they pretend to be.  any 
more suggestions would be very highly appreciated.

sincerely,

/iaw
---
ivo welch


-----Original Message-----
From: Paul Murrell <p.murrell at auckland.ac.nz>
To: Paul Murrell <paul at stat.auckland.ac.nz>
Cc: ivo_welch-rstat8303 at mailblocks.com; ripley at stats.ox.ac.uk; 
r-help at stat.math.ethz.ch
Sent: Tue, 30 Aug 2005 10:04:11 +1200
Subject: Re: [R] pdf font embedding --- again

Hi
Paul Murrell wrote:
> Hi
 > > I think there are two problems:
 > > (i) You are specifying the font incorrectly. Try ...
 > > # You might need to specify full paths to these
  > afmfiles <- c("lbr.afm", "lbd.afm", "lbi.afm", "lbdi.afm", 
"lbms.afm");
 > # Set up the mapping for "lucida" font family
 > postscriptFonts(lucida=postscriptFont("Lucida", metrics=afmfiles))
 > # Specify that the "lucida" font is to be used
 > postscript(file="test.ps", family="lucida");

 Thanks to Brian Ripley for pointing out that that should be ...

 postscript(file="test.ps", fonts="lucida");

 > l<- 40:80;
 > plot(l,l,pch=l);
 > dev.off();
 > > Should work for pdf() too.
  > > This should put a reference to the appropriate font in the 
PostScript or > PDF file that R creates.
  > > (ii) R does not embed font information. But you can, for example, 
use > ghostscript to do it, as long as you tell ghostscript about the 
font > too. You might have to set up a file 'FontMap' which looks 
something > like ...
 > > /Lucida (PATH_TO/lb___.pfb);
  > > ... (assuming that lb___.pfb is the name of the .pfb file for the 
Lucida > font). Then try something like (NOTE that you have to specify
> > GS_FONTPATH=PATH_TO_FontMap gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite
> > This should give you a file with the font info embedded and then 
you > should be able to include that in a LaTeX document.
 > > Paul
  > > p.s. Thanks for the segfault report. I will look at why that is 
happening.
> > > ivo_welch-rstat8303 at mailblocks.com wrote:
> >> Thank you---as always.
 >>
 >> still, I remain font-desparate.
 >>
  >> I would love to use the fonts from my book, but [a] I cannot figure 
 >> out how to do this yet even in the R postscript device; and [b] I am 
 >> using the R pdf device, not the postscript device. I guess if I can 
 >> solve [a], then I can rewrite all my graphics creations now into the 
 >> postscript device, and replace the dev.off() with something that >> 
follows it with ps2pdf. The following attempt, however, does not work:
 >>
  >> afmfiles <- c("lbr.afm", "lbd.afm", "lbi.afm", "lbdi.afm", >> 
"lbms.afm");
 >> Lucida <- postscriptFont("Lucida", metrics=afmfiles);
 >> postscript(file="test.ps", family=Lucida);
 >> l<- 40:80;
 >> plot(l,l,pch=l);
 >> dev.off();
 >>
  >> By the way, if I try " postscript(family=afmfiles);" then I do not 
 >> get an R error, but R 2.1.0 segfaults, which is probably not >> 
desirable. This occurs even if there is no .afm file in the current >> 
directory.
 >>
 >>
  >> Can I make a suggestion to the R team? It would be nice if I could 
 >> specify a pdf() device parameter that says "choose font settings to 
 >> embed all fonts" (i.e., do not use fonts that cannot be embedded, >> 
either). Something that guarantees me that I get a figure that I can >> 
give to someone that is fully specified. Right now, accomplishing >> 
this is not easy to figure out, and perhaps not even possible. Yes, >> 
in the list of font families that R recognizes are some fonts that do 
 >> not seem among the 13 standard fonts (such as URWbookman). moreover, 
 >> if I choose it as my pdf font family, it is smart enough to use a >> 
different symbol file ('StandardSymL'), which I hope is also open and 
 >> not adobe. If so, they could be used in principle. How do I get R to 
 >> embed URWbookman? ZapfDingbats always seems to be included, so I 
hope >> this is open and embeddable.
 >>
 >> more help would be highly appreciated.
 >>
 >> Regards,
 >>
 >> /iaw
 >> ---
 >> ivo welch
 >>
 >> -----Original Message-----
 >> From: Prof Brian Ripley <ripley at stats.ox.ac.uk>
 >> To: ivo_welch-rstat8303 at mailblocks.com
 >> Cc: r-help at stat.math.ethz.ch
 >> Sent: Mon, 22 Aug 2005 17:07:14 +0100 (BST)
 >> Subject: Re: [R] pdf font embedding --- again
 >>
>> On Mon, 22 Aug 2005 ivo_welch-rstat8303 at mailblocks.com wrote:
>>
 >> >
  >> > dear R wizards--- I would like to do some book-on-demand printing
>> > popular printer named lulu, but lulu requires inclusion even of 
the
  >> > basic postscript fonts. Interestingly, my book itself does not 
need
  >> > the 14 base acrobat fonts, only the embedded R figures do. Of 
course,
  >> > I really would like to get pdftex to embed the fonts, but how to 
do
  >> > this is not obvious either. [This method seems to be what the R 
help
  >> > page is indicating... The software including the PostScript plot 
file
  >> > should either embed the font outlines (usually from '.pfb' or 
'.pfa'
  >> > files) or use DSC comments to instruct the print spooler to do 
so.)
 >>
  >> Why not use the fonts your book does use in the figures? (That's 
how
 >> my books are done.)
 >>
  >> > So, I would really, really like to embed the necessary fonts with
>> > figures. I first reread the discussion in this mailing list about
  >> > (eps) font embedding earlier this year. This was ultimately not 
very
  >> > helpful. First, I do not know how to instruct my embedding 
program to
  >> > include the fonts that R figures want. Second, I already start 
with
  >> > the pdf device, so distilling eps files is not a good option--and 
it
 >> > would seem a bit crazy to first use the wrong output device
  >> > (postscript), then ship my files over to a windows machine 
somewhere
  >> > that has distiller installed, run distiller by hand, then ftp 
them >> back
 >> > to my linux machine---just for getting the fonts embedded.
 >> >
 >> > Is it impossible to get R to embed the necessary fonts in its pdf
 >> > output?
 >>
  >> Yes, as it has no access to them. They are not Open Source. You may
>>
 >> -- Brian D. Ripley, ripley at stats.ox.ac.uk
 >> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
 >> University of Oxford, Tel: +44 1865 272861 (self)
 >> 1 South Parks Road, +44 1865 272866 (PA)
 >> Oxford OX1 3TG, UK Fax: +44 1865 272595
 >>
 >> ______________________________________________
 >> R-help at stat.math.ethz.ch mailing list
 >> https://stat.ethz.ch/mailman/listinfo/r-help
  >> PLEASE do read the posting guide! >> 
http://www.R-project.org/posting-guide.html
 > > >
 -- 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/
#
Ooops.  hit the button too soon.  I have tried as arguments variation 
of the fonts and family arguments to postscript, such as getting the 
case right (i.e., lucida rather than Lucida).  Alas

  > postscript(file="test.ps", fonts="lucida");
  *** glibc detected *** free(): invalid pointer: 0x0000000000f7dfb8 ***

this is under R 2.1.1, 2005-06-20, built under gentoo from scratch.

so, the problem is probably now internal, not the commands.  I guess I 
will now investigate glibc in a little more detail...

Regards, /iaw

---
ivo welch
professor of finance and economics
brown / nber / yale


-----Original Message-----
From: Paul Murrell <p.murrell at auckland.ac.nz>
To: Paul Murrell <paul at stat.auckland.ac.nz>
Cc: ivo_welch-rstat8303 at mailblocks.com; ripley at stats.ox.ac.uk; 
r-help at stat.math.ethz.ch
Sent: Tue, 30 Aug 2005 10:04:11 +1200
Subject: Re: [R] pdf font embedding --- again

Hi
Paul Murrell wrote:
> Hi
 > > I think there are two problems:
 > > (i) You are specifying the font incorrectly. Try ...
 > > # You might need to specify full paths to these
  > afmfiles <- c("lbr.afm", "lbd.afm", "lbi.afm", "lbdi.afm", 
"lbms.afm");
 > # Set up the mapping for "lucida" font family
 > postscriptFonts(lucida=postscriptFont("Lucida", metrics=afmfiles))
 > # Specify that the "lucida" font is to be used
 > postscript(file="test.ps", family="lucida");

 Thanks to Brian Ripley for pointing out that that should be ...

 postscript(file="test.ps", fonts="lucida");

 > l<- 40:80;
 > plot(l,l,pch=l);
 > dev.off();
 > > Should work for pdf() too.
  > > This should put a reference to the appropriate font in the 
PostScript or > PDF file that R creates.
  > > (ii) R does not embed font information. But you can, for example, 
use > ghostscript to do it, as long as you tell ghostscript about the 
font > too. You might have to set up a file 'FontMap' which looks 
something > like ...
 > > /Lucida (PATH_TO/lb___.pfb);
  > > ... (assuming that lb___.pfb is the name of the .pfb file for the 
Lucida > font). Then try something like (NOTE that you have to specify
> > GS_FONTPATH=PATH_TO_FontMap gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite
> > This should give you a file with the font info embedded and then 
you > should be able to include that in a LaTeX document.
 > > Paul
  > > p.s. Thanks for the segfault report. I will look at why that is 
happening.
> > > ivo_welch-rstat8303 at mailblocks.com wrote:
> >> Thank you---as always.
 >>
 >> still, I remain font-desparate.
 >>
  >> I would love to use the fonts from my book, but [a] I cannot figure 
 >> out how to do this yet even in the R postscript device; and [b] I am 
 >> using the R pdf device, not the postscript device. I guess if I can 
 >> solve [a], then I can rewrite all my graphics creations now into the 
 >> postscript device, and replace the dev.off() with something that >> 
follows it with ps2pdf. The following attempt, however, does not work:
 >>
  >> afmfiles <- c("lbr.afm", "lbd.afm", "lbi.afm", "lbdi.afm", >> 
"lbms.afm");
 >> Lucida <- postscriptFont("Lucida", metrics=afmfiles);
 >> postscript(file="test.ps", family=Lucida);
 >> l<- 40:80;
 >> plot(l,l,pch=l);
 >> dev.off();
 >>
  >> By the way, if I try " postscript(family=afmfiles);" then I do not 
 >> get an R error, but R 2.1.0 segfaults, which is probably not >> 
desirable. This occurs even if there is no .afm file in the current >> 
directory.
 >>
 >>
  >> Can I make a suggestion to the R team? It would be nice if I could 
 >> specify a pdf() device parameter that says "choose font settings to 
 >> embed all fonts" (i.e., do not use fonts that cannot be embedded, >> 
either). Something that guarantees me that I get a figure that I can >> 
give to someone that is fully specified. Right now, accomplishing >> 
this is not easy to figure out, and perhaps not even possible. Yes, >> 
in the list of font families that R recognizes are some fonts that do 
 >> not seem among the 13 standard fonts (such as URWbookman). moreover, 
 >> if I choose it as my pdf font family, it is smart enough to use a >> 
different symbol file ('StandardSymL'), which I hope is also open and 
 >> not adobe. If so, they could be used in principle. How do I get R to 
 >> embed URWbookman? ZapfDingbats always seems to be included, so I 
hope >> this is open and embeddable.
 >>
 >> more help would be highly appreciated.
 >>
 >> Regards,
 >>
 >> /iaw
 >> ---
 >> ivo welch
 >>
 >> -----Original Message-----
 >> From: Prof Brian Ripley <ripley at stats.ox.ac.uk>
 >> To: ivo_welch-rstat8303 at mailblocks.com
 >> Cc: r-help at stat.math.ethz.ch
 >> Sent: Mon, 22 Aug 2005 17:07:14 +0100 (BST)
 >> Subject: Re: [R] pdf font embedding --- again
 >>
>> On Mon, 22 Aug 2005 ivo_welch-rstat8303 at mailblocks.com wrote:
>>
 >> >
  >> > dear R wizards--- I would like to do some book-on-demand printing
>> > popular printer named lulu, but lulu requires inclusion even of 
the
  >> > basic postscript fonts. Interestingly, my book itself does not 
need
  >> > the 14 base acrobat fonts, only the embedded R figures do. Of 
course,
  >> > I really would like to get pdftex to embed the fonts, but how to 
do
  >> > this is not obvious either. [This method seems to be what the R 
help
  >> > page is indicating... The software including the PostScript plot 
file
  >> > should either embed the font outlines (usually from '.pfb' or 
'.pfa'
  >> > files) or use DSC comments to instruct the print spooler to do 
so.)
 >>
  >> Why not use the fonts your book does use in the figures? (That's 
how
 >> my books are done.)
 >>
  >> > So, I would really, really like to embed the necessary fonts with
>> > figures. I first reread the discussion in this mailing list about
  >> > (eps) font embedding earlier this year. This was ultimately not 
very
  >> > helpful. First, I do not know how to instruct my embedding 
program to
  >> > include the fonts that R figures want. Second, I already start 
with
  >> > the pdf device, so distilling eps files is not a good option--and 
it
 >> > would seem a bit crazy to first use the wrong output device
  >> > (postscript), then ship my files over to a windows machine 
somewhere
  >> > that has distiller installed, run distiller by hand, then ftp 
them >> back
 >> > to my linux machine---just for getting the fonts embedded.
 >> >
 >> > Is it impossible to get R to embed the necessary fonts in its pdf
 >> > output?
 >>
  >> Yes, as it has no access to them. They are not Open Source. You may
>>
 >> -- Brian D. Ripley, ripley at stats.ox.ac.uk
 >> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
 >> University of Oxford, Tel: +44 1865 272861 (self)
 >> 1 South Parks Road, +44 1865 272866 (PA)
 >> Oxford OX1 3TG, UK Fax: +44 1865 272595
 >>
 >> ______________________________________________
 >> R-help at stat.math.ethz.ch mailing list
 >> https://stat.ethz.ch/mailman/listinfo/r-help
  >> PLEASE do read the posting guide! >> 
http://www.R-project.org/posting-guide.html
 > > >
 -- 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/