[tex-live] Omega dvips patch

Roozbeh Pournader roozbeh@sharif.edu
Sun, 29 Sep 2002 19:54:21 +0330 (IRT)


Dear all,

Following is a delayed patch for Omega related parts of dvips, which was
most probably forgotten to be sent to Olaf when Omega 1.23 release were
done, and has been the source of many confusions. The patch is done
against the dvipsk sources in TeX Live 7 (5.90a?), but I can redo it if it
cannot be incorporated in the current dvips.

All changes are #ifdef-ed for Omega, or are otherwise clearly
Omega-related. The only exception is a change to 'texps.lpro' which I
don't understand since I don't understand other than it is related to
PostScript Type 0 fonts.

It would be great if this gets incorporated into dvips, web2c, etc. Please
contact me in case of any problems. (And finally sorry for CC-ing the
world, since I'm still in full confusion about who is responsible for
what.)

Roozbeh (for the Omega project)


diff -r -u dvipsk.orig/bbox.c dvipsk/bbox.c
--- dvipsk.orig/bbox.c	Sat Sep 21 04:35:29 2002
+++ dvipsk/bbox.c	Sat Sep 21 04:55:51 2002
@@ -43,17 +43,23 @@
 
 void bbtfmload P1C(int, n)
 {
+#ifdef Omega
+   register integer i, j ;
+#else
    register shalfword i ;
+#endif
    register integer li ;
    integer scaledsize ;
    shalfword nw, nh, nd, ns, hd ;
-   shalfword bc, ec ;
 #ifdef Omega
+   integer bc, ec ;
+   integer nco, ncw, npc, no_repeats ;
    integer scaled[65536] ;
    unsigned chardat[65536] ;
    integer font_level;
    integer pretend_no_chars;
 #else
+   shalfword bc, ec ;
    integer scaled[300] ;
    integer chardat[256] ;
 #endif
@@ -92,9 +98,12 @@
       ns += tfm32() ;
       ns += tfm32() ;
       li = tfm32() ;
+      li = tfm32() ;
       if (font_level==1) {
-         fprintf(stderr, "Level 1 Fonts unsupported");
-         abort();
+         nco = tfm32() ;
+         ncw = tfm32() ;
+         npc = tfm32() ;
+         for (i=0; i<12; i++) li=tfm32();
       }
    }
 #else
@@ -111,27 +120,49 @@
    check_checksum (li, curfnt->checksum, curfnt->name);
 
    li = tfm32() ;
-   for (i=2; i<hd; i++)
-      li = tfm32() ;
 #ifdef Omega
    pretend_no_chars=ec+1;
    if (pretend_no_chars<256) pretend_no_chars=256;
    bbcurfnt->bbchardesc = (bbchardesctype *)
                           xmalloc(pretend_no_chars*sizeof(bbchardesctype));
+   for (i=2; i<((font_level==1)?nco-29:hd); i++)
+      li = tfm32() ;
+   no_repeats = 0 ;
    for (i=0; i<pretend_no_chars; i++)
 #else
+   for (i=2; i<hd; i++)
+      li = tfm32() ;
    for (i=0; i<256; i++)
 #endif
       chardat[i] = -1 ;
    for (i=bc; i<=ec; i++) {
 #ifdef Omega
-      chardat[i] = tfm32() ;
-      li = tfm32() ;
+      if (no_repeats>0) {
+         chardat[i] = chardat[i-1] ;
+         no_repeats-- ;
+      } else if (font_level>=0) {
+         chardat[i] = tfm32() ;
+         li = tfm32() ;
+         if (font_level==1) {
+            no_repeats = tfm16() ;
+            for (j=0; j<(npc|1); j++) tfm16() ;
+            ncw -= 3 + npc/2 ;
+         }
+      } else {
+         chardat[i] = tfm16() ;
+         li = tfm16() ;
+      }
 #else
       chardat[i] = tfm16() ;
       li = tfm16() ;
 #endif
    }
+#ifdef Omega
+   if (font_level==1&&ncw!=0) {
+      sprintf(errbuf, "Table size mismatch in %s", curfnt->name) ;
+      error(errbuf) ;
+   }
+#endif
    scaledsize = curfnt->scaledsize ;
    for (i=0; i<nw + nh + nd; i++)
       scaled[i] = scalewidth(tfm32(), scaledsize) ;
diff -r -u dvipsk.orig/dospecial.c dvipsk/dospecial.c
--- dvipsk.orig/dospecial.c	Sat Sep 21 04:35:29 2002
+++ dvipsk/dospecial.c	Sat Sep 21 04:52:57 2002
@@ -303,6 +303,7 @@
    register char *p = nextstring ;
    register int i = 0 ;
    int j ;
