]> git.donarmstrong.com Git - lilypond.git/blob - ttftool/ttfps.c
Added color names.
[lilypond.git] / ttftool / ttfps.c
1 /* Copyright (c) 1997-1998 by Juliusz Chroboczek */
2
3 #include <sys/types.h>
4 #include <stdio.h>
5 #include <fcntl.h>
6 #include <unistd.h>
7 #include <stdlib.h>
8 #include "types.h"
9 #include "proto.h"
10
11
12 static void endianness_test (void);
13 static void usage (char *);
14
15 int ttf_verbosity = 0;
16
17 void
18 create_type42 (const char *infile, void *out)
19 {
20   FILE *fd = 0;
21   int  i;
22   struct OffsetTable ot;
23   struct HeadTable *ht;
24   struct PostTable *pt;
25   struct TableDirectoryEntry *td;
26   void *loca = NULL;
27   struct HheaTable *hhea = NULL;
28   struct Box *bbox = NULL;
29   longHorMetric *hmtx = NULL;
30   char **strings = NULL;
31   struct GlyphName *gnt = NULL;
32   struct KernEntry0 **ke;
33   int *nke;
34   int nglyphs, postType, nkern;
35   off_t headOff = 0, maxpOff = 0, postOff = 0, nameOff = 0,
36     locaOff = 0, glyfOff = 0, hheaOff = 0, hmtxOff = 0, kernOff = 0;
37
38   extern char *optarg;
39   extern int optind;
40   int c;
41
42   endianness_test ();
43
44   if ((fd = fopen (infile, "rb")) == NULL)
45     {
46       syserror ("Error opening input file");
47     }
48
49   td = readDirectory (fd, &ot);
50   if (ttf_verbosity >= 2)
51     fprintf (stderr, "True type version %d.%u\n",
52              ot.version.mantissa, ot.version.fraction);
53
54   for (i = 0; i < ot.numTables; i++)
55     {
56       if (ttf_verbosity >= 2)
57         fprintf (stderr, "Found `%c%c%c%c' table\n",
58                  (char) (td[i].tag >> 24),
59                  (char) (td[i].tag >> 16) & 255,
60                  (char) (td[i].tag >> 8) & 255, (char) td[i].tag & 255);
61       switch (td[i].tag)
62         {
63         case MAKE_ULONG ('m', 'a', 'x', 'p'):
64           maxpOff = td[i].offset;
65           break;
66         case MAKE_ULONG ('h', 'e', 'a', 'd'):
67           headOff = td[i].offset;
68           break;
69         case MAKE_ULONG ('p', 'o', 's', 't'):
70           postOff = td[i].offset;
71           break;
72         case MAKE_ULONG ('n', 'a', 'm', 'e'):
73           nameOff = td[i].offset;
74           break;
75         case MAKE_ULONG ('l', 'o', 'c', 'a'):
76           locaOff = td[i].offset;
77           break;
78         case MAKE_ULONG ('g', 'l', 'y', 'f'):
79           glyfOff = td[i].offset;
80           break;
81         case MAKE_ULONG ('h', 'h', 'e', 'a'):
82           hheaOff = td[i].offset;
83           break;
84         case MAKE_ULONG ('h', 'm', 't', 'x'):
85           hmtxOff = td[i].offset;
86           break;
87         case MAKE_ULONG ('k', 'e', 'r', 'n'):
88           kernOff = td[i].offset;
89           break;
90         }
91     }
92   if (maxpOff == 0 || headOff == 0 || postOff == 0 || nameOff == 0)
93     ttf_error ("Incomplete TTF file\n");
94
95   if (ttf_verbosity >= 1)
96     fprintf (stderr, "Processing `maxp' table\n");
97   surely_lseek (fd, maxpOff, SEEK_SET);
98   nglyphs = readMaxpTable (fd);
99   if (ttf_verbosity >= 1)
100     fprintf (stderr, "  %d glyphs\n", nglyphs);
101
102   if (ttf_verbosity >= 1)
103     fprintf (stderr, "Processing `head' table\n");
104   surely_lseek (fd, headOff, SEEK_SET);
105   ht = mymalloc (sizeof (struct HeadTable));
106   readHeadTable (fd, ht);
107
108   if (ttf_verbosity >= 1)
109     fprintf (stderr, "Processing `post' table\n");
110   surely_lseek (fd, postOff, SEEK_SET);
111   pt = mymalloc (sizeof (struct PostTable));
112   postType = readPostTable (fd, nglyphs, pt, &gnt);
113
114   if (ttf_verbosity >= 1)
115     fprintf (stderr, "Processing `name' table\n");
116   surely_lseek (fd, nameOff, SEEK_SET);
117   strings = readNamingTable (fd);
118
119   if (ttf_verbosity >= 1)
120     fprintf (stderr, "Generating PS file\n");
121   printPSFont (out, ht, strings, nglyphs, postType, pt, gnt, fd);
122   lily_cookie_fclose (out);
123   if (ttf_verbosity >= 1)
124     fprintf (stderr, "Done.\n");
125   fclose (fd);
126 }
127
128
129 static void
130 endianness_test ()
131 {
132   union
133   {
134     BYTE b[4];
135     ULONG l;
136   } x;
137   ULONG v;
138
139   x.b[0] = 1;
140   x.b[1] = 2;
141   x.b[2] = 3;
142   x.b[3] = 4;
143
144   v = UL (x.l);
145
146   if (v != (((((1 << 8) + 2) << 8) + 3) << 8) + 4)
147     {
148       fprintf (stderr, "Code badly compiled for this architecture\n");
149       fprintf (stderr, "Please set SMALLENDIAN and recompile\n");
150       exit (2);
151     }
152 }