Synchronize with FreeType.
[ttfautohint.git] / lib / tafont.c
blob852f1dbc69a434858f33431207423f7de3a2e49e
1 /* tafont.c */
3 /*
4 * Copyright (C) 2011-2016 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,
38 font->in_buf,
39 (FT_Long)font->in_len,
40 -1,
41 &f);
42 if (error)
43 return error;
44 font->num_sfnts = f->num_faces;
45 FT_Done_Face(f);
47 /* it is a TTC if we have more than a single subfont */
48 font->sfnts = (SFNT*)calloc(1, (size_t)font->num_sfnts * sizeof (SFNT));
49 if (!font->sfnts)
50 return FT_Err_Out_Of_Memory;
52 return TA_Err_Ok;
56 void
57 TA_font_unload(FONT* font,
58 const char* in_buf,
59 char** out_bufp,
60 const char* control_buf)
62 /* in case of error it is expected that unallocated pointers */
63 /* are NULL (and counters are zero) */
65 if (!font)
66 return;
68 if (font->loader)
69 ta_loader_done(font);
71 if (font->tables)
73 FT_ULong i;
76 for (i = 0; i < font->num_tables; i++)
78 free(font->tables[i].buf);
79 if (font->tables[i].data)
81 if (font->tables[i].tag == TTAG_glyf)
83 glyf_Data* data = (glyf_Data*)font->tables[i].data;
84 FT_UShort j;
87 for (j = 0; j < data->num_glyphs; j++)
89 free(data->glyphs[j].buf);
90 free(data->glyphs[j].ins_buf);
91 free(data->glyphs[j].ins_extra_buf);
92 free(data->glyphs[j].components);
93 free(data->glyphs[j].pointsums);
95 free(data->glyphs);
96 free(data);
100 free(font->tables);
103 if (font->sfnts)
105 FT_Long i;
108 for (i = 0; i < font->num_sfnts; i++)
110 FT_Done_Face(font->sfnts[i].face);
111 free(font->sfnts[i].table_infos);
113 free(font->sfnts);
116 number_set_free(font->x_height_snapping_exceptions);
118 FT_Done_FreeType(font->lib);
120 /* in case the user provided file handles, */
121 /* free the allocated buffers for the file contents */
122 if (!in_buf)
123 free(font->in_buf);
124 if (!out_bufp)
125 free(font->out_buf);
126 if (!control_buf)
127 free(font->control_buf);
128 free(font);
131 /* end of tafont.c */