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