(postscript->pdf): Invoke gs instead of
[lilypond/patrick.git] / ttftool / ps.c
blob13ee16a2dab5652e79f45202fa9b86f2e74c6e4a
1 /* Copyright (c) 1997-1998 by Juliusz Chroboczek */
3 #include <sys/types.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <stdlib.h>
7 #include "types.h"
8 #include "proto.h"
10 #define ALIAS_FILE_TO_FILECOOKIE
12 #include "libc-extension.hh"
14 #define CHUNKSIZE 65534
16 #define NAMEOF(i) \
17 ((i)==0?\
18 ".notdef":\
19 ((postType==2)?\
20 ((gnt[i].type==0)?\
21 (gnt[i].name.index==0?NULL:macGlyphEncoding[gnt[i].name.index]):\
22 gnt[i].name.name):\
23 ((i)<258?macGlyphEncoding[i]:NULL)))
26 void
27 printPSFont (FILE * out, struct HeadTable *ht,
28 char **strings, int nglyphs, int postType,
29 struct PostTable *pt, struct GlyphName *gnt, int fd)
31 printPSHeader (out, ht, strings, pt);
32 printPSData (out, fd);
33 printPSTrailer (out, nglyphs, postType, gnt);
36 void
37 printPSHeader (FILE * out, struct HeadTable *ht,
38 char **strings, struct PostTable *pt)
40 fprintf (out, "%%!PS-TrueTypeFont\n");
41 if (pt->maxMemType42)
42 fprintf (out, "%%%%VMUsage: %ld %ld\n", pt->minMemType42,
43 pt->maxMemType42);
44 fprintf (out, "%d dict begin\n", 11);
45 fprintf (out, "/FontName /%s def\n", strings[6] ? strings[6] : "Unknown");
46 fprintf (out, "/Encoding StandardEncoding def\n");
47 fprintf (out, "/PaintType 0 def\n/FontMatrix [1 0 0 1 0 0] def\n");
48 fprintf (out, "/FontBBox [%ld %ld %ld %ld] def\n",
49 ht->xMin * 1000L / ht->unitsPerEm,
50 ht->yMin * 1000L / ht->unitsPerEm,
51 ht->xMax * 1000L / ht->unitsPerEm,
52 ht->yMax * 1000L / ht->unitsPerEm);
53 fprintf (out, "/FontType 42 def\n");
54 fprintf (out, "/FontInfo 8 dict dup begin\n");
55 fprintf (out, "/version (%d.%d) def\n",
56 ht->fontRevision.mantissa, ht->fontRevision.fraction);
57 if (strings[0])
59 fprintf (out, "/Notice (");
60 fputpss (strings[0], out);
61 fprintf (out, ") def\n");
63 if (strings[4])
65 fprintf (out, "/FullName (");
66 fputpss (strings[4], out);
67 fprintf (out, ") def\n");
69 if (strings[1])
71 fprintf (out, "/FamilyName (");
72 fputpss (strings[1], out);
73 fprintf (out, ") def\n");
75 fprintf (out, "/isFixedPitch %s def\n",
76 pt->isFixedPitch ? "true" : "false");
77 fprintf (out, "/UnderlinePosition %ld def\n",
78 pt->underlinePosition * 1000L / ht->unitsPerEm);
79 fprintf (out, "/UnderlineThickness %ld def\n",
80 pt->underlineThickness * 1000L / ht->unitsPerEm);
81 fprintf (out, "end readonly def\n");
84 void
85 printPSData (FILE * out, int fd)
87 static char xdigits[] = "0123456789ABCDEF";
89 unsigned char *buffer;
90 int i, j;
92 surely_lseek (fd, 0, SEEK_SET);
94 buffer = mymalloc (CHUNKSIZE);
96 fprintf (out, "/sfnts [");
97 for (;;)
99 i = read (fd, buffer, CHUNKSIZE);
100 if (i == 0)
101 break;
102 fprintf (out, "\n<");
103 for (j = 0; j < i; j++)
105 if (j != 0 && j % 36 == 0)
106 putc ('\n', out);
107 /* fprintf(out,"%02X",(int)buffer[j]) is too slow */
108 putc (xdigits[(buffer[j] & 0xF0) >> 4], out);
109 putc (xdigits[buffer[j] & 0x0F], out);
111 fprintf (out, "00>"); /* Adobe bug? */
112 if (i < CHUNKSIZE)
113 break;
115 fprintf (out, "\n] def\n");
116 free (buffer);
119 void
120 printPSTrailer (FILE * out, int nglyphs, int postType, struct GlyphName *gnt)
122 int i, n;
123 char *name;
125 fprintf (out, "/CharStrings %d dict dup begin\n", nglyphs);
126 switch (postType)
128 case 2:
129 for (n = i = 0; i < nglyphs; i++)
131 if (n != 0 && n % 4 == 0)
132 fprintf (out, "\n");
133 name = NAMEOF (i);
134 if (name)
136 fprintf (out, "/%s %d def ", name, i);
137 n++;
140 break;
141 default:
142 if (postType != 1)
144 if (verbosity > -2)
145 fprintf (stderr,
146 "No glyph name table; assuming MacGlyphEncoding\n");
148 for (i = 0; i < 258 && i < nglyphs; i++)
150 fprintf (out, "/%s %d def ", macGlyphEncoding[i], i);
151 if (i != 0 && i % 4 == 0)
152 fprintf (out, "\n");
154 break;
156 fprintf (out, "end readonly def\n");
157 fprintf (out, "FontName currentdict end definefont pop\n");