Debian Codegraph @

texk/ttfdump/libttf/ttc.c

raw
1 /* ttc.c -- True Type Collection Support
2 * Copyright (C) 1997 Li-Da Lho, All right reserved
3 */
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 #include "ttf.h"
13 #include "ttfutil.h"
14 #include "ttc.h"
15
16 /* $Id: ttc.c,v 1.1.1.1 1998/06/05 07:47:52 robert Exp $ */
17
18 static void ttfLoadTTCFont(TTCHeaderPtr ttc, FILE *fp, const char *filename);
19
20 TTCHeaderPtr ttfLoadTTCHeader(char * filename)
21 {
22 ULONG tag = FT_MAKE_TAG ('t', 't', 'c', 'f');
23 TTCHeaderPtr ttc;
24 FILE *fp;
25
26 if ((fp = fopen_truetype (filename)) == NULL)
27 {
28 fprintf(stderr,"Can't open ttc file %s\n",filename);
29 return NULL;
30 }
31 ttc = XCALLOC1 (TTCHeader);
32
33 /* True Type Collection's TTCHeader */
34 if ((ttc->TTCTag = ttfGetULONG(fp)) == tag)
35 {
36 ttc->version = ttfGetFixed(fp);
37 ttc->DirCount = (USHORT) ttfGetULONG(fp);
38 ttc->offset = ttfMakeULONG (ttc->DirCount, fp);
39 ttfLoadTTCFont(ttc,fp,filename);
40 return ttc;
41 }
42 else
43 /* a file with ttc in name but no ttc tag in it */
44 return NULL;
45 }
46
47 static void ttfLoadTTCFont(TTCHeaderPtr ttc,FILE *fp,const char *filename)
48 {
49 unsigned int i;
50
51 ttc->font = XCALLOC (ttc->DirCount, TTFont);
52
53 /* currently, we are loading all fonts in a TTC file.
54 * I still can't find a good way to share the data. */
55 for (i=0;i<ttc->DirCount;i++)
56 {
57 (ttc->font+i) -> fp = fp;
58 (ttc->font+i) -> ttfname = XTALLOC (strlen(filename)+16, char);
59 sprintf ((ttc->font+i)->ttfname, "%s:%u", filename, i);
60 ttfLoadFont((ttc->font+i),(ttc->offset)[i]);
61 }
62 }
63
64 void ttfFreeTTCFont(TTCHeaderPtr ttc)
65 {
66 int i;
67
68 for (i=0;i<ttc->DirCount;i++)
69 {
70 ttfFreeRequiredTables(ttc->font+i);
71
72 ttfFreeOptionalTables(ttc->font+i);
73
74 ttfFreeTableDir((ttc->font+i)->dir);
75 free((ttc->font+i)->refcount);
76 }
77
78 free(ttc->offset);
79 free(ttc->font);
80 free(ttc);
81 }