blob: 54f7cc33aaf65752ef24af7dcb4dc1e2e2c99368 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.com9781ca52009-04-14 14:28:22 +00008#include "SkEndian.h"
9#include "SkSfntUtils.h"
10
11static uint16_t parse_be16(const uint8_t*& p) {
12 uint16_t value = (p[0] << 8) | p[1];
13 p += 2;
14 return value;
15}
16
17static uint32_t parse_be32(const uint8_t*& p) {
18 uint32_t value = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
19 p += 4;
20 return value;
21}
22
23static Sk64 parse_be64(const uint8_t*& p) {
24 Sk64 value;
25 value.fHi = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
26 value.fLo = (p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7];
27 p += 8;
28 return value;
29}
30
31///////////////////////////////////////////////////////////////////////////////
32
33bool SkSfntUtils::ReadTable_head(SkFontID fontID, SkSfntTable_head* head) {
34 static const uint32_t gTag = SkSetFourByteTag('h', 'e', 'a', 'd');
reed@android.com9e0c2fc2009-06-02 18:54:28 +000035 static const size_t gSize = 54;
reed@android.com9781ca52009-04-14 14:28:22 +000036
37 uint8_t storage[gSize];
reed@android.com9e0c2fc2009-06-02 18:54:28 +000038 size_t size = SkFontHost::GetTableData(fontID, gTag, 0, gSize, storage);
reed@android.com9781ca52009-04-14 14:28:22 +000039 if (size != gSize) {
40 return false;
41 }
42
43 const uint8_t* p = storage;
44 head->fVersion = parse_be32(p);
45 head->fRevision = parse_be32(p);
46 head->fCheckSumAdjustment = parse_be32(p);
47 head->fMagicNumber = parse_be32(p);
48 head->fFlags = parse_be16(p);
49 head->fUnitsPerEm = parse_be16(p);
50 head->fDateCreated = parse_be64(p);
51 head->fDateModified = parse_be64(p);
52 head->fXMin = parse_be16(p);
53 head->fXMin = parse_be16(p);
54 head->fXMin = parse_be16(p);
55 head->fXMin = parse_be16(p);
56 head->fMacStyle = parse_be16(p);
57 head->fLowestPPEM = parse_be16(p);
58 head->fFontDirectionHint = parse_be16(p);
59 head->fIndexToLocFormat = parse_be16(p);
60 head->fGlyphDataFormat = parse_be16(p);
reed@android.comf2afb672009-09-28 16:12:48 +000061 SkASSERT(p - storage == (long)size);
reed@android.com9781ca52009-04-14 14:28:22 +000062 return true;
63}
64
65bool SkSfntUtils::ReadTable_maxp(SkFontID fontID, SkSfntTable_maxp* maxp) {
66 static const uint32_t gTag = SkSetFourByteTag('m', 'a', 'x', 'p');
reed@android.com9e0c2fc2009-06-02 18:54:28 +000067 static const size_t gSize = 32;
reed@android.com9781ca52009-04-14 14:28:22 +000068
69 uint8_t storage[gSize];
reed@android.com9e0c2fc2009-06-02 18:54:28 +000070 size_t size = SkFontHost::GetTableData(fontID, gTag, 0, gSize, storage);
reed@android.com9781ca52009-04-14 14:28:22 +000071 if (size != gSize) {
72 return false;
73 }
74
75 const uint8_t* p = storage;
76 maxp->fVersion = parse_be32(p);
77 maxp->fNumGlyphs = parse_be16(p);
78 maxp->fMaxPoints = parse_be16(p);
79 maxp->fMaxContours = parse_be16(p);
80 maxp->fMaxComponentPoints = parse_be16(p);
81 maxp->fMaxComponentContours = parse_be16(p);
82 maxp->fMaxZones = parse_be16(p);
83 maxp->fMaxTwilightPoints = parse_be16(p);
84 maxp->fMaxStorage = parse_be16(p);
85 maxp->fMaxFunctionDefs = parse_be16(p);
86 maxp->fMaxInstructionDefs = parse_be16(p);
87 maxp->fMaxStackElements = parse_be16(p);
88 maxp->fMaxSizeOfInstructions = parse_be16(p);
89 maxp->fMaxComponentElements = parse_be16(p);
90 maxp->fMaxComponentDepth = parse_be16(p);
reed@android.comf2afb672009-09-28 16:12:48 +000091 SkASSERT(p - storage == (long)size);
reed@android.com9781ca52009-04-14 14:28:22 +000092 return true;
93}
94