[R] pdf device and TeXencoding?

ivo welch ivo_welch at brown.edu
Mon Nov 7 23:10:58 CET 2005


hi:  as usual, I am trying to be brief, and end up being too brief.  let me be more specific on [a].

$ cat test.R
luafmfiles <- c("/usr/share/texmf/fonts/afm/yandy/lubright/lbr.afm",
                "/usr/share/texmf/fonts/afm/yandy/lubright/lbd.afm",
                "/usr/share/texmf/fonts/afm/yandy/lubright/lbi.afm",
                "/usr/share/texmf/fonts/afm/yandy/lubright/lbdi.afm",
                "/usr/share/texmf/fonts/afm/yandy/lumath/lbms.afm")

grDevices::postscriptFonts(lucida=grDevices::postscriptFont("Lucida", metrics=luafmfiles, encoding="TeXtext.enc"));

pdf(file="test.pdf", fonts="lucida", version="1.4");
par(family="lucida");
plot( c(0,1),c(0,1) );
text( 0.5, 0.5, "this is some text" );
dev.off();

$ R CMD BATCH test.R

$ pdffonts test.pdf
name                                 type         emb sub uni object ID
------------------------------------ ------------ --- --- --- ---------
Error: Wrong type in font encoding resource differences (array)
Error: Wrong type in font encoding resource differences (array)
Error: Wrong type in font encoding resource differences (array)
Error: Wrong type in font encoding resource differences (array)
ZapfDingbats                         Type 1       no  no  no       5  0
Helvetica                            Type 1       no  no  no      11  0
Helvetica-Bold                       Type 1       no  no  no      12  0
Helvetica-Oblique                    Type 1       no  no  no      13  0
Helvetica-BoldOblique                Type 1       no  no  no      14  0
Symbol                               Type 1       no  no  no      15  0
LucidaBright                         Type 1       no  no  no      16  0
LucidaBright-Demi                    Type 1       no  no  no      17  0
LucidaBright-Italic                  Type 1       no  no  no      18  0
LucidaBright-DemiItalic              Type 1       no  no  no      19  0
LucidaNewMath-Symbol                 Type 1       no  no  no      20  0


$ ps2pdf13 -dPDFSETTINGS=/printer test.pdf a.pdf
Error: /typecheck in --.max--
Operand stack:
   --dict:4/4(L)--   F7   1   --dict:5/5(L)--   --dict:5/5(L)--   --dict:11/11(ro)(G)--   --nostringval--   --nostringval--   --nostringval--   256
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1   3   %oparray_pop   1   3   %oparray_pop   --nostringval--   2   1   1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--   --nostringval--   %array_continue   --nostringval--   false   1   %stopped_push   --nostringval--   %loop_continue   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--
Dictionary stack:
   --dict:1052/1417(ro)(G)--   --dict:0/20(G)--   --dict:73/200(L)--   --dict:73/200(L)--   --dict:97/127(ro)(G)--   --dict:229/230(ro)(G)--   --dict:19/24(L)--   --dict:4/6(L)--   --dict:19/20(L)--   --dict:12/13(L)--
Current allocation mode is local
ESP Ghostscript 7.07.1: Unrecoverable error, exit code 1


if I use the postscript device,  this error does not occur.  if I use the standard helvetica fonts, this error does not occur.  I believe this error is from the textext encoding used in the pdf device.


I am sorry, I know so little about (postscript) fonts.  (I also need to end up with all fonts embedded in my figures.)  I was really trying to avoid complexity by avoiding "families of fonts".  I really want the most simple possible access given that I have exactly one .pfb font---I just want R to write a string in this font to a particular location.  [if it could embed the font itself, it would be much better, but I believe R cannot embed fonts itself; instead it requires an external tool like ghostscript.]  long story, short moral:  my desire for simplicity here is not just my stupidity (although there is plenty), but other tools (e.g., ghostscript) are sometimes quiet on errors or just substitute other fonts without asking ('feature'), and it takes a lot of experimenting to get the basics right.  so, the more basic, the better.

regards,

/iaw


Prof Brian Ripley wrote:

>> On Mon, 7 Nov 2005, ivo welch wrote:
>> 
>
>>>> [a] I believe that the pdf device does not yet fully support
>>>> TeXencoding.  (under R-2.2.0, the pdf file created with Textext as
>>>> font encoding still dies when post-processed by ghostscript.)  are
>>>> there any workarounds, or are there utilities that would allow a
>>>> TeXencoded font to be re-encoded/converted into ISOLatin, perhaps,
>>>> which R could then handle beautifully?
>
>> 
>> 
>> 1) What does `dies' mean?
>> 2) See the following R-patched NEWS entry
>> 
>>     o    pdf() was not writing details of the encoding to the file
>>     correctly.  (Spotted by Alexey Shipunov in Russian encodings.)
>> 
>> so this may well be solved in current R (R-patched/R-devel).
>> 
>
>>>> [b] is there a way to use an arbitrary postscript font and position it
>>>> into a ps or pdf graphic (i.e., without it being in the family {5
>>>> fonts} that I am using for the main drawing)?  in a weird latex/R mix,
>>>> my intent is something like
>
>> 
>> 
>> Yes, see par(family=) and (in 2.2.x)  ?postscriptFont to create a family.
>> 
>
>>>>     pdf(file="test.pdf");
>>>>     plot( c(0,1),c(0,1) );
>>>>     test.font = fontis("postscriptfont.pfb");  # may need a tfm
>>>> specification, too?
>>>>     text( 0.5, 0.5, fontobject("some text", test.font));
>>>>     dev.off();
>>>>
>>>> help would be highly appreciated, as always.
>
>> 
>> 
>> This area is all under development as we allow for CJK fonts.  In
>> R-devel, something like
>> 
>> myfam <- Type1Font("test", rep("postscriptfont.afm"), 4)
>> pdf(file="test.pdf", fonts=myfam)
>> plot( c(0,1),c(0,1) )
>> text( 0.5, 0.5, "some text", family=myfam)
>> dev.off()
>> 
>> will work (and with amendments if this is a TeX-encoded font).
>> 
>>




More information about the R-help mailing list