| 1 |
/* |
| 2 |
* newobj.c |
| 3 |
* |
| 4 |
* This file is part of the ttf2pk package. |
| 5 |
* |
| 6 |
* Copyright 1997-1999, 2000, 2002 by |
| 7 |
* Frederic Loyer <[email protected]> |
| 8 |
* Werner Lemberg <[email protected]> |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifdef HAVE_CONFIG_H |
| 12 |
#include <config.h> |
| 13 |
#endif |
| 14 |
|
| 15 |
#include <stdlib.h> |
| 16 |
#include <stddef.h> /* for size_t */ |
| 17 |
#include <string.h> |
| 18 |
|
| 19 |
#include "newobj.h" |
| 20 |
#include "ttf2tfm.h" |
| 21 |
#include "errormsg.h" |
| 22 |
#include "texenc.h" |
| 23 |
|
| 24 |
|
| 25 |
#if !defined(HAVE_LIBKPATHSEA) |
| 26 |
void * |
| 27 |
mymalloc(size_t len) |
| 28 |
{ |
| 29 |
void *p; |
| 30 |
|
| 31 |
|
| 32 |
#ifdef SMALLMALLOC |
| 33 |
if (len > 65500L) |
| 34 |
oops("Cannot allocate more than 64kByte."); |
| 35 |
#endif |
| 36 |
|
| 37 |
if (len) |
| 38 |
p = malloc(len); |
| 39 |
else |
| 40 |
p = malloc(1); |
| 41 |
|
| 42 |
if (p == NULL) |
| 43 |
oops("Out of memory."); |
| 44 |
|
| 45 |
return p; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
void * |
| 50 |
mycalloc(size_t nmemb, size_t len) |
| 51 |
{ |
| 52 |
void *p; |
| 53 |
|
| 54 |
p = calloc(nmemb ? nmemb : 1, len ? len : 1); |
| 55 |
|
| 56 |
if (p == NULL) |
| 57 |
oops("Out of memory."); |
| 58 |
|
| 59 |
return p; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
void * |
| 64 |
myrealloc(void *oldp, size_t len) |
| 65 |
{ |
| 66 |
void *p; |
| 67 |
|
| 68 |
|
| 69 |
#ifdef SMALLMALLOC |
| 70 |
if (len > 65500L) |
| 71 |
oops("Cannot allocate more than 64kByte."); |
| 72 |
#endif |
| 73 |
|
| 74 |
if (len) |
| 75 |
p = realloc(oldp, len); |
| 76 |
else |
| 77 |
p = realloc(oldp, 1); |
| 78 |
|
| 79 |
if (p == NULL) |
| 80 |
oops("Out of memory."); |
| 81 |
|
| 82 |
return p; |
| 83 |
} |
| 84 |
#endif |
| 85 |
|
| 86 |
|
| 87 |
/* |
| 88 |
* This routine gets a line from a file, supporting continuation with |
| 89 |
* '\' as the last character on the line. |
| 90 |
* |
| 91 |
* In case of error, NULL is returned. If EOF is reached a pointer to |
| 92 |
* a null string is returned. The final newline will be retained. |
| 93 |
*/ |
| 94 |
|
| 95 |
char * |
| 96 |
get_line(FILE *f) |
| 97 |
{ |
| 98 |
size_t linelen, len; |
| 99 |
char *buffer; |
| 100 |
int c; |
| 101 |
|
| 102 |
|
| 103 |
linelen = 80; |
| 104 |
len = 0; |
| 105 |
|
| 106 |
buffer = (char *)mymalloc(linelen); |
| 107 |
|
| 108 |
while (1) |
| 109 |
{ |
| 110 |
c = fgetc(f); |
| 111 |
buffer[len++] = c; |
| 112 |
|
| 113 |
if (len == linelen - 1) |
| 114 |
{ |
| 115 |
linelen += 80; |
| 116 |
buffer = (char *)myrealloc(buffer, linelen); |
| 117 |
} |
| 118 |
|
| 119 |
again: |
| 120 |
switch (c) |
| 121 |
{ |
| 122 |
case '\\': |
| 123 |
c = fgetc(f); |
| 124 |
if (c == '\n') |
| 125 |
{ |
| 126 |
len--; |
| 127 |
break; |
| 128 |
} |
| 129 |
else |
| 130 |
{ |
| 131 |
buffer[len++] = c; |
| 132 |
goto again; |
| 133 |
} |
| 134 |
case '\n': |
| 135 |
buffer[len] = '\0'; |
| 136 |
return buffer; |
| 137 |
case EOF: |
| 138 |
buffer[len - 1] = '\0'; |
| 139 |
if (feof(f)) |
| 140 |
return buffer; |
| 141 |
else |
| 142 |
return NULL; |
| 143 |
default: |
| 144 |
break; |
| 145 |
} |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
/* |
| 151 |
* texlive_getline() is a wrapper function for get_line(). It returns `False' in |
| 152 |
* case of error and expects a pointer to a buffer to store the current |
| 153 |
* line. Additionally, the final newline character is stripped. |
| 154 |
*/ |
| 155 |
|
| 156 |
Boolean |
| 157 |
texlive_getline(char **bufferp, FILE *f) |
| 158 |
{ |
| 159 |
size_t l; |
| 160 |
|
| 161 |
|
| 162 |
*bufferp = get_line(f); |
| 163 |
|
| 164 |
if (!(*bufferp && **bufferp)) |
| 165 |
return 0; |
| 166 |
|
| 167 |
l = strlen(*bufferp); |
| 168 |
if (l > 0) |
| 169 |
(*bufferp)[l - 1] = '\0'; |
| 170 |
|
| 171 |
return 1; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
char * |
| 176 |
newstring(const char *s) |
| 177 |
{ |
| 178 |
char *q; |
| 179 |
|
| 180 |
if (s) |
| 181 |
{ |
| 182 |
q = mymalloc(strlen(s) + 1); |
| 183 |
(void)strcpy(q, s); |
| 184 |
return q; |
| 185 |
} |
| 186 |
else |
| 187 |
return NULL; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
ttfinfo * |
| 192 |
newchar(Font *fnt) |
| 193 |
{ |
| 194 |
register ttfinfo *ti; |
| 195 |
|
| 196 |
|
| 197 |
ti = (ttfinfo *)mymalloc(sizeof (ttfinfo)); |
| 198 |
|
| 199 |
ti->next = fnt->charlist; |
| 200 |
|
| 201 |
ti->charcode = -1; |
| 202 |
ti->glyphindex = -1; |
| 203 |
ti->incode = -1; |
| 204 |
ti->outcode = -1; |
| 205 |
ti->adobename = NULL; |
| 206 |
|
| 207 |
ti->width = -1; |
| 208 |
ti->llx = -1; |
| 209 |
ti->lly = -1; |
| 210 |
ti->urx = -1; |
| 211 |
ti->ury = -1; |
| 212 |
|
| 213 |
ti->ligs = NULL; |
| 214 |
ti->kerns = NULL; |
| 215 |
ti->kern_equivs = NULL; |
| 216 |
ti->pccs = NULL; |
| 217 |
|
| 218 |
ti->constructed = False; |
| 219 |
|
| 220 |
ti->wptr = 0; |
| 221 |
ti->hptr = 0; |
| 222 |
ti->dptr = 0; |
| 223 |
ti->iptr = 0; |
| 224 |
|
| 225 |
ti->fntnum = -1; |
| 226 |
|
| 227 |
fnt->charlist = ti; |
| 228 |
|
| 229 |
return ti; |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
kern * |
| 234 |
newkern(void) |
| 235 |
{ |
| 236 |
register kern *nk; |
| 237 |
|
| 238 |
|
| 239 |
nk = (kern *)mymalloc(sizeof (kern)); |
| 240 |
nk->next = NULL; |
| 241 |
nk->succ = NULL; |
| 242 |
nk->delta = 0; |
| 243 |
|
| 244 |
return nk; |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
pcc * |
| 249 |
newpcc(void) |
| 250 |
{ |
| 251 |
register pcc *np; |
| 252 |
|
| 253 |
|
| 254 |
np = (pcc *)mymalloc(sizeof (pcc)); |
| 255 |
np->next = NULL; |
| 256 |
np->partname = NULL; |
| 257 |
np->xoffset = 0; |
| 258 |
np->yoffset = 0; |
| 259 |
|
| 260 |
return np; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
lig * |
| 265 |
newlig(void) |
| 266 |
{ |
| 267 |
register lig *nl; |
| 268 |
|
| 269 |
|
| 270 |
nl = (lig *)mymalloc(sizeof (lig)); |
| 271 |
nl->next = NULL; |
| 272 |
nl->succ = NULL; |
| 273 |
nl->sub = NULL; |
| 274 |
nl->op = 0; /* the default =: op */ |
| 275 |
nl->boundleft = 0; |
| 276 |
|
| 277 |
return nl; |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
stringlist * |
| 282 |
newstringlist(void) |
| 283 |
{ |
| 284 |
register stringlist *sl; |
| 285 |
|
| 286 |
|
| 287 |
sl = (stringlist *)mymalloc(sizeof (stringlist)); |
| 288 |
sl->next = NULL; |
| 289 |
sl->old_name = NULL; |
| 290 |
sl->new_name = NULL; |
| 291 |
sl->single_replacement = False; |
| 292 |
|
| 293 |
return sl; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
void |
| 298 |
init_font_structure(Font *fnt) |
| 299 |
{ |
| 300 |
int i; |
| 301 |
|
| 302 |
|
| 303 |
fnt->ttfname = NULL; |
| 304 |
|
| 305 |
fnt->tfm_path = NULL; |
| 306 |
fnt->tfm_ext = NULL; |
| 307 |
|
| 308 |
fnt->outname = NULL; |
| 309 |
fnt->subfont_name = NULL; |
| 310 |
fnt->outname_postfix = NULL; |
| 311 |
fnt->fullname = NULL; |
| 312 |
|
| 313 |
fnt->vplout = NULL; |
| 314 |
fnt->tfmout = NULL; |
| 315 |
|
| 316 |
fnt->inencname = NULL; |
| 317 |
fnt->inencoding = NULL; |
| 318 |
|
| 319 |
fnt->replacements = NULL; |
| 320 |
fnt->replacementname = NULL; |
| 321 |
|
| 322 |
fnt->outencname = NULL; |
| 323 |
fnt->outencoding = NULL; |
| 324 |
|
| 325 |
fnt->sfdname = NULL; |
| 326 |
|
| 327 |
fnt->sawligkern = False; |
| 328 |
fnt->subfont_ligs = False; |
| 329 |
fnt->ligname = NULL; |
| 330 |
fnt->write_enc = False; |
| 331 |
|
| 332 |
fnt->charlist = NULL; |
| 333 |
|
| 334 |
fnt->boundarychar = -1; |
| 335 |
fnt->codingscheme = default_codingscheme; |
| 336 |
fnt->titlebuf = NULL; |
| 337 |
|
| 338 |
fnt->cksum = 0; |
| 339 |
fnt->subfont_num = 0; |
| 340 |
fnt->subfont_list = NULL; |
| 341 |
|
| 342 |
fnt->units_per_em = 0; |
| 343 |
fnt->italicangle = 0.0; |
| 344 |
fnt->fixedpitch = 0; |
| 345 |
|
| 346 |
fnt->fontindex = 0; |
| 347 |
fnt->pid = 3; |
| 348 |
fnt->eid = 1; |
| 349 |
|
| 350 |
fnt->xheight = 0; |
| 351 |
fnt->fontspace = 0; |
| 352 |
|
| 353 |
fnt->y_offset = 0.25; |
| 354 |
|
| 355 |
fnt->efactor = 1.0; |
| 356 |
fnt->slant = 0; |
| 357 |
fnt->capheight = 0.8; |
| 358 |
fnt->PSnames = No; |
| 359 |
fnt->rotate = False; |
| 360 |
|
| 361 |
fnt->efactorparam = NULL; |
| 362 |
fnt->slantparam = NULL; |
| 363 |
fnt->fontindexparam = NULL; |
| 364 |
fnt->pidparam = NULL; |
| 365 |
fnt->eidparam = NULL; |
| 366 |
fnt->y_offsetparam = NULL; |
| 367 |
|
| 368 |
for (i = 0; i < 256; i++) |
| 369 |
{ |
| 370 |
fnt->inencptrs[i] = NULL; |
| 371 |
fnt->outencptrs[i] = NULL; |
| 372 |
fnt->uppercase[i] = NULL; |
| 373 |
fnt->lowercase[i] = NULL; |
| 374 |
fnt->sf_code[i] = -1; |
| 375 |
fnt->nextout[i] = -1; /* encoding chains have length 0 */ |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
/* end */ |