Bug 14326 - PDFfontNumber return error num when using family and fonts options in pdf()
PDFfontNumber return error num when using family and fonts options in pdf()
Status: RESOLVED FIXED
Product: R
Classification: Unclassified
Component: Graphics
R 2.11.1
ix86 (32-bit) Windows 32-bit
: P5 enhancement
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-07-01 09:02 UTC by Jinsong Zhao
Modified: 2010-07-04 01:16 UTC (History)
1 user (show)

See Also:


Attachments
a patch to devPS (1.43 KB, patch)
2010-07-03 03:42 UTC, Jinsong Zhao
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jinsong Zhao 2010-07-01 09:02:27 UTC
In PDF_endfile function in devPS.c of grDevices library, the number of CID font start from 1001. Normally, F1001 is for a regular font (plain style?).

In PDFfontNumber function, if strlen(family) > 0, then the first number of CID font is 1002, thus F1001 cannot be access.

This bug will be invoked, if pdf() was call with fonts came from a different CID font family, e.g., pdf("chinese.pdf", family = "Times", fonts = "GB1").

The following is the code that could reproduced the problem:

pdf("test_2.pdf", family = "Times", fonts = "GB1")
plot(1:12, type = "n")
text(5,1, "\u4F60\u597D", family = "GB1", font = 1) # /F1002 bold 
text(5,2, "\u4F60\u597D", family = "GB1", font = 2) # /F1003 italic
text(5,3, "\u4F60\u597D", family = "GB1", font = 3) # /F1004 bold italic
text(5,4, "\u4F60\u597D", family = "GB1", font = 4) # /F1005 symbol
text(5,5, "is 'hello' in Chinese", font = 1) # /F2 plain
text(5,6, "is 'hello' in Chinese", font = 2) # /F3 bold
text(5,7, "is 'hello' in Chinese", font = 3) # /F4 italic
text(5,8, "is 'hello' in Chinese", font = 4) # /F5 bold italic
dev.off()

In fact, the /F1002 should be /F1001 for the plain text, and /F1003 should be /F1002, and so on...

I think I get the solution, but I cannot test it.

Change the following line in PDFfontNumber function in devPS.c:

        num = 1000 + (cidfontIndex - 1)*5 + 1 + face;
to
        num = 1000 + (cidfontIndex - 1)*5 + face;

It appears two times in the function.

Regards,
Jinsong
Comment 1 Jinsong Zhao 2010-07-02 03:06:12 UTC
I have compiled R 2.11.1 on a Linux machine, and confirmed that PDFfontNumber function in devPS.c (grDevices library) has a bug, which causes the plain face of CID fonts cannot be accessed when CID fonts were used together with default font family in pdf().

the following is the patch.

--- devPS_orig.c	Sun Apr 25 06:10:04 2010
+++ devPS.c	Fri Jul 02 09:46:55 2010
@@ -7267,7 +7267,7 @@
 	     * Use very high font number for CID fonts to avoid
 	     * Type 1 fonts
 	     */
-	    num = 1000 + (cidfontIndex - 1)*5 + 1 + face;
+	    num = 1000 + (cidfontIndex - 1)*5 + face;
 	else {
 	    /*
 	     * Check whether the font is loaded and, if not,
@@ -7303,7 +7303,7 @@
 		} else /* (isCIDFont(family, PDFFonts)) */ {
 		    if (addPDFDeviceCIDfont(cidfontfamily, pd,
 					    &cidfontIndex)) {
-			num = 1000 + (cidfontIndex - 1)*5 + 1 + face;
+			num = 1000 + (cidfontIndex - 1)*5 + face;
 		    } else {
 			cidfontfamily = NULL;
Comment 2 Jinsong Zhao 2010-07-03 03:42:37 UTC
Created attachment 1113 [details]
a patch to devPS

patch to devPS, which will do:

1) correct the binary comment (second line)
2) remove a strange ^M
3) give correct font number for CID fonts when were used with default fonts.
Comment 3 Paul Murrell 2010-07-04 01:16:29 UTC
Fixed in r52446.