[pdftex] Newer patch for pdftex for subsetted font printing problem]

Tom Kacvinsky tjk at ams.org
Wed Jun 20 08:58:34 CEST 2001


Here is a new patch.  Tom Kiffe told me that it fixed the problem he had.

Tom

On Tue, 19 Jun 2001, Tom Kacvinsky wrote:

> Tom Kiffe gave me a problem file that pointed out a problem with my patch
> (and now that I think about it, exhibits how *weird* the Acrobat problem
> really is).
>
> I am in the midst of figuring out how to fix the problem.  The issue only
> arises when the subrs start with RD (-|) and end with something other
> than the matching end token NP (|, respectively).  And this only happens
> with *old* fonts.
>
> Tom
>
> On Fri, 15 Jun 2001, Tom Kacvinsky wrote:
>
> > Hi all,
> >
> > Attached is a patch for pdftex 3.14159-14h-released-20010417 that fixes the
> > following problem:
> >
> >   PDF files generated by pdftex in which Type 1 fonts are subsetted do
> >   not print correctly from Acrobat (Reader) 5.0.
> >
> > Having been down this road before (sending a patch in for pdftex whilst
> > Thanh is away), I feel compelled to state that this patch is for those who
> > want to use it, and I am not asking for it to be the definitive, official
> > fix for this problem.
> >
> > With that said, the patch just simply fills in the gaps in the Subrs array
> > with subroutines do nothing.  This does not yield the smallest possible
> > subsetted font. To do that, one needs to renumber all of the subroutines,
> > and make sure the charstrings which call these renumbered subroutines use
> > the new numbers, etc...
> >
> > The limited tests I have run indicate the patch does work and does not
> > introduce any new bugs.  Comments and more testing would be appreciated.
> >
> > Regards,
> >
> > Tom
> >
>
> _______________________________________________
> pdftex mailing list
> pdftex at tug.org
> http://tug.org/mailman/listinfo/pdftex
>
-------------- next part --------------
--- writet1.c	2001/06/15 22:54:57	1.1
+++ writet1.c	2001/06/19 23:54:06	1.4
@@ -199,7 +199,8 @@
 
 static unsigned short t1_dr, t1_er;
 static unsigned short t1_c1 = 52845, t1_c2 = 22719;
-static unsigned short t1_cslen, t1_lenIV;
+static unsigned short t1_cslen;
+static short t1_lenIV;
 static char t1_line[T1_BUF_SIZE], t1_buf[T1_BUF_SIZE], *t1_line_ptr;
 static char enc_line[ENC_BUF_SIZE];
 
@@ -213,6 +214,13 @@
 static char *subr_array_start, *subr_array_end;
 static int subr_max, subr_size, subr_size_pos;
 
+/* This array contains the begin/end tokens commonly used in the */
+/* /Subrs array of a Type 1 font.                                */
+static char *cs_token_pairs[3][2] = { {"RD", "NP"}, {"-|", "|"}, {"RD", "noaccess put"}};
+
+/* Which begin/end token set do we use for the font? */
+static int  cs_token_choice = 0;
+
 static boolean t1_pfa, t1_cs, t1_scan, t1_eexec_encrypt, t1_synthetic;
 static int  t1_in_eexec; /* 0 before eexec-encrypted, 1 during, 2 after */
 static long t1_block_length;
@@ -417,6 +425,13 @@
     return cipher;
 }
 
+static byte cencrypt(byte plain, unsigned short *cr)
+{
+    byte cipher = (plain^(*cr >> 8));
+    *cr = (cipher + *cr)*t1_c1 + t1_c2;
+    return cipher;
+}
+
 static char *eol(char *s)
 {
     char *p = strend(s);
@@ -485,6 +500,7 @@
             break;
         if (t1_cs && t1_cslen == 0 && (t1_line_ptr - t1_line > 4) && 
            (t1_suffix(" RD ") || t1_suffix(" -| "))) {
+              
             p = t1_line_ptr - 5;
             while (*p != ' ')
                 p--;
@@ -1056,9 +1072,21 @@
             ptr->name = xstrdup(t1_buf + 1); 
     }
     memcpy(t1_buf, cs_start - 4, (unsigned)(t1_cslen + 4)); /* copy " RD " + cs data to t1_buf */
-    for (p = cs_start + t1_cslen, q = t1_buf + t1_cslen + 4; *p != 10; *q++ = *p++);
+
     /* copy the end of cs data to t1_buf */
-    *q++ = 10; 
+    for (p = cs_start + t1_cslen, q = t1_buf + t1_cslen + 4; *p != 10; *q++ = *p++);
+    *q++ = 10;
+
+    /* get the begin/end token pairs.  Modify this as necessary for other token pairs. */
+    if (is_subr) {
+      if (t1_suffix("NP"))
+        cs_token_choice = 0;
+      else if (t1_suffix("|"))
+        cs_token_choice = 1;
+      else if (t1_suffix("noaccess put"))
+        cs_token_choice = 2;
+    }
+
     ptr->len = q - t1_buf;
     ptr->cslen = t1_cslen;
     ptr->data = xtalloc(ptr->len, byte);
@@ -1447,16 +1475,18 @@
 static void t1_flush_cs(boolean is_subr)
 {
     char *p;
+    byte *r, return_cs[T1_BUF_SIZE];
     cs_entry *tab, *end_tab, *ptr;
     char *start_line, *line_end;
     int count, size_pos;
+    unsigned short cr, cs_len;
     if (is_subr) {
         start_line = subr_array_start;
         line_end = subr_array_end;
         size_pos = subr_size_pos;
         tab = subr_tab;
-        end_tab = subr_tab + subr_size;
         count = subr_max + 1;
+        end_tab = subr_tab + count;
     }
     else {
         start_line = cs_dict_start;
@@ -1475,7 +1505,23 @@
     strcat(t1_line_ptr, p);
     t1_line_ptr = eol(t1_line);
     t1_putline();
+
+    if (is_subr) {
+        cr = 4330;
+        cs_len = 0;
+        if (t1_lenIV >= 0) {
+	    for (cs_len = 0, r = return_cs; cs_len < t1_lenIV; cs_len++, r++)
+	        *r = cencrypt(0x00, &cr);
+	    *r = cencrypt(CS_RETURN, &cr);
+        }
+        else
+	    *return_cs = CS_RETURN;
+
+        cs_len++;
+    }
+
     for (ptr = tab; ptr < end_tab; ptr++) {
+    
         if (ptr->used) {
             if (is_subr)
                 sprintf(t1_line, "dup %u %u", ptr - tab, ptr->cslen);
@@ -1485,6 +1531,19 @@
             memcpy(p, ptr->data, ptr->len);
             t1_line_ptr = p + ptr->len;
             t1_putline();
+        }
+        else {
+            if (is_subr) {
+                sprintf(t1_line, "dup %u %u %s ", ptr - tab, cs_len,
+                        cs_token_pairs[cs_token_choice][0]);
+                p = strend(t1_line);
+                memcpy(p, return_cs, cs_len);
+                t1_line_ptr = p + cs_len;
+                t1_putline();
+                sprintf(t1_line, " %s", cs_token_pairs[cs_token_choice][1]);
+                t1_line_ptr = eol(t1_line);
+                t1_putline();
+            }
         }
         xfree(ptr->data);
         if (ptr->name != 0 && ptr->name != notdef)


More information about the pdftex mailing list