Debian Codegraph @

texk/web2c/mfluadir/otfcc/lib/otf-reader/otf-reader.c

raw
1 #include "support/util.h"
2 #include "otfcc/font.h"
3 #include "table/all.h"
4
5 #include "unconsolidate.h"
6
7 #define OTFCC_CHR(a,b,c,d) ( ((a)<<24) | ((b)<<16) | ((c)<<8) | (d) )
8
9 static otfcc_font_subtype decideFontSubtypeOTF(otfcc_SplineFontContainer *sfnt, uint32_t index) {
10 otfcc_Packet packet = sfnt->packets[index];
11 FOR_TABLE_SILENT(OTFCC_CHR('C','F','F',' '), table) {
12 return FONTTYPE_CFF;
13 }
14 return FONTTYPE_TTF;
15 }
16
17 static otfcc_Font *readOtf(void *_sfnt, uint32_t index, const otfcc_Options *options) {
18 otfcc_SplineFontContainer *sfnt = (otfcc_SplineFontContainer *)_sfnt;
19 if (sfnt->count - 1 < index) {
20 return NULL;
21 } else {
22 otfcc_Font *font = otfcc_iFont.create();
23 otfcc_Packet packet = sfnt->packets[index];
24 font->subtype = decideFontSubtypeOTF(sfnt, index);
25 font->fvar = otfcc_readFvar(packet, options);
26 font->head = otfcc_readHead(packet, options);
27 font->maxp = otfcc_readMaxp(packet, options);
28 font->name = otfcc_readName(packet, options);
29 font->meta = otfcc_readMeta(packet, options);
30 font->OS_2 = otfcc_readOS_2(packet, options);
31 font->post = otfcc_readPost(packet, options);
32 font->hhea = otfcc_readHhea(packet, options);
33 font->cmap = otfcc_readCmap(packet, options);
34 if (font->subtype == FONTTYPE_TTF) {
35 font->hmtx = otfcc_readHmtx(packet, options, font->hhea, font->maxp);
36 font->vhea = otfcc_readVhea(packet, options);
37 if (font->vhea) font->vmtx = otfcc_readVmtx(packet, options, font->vhea, font->maxp);
38 font->fpgm = otfcc_readFpgmPrep(packet, options, OTFCC_CHR('f','p','g','m'));
39 font->prep = otfcc_readFpgmPrep(packet, options, OTFCC_CHR('p','r','e','p'));
40 font->cvt_ = otfcc_readCvt(packet, options, OTFCC_CHR('c','v','t',' '));
41 font->gasp = otfcc_readGasp(packet, options);
42 font->VDMX = otfcc_readVDMX(packet, options);
43 font->LTSH = otfcc_readLTSH(packet, options);
44
45 GlyfIOContext ctx = {.locaIsLong = font->head->indexToLocFormat,
46 .numGlyphs = font->maxp->numGlyphs,
47 .nPhantomPoints = 4, // Since MS rasterizer v1.7,
48 // it would always add 4 phantom points
49 .fvar = font->fvar};
50 font->glyf = otfcc_readGlyf(packet, options, &ctx);
51 } else {
52 table_CFFAndGlyf cffpr = otfcc_readCFFAndGlyfTables(packet, options, font->head);
53 font->CFF_ = cffpr.meta;
54 font->glyf = cffpr.glyphs;
55 font->vhea = otfcc_readVhea(packet, options);
56 if (font->vhea) {
57 font->vmtx = otfcc_readVmtx(packet, options, font->vhea, font->maxp);
58 font->VORG = otfcc_readVORG(packet, options);
59 }
60 }
61 if (font->glyf) {
62 font->GSUB = otfcc_readOtl(packet, options, OTFCC_CHR('G','S','U','B'), font->glyf->length);
63 font->GPOS = otfcc_readOtl(packet, options, OTFCC_CHR('G','P','O','S'), font->glyf->length);
64 font->GDEF = otfcc_readGDEF(packet, options);
65 }
66 font->BASE = otfcc_readBASE(packet, options);
67
68 // Color font
69 font->CPAL = otfcc_readCPAL(packet, options);
70 font->COLR = otfcc_readCOLR(packet, options);
71 font->SVG_ = otfcc_readSVG(packet, options);
72
73 // VTT TSI entries
74 font->TSI_01 = otfcc_readTSI(packet, options, OTFCC_CHR('T','S','I','0'), OTFCC_CHR('T','S','I','1'));
75 font->TSI_23 = otfcc_readTSI(packet, options, OTFCC_CHR('T','S','I','2'), OTFCC_CHR('T','S','I','3'));
76 font->TSI5 = otfcc_readTSI5(packet, options);
77
78 otfcc_unconsolidateFont(font, options);
79 return font;
80 }
81 }
82 static INLINE void freeReader(otfcc_IFontBuilder *self) {
83 free(self);
84 }
85 otfcc_IFontBuilder *otfcc_newOTFReader() {
86 otfcc_IFontBuilder *reader;
87 NEW(reader);
88 reader->read = readOtf;
89 reader->free = freeReader;
90 return reader;
91 }