summaryrefslogtreecommitdiff
path: root/Build/source/texk/ttf2pk2/newobj.c
blob: 9be49ed9c2a57074f2e3815444015e5255b44027 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*
 *   newobj.c
 *
 *   This file is part of the ttf2pk package.
 *
 *   Copyright 1997-1999, 2000, 2002 by
 *     Frederic Loyer <loyer@ensta.fr>
 *     Werner Lemberg <wl@gnu.org>
 */

#include <stdlib.h>
#include <stddef.h>         /* for size_t */
#include <string.h>

#include "newobj.h"
#include "ttf2tfm.h"
#include "errormsg.h"
#include "texenc.h"


void *
mymalloc(size_t len)
{
  void *p;


#ifdef SMALLMALLOC
  if (len > 65500L)
    oops("Cannot allocate more than 64kByte.");
#endif

  if (len)
    p = malloc(len);
  else
    p = malloc(1);

  if (p == NULL)
    oops("Out of memory.");

  return p;
}


void *
myrealloc(void *oldp, size_t len)
{
  void *p;


#ifdef SMALLMALLOC
  if (len > 65500L)
    oops("Cannot allocate more than 64kByte.");
#endif

  if (len)
    p = realloc(oldp, len);
  else
    p = realloc(oldp, 1);

  if (p == NULL)
    oops("Out of memory.");

  return p;
}


/*
 *   This routine gets a line from a file, supporting continuation with
 *   '\' as the last character on the line.
 *
 *   In case of error, NULL is returned.  If EOF is reached a pointer to
 *   a null string is returned.  The final newline will be retained.
 */

char *
get_line(FILE *f)
{
  size_t linelen, len;
  char *buffer;
  int c;


  linelen = 80;
  len = 0;

  buffer = (char *)mymalloc(linelen);

  while (1)
  {
    c = fgetc(f);
    buffer[len++] = c;

    if (len == linelen - 1)
    {
      linelen += 80;
      buffer = (char *)myrealloc(buffer, linelen);
    }

  again:
    switch (c)
    {
    case '\\':
      c = fgetc(f);
      if (c == '\n')
      {
        len--;
        break;
      }
      else
      {
        buffer[len++] = c;
        goto again;
      }
    case '\n':
      buffer[len] = '\0';
      return buffer;
    case EOF:
      buffer[len - 1] = '\0';
      if (feof(f))
        return buffer;
      else
        return NULL;
    default:
      break;
    }
  }
}


/*
 *   texlive_getline() is a wrapper function for get_line().  It returns `False' in
 *   case of error and expects a pointer to a buffer to store the current
 *   line.   Additionally, the final newline character is stripped.
 */

Boolean
texlive_getline(char **bufferp, FILE *f)
{
  size_t l;


  *bufferp = get_line(f);

  if (!(*bufferp && **bufferp))
    return 0;

  l = strlen(*bufferp);
  if (l > 0)
    (*bufferp)[l - 1] = '\0';

  return 1;
}


char *
newstring(const char *s)
{
  char *q;

  if (s)
  {
    q = mymalloc(strlen(s) + 1);
    (void)strcpy(q, s);
    return q;
  }
  else
    return NULL;
}


ttfinfo *
newchar(Font *fnt)
{
  register ttfinfo *ti;


  ti = (ttfinfo *)mymalloc(sizeof (ttfinfo));

  ti->next = fnt->charlist;

  ti->charcode = -1;
  ti->glyphindex = -1;
  ti->incode = -1;
  ti->outcode = -1;
  ti->adobename = NULL;

  ti->width = -1;
  ti->llx = -1;
  ti->lly = -1;
  ti->urx = -1;
  ti->ury = -1;

  ti->ligs = NULL;
  ti->kerns = NULL;
  ti->kern_equivs = NULL;
  ti->pccs = NULL;

  ti->constructed = False;

  ti->wptr = 0;
  ti->hptr = 0;
  ti->dptr = 0;
  ti->iptr = 0;

  fnt->charlist = ti;

  return ti;
}


kern *
newkern(void)
{
  register kern *nk;


  nk = (kern *)mymalloc(sizeof (kern));
  nk->next = NULL;
  nk->succ = NULL;
  nk->delta = 0;

  return nk;
}


pcc *
newpcc(void)
{
  register pcc *np;


  np = (pcc *)mymalloc(sizeof (pcc));
  np->next = NULL;
  np->partname = NULL;
  np->xoffset = 0;
  np->yoffset = 0;

  return np;
}


lig *
newlig(void)
{
  register lig *nl;


  nl = (lig *)mymalloc(sizeof (lig));
  nl->next = NULL;
  nl->succ = NULL;
  nl->sub = NULL;
  nl->op = 0;               /* the default =: op */
  nl->boundleft = 0;

  return nl;
}


stringlist *
newstringlist(void)
{
  register stringlist *sl;


  sl = (stringlist *)mymalloc(sizeof (stringlist));
  sl->next = NULL;
  sl->old_name = NULL;
  sl->new_name = NULL;
  sl->single_replacement = False;

  return sl;
}


void
init_font_structure(Font *fnt)
{
  int i;


  fnt->ttfname = NULL;

  fnt->tfm_path = NULL;
  fnt->tfm_ext = NULL;

  fnt->outname = NULL;
  fnt->subfont_name = NULL;
  fnt->outname_postfix = NULL;
  fnt->fullname = NULL;

  fnt->vplout = NULL;
  fnt->tfmout = NULL;

  fnt->inencname = NULL;
  fnt->inencoding = NULL;

  fnt->replacements = NULL;
  fnt->replacementname = NULL;

  fnt->outencname = NULL;
  fnt->outencoding = NULL;

  fnt->sfdname = NULL;

  fnt->sawligkern = False;
  fnt->subfont_ligs = False;
  fnt->ligname = NULL;
  fnt->write_enc = False;

  fnt->charlist = NULL;

  fnt->boundarychar = -1;
  fnt->codingscheme = default_codingscheme;
  fnt->titlebuf = NULL;

  fnt->units_per_em = 0;
  fnt->italicangle = 0.0;
  fnt->fixedpitch = 0;

  fnt->fontindex = 0;
  fnt->pid = 3;
  fnt->eid = 1;

  fnt->xheight = 400;
  fnt->fontspace = 0;

  fnt->y_offset = 0.25;

  fnt->efactor = 1.0;
  fnt->slant = 0;
  fnt->capheight = 0.8;
  fnt->PSnames = No;
  fnt->rotate = No;

  fnt->efactorparam = NULL;
  fnt->slantparam = NULL;
  fnt->fontindexparam = NULL;
  fnt->pidparam = NULL;
  fnt->eidparam = NULL;
  fnt->y_offsetparam = NULL;

  for (i = 0; i < 256; i++)
  {
    fnt->inencptrs[i] = NULL;
    fnt->outencptrs[i] = NULL;
    fnt->uppercase[i] = NULL;
    fnt->lowercase[i] = NULL;
    fnt->sf_code[i] = -1;
    fnt->nextout[i] = -1;           /* encoding chains have length 0 */
  }
}


/* end */