summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvipsk/bbox.c
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2010-05-05 09:37:32 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2010-05-05 09:37:32 +0000
commit149d652144fe416dbe4ecf9fc5cef71617ef01ff (patch)
treedd6af91d94b7a0fa3ee43fbf5996539d481c3285 /Build/source/texk/dvipsk/bbox.c
parent52fa6e36fd5539d6bd3546acdfb401bd99d899d6 (diff)
dvips pTeX extensions, based on patches sent by Akira
git-svn-id: svn://tug.org/texlive/trunk@18107 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvipsk/bbox.c')
-rw-r--r--Build/source/texk/dvipsk/bbox.c378
1 files changed, 255 insertions, 123 deletions
diff --git a/Build/source/texk/dvipsk/bbox.c b/Build/source/texk/dvipsk/bbox.c
index 5a321890e6a..8073df25fb6 100644
--- a/Build/source/texk/dvipsk/bbox.c
+++ b/Build/source/texk/dvipsk/bbox.c
@@ -33,9 +33,12 @@ bbtfmload(register fontdesctype *curfnt)
register integer i, j;
register integer li, cd = 0;
integer scaledsize;
+ integer id, nt = 0;
integer nw, nh, nd, ns, hd;
integer bc, ec;
integer nco = 0, ncw = 0, npc = 0, no_repeats = 0;
+ halfword *index = NULL;
+ halfword *chartype = NULL;
integer *scaled;
integer *chardat;
int font_level;
@@ -51,9 +54,15 @@ bbtfmload(register fontdesctype *curfnt)
* Next, we read the font data from the tfm file, and store it in
* our own arrays.
*/
- li = tfm16();
- if (li!=0) {
+ curfnt->dir = 0;
+ id = tfm16();
+ if (id != 0) {
font_level = -1;
+ if (id == 9 || id == 11) {
+ if (noptex) badtfm("length");
+ if (id == 9) curfnt->dir = id;
+ nt = tfm16(); li = tfm16();
+ }
hd = tfm16();
bc = tfm16(); ec = tfm16();
nw = tfm16(); nh = tfm16(); nd = tfm16();
@@ -62,7 +71,8 @@ bbtfmload(register fontdesctype *curfnt)
ns += tfm16();
ns += tfm16();
li = tfm16();
- if (hd<2 || bc>ec+1 || ec>255 || nw>256 || nh>16 || nd>16)
+ if ((hd<2 || bc>ec+1 || ec>255 || nw>256 || nh>16 || nd>16) &&
+ id != 9 && id != 11)
badtfm("header");
} else { /* In an .ofm file */
if (noomega) badtfm("length");
@@ -81,10 +91,10 @@ bbtfmload(register fontdesctype *curfnt)
|| bc>ec+1 || ec>65535 || nw>65536 || nh>256 || nd>256)
badtfm("header");
if (font_level==1) {
- nco = tfm32();
- ncw = tfm32();
- npc = tfm32();
- for (i=0; i<12; i++) li=tfm32();
+ nco = tfm32();
+ ncw = tfm32();
+ npc = tfm32();
+ for (i=0; i<12; i++) li=tfm32();
}
}
li = tfm32();
@@ -92,30 +102,54 @@ bbtfmload(register fontdesctype *curfnt)
li = tfm32();
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();
- chardat = (integer *) xmalloc(pretend_no_chars*sizeof(integer));
- for (i=0; i<pretend_no_chars; i++)
- chardat[i] = -1;
- for (i=bc; i<=ec; i++) {
- if (no_repeats>0) {
- no_repeats--;
- } else if (font_level>=0) {
- cd = tfm32();
+ if (id == 9 || id == 11) {
+ chardat = (integer *) xmalloc(256*sizeof(integer));
+ bbcurfnt->bbchardesc = (bbchardesctype *)
+ xmalloc((MAX_2BYTES_CODE+1)*sizeof(bbchardesctype));
+ for (i=2; i<hd; i++)
li = tfm32();
- if (font_level==1) {
- no_repeats = tfm16();
- for (j=0; j<(npc|1); j++) tfm16();
- ncw -= 3 + npc/2;
- }
- } else {
- cd = tfm16();
+ index = (halfword *)xmalloc(nt * sizeof(halfword));
+ chartype = (halfword *)xmalloc(nt * sizeof(halfword));
+ li = tfm16();
+ li = tfm16();
+ for (i=1; i<nt; i++) {
li = tfm16();
+ index[i] = li;
+ chartype[i] = tfm16();
+ }
+ for (i=0; i<256; i++)
+ chardat[i] = -1;
+ } else {
+ 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();
+ chardat = (integer *) xmalloc(pretend_no_chars*sizeof(integer));
+ for (i=0; i<pretend_no_chars; i++)
+ chardat[i] = -1;
+ }
+ for (i=bc; i<=ec; i++) {
+ if (id == 9 || id == 11) {
+ chardat[i] = tfm16();
+ li = tfm16();
+ } else {
+ if (no_repeats>0) {
+ no_repeats--;
+ } else if (font_level>=0) {
+ cd = tfm32();
+ li = tfm32();
+ if (font_level==1) {
+ no_repeats = tfm16();
+ for (j=0; j<(npc|1); j++) tfm16();
+ ncw -= 3 + npc/2;
+ }
+ } else {
+ cd = tfm16();
+ li = tfm16();
+ }
+ if (cd) chardat[i] = cd;
}
- if (cd) chardat[i] = cd;
}
if (font_level==1&&ncw!=0) {
char *msg = concat ("Table size mismatch in ", curfnt->name);
@@ -123,68 +157,125 @@ bbtfmload(register fontdesctype *curfnt)
free(msg);
}
scaledsize = curfnt->scaledsize;
- scaled = (integer *) xmalloc((nh + nd)*sizeof(integer));
- for (i=0; i<nw; i++)
- tfm32();
- for (i=0; i<nh + nd; i++)
- scaled[i] = scalewidth(tfm32(), scaledsize);
+ if (id == 9 || id == 11) {
+ scaled = (integer *) xmalloc(300*sizeof(integer));
+ for (i=0; i<nw + nh + nd; i++)
+ scaled[i] = scalewidth(tfm32(), scaledsize);
+ } else {
+ scaled = (integer *) xmalloc((nh + nd)*sizeof(integer));
+ for (i=0; i<nw; i++)
+ tfm32();
+ for (i=0; i<nh + nd; i++)
+ scaled[i] = scalewidth(tfm32(), scaledsize);
+ }
for (i=0; i<ns; i++)
tfm32();
slant = tfm32();
(void)fclose(tfmfile);
- for (i=0; i<pretend_no_chars; i++) {
- cc = &(bbcurfnt->bbchardesc[i]);
- if (chardat[i] != -1) {
- halfword iw;
- int ih, id;
- if (font_level>=0) {
- iw = chardat[i] >> 16;
- ih = (chardat[i] >> 8) & 255;
- id = chardat[i] & 255;
+
+ if (id == 9 || id == 11) {
+ for (i=0; i<MAX_2BYTES_CODE+1; i++) {
+ cc = &(bbcurfnt->bbchardesc[i]);
+ if (chardat[0] != -1) {
+ cc->ury = scaled[((chardat[0] >> 4) & 15) + nw];
+ cc->lly = - scaled[(chardat[0] & 15) + nw + nh];
+ cc->llx = 0;
+ cc->urx = curfnt->chardesc[0].TFMwidth;
} else {
- iw = chardat[i] >> 8;
- ih = (chardat[i] >> 4) & 15;
- id = chardat[i] & 15;
+ cc->llx = cc->lly = cc->urx = cc->ury = 0;
}
- if (iw>=nw || ih>=nh || id>=nd) badtfm("char info");
- cc->ury = scaled[ih];
- cc->lly = - scaled[nh + id];
- cc->llx = 0;
- cc->urx = curfnt->chardesc[i].TFMwidth;
- } else {
- cc->llx = cc->lly = cc->urx = cc->ury = 0;
}
- }
- if (slant) {
+ for (i=1; i<nt; i++) {
+ cc = &(bbcurfnt->bbchardesc[index[i]]);
+ if (chardat[chartype[i]] != -1) {
+ cc->ury = scaled[((chardat[chartype[i]] >> 4) & 15) + nw];
+ cc->lly = - scaled[(chardat[chartype[i]] & 15) + nw + nh];
+ cc->llx = 0;
+ cc->urx = curfnt->chardesc[index[i]].TFMwidth;
+ } else {
+ cc->llx = cc->lly = cc->urx = cc->ury = 0;
+ }
+ }
+ free(index);
+ free(chartype);
+ } else {
for (i=0; i<pretend_no_chars; i++) {
cc = &(bbcurfnt->bbchardesc[i]);
- li = scalewidth(cc->lly, slant);
- if (slant > 0) cc->llx += li;
- else cc->urx += li;
- li = scalewidth(cc->ury, slant);
- if (slant > 0) cc->urx += li;
- else cc->llx += li;
+ if (chardat[i] != -1) {
+ halfword iw;
+ int ih, id;
+ if (font_level>=0) {
+ iw = chardat[i] >> 16;
+ ih = (chardat[i] >> 8) & 255;
+ id = chardat[i] & 255;
+ } else {
+ iw = chardat[i] >> 8;
+ ih = (chardat[i] >> 4) & 15;
+ id = chardat[i] & 15;
+ }
+ if (iw>=nw || ih>=nh || id>=nd) badtfm("char info");
+ cc->ury = scaled[ih];
+ cc->lly = - scaled[nh + id];
+ cc->llx = 0;
+ cc->urx = curfnt->chardesc[i].TFMwidth;
+ } else {
+ cc->llx = cc->lly = cc->urx = cc->ury = 0;
+ }
+ }
+ }
+ if (slant) {
+ if (id == 9 || id == 11) {
+ for (i=0; i<MAX_2BYTES_CODE+1; i++) {
+ cc = &(bbcurfnt->bbchardesc[i]);
+ li = scalewidth(cc->lly, slant);
+ if (slant > 0) cc->llx += li;
+ else cc->urx += li;
+ li = scalewidth(cc->ury, slant);
+ if (slant > 0) cc->urx += li;
+ else cc->llx += li;
+ }
+ } else {
+ for (i=0; i<pretend_no_chars; i++) {
+ cc = &(bbcurfnt->bbchardesc[i]);
+ li = scalewidth(cc->lly, slant);
+ if (slant > 0) cc->llx += li;
+ else cc->urx += li;
+ li = scalewidth(cc->ury, slant);
+ if (slant > 0) cc->urx += li;
+ else cc->llx += li;
+ }
}
}
free(chardat);
free(scaled);
}
static integer llx, lly, urx, ury;
-void
-bbspecial(integer h, integer v, int nbytes)
+static void
+bbspecial(integer h, integer v, integer dir, int nbytes)
{
float *r = bbdospecial(nbytes);
if (r) {
/* convert from magnified PostScript units back to scaled points */
real conv = 72.0 * (real)num / (real)den * (real)mag / 254000000.0;
- if (llx > h + r[0] / conv)
- llx = (integer) (h + r[0] / conv);
- if (lly > v - r[3] / conv)
- lly = (integer) (v - r[3] / conv);
- if (urx < h + r[2] / conv)
- urx = (integer) (h + r[2] / conv);
- if (ury < v - r[1] / conv)
- ury = (integer) (v - r[1] / conv);
+ if (!dir) {
+ if (llx > h + r[0] / conv)
+ llx = (integer) (h + r[0] / conv);
+ if (lly > v - r[3] / conv)
+ lly = (integer) (v - r[3] / conv);
+ if (urx < h + r[2] / conv)
+ urx = (integer) (h + r[2] / conv);
+ if (ury < v - r[1] / conv)
+ ury = (integer) (v - r[1] / conv);
+ } else {
+ if (llx > h + r[1] / conv)
+ llx = (integer)(h + r[1] / conv);
+ if (lly > v + r[2] / conv)
+ lly = (integer)(v + r[2] / conv);
+ if (urx < h + r[3] / conv)
+ urx = (integer)(h + r[3] / conv);
+ if (ury < v + r[0] / conv)
+ ury = (integer)(v + r[0] / conv);
+ }
}
}
void
@@ -197,14 +288,14 @@ bbdopage(void)
register fontmaptype *cfnt;
bbfontmaptype *bbcfnt;
integer fnt;
- integer mychar;
+ integer mychar;
int charmove;
struct dvistack *sp = stack;
- integer v, w, x, y, z;
+ integer v, w, x, y, z, dir;
register fontdesctype *curfnt = 0;
register bbfontdesctype *bbcurfnt = 0;
- w = x = y = z = 0;
+ w = x = y = z = dir = 0;
h = 0; v = 0;
llx = lly = 1000000000;
urx = ury = -1000000000;
@@ -212,6 +303,20 @@ bbdopage(void)
while (1) {
switch (cmd=dvibyte()) {
case 138: break;
+case 135: /* put3 */
+ if (noptex) error("! synch");
+ mychar = dvibyte();
+ mychar = (mychar << 8) + dvibyte();
+ mychar = (mychar << 8) + dvibyte();
+ charmove = 0;
+ goto dochar;
+case 130: /* set3 */
+ if (noptex) error("! synch");
+ mychar = dvibyte();
+ mychar = (mychar << 8) + dvibyte();
+ mychar = (mychar << 8) + dvibyte();
+ charmove = 1;
+ goto dochar;
case 134: /* put2 */
if (noomega) error("! synch");
mychar = dvibyte();
@@ -234,35 +339,62 @@ default: /* these are commands 0 (setchar0) thru 127 (setchar127) */
charmove = 1;
dochar:
cd = &(curfnt->chardesc[mychar]);
- bcd = &(bbcurfnt->bbchardesc[mychar]);
- if (h + bcd->llx < llx) llx = h + bcd->llx;
- if (h + bcd->urx > urx) urx = h + bcd->urx;
- if (v - bcd->ury < lly) lly = v - bcd->ury;
- if (v - bcd->lly > ury) ury = v - bcd->lly;
- if (charmove)
- h += cd->TFMwidth;
+ bcd = &(bbcurfnt->bbchardesc[CD_IDX(mychar)]);
+ if (!dir) {
+ if (h + bcd->llx < llx) llx = h + bcd->llx;
+ if (h + bcd->urx > urx) urx = h + bcd->urx;
+ if (v - bcd->ury < lly) lly = v - bcd->ury;
+ if (v - bcd->lly > ury) ury = v - bcd->lly;
+ } else {
+ if (h + bcd->ury < llx) llx = h + bcd->ury;
+ if (h + bcd->lly > urx) urx = h + bcd->lly;
+ if (v + bcd->llx < lly) lly = v + bcd->llx;
+ if (v + bcd->urx > ury) ury = v + bcd->urx;
+ }
+ if (charmove) {
+ if (!dir)
+ h += cd->TFMwidth;
+ else
+ v += cd->TFMwidth;
+ }
break;
-case 130: case 131: case 135: case 136: case 139:
-case 247: case 248: case 249: case 250: case 251: case 252: case 253:
-case 254: case 255: /* unimplemented or illegal commands */
+case 255: /* pTeX's dir or undefined */
+ if (!noptex) {
+ dir = dvibyte();
+ break;
+ }
+case 131: case 136: case 139: /* set4, put4, bop */
+case 247: case 248: case 249: /* pre, post, post_post */
+case 250: case 251: case 252: case 253: case 254: /* undefined */
error("! synch");
case 132: case 137: /* rules */
{ integer ry, rx;
ry = signedquad(); rx = signedquad();
if (rx>0 && ry>0) {
- if (h < llx) llx = h;
- if (v - ry < lly) lly = v - ry;
- if (h + rx > urx) urx = h + rx;
- if (v > ury) ury = v;
+ if (!dir) {
+ if (h < llx) llx = h;
+ if (v - ry < lly) lly = v - ry;
+ if (h + rx > urx) urx = h + rx;
+ if (v > ury) ury = v;
+ } else {
+ if (h < llx) llx = h;
+ if (v + rx < lly) lly = v + rx;
+ if (h + ry > urx) urx = h + ry;
+ if (v > ury) ury = v;
+ }
} else
rx = 0;
- if (cmd != 137)
- h += rx;
+ if (cmd != 137) {
+ if (!dir)
+ h += rx;
+ else
+ v += rx;
+ }
break;
}
case 141: /* push */
sp->h = h; sp->v = v;
- sp->w = w; sp->x = x; sp->y = y; sp->z = z;
+ sp->w = w; sp->x = x; sp->y = y; sp->z = z; sp->dir = dir;
if (++sp >= &stack[STACKSIZE]) error("! Out of stack space");
break;
case 140: /* eop or end of virtual character */
@@ -270,36 +402,36 @@ case 140: /* eop or end of virtual character */
case 142: /* pop */
if (--sp < stack) error("! More pops than pushes");
h = sp->h; v = sp->v;
- w = sp->w; x = sp->x; y = sp->y; z = sp->z;
+ w = sp->w; x = sp->x; y = sp->y; z = sp->z; dir = sp->dir;
break;
-case 143: h += signedbyte(); break;
-case 144: h += signedpair(); break;
-case 145: h += signedtrio(); break;
-case 146: h += signedquad(); break;
-case 147: h += w; break;
-case 148: h += (w = signedbyte()); break;
-case 149: h += (w = signedpair()); break;
-case 150: h += (w = signedtrio()); break;
-case 151: h += (w = signedquad()); break;
-case 152: h += x; break;
-case 153: h += (x = signedbyte()); break;
-case 154: h += (x = signedpair()); break;
-case 155: h += (x = signedtrio()); break;
-case 156: h += (x = signedquad()); break;
-case 157: v += signedbyte(); break;
-case 158: v += signedpair(); break;
-case 159: v += signedtrio(); break;
-case 160: v += signedquad(); break;
-case 161: v += y; break;
-case 162: v += (y = signedbyte()); break;
-case 163: v += (y = signedpair()); break;
-case 164: v += (y = signedtrio()); break;
-case 165: v += (y = signedquad()); break;
-case 166: v += z; break;
-case 167: v += (z = signedbyte()); break;
-case 168: v += (z = signedpair()); break;
-case 169: v += (z = signedtrio()); break;
-case 170: v += (z = signedquad()); break;
+case 143: if (!dir) h += signedbyte(); else v += signedbyte(); break;
+case 144: if (!dir) h += signedpair(); else v += signedpair(); break;
+case 145: if (!dir) h += signedtrio(); else v += signedtrio(); break;
+case 146: if (!dir) h += signedquad(); else v += signedquad(); break;
+case 147: if (!dir) h += w; else v += w; break;
+case 148: if (!dir) h += (w = signedbyte()); else v += (w = signedbyte()); break;
+case 149: if (!dir) h += (w = signedpair()); else v += (w = signedpair()); break;
+case 150: if (!dir) h += (w = signedtrio()); else v += (w = signedtrio()); break;
+case 151: if (!dir) h += (w = signedquad()); else v += (w = signedquad()); break;
+case 152: if (!dir) h += x; else v += x; break;
+case 153: if (!dir) h += (x = signedbyte()); else v += (x = signedbyte()); break;
+case 154: if (!dir) h += (x = signedpair()); else v += (x = signedpair()); break;
+case 155: if (!dir) h += (x = signedtrio()); else v += (x = signedtrio()); break;
+case 156: if (!dir) h += (x = signedquad()); else v += (x = signedquad()); break;
+case 157: if (!dir) v += signedbyte(); else h -= signedbyte(); break;
+case 158: if (!dir) v += signedpair(); else h -= signedpair(); break;
+case 159: if (!dir) v += signedtrio(); else h -= signedtrio(); break;
+case 160: if (!dir) v += signedquad(); else h -= signedquad(); break;
+case 161: if (!dir) v += y; else h -= y; break;
+case 162: if (!dir) v += (y = signedbyte()); else h -= (y = signedbyte()); break;
+case 163: if (!dir) v += (y = signedpair()); else h -= (y = signedpair()); break;
+case 164: if (!dir) v += (y = signedtrio()); else h -= (y = signedtrio()); break;
+case 165: if (!dir) v += (y = signedquad()); else h -= (y = signedquad()); break;
+case 166: if (!dir) v += z; else h += z; break;
+case 167: if (!dir) v += (z = signedbyte()); else h -= (z = signedbyte()); break;
+case 168: if (!dir) v += (z = signedpair()); else h -= (z = signedpair()); break;
+case 169: if (!dir) v += (z = signedtrio()); else h -= (z = signedtrio()); break;
+case 170: if (!dir) v += (z = signedquad()); else h -= (z = signedquad()); break;
case 171: case 172: case 173: case 174: case 175: case 176: case 177:
case 178: case 179: case 180: case 181: case 182: case 183: case 184:
case 185: case 186: case 187: case 188: case 189: case 190: case 191:
@@ -332,10 +464,10 @@ case 243: case 244: case 245: case 246: /*fntdef1 */
skipover(cmd - 230);
skipover(dvibyte() + dvibyte());
break;
-case 239: bbspecial(h, v, (int)dvibyte()); break;
-case 240: bbspecial(h, v, (int)twobytes()); break;
-case 241: bbspecial(h, v, (int)threebytes()); break;
-case 242: bbspecial(h, v, (int)signedquad()); break;
+case 239: bbspecial(h, v, dir, (int)dvibyte()); break;
+case 240: bbspecial(h, v, dir, (int)twobytes()); break;
+case 241: bbspecial(h, v, dir, (int)threebytes()); break;
+case 242: bbspecial(h, v, dir, (int)signedquad()); break;
}
}
}