1 #include "SkEndian.h"
2 #include "SkSfntUtils.h"
3
parse_be16(const uint8_t * & p)4 static uint16_t parse_be16(const uint8_t*& p) {
5 uint16_t value = (p[0] << 8) | p[1];
6 p += 2;
7 return value;
8 }
9
parse_be32(const uint8_t * & p)10 static uint32_t parse_be32(const uint8_t*& p) {
11 uint32_t value = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
12 p += 4;
13 return value;
14 }
15
parse_be64(const uint8_t * & p)16 static Sk64 parse_be64(const uint8_t*& p) {
17 Sk64 value;
18 value.fHi = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
19 value.fLo = (p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7];
20 p += 8;
21 return value;
22 }
23
24 ///////////////////////////////////////////////////////////////////////////////
25
ReadTable_head(SkFontID fontID,SkSfntTable_head * head)26 bool SkSfntUtils::ReadTable_head(SkFontID fontID, SkSfntTable_head* head) {
27 static const uint32_t gTag = SkSetFourByteTag('h', 'e', 'a', 'd');
28 static const size_t gSize = 54;
29
30 uint8_t storage[gSize];
31 size_t size = SkFontHost::GetTableData(fontID, gTag, 0, gSize, storage);
32 if (size != gSize) {
33 return false;
34 }
35
36 const uint8_t* p = storage;
37 head->fVersion = parse_be32(p);
38 head->fRevision = parse_be32(p);
39 head->fCheckSumAdjustment = parse_be32(p);
40 head->fMagicNumber = parse_be32(p);
41 head->fFlags = parse_be16(p);
42 head->fUnitsPerEm = parse_be16(p);
43 head->fDateCreated = parse_be64(p);
44 head->fDateModified = parse_be64(p);
45 head->fXMin = parse_be16(p);
46 head->fXMin = parse_be16(p);
47 head->fXMin = parse_be16(p);
48 head->fXMin = parse_be16(p);
49 head->fMacStyle = parse_be16(p);
50 head->fLowestPPEM = parse_be16(p);
51 head->fFontDirectionHint = parse_be16(p);
52 head->fIndexToLocFormat = parse_be16(p);
53 head->fGlyphDataFormat = parse_be16(p);
54 SkASSERT(p - storage == (long)size);
55 return true;
56 }
57
ReadTable_maxp(SkFontID fontID,SkSfntTable_maxp * maxp)58 bool SkSfntUtils::ReadTable_maxp(SkFontID fontID, SkSfntTable_maxp* maxp) {
59 static const uint32_t gTag = SkSetFourByteTag('m', 'a', 'x', 'p');
60 static const size_t gSize = 32;
61
62 uint8_t storage[gSize];
63 size_t size = SkFontHost::GetTableData(fontID, gTag, 0, gSize, storage);
64 if (size != gSize) {
65 return false;
66 }
67
68 const uint8_t* p = storage;
69 maxp->fVersion = parse_be32(p);
70 maxp->fNumGlyphs = parse_be16(p);
71 maxp->fMaxPoints = parse_be16(p);
72 maxp->fMaxContours = parse_be16(p);
73 maxp->fMaxComponentPoints = parse_be16(p);
74 maxp->fMaxComponentContours = parse_be16(p);
75 maxp->fMaxZones = parse_be16(p);
76 maxp->fMaxTwilightPoints = parse_be16(p);
77 maxp->fMaxStorage = parse_be16(p);
78 maxp->fMaxFunctionDefs = parse_be16(p);
79 maxp->fMaxInstructionDefs = parse_be16(p);
80 maxp->fMaxStackElements = parse_be16(p);
81 maxp->fMaxSizeOfInstructions = parse_be16(p);
82 maxp->fMaxComponentElements = parse_be16(p);
83 maxp->fMaxComponentDepth = parse_be16(p);
84 SkASSERT(p - storage == (long)size);
85 return true;
86 }
87
88