Home | History | Annotate | Download | only in utils
      1 
      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  */
      8 #include "SkEndian.h"
      9 #include "SkSfntUtils.h"
     10 
     11 static 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 
     17 static 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 
     23 static 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 
     33 bool SkSfntUtils::ReadTable_head(SkFontID fontID, SkSfntTable_head* head) {
     34     static const uint32_t gTag = SkSetFourByteTag('h', 'e', 'a', 'd');
     35     static const size_t gSize = 54;
     36 
     37     uint8_t storage[gSize];
     38     size_t size = SkFontHost::GetTableData(fontID, gTag, 0, gSize, storage);
     39     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);
     61     SkASSERT(p - storage == (long)size);
     62     return true;
     63 }
     64 
     65 bool SkSfntUtils::ReadTable_maxp(SkFontID fontID, SkSfntTable_maxp* maxp) {
     66     static const uint32_t gTag = SkSetFourByteTag('m', 'a', 'x', 'p');
     67     static const size_t gSize = 32;
     68 
     69     uint8_t storage[gSize];
     70     size_t size = SkFontHost::GetTableData(fontID, gTag, 0, gSize, storage);
     71     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);
     91     SkASSERT(p - storage == (long)size);
     92     return true;
     93 }
     94 
     95