[doc] Improve formatting of tables in HTML format.
[ttfautohint.git] / lib / tafont.c
blob0aea304c2610b56308f3c592997eb1f8c969973b
1 /* tafont.c */
3 /*
4 * Copyright (C) 2011-2013 by Werner Lemberg.
6 * This file is part of the ttfautohint library, and may only be used,
7 * modified, and distributed under the terms given in `COPYING'. By
8 * continuing to use, modify, or distribute this file you indicate that you
9 * have read `COPYING' and understand and accept it fully.
11 * The file `COPYING' mentioned in the previous paragraph is distributed
12 * with the ttfautohint library.
16 #include "ta.h"
19 FT_Error
20 TA_font_init(FONT* font)
22 FT_Error error;
23 FT_Face f;
24 FT_Int major, minor, patch;
27 error = FT_Init_FreeType(&font->lib);
28 if (error)
29 return error;
31 /* assure correct FreeType version to avoid using the wrong DLL */
32 FT_Library_Version(font->lib, &major, &minor, &patch);
33 if (((major*1000 + minor)*1000 + patch) < 2004005)
34 return TA_Err_Invalid_FreeType_Version;
36 /* get number of faces (i.e. subfonts) */
37 error = FT_New_Memory_Face(font->lib, font->in_buf, font->in_len, -1, &f);
38 if (error)
39 return error;
40 font->num_sfnts = f->num_faces;
41 FT_Done_Face(f);
43 /* it is a TTC if we have more than a single subfont */
44 font->sfnts = (SFNT*)calloc(1, font->num_sfnts * sizeof (SFNT));
45 if (!font->sfnts)
46 return FT_Err_Out_Of_Memory;
48 return TA_Err_Ok;
52 void
53 TA_font_unload(FONT* font,
54 const char* in_buf,
55 char** out_bufp)
57 /* in case of error it is expected that unallocated pointers */
58 /* are NULL (and counters are zero) */
60 if (!font)
61 return;
63 if (font->loader)
64 ta_loader_done(font);
66 if (font->tables)
68 FT_ULong i;
71 for (i = 0; i < font->num_tables; i++)
73 free(font->tables[i].buf);
74 if (font->tables[i].data)
76 if (font->tables[i].tag == TTAG_glyf)
78 glyf_Data* data = (glyf_Data*)font->tables[i].data;
79 FT_UShort j;
82 for (j = 0; j < data->num_glyphs; j++)
84 free(data->glyphs[j].buf);
85 free(data->glyphs[j].ins_buf);
86 free(data->glyphs[j].components);
87 free(data->glyphs[j].pointsums);
89 free(data->glyphs);
90 free(data);
94 free(font->tables);
97 if (font->sfnts)
99 FT_Long i;
102 for (i = 0; i < font->num_sfnts; i++)
104 FT_Done_Face(font->sfnts[i].face);
105 free(font->sfnts[i].table_infos);
107 free(font->sfnts);
110 number_set_free(font->x_height_snapping_exceptions);
112 FT_Done_FreeType(font->lib);
113 if (!in_buf)
114 free(font->in_buf);
115 if (!out_bufp)
116 free(font->out_buf);
117 free(font);
120 /* end of tafont.c */