+   static int omega_specials = 0;
 
    if (nextstring + numbytes > maxstring) {
       p = nextstring = mymalloc(1000 + 2 * numbytes) ;
@@ -338,6 +339,15 @@
  */
 
    switch (*p) {
+case 'o':
+   if (strncmp(p, "om:", 3)==0) {       /* Omega specials ignored */
+        if (omega_specials==0) {
+                fprintf(stderr, "Omega specials are currently ignored\n");
+                omega_specials++;
+        }
+        return;
+   }
+   break ;
 case 'l':
    if (strncmp(p, "landscape", 9)==0) {
       if (hpapersize || vpapersize)
@@ -501,6 +511,11 @@
 #endif
 
    switch (*p) {
+case 'o':
+   if (strncmp(p, "om:", 3)==0) {       /* Omega specials ignored */
+        return;
+   }
+   break ;
 case 'e':
    if (strncmp(p, "em:", 3)==0) {	/* emTeX specials in emspecial.c */
 	emspecial(p);
diff -r -u dvipsk.orig/download.c dvipsk/download.c
--- dvipsk.orig/download.c	Sat Sep 21 04:35:29 2002
+++ dvipsk/download.c	Sat Sep 21 04:52:57 2002
@@ -222,11 +222,13 @@
    curfnt->psname = psfont ;
    if (curfnt->resfont) {
       struct resfont *rf = curfnt->resfont ;
+#ifndef Omega /* from ASCII jpatch */
       for (b=0; b<16; b++)
         if(p->bitmap[b] !=0)
             non_empty =1;
       if(non_empty==0)
         return;
+#endif
       cmdout(name) ;
 /* following code re-arranged - Rob Hutchings 1992Apr02 */
       c = curfnt->chardesc + 255 ;
diff -r -u dvipsk.orig/dvips.h dvipsk/dvips.h
--- dvipsk.orig/dvips.h	Sat Sep 21 04:35:29 2002
+++ dvipsk/dvips.h	Sat Sep 21 04:52:57 2002
@@ -194,6 +194,7 @@
    quarterword psflag;
 #ifdef Omega
    chardesctype *chardesc ;
+   quarterword codewidth ;
 #else
    chardesctype chardesc[256] ;
 #endif
diff -r -u dvipsk.orig/fontdef.c dvipsk/fontdef.c
--- dvipsk.orig/fontdef.c	Sat Sep 21 04:35:29 2002
+++ dvipsk/fontdef.c	Sat Sep 21 04:52:57 2002
@@ -40,6 +40,7 @@
    fp = (fontdesctype *)mymalloc((integer)sizeof(fontdesctype)) ;
 #ifdef Omega
 fp->chardesc = (chardesctype *)mymalloc(256*(integer)sizeof(chardesctype)) ;
+   fp->codewidth = 1 ;
 #endif
    fp->psname = 0 ;
    fp->loaded = 0 ;
diff -r -u dvipsk.orig/output.c dvipsk/output.c
--- dvipsk.orig/output.c	Sat Sep 21 04:35:29 2002
+++ dvipsk/output.c	Sat Sep 21 04:52:57 2002
@@ -676,6 +676,17 @@
    }
 }
 
+#ifdef Omega
+void
+scout2 P1C(int, c)
+{
+   char s[64] ;
+
+   sprintf(s, "<%04x>p", c) ;
+   cmdout(s) ;
+}
+#endif
+
 void
 cmdout P1C(char *, s)
 {
@@ -1478,7 +1489,12 @@
       fontout((int)curfnt->psname) ;
       lastfont = curfnt->psname ;
    }
+#ifdef Omega
+   if (curfnt->codewidth==1) scout((unsigned char)cc) ;
+   else scout2(cc) ;
+#else
    scout((unsigned char)cc) ;
+#endif
    rhh = hh + c->pixelwidth ; /* rvv = rv */
 }
 /*
diff -r -u dvipsk.orig/texps.lpro dvipsk/texps.lpro
--- dvipsk.orig/texps.lpro	Sat Sep 21 04:35:30 2002
+++ dvipsk/texps.lpro	Sat Sep 21 04:52:57 2002
@@ -51,6 +51,9 @@
 % The top of stack is now `n [ AT 0 S at*aspect 0 0]';
 % we use this matrix to scale the font later.  We store it in Metrics,
 % which we'll give a different definition to anyway later.
+    FontType 0 ne {
        /Metrics exch def
 % Now we start the dictionary of length n that will eventually be Metrics:
         dict begin
@@ -71,6 +74,11 @@
 % Now we put the widths dictionary into the font, after grabbing
 % the current definition of Metrics back.
         Metrics /Metrics currentdict end def
+    } {
+        { 1 index type /nametype eq { exit } if exch pop } loop
+    } ifelse
 % and duplicate /foo so that it can be used both in definefont
 % and as the name of the macro, which is created first as a 
 % non-executable array so that we can put the new font dictionary 
diff -r -u dvipsk.orig/tfmload.c dvipsk/tfmload.c
--- dvipsk.orig/tfmload.c	Sat Sep 21 04:35:30 2002
+++ dvipsk/tfmload.c	Sat Sep 21 04:52:57 2002
@@ -99,13 +99,26 @@
 int
 tfmload P1C(register fontdesctype *, curfnt)
 {
+#ifdef Omega
+   register integer i, j ;
+#else
    register shalfword i ;
+#endif
    register integer li ;
    integer scaledsize ;
    shalfword nw, hd ;
+#ifdef Omega
+   integer bc, ec ;
+   integer nco, ncw, npc, no_repeats ;
+   integer scaled[65536] ;
+   integer chardat[65536] ;
+   integer font_level ;
+   integer pretend_no_chars ;
+#else
    shalfword bc, ec ;
    integer scaled[256] ;
    halfword chardat[256] ;
+#endif
    int charcount = 0 ;
 
    tfmopen(curfnt) ;
@@ -113,10 +126,33 @@
  *   Next, we read the font data from the tfm file, and store it in
  *   our own arrays.
  */
+#ifdef Omega
+   li = tfm16() ;
+   if (li!=0) {
+      font_level = -1 ;
+      hd = tfm16() ;
+      bc = tfm16() ; ec = tfm16() ;
+      nw = tfm16() ;
+      li = tfm32() ; li = tfm32() ; li = tfm32() ; li = tfm16() ;
+   } else {  /* In an .ofm file */
+      font_level = tfm16();
+      li = tfm32() ; hd = tfm32() ;
+      bc = tfm32() ; ec = tfm32() ;
+      nw = tfm32() ;
+      for (i=0; i<8; i++) li=tfm32();
+      if (font_level==1) {
+         nco = tfm32() ;
+         ncw = tfm32() ;
+         npc = tfm32() ;
+         for (i=0; i<12; i++) li=tfm32();
+      }
+   }
+#else
    li = tfm16() ; hd = tfm16() ;
    bc = tfm16() ; ec = tfm16() ;
    nw = tfm16() ;
    li = tfm32() ; li = tfm32() ; li = tfm32() ; li = tfm16() ;
+#endif
    li = tfm32() ;
    check_checksum (li, curfnt->checksum, curfnt->name);
    li = (integer)(alpha * (real)tfm32()) ;
@@ -125,23 +161,68 @@
       (void)sprintf(errbuf,"Design size mismatch in %s", name) ;
       error(errbuf) ;
    }
+#ifdef Omega
+   pretend_no_chars=ec+1 ;
+   if (pretend_no_chars<256) pretend_no_chars=256 ;
+   curfnt->chardesc = (chardesctype *)
+         realloc(curfnt->chardesc, sizeof(chardesctype)*pretend_no_chars) ;
+   for (i=2; i<((font_level==1)?nco-29:hd); i++)
+      li = tfm32() ;
+   for (i=0; i<pretend_no_chars; i++)
+      chardat[i] = -1 ;
+   no_repeats = 0 ;
+#else
    for (i=2; i<hd; i++)
       li = tfm32() ;
    for (i=0; i<256; i++)
       chardat[i] = 256 ;
+#endif
    for (i=bc; i<=ec; i++) {
+#ifdef Omega
+      if (no_repeats>0) {
+         chardat[i] = chardat[i-1] ;
+         no_repeats-- ;
+      } else if (font_level>=0) {
+         chardat[i] = tfm16() ;
+         li = tfm32() ;
+         li |= tfm16() ;
+         if (font_level==1) {
+            no_repeats = tfm16() ;
+            for (j=0; j<(npc|1); j++) tfm16() ;
+            ncw -= 3 + npc/2 ;
+         }
+      } else {
+         chardat[i] = tfmbyte() ;
+         li = tfm16() ;
+         li |= tfmbyte() ;
+      }
+      if (li || chardat[i])
+         charcount++ ;
+#else
       chardat[i] = tfmbyte() ;
       li = tfm16() ;
       li |= tfmbyte() ;
       if (li || chardat[i])
          charcount++ ;
+#endif
+   }
+#ifdef Omega
+   if (font_level==1&&ncw!=0) {
+      sprintf(errbuf, "Table size mismatch in %s", curfnt->name) ;
+      error(errbuf) ;
    }
+#endif
    scaledsize = curfnt->scaledsize ;
    for (i=0; i<nw; i++)
       scaled[i] = scalewidth(tfm32(), scaledsize) ;
    (void)fclose(tfmfile) ;
+#ifdef Omega
+   for (i=0; i<pretend_no_chars; i++)
+      if (chardat[i]!= -1) {
+#else
    for (i=0; i<256; i++)
       if (chardat[i]!= 256) {
+#endif
          li = scaled[chardat[i]] ;
          curfnt->chardesc[i].TFMwidth = li ;
          if (li >= 0)
@@ -151,6 +232,9 @@
          curfnt->chardesc[i].flags = (curfnt->resfont ? EXISTS : 0) ;
          curfnt->chardesc[i].flags2 = EXISTS ;
       }
+#ifdef Omega
+   if (ec>=256) curfnt->codewidth = 2 ; /* XXX: 2byte-code can have ec<256 */
+#endif
    curfnt->loaded = 1 ;
    return charcount ;
 }