Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!rsalz From: rsalz@uunet.UU.NET (Rich Salz) Newsgroups: comp.sources.unix Subject: v12i062: A PostScript interpreter, Part13/18 Message-ID: <2880@uunet.UU.NET> Date: Sun, 8-Nov-87 16:22:49 EST Article-I.D.: uunet.2880 Posted: Sun Nov 8 16:22:49 1987 Date-Received: Mon, 9-Nov-87 02:36:12 EST Organization: UUNET Communications Services, Arlington, VA Lines: 6706 Approved: rs@uunet.UU.NET Submitted-by: Crispin Goswell Posting-number: Volume 12, Issue 62 Archive-name: postscript/part13 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'postscript/fonts/SANS/italic.r' <<'END_OF_FILE' XCharStrings X/zero X Xput XMetrics X/zero X[2 X21] Xput XCharStrings X/one X Xput XMetrics X/one X[2 X21] Xput XCharStrings X/two X Xput XMetrics X/two X[2 X21] Xput XCharStrings X/three X Xput XMetrics X/three X[2 X21] Xput XCharStrings X/four X Xput XMetrics X/four X[2 X21] Xput XCharStrings X/five X Xput XMetrics X/five X[2 X21] Xput XCharStrings X/six X Xput XMetrics X/six X[2 X21] Xput XCharStrings X/seven X Xput XMetrics X/seven X[2 X21] Xput XCharStrings X/eight X Xput XMetrics X/eight X[2 X21] Xput XCharStrings X/nine X Xput XMetrics X/nine X[2 X21] Xput XCharStrings X/period X Xput XMetrics X/period X[-2 X11] Xput XCharStrings X/comma X Xput XMetrics X/comma X[-1 X11] Xput XCharStrings X/colon X Xput XMetrics X/colon X[0 X11] Xput XCharStrings X/semicolon X Xput XMetrics X/semicolon X[0 X11] Xput XCharStrings X/exclam X Xput XMetrics X/exclam X[7 X11] Xput XCharStrings X/question X Xput XMetrics X/question X[2 X21] Xput XCharStrings X/quoteleft X Xput XMetrics X/quoteleft X[7 X11] Xput XCharStrings X/quoteright X Xput XMetrics X/quoteright X[7 X11] Xput XCharStrings X/ampersand X Xput XMetrics X/ampersand X[-1 X26] Xput XCharStrings X/dollar X Xput XMetrics X/dollar X[6 X21] Xput XCharStrings X/slash X Xput XMetrics X/slash X[5 X22] Xput XCharStrings X/parenleft X Xput XMetrics X/parenleft X[9 X15] Xput XCharStrings X/parenright X Xput XMetrics X/parenright X[8 X15] Xput XCharStrings X/asterisk X Xput XMetrics X/asterisk X[4 X17] Xput XCharStrings X/minus X Xput XMetrics X/minus X[-4 X26] Xput XCharStrings X/plus X Xput XMetrics X/plus X[-4 X26] Xput XCharStrings X/equal X Xput XMetrics X/equal X[-4 X26] Xput XCharStrings X/quotesingle X Xput XMetrics X/quotesingle X[8 X9] Xput XCharStrings X/quotedbl X Xput XMetrics X/quotedbl X[3 X18] Xput XCharStrings X/ring X Xput XMetrics X/ring X[5 X15] Xput XCharStrings X/A Xput XMetrics X/A[1 X23] Xput XCharStrings X/B Xput XMetrics X/B[0 X24] Xput XCharStrings X/C Xput XMetrics X/C[2 X21] Xput XCharStrings X/D Xput XMetrics X/D[0 X23] Xput XCharStrings X/E Xput XMetrics X/E[3 X19] Xput XCharStrings X/F Xput XMetrics X/F[1 X21] Xput XCharStrings X/G Xput XMetrics X/G[1 X22] Xput XCharStrings X/H Xput XMetrics X/H[0 X24] Xput XCharStrings X/I Xput XMetrics X/I[3 X16] Xput XCharStrings X/J Xput XMetrics X/J[3 X17] Xput XCharStrings X/K Xput XMetrics X/K[0 X24] Xput XCharStrings X/L Xput XMetrics X/L[3 X18] Xput XCharStrings X/M Xput XMetrics X/M[2 X28] Xput XCharStrings X/N Xput XMetrics X/N[2 X23] Xput XCharStrings X/O Xput XMetrics X/O[2 X21] Xput XCharStrings X/P Xput XMetrics X/P[0 X23] Xput XCharStrings X/Q Xput XMetrics X/Q[2 X21] Xput XCharStrings X/R Xput XMetrics X/R[0 X24] Xput XCharStrings X/S Xput XMetrics X/S[2 X20] Xput XCharStrings X/T Xput XMetrics X/T[3 X18] Xput XCharStrings X/U Xput XMetrics X/U[1 X22] Xput XCharStrings X/V Xput XMetrics X/V[1 X21] Xput XCharStrings X/W Xput XMetrics X/W[0 X23] Xput XCharStrings X/X Xput XMetrics X/X[2 X20] Xput XCharStrings X/Y Xput XMetrics X/Y[1 X22] Xput XCharStrings X/Z Xput XMetrics X/Z[1 X21] Xput XCharStrings X/a Xput XMetrics X/a[-1 X16] Xput XCharStrings X/b Xput XMetrics X/b[6 X14] Xput XCharStrings X/c Xput XMetrics X/c[-1 X12] Xput XCharStrings X/d Xput XMetrics X/d[5 X16] Xput XCharStrings X/e Xput XMetrics X/e[-1 X12] Xput XCharStrings X/f Xput XMetrics X/f[9 X9] Xput XCharStrings X/g Xput XMetrics X/g[-1 X16] Xput XCharStrings X/h Xput XMetrics X/h[6 X15] Xput XCharStrings X/i Xput XMetrics X/i[2 X8] Xput XCharStrings X/j Xput XMetrics X/j[7 X8] Xput XCharStrings X/k Xput XMetrics X/k[6 X14] Xput XCharStrings X/l Xput XMetrics X/l[8 X8] Xput XCharStrings X/m Xput XMetrics X/m[0 X25] Xput XCharStrings X/n Xput XMetrics X/n[0 X18] Xput XCharStrings X/o Xput XMetrics X/o[-1 X14] Xput XCharStrings X/p Xput XMetrics X/p[4 X15] Xput XCharStrings X/q Xput XMetrics X/q[-1 X16] Xput XCharStrings X/r Xput XMetrics X/r[0 X14] Xput XCharStrings X/s Xput XMetrics X/s[0 X12] Xput XCharStrings X/t Xput XMetrics X/t[8 X8] Xput XCharStrings X/u Xput XMetrics X/u[-1 X16] Xput XCharStrings X/v Xput XMetrics X/v[-1 X15] Xput XCharStrings X/w Xput XMetrics X/w[-1 X21] Xput XCharStrings X/x Xput XMetrics X/x[0 X16] Xput XCharStrings X/y Xput XMetrics X/y[-1 X16] Xput XCharStrings X/z Xput XMetrics X/z[1 X13] Xput END_OF_FILE if test 15498 -ne `wc -c <'postscript/fonts/SANS/italic.r'`; then echo shar: \"'postscript/fonts/SANS/italic.r'\" unpacked with wrong size! fi # end of 'postscript/fonts/SANS/italic.r' fi if test -f 'postscript/fonts/SANS/roman.r' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'postscript/fonts/SANS/roman.r'\" else echo shar: Extracting \"'postscript/fonts/SANS/roman.r'\" \(16026 characters\) sed "s/^X//" >'postscript/fonts/SANS/roman.r' <<'END_OF_FILE' XCharStrings X/A Xput XMetrics X/A[2 X20] Xput XCharStrings X/B Xput XMetrics X/B[2 X20] Xput XCharStrings X/C Xput XMetrics X/C[2 X21] Xput XCharStrings X/D Xput XMetrics X/D[2 X21] Xput XCharStrings X/E Xput XMetrics X/E[3 X19] Xput XCharStrings X/F Xput XMetrics X/F[3 X18] Xput XCharStrings X/G Xput XMetrics X/G[2 X21] Xput XCharStrings X/H Xput XMetrics X/H[1 X22] Xput XCharStrings X/I Xput XMetrics X/I[8 X9] Xput XCharStrings X/J Xput XMetrics X/J[4 X17] Xput XCharStrings X/K Xput XMetrics X/K[2 X21] Xput XCharStrings X/L Xput XMetrics X/L[3 X17] Xput XCharStrings X/M Xput XMetrics X/M[0 X24] Xput XCharStrings X/N Xput XMetrics X/N[1 X22] Xput XCharStrings X/O Xput XMetrics X/O[1 X22] Xput XCharStrings X/P Xput XMetrics X/P[2 X20] Xput XCharStrings X/Q Xput XMetrics X/Q[1 X22] Xput XCharStrings X/R Xput XMetrics X/R[2 X20] Xput XCharStrings X/S Xput XMetrics X/S[2 X20] Xput XCharStrings X/T Xput XMetrics X/T[4 X17] Xput XCharStrings X/U Xput XMetrics X/U[1 X22] Xput XCharStrings X/V Xput XMetrics X/V[2 X20] Xput XCharStrings X/W Xput XMetrics X/W[-1 X26] Xput XCharStrings X/X Xput XMetrics X/X[2 X20] Xput XCharStrings X/Y Xput XMetrics X/Y[3 X19] Xput XCharStrings X/Z Xput XMetrics X/Z[2 X20] Xput XCharStrings X/zero X Xput XMetrics X/zero X[2 X20] Xput XCharStrings X/one X Xput XMetrics X/one X[2 X20] Xput XCharStrings X/two X Xput XMetrics X/two X[2 X20] Xput XCharStrings X/three X Xput XMetrics X/three X[2 X20] Xput XCharStrings X/four X Xput XMetrics X/four X[2 X20] Xput XCharStrings X/five X Xput XMetrics X/five X[2 X20] Xput XCharStrings X/six X Xput XMetrics X/six X[2 X20] Xput XCharStrings X/seven X Xput XMetrics X/seven X[2 X20] Xput XCharStrings X/eight X Xput XMetrics X/eight X[2 X20] Xput XCharStrings X/nine X Xput XMetrics X/nine X[2 X20] Xput XCharStrings X/period X Xput XMetrics X/period X[-4 X11] Xput XCharStrings X/comma X Xput XMetrics X/comma X[-4 X11] Xput XCharStrings X/colon X Xput XMetrics X/colon X[0 X11] Xput XCharStrings X/semicolon X Xput XMetrics X/semicolon X[0 X11] Xput XCharStrings X/exclam X Xput XMetrics X/exclam X[7 X11] Xput XCharStrings X/question X Xput XMetrics X/question X[3 X19] Xput XCharStrings X/quoteleft X Xput XMetrics X/quoteleft X[7 X11] Xput XCharStrings X/quoteright X Xput XMetrics X/quoteright X[7 X11] Xput XCharStrings X/ampersand X Xput XMetrics X/ampersand X[0 X25] Xput XCharStrings X/dollar X Xput XMetrics X/dollar X[7 X19] Xput XCharStrings X/slash X Xput XMetrics X/slash X[5 X23] Xput XCharStrings X/parenleft X Xput XMetrics X/parenleft X[9 X14] Xput XCharStrings X/parenright X Xput XMetrics X/parenright X[9 X14] Xput XCharStrings X/asterisk X Xput XMetrics X/asterisk X[4 X16] Xput X% XCharStrings X/minus X Xput XMetrics X/minus X[-4 X25] Xput XCharStrings X/plus X Xput XMetrics X/plus X[-3 X25] Xput XCharStrings X/equal X Xput XMetrics X/equal X[-4 X25] Xput XCharStrings X/quotesingle X Xput XMetrics X/quotesingle X[8 X9] Xput XCharStrings X/quotedbl X Xput XMetrics X/quotedbl X[3 X18] Xput XCharStrings X/ring X Xput XMetrics X/ring X[5 X14] Xput XCharStrings X/a Xput XMetrics X/a[-3 X20] Xput XCharStrings X/b Xput XMetrics X/b[2 X20] Xput XCharStrings X/c Xput XMetrics X/c[-3 X18] Xput XCharStrings X/d Xput XMetrics X/d[2 X20] Xput XCharStrings X/e Xput XMetrics X/e[-3 X18] Xput XCharStrings X/f Xput XMetrics X/f[6 X14] Xput XCharStrings X/g Xput XMetrics X/g[-3 X20] Xput XCharStrings X/h Xput XMetrics X/h[2 X20] Xput XCharStrings X/i Xput XMetrics X/i[8 X9] Xput XCharStrings X/j Xput XMetrics X/j[7 X10] Xput XCharStrings X/k Xput XMetrics X/k[2 X19] Xput XCharStrings X/l Xput XMetrics X/l[8 X9] Xput XCharStrings X/m Xput XMetrics X/m[-4 X31] Xput XCharStrings X/n Xput XMetrics X/n[-4 X20] Xput XCharStrings X/o Xput XMetrics X/o[-3 X19] Xput XCharStrings X/p Xput XMetrics X/p[-4 X20] Xput XCharStrings X/q Xput XMetrics X/q[-3 X20] Xput XCharStrings X/r Xput XMetrics X/r[-2 X14] Xput XCharStrings X/s Xput XMetrics X/s[-3 X17] Xput XCharStrings X/t Xput XMetrics X/t[7 X11] Xput XCharStrings X/u Xput XMetrics X/u[-4 X20] Xput XCharStrings X/v Xput XMetrics X/v[-2 X16] Xput XCharStrings X/w Xput XMetrics X/w[-3 X24] Xput XCharStrings X/x Xput XMetrics X/x[-3 X18] Xput XCharStrings X/y Xput XMetrics X/y[-2 X16] Xput XCharStrings X/z Xput XMetrics X/z[-3 X18] Xput X XCharStrings X/.notdef X Xput XMetrics X/.notdef X[3 X18] Xput XCharStrings X/space X() Xput XMetrics X/space X[0 X20] Xput XCharStrings X/numbersign X Xput XMetrics X/numbersign X[2 X21] Xput XCharStrings X/bracketleft X Xput XMetrics X/bracketleft X[9 X14] Xput XCharStrings X/bracketright X Xput XMetrics X/bracketright X[9 X14] Xput XCharStrings X/braceleft X Xput XMetrics X/braceleft X[9 X14] Xput XCharStrings X/braceright X Xput XMetrics X/braceright X[9 X14] Xput XCharStrings X/minus X Xput XMetrics X/minus X[-4 X26] Xput XCharStrings X/percent X Xput XMetrics X/percent X[0 X24] Xput XCharStrings X/underscore X Xput XMetrics X/underscore X[0 X16] Xput XCharStrings X/backslash X Xput XMetrics X/backslash X[-4 X26] Xput XCharStrings X/asciitilde X Xput XMetrics X/asciitilde X[-3 X24] Xput XCharStrings X/less X Xput XMetrics X/less X[-3 X24] Xput XCharStrings X/greater X Xput XMetrics X/greater X[-3 X24] Xput XCharStrings X/asciicircum X Xput XMetrics X/asciicircum X[-3 X22] Xput XCharStrings X/asciitilde X Xput XMetrics X/asciitilde X[-3 X24] Xput XCharStrings X/bar X Xput XMetrics X/bar X[12 X8] Xput END_OF_FILE if test 16026 -ne `wc -c <'postscript/fonts/SANS/roman.r'`; then echo shar: \"'postscript/fonts/SANS/roman.r'\" unpacked with wrong size! fi # end of 'postscript/fonts/SANS/roman.r' fi if test -f 'source/font.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'source/font.c'\" else echo shar: Extracting \"'source/font.c'\" \(16487 characters\) sed "s/^X//" >'source/font.c' <<'END_OF_FILE' X/* X * Copyright (C) Rutherford Appleton Laboratory 1987 X * X * This source may be copied, distributed, altered or used, but not sold for profit X * or incorporated into a product except under licence from the author. X * It is not in the public domain. X * This notice should remain in the source unaltered, and any changes to the source X * made by persons other than the author should be marked as such. X * X * Crispin Goswell @ Rutherford Appleton Laboratory caag@uk.ac.rl.vd X */ X#include "main.h" X#include "graphics.h" X X#define MOVETO 0x80 X#define BYTE 0xFF X X#define FONT_USER 3 X Xstatic struct show_context show_stack [MAXGSAVES]; X Xint MoveTo (), LineTo (); X Xstatic int PCurrentFont (); Xstatic int PDefineFont (); Xstatic int PFindFont (); Xstatic int PScaleFont (); Xstatic int PMakeFont (); Xstatic int PSetFont (); X Xstatic int BuildHershey (); Xstatic int PShow (); Xstatic int PWidthShow (); Xstatic int PAShow (); Xstatic int PAWidthShow (); Xstatic int PStringWidth (); Xstatic int PAdjust (); X Xstatic Vector GetMetrics (); X Xstatic int ShowString (); Xstatic int ShowStop (); Xstatic int ShowStopped (); X XObject Fid, FD, FontMatrix, FontType, Encoding, FontBBox, OpShowStop, OpShowString, OpStopped; XObject UserShow, CharStrings, Metrics, BuildChar, FontName; X Xstatic last_fid = 0; X Xstatic int Update (); X Xstatic Point zeroPoint; Xstatic HardPoint zeroHardPoint; X Xextern Matrix HardPointTranslate (); X XInitFont () X { X Fid = NameFrom ("FID"); X FontMatrix = NameFrom ("FontMatrix"); X FontType = NameFrom ("FontType"); X Encoding = NameFrom ("Encoding"); X FontBBox = NameFrom ("FontBBox"); X UserShow = NameFrom (".show"); X CharStrings = NameFrom ("CharStrings"); X Metrics = NameFrom ("Metrics"); X BuildChar = NameFrom ("BuildChar"); X FontName = NameFrom ("FontName"); X X OpShowStop = MakeOp ("(showstop)", ShowStop, 1, 0, 0, 0, Boolean); X OpShowString = MakeOp ("(showstring)", ShowString, 1, 0, 0, 0, String); X OpStopped = MakeOp ("(showstopped)", ShowStopped,0, 1, 1, 0); X X InstallOp ("currentfont", PCurrentFont, 0, 1, 0, 0); X InstallOp ("definefont", PDefineFont, 2, 1, 0, 0, Poly, Dictionary); X InstallOp ("findfont", PFindFont, 1, 1, 0, 0, Poly); X InstallOp ("scalefont", PScaleFont, 2, 1, 0, 0, Dictionary, Float); X InstallOp ("makefont", PMakeFont, 2, 1, 0, 0, Dictionary, Array); X InstallOp ("setfont", PSetFont, 1, 0, 0, 0, Dictionary); X X InstallOp ("show", PShow, 1, 0, 0, 0, String); X InstallOp ("widthshow", PWidthShow, 4, 0, 0, 0, Float, Float, Integer, String); X InstallOp ("ashow", PAShow, 3, 0, 0, 0, Float, Float, String); X InstallOp ("awidthshow", PAWidthShow, 6, 0, 0, 0, Float, Float, Integer, Float, Float, String); X InstallOp ("stringwidth", PStringWidth, 1, 2, 0, 0, String); X InstallOp (".adjust", PAdjust, 1, 0, 0, 0, Integer); X InstallOp ("buildhershey", BuildHershey, 2, 0, 0, 0, Dictionary, Integer); X InstallOp ("update", Update, 1, 0, 0, 0, Boolean); X X Install ("FontDirectory", FD = MakeDict (20)); X X zeroPoint = NewPoint (0.0, 0.0); X zeroHardPoint = NewHardPoint (0.0, 0.0); X } X XHardPoint DExtToInt (p) Point p; X { X Matrix m; X HardPoint res; X X m = gstate->CTM; X res.hx = p.x * m.A + p.y * m.C; X res.hy = p.x * m.B + p.y * m.D; X X return res; X } X Xstatic int update_state = TRUE; X Xstatic int Update (bool) Object bool; X { X int new = BodyBoolean (bool); X X if (new != update_state) X UpdateControl (gstate->device->dev, update_state = new); X return TRUE; X } X XInitShowContext () X { X gstate->show = show_stack; X } X XHardPoint Adjust (basic, code) HardPoint basic; char code; X { X if (code == gstate->show->space) X return MoveHardPoint (MoveHardPoint (gstate->show->shim, gstate->show->space_shim), basic); X else X return MoveHardPoint (gstate->show->shim, basic); X } X Xstatic int PAdjust (code) Object code; X { X gstate->CTM = HardPointTranslate (gstate->CTM, Adjust (ExtToInt (NewPoint (0.0, 0.0)), BodyInteger (code))); X X return TRUE; X } X Xstatic int PCurrentFont () X { X return Push (OpStack, gstate->font); X } X Xstatic int PFindFont (key) Object key; X { X Object res; X X res = DictLoad (FD, key); X if (TypeOf (res) == Condition) X return Error (PInvFont); X return Push (OpStack, res); X } X Xstatic Object *encodingCache = NULL; Xstatic Matrix fontmatrixCache; Xstatic int fonttypeCache; Xint fidCache; Xfloat fontbboxCache[4]; X Xstatic int PSetFont (font) Object font; X { X if (!CheckFont (font)) X return Error (PInvFont); X gstate->font = font; X ExtractMatrix (&fontmatrixCache, DictLoad (font, FontMatrix)); X encodingCache = BodyArray (DictLoad (font, Encoding)); X fonttypeCache = BodyInteger (DictLoad (font, FontType)); X fidCache = BodyFontID (DictLoad (font, Fid)); X ExtractBBox (fontbboxCache, DictLoad (font, FontBBox)); X return TRUE; X } X Xint CheckFont (font) Object font; X { X Object mat, bbox, enc, fonttype; X Matrix dummy; X float bboxdummy[4]; X X mat = DictLoad (font, FontMatrix); X if (TypeOf (mat) == Condition || !ExtractMatrix (&dummy, mat)) X return FALSE; X fonttype = DictLoad (font, FontType); X if (TypeOf (fonttype) != Integer) X return FALSE; X bbox = DictLoad (font, FontBBox); X if (TypeOf (bbox) != Array || lengthArray (bbox) != 4 || !ExtractBBox (bboxdummy, bbox)) X return FALSE; X enc = DictLoad (font, Encoding); X if (TypeOf (enc) != Array || lengthArray (enc) != 256) X return FALSE; X X switch (BodyInteger (fonttype)) X { X case FONT_USER: return TRUE; X X default: return TRUE; X } X } X Xint CheckHershey (font, encoding) Object font, *encoding; X { X Object cs, metrics; X int i; X cs = DictLoad (font, CharStrings); X if (TypeOf (cs) != Dictionary) X return FALSE; X metrics = DictLoad (font, Metrics); X if (TypeOf (metrics) != Dictionary) X return FALSE; X X for (i = 0; i < 256; i++) X { X Object met; X X met = DictLoad (metrics, encoding[i]); X if (TypeOf (met) == Array) X { X Object *m = BodyArray (met); X int j, l = lengthArray (met); X X if (l != 1 && l != 2 && l != 4) X return FALSE; X X for (j = 0; j < l; j++) X if (TypeOf (m[j]) != Integer && TypeOf (m[j]) != Real) X return FALSE; X } X else if (TypeOf (metrics) != Integer && TypeOf (metrics) != Real) X return FALSE; X } X return TRUE; X } X Xint ExtractBBox (bbox, array) float *bbox; Object array; X { X Object num; X int i; X X if (lengthArray (array) != 4) X return FALSE; X for (i = 0; i < 4; i++) X { X num = getArray (array, i); X X if (TypeOf (num) == Integer) X bbox [i] = BodyInteger (num); X else if (TypeOf (num) == Real) X bbox [i] = BodyReal (num); X else X return FALSE; X } X return TRUE; X } X Xstatic Object MakeFontID () X { X Object res; X X res = MakeObject (FontID); X res.u.Font = last_fid++; /* just for uniqueness */ X X return res; X } X Xint BodyFontID (fid) Object fid; X { X return fid.u.Font; X } X Xstatic int PDefineFont (key, dict) Object key, dict; X { X if (maxDict (dict) == lengthDict (dict) || maxDict (FD) == lengthDict (FD)) X return Error (PDictFull); X X if (!CheckFont (dict)) X return Error (PInvFont); X X DictStore (FD, key, ReadOnly (dict)); X DictStore (dict, Fid, MakeFontID ()); X return Push (OpStack, ReadOnly (dict)); X } X Xstruct font_entry X { X Object font; X Matrix mat; X int fid; X struct font_entry *font_next; X } *font_list = NULL; X XObject LookupFont (font, matrix) Object font; Matrix matrix; X { X Object res, mat, new; X Matrix m, n; X struct font_entry *p, *fe; X int fid = BodyFontID (DictLoad (font, Fid)); X X mat = DictLoad (font, FontMatrix); X ExtractMatrix (&m, mat); X n = MatMult (matrix, m); X X for (p = font_list; p != NULL; p = p->font_next) X if (p->fid == fid && EqFont (p->mat, n)) X { X Message ("font matched"); X return p->font; X } X Message ("building a font dict"); X X copyDict (font, res = MakeDict (maxDict (font))); X new = MakeArray ((Object *) Malloc ((unsigned) 6 * sizeof (Object)), 6); X VOID AssignMatrix (new, n); X DictStore (res, FontMatrix, new); X X res = ReadOnly (res); X X fe = (struct font_entry *) Malloc (sizeof (struct font_entry)); X fe->mat = n; X fe->font = res; X fe->font_next = font_list; X fe->fid = fid; X font_list = fe; X X return res; X } X Xstatic int PScaleFont (font, scale) Object font, scale; X { X Object res; X float s = BodyReal (scale); X X if (!CheckFont (font)) X return Error (PInvFont); X res = LookupFont (font, NewMatrix (s, 0.0, 0.0, s, 0.0, 0.0)); X X return Push (OpStack, res); X } X Xstatic int PMakeFont (font, matrix) Object font, matrix; X { X Object res; X Matrix m; X X if (!CheckFont (font)) X return Error (PInvFont); X ExtractMatrix (&m, matrix); X res = LookupFont (font, m); X X return Push (OpStack, res); X } X Xstatic Vector GetMetrics (ob) Object ob; X { X if (TypeOf (ob) == Integer || TypeOf (ob) == Real) X return NewVector (BodyFloat (ob), 0.0, 0.0); X else if (TypeOf (ob) != Array) X return NewVector (0.0, 0.0, 1.0); X else if (lengthArray (ob) == 2) X return NewVector (BodyFloat (getArray (ob, 1)), 0.0, 0.0); X else if (lengthArray (ob) == 4) X return NewVector (BodyFloat (getArray (ob, 2)), BodyFloat (getArray (ob, 3)), 0.0); X else X return NewVector (0.0, 0.0, 1.0); X } X Xstatic int BuildHershey (font, code) Object font, code; X { X Vector met; X Object *bbox, string, nm; X unsigned char *s; X Path p; X int i, l; X X bbox = BodyArray (DictLoad (font, FontBBox)); X nm = BodyArray (DictLoad (font, Encoding)) [BodyInteger (code)]; X met = GetMetrics (DictLoad (DictLoad (font, Metrics), nm)); X met.vx -= 2; /* hershey bodge - they look better closer */ X string = DictLoad (DictLoad (font, CharStrings), nm); X X SetCacheDevice (nm, NewPoint (met.vx, met.vy), X BodyReal (bbox[0]), BodyReal (bbox[1]), X BodyReal (bbox[2]), BodyReal (bbox[3])); X X if (TypeOf (string) != String) X return TRUE; X gstate->line_width = 1.5; X gstate->line_join = 2; X gstate->line_cap = 0; X gstate->dash_length = 0; X X s = BodyString (string); X l = lengthString (string) / 2; X p = gstate->path; X X VOID PNewPath (); X for (i = 0; i < l; i++, s++, s++) X { X Point po; X /* SUN2 FLOATING POINT BUG: (float) (int) is necessary, where (float) should be sufficient */ X po = NewPoint ((float) (int) ((*s & ~MOVETO) - 64), (float) (int) ((s[1] & ~MOVETO) - 73)); X (*(*s & MOVETO ? MoveTo : LineTo)) X (p, ExtToInt (po)); X } X return Push (ExecStack, Cvx (NameFrom ("stroke"))); X } X X/* X Persistent state important across a BuildChar call-back X InShow - the fact that we're in a call back X gstate - graphics state X ccache - the current cache device X gstate->device - whether a cache device has been set or not. X The old device if a cache device is installed. X The old CTM. X Width - current width information - used for moving cp X awx, awy - shim adjustment parameters X scode, X axcode, aycode - spacing adjustment parameters X X XXXXXXX XXXXXX XXXXXXXXXX XXXXXXXXX X XXXXXXX XXXXXX XXXXXXXXXX XXXXXXXXX X XXXXXXX XXXXXX XXXXXXXXXX XXXXXXXXX X XXXXXXX XXXXXX XXXXXXXXXX XXXXXXXXX X XXXXXXX XXXXXX XXXXXXXXXX XXXXXXXXX X |_______| |_______| |_______| X | X ashow/widthshow width vector X X ShowUser shows the first character (to avoid a leading gap). X It may have to call buildchar if the character is not cached. X ShowString finishes off a BuildChar (if necessary) X then shows gaps and characters until it encounters X one which is not cached. X It then stacks: X a stopped context to reset things if an error occurs. X another ShowString to continue output. X A buildchar to build a character X*/ X Xstatic int Show (string, space, shim, space_shim) X Object string; char space; HardPoint shim, space_shim; X { X if (!gstate->cp_defined) X return Error (PNoCurrentPoint); X X switch (fonttypeCache) X { X case FONT_USER: X return ShowUser (string, fontmatrixCache, space, shim, space_shim); X X default: X return Error (PInvFont); X } X } X Xstatic int ShowStopped () X { X VOID Pop (ExecStack); X VOID Push (OpStack, False); X return TRUE; X } X X#define lengthString(s) ((s).Length) X X#define BodyString(s) ((s).u.String) X Xint ShowUser (string, m, space, shim, space_shim) X Object string; Matrix m; char space; HardPoint shim, space_shim; X { X unsigned char *s = BodyString (string); X int l = lengthString (string); X X if (l == 0) X return TRUE; X X /* GSave (); */ X X ++gstate->show; X gstate->show->InShow = TRUE; X gstate->show->shim = shim; X gstate->show->space_shim = space_shim; X gstate->show->space = space; X gstate->show->mat = gstate->CTM; X X gstate->CTM.tx = gstate->cp.hx; X gstate->CTM.ty = gstate->cp.hy; X X gstate->CTM = MatMult (m, gstate->CTM); X FindCache (); X X UpdateControl (gstate->device->dev, FALSE); X X gstate->cp.hx = gstate->CTM.tx; X gstate->cp.hy = gstate->CTM.ty; X if (CacheShow (encodingCache [*s], gstate->cp)) X return ShowStringAux (string, s, l, gstate->show->Width); X X UpdateControl (gstate->device->dev, TRUE); X X GSave (); X VOID Push (ExecStack, OpShowStop); X PStopped (OpShowString); X VOID Push (OpStack, string); X VOID Push (OpStack, gstate->font); X VOID Push (OpStack, MakeInteger (*s)); X VOID Push (ExecStack, DictLoad (gstate->font, BuildChar)); X return TRUE; X } X Xstatic int ShowString (string) Object string; X { X int l = lengthString (string); X unsigned char *st = BodyString (string); X Point last_width; X X Pop (ExecStack); X Pop (ExecStack); X Pop (ExecStack); X GRestore (); X X UpdateControl (gstate->device->dev, FALSE); X X last_width = gstate->show->Width; X CacheShow (encodingCache [*st], gstate->cp); X X return ShowStringAux (string, st, l, last_width); X } X XShowStringAux (string, st, l, last_width) Object string; unsigned char *st; int l; Point last_width; X { X unsigned char *s = st; X HardPoint loc; X X loc.hx = gstate->CTM.tx; loc.hy = gstate->CTM.ty; X for (;;) X { X int code = *++s; X HardPoint offset, cp; X X offset = Adjust (DExtToInt (last_width), code); X loc.hx += offset.hx; X loc.hy += offset.hy; X if (--l == 0) X break; X if (!CacheShow (encodingCache [code], loc)) X { X gstate->cp = loc; X gstate->CTM.tx = loc.hx; gstate->CTM.ty = loc.hy; X X VOID Push (ExecStack, OpShowStop); X PStopped (OpShowString); X X VOID Push (OpStack, getIString (string, s - st, l)); X X VOID Push (OpStack, gstate->font); X VOID Push (OpStack, MakeInteger (*s)); X VOID Push (ExecStack, DictLoad (gstate->font, BuildChar)); X UpdateControl (gstate->device->dev, TRUE); X X GSave (); X X return TRUE; X } X last_width = gstate->show->Width; X } X gstate->CTM.tx = loc.hx; gstate->CTM.ty = loc.hy; X UpdateControl (gstate->device->dev, TRUE); X X return ShowStopAux (); X } X Xstatic int ShowStop (st) Object st; X { X GRestore (); X ShowStopAux (); X if (BodyBoolean (st)) X return PStop (); X return TRUE; X } X XShowStopAux () X { X HardPoint cp; X X cp.hx = gstate->CTM.tx; X cp.hy = gstate->CTM.ty; X /* GRestore (); */ X gstate->CTM = gstate->show->mat; X --gstate->show; X gstate->cp = cp; X X return TRUE; X } X Xstatic int PShow (string) Object string; X { X return Show (string, 0, zeroHardPoint, zeroHardPoint); X } X Xstatic int PWidthShow (x, y, code, string) Object x, y, code, string; X { X return Show (string, BodyInteger (code), zeroHardPoint, DExtToInt (NewPoint (BodyReal (x), BodyReal (y)))); X } X Xstatic int PAShow (ax, ay, string) Object ax, ay, string; X { X return Show (string, 0, DExtToInt (NewPoint (BodyReal (ax), BodyReal (ay))), zeroHardPoint); X } X Xstatic int PAWidthShow (x, y, code, ax, ay, string) Object x, y, code, ax, ay, string; X { X return Show (string, X BodyInteger (code), X DExtToInt (NewPoint (BodyReal (x), BodyReal (y))), X DExtToInt (NewPoint (BodyReal (ax), BodyReal (ay)))); X } X Xstatic int PStringWidth (string) Object string; X { X Matrix m; X Vector v; X Object *enc, met; X int i, l = lengthString (string); X unsigned char *s = BodyString (string); X float x = 0, y = 0; X X if (!CheckFont (gstate->font)) X return Error (PInvFont); X if (BodyInteger (DictLoad (gstate->font, FontType)) == 3) X { X VOID Push (OpStack, string); X VOID Push (ExecStack, Cvx (NameFrom (".stringwidth"))); X return TRUE; X } X enc = BodyArray (DictLoad (gstate->font, Encoding)); X met = DictLoad (gstate->font, Metrics); X for (i = 0; i < l; i++) X { X v = GetMetrics (DictLoad (met, enc[s[i]])); X x += v.vx; X y += v.vy; X } X ExtractMatrix (&m, DictLoad (gstate->font, FontMatrix)); X v = Transform (NewVector (x, y, 0.0), m); X return Push (OpStack, MakeReal (v.vx)), Push (OpStack, MakeReal (v.vy)); X } END_OF_FILE if test 16487 -ne `wc -c <'source/font.c'`; then echo shar: \"'source/font.c'\" unpacked with wrong size! fi # end of 'source/font.c' fi echo shar: End of archive 13 \(of 18\). cp /dev/null ark13isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 18 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0