Home | History | Annotate | Download | only in sfnt
      1 /*
      2  * Copyright 2014 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkOTTable_EBLC_DEFINED
      9 #define SkOTTable_EBLC_DEFINED
     10 
     11 #include "SkEndian.h"
     12 #include "SkOTTable_EBDT.h"
     13 #include "SkOTTableTypes.h"
     14 
     15 #pragma pack(push, 1)
     16 
     17 struct SkOTTableEmbeddedBitmapLocation {
     18     static const SK_OT_CHAR TAG0 = 'E';
     19     static const SK_OT_CHAR TAG1 = 'B';
     20     static const SK_OT_CHAR TAG2 = 'L';
     21     static const SK_OT_CHAR TAG3 = 'C';
     22     static const SK_OT_ULONG TAG = SkOTTableTAG<SkOTTableEmbeddedBitmapLocation>::value;
     23 
     24     SK_OT_Fixed version;
     25     static const SK_OT_Fixed version_initial = SkTEndian_SwapBE32(0x00020000);
     26 
     27     SK_OT_ULONG numSizes;
     28 
     29     struct SbitLineMetrics {
     30         SK_OT_CHAR ascender;
     31         SK_OT_CHAR descender;
     32         SK_OT_BYTE widthMax;
     33         SK_OT_CHAR caretSlopeNumerator;
     34         SK_OT_CHAR caretSlopeDenominator;
     35         SK_OT_CHAR caretOffset;
     36         SK_OT_CHAR minOriginSB;
     37         SK_OT_CHAR minAdvanceSB;
     38         SK_OT_CHAR maxBeforeBL;
     39         SK_OT_CHAR minAfterBL;
     40         SK_OT_CHAR pad1;
     41         SK_OT_CHAR pad2;
     42     };
     43 
     44     struct BitmapSizeTable {
     45         SK_OT_ULONG indexSubTableArrayOffset; //offset to indexSubtableArray from beginning of EBLC.
     46         SK_OT_ULONG indexTablesSize; //number of bytes in corresponding index subtables and array
     47         SK_OT_ULONG numberOfIndexSubTables; //an index subtable for each range or format change
     48         SK_OT_ULONG colorRef; //not used; set to 0.
     49         SbitLineMetrics hori; //line metrics for text rendered horizontally
     50         SbitLineMetrics vert; //line metrics for text rendered vertically
     51         SK_OT_USHORT startGlyphIndex; //lowest glyph index for this size
     52         SK_OT_USHORT endGlyphIndex; //highest glyph index for this size
     53         SK_OT_BYTE ppemX; //horizontal pixels per Em
     54         SK_OT_BYTE ppemY; //vertical pixels per Em
     55         struct BitDepth {
     56             enum Value : SK_OT_BYTE {
     57                 BW = 1,
     58                 Gray4 = 2,
     59                 Gray16 = 4,
     60                 Gray256 = 8,
     61             };
     62             SK_OT_BYTE value;
     63         } bitDepth; //the Microsoft rasterizer v.1.7 or greater supports
     64         union Flags {
     65             struct Field {
     66                 //0-7
     67                 SK_OT_BYTE_BITFIELD(
     68                     Horizontal, // Horizontal small glyph metrics
     69                     Vertical,  // Vertical small glyph metrics
     70                     Reserved02,
     71                     Reserved03,
     72                     Reserved04,
     73                     Reserved05,
     74                     Reserved06,
     75                     Reserved07)
     76             } field;
     77             struct Raw {
     78                 static const SK_OT_CHAR Horizontal = 1u << 0;
     79                 static const SK_OT_CHAR Vertical = 1u << 1;
     80                 SK_OT_CHAR value;
     81             } raw;
     82         } flags;
     83     }; //bitmapSizeTable[numSizes];
     84 
     85     struct IndexSubTableArray {
     86         SK_OT_USHORT firstGlyphIndex; //first glyph code of this range
     87         SK_OT_USHORT lastGlyphIndex; //last glyph code of this range (inclusive)
     88         SK_OT_ULONG additionalOffsetToIndexSubtable; //add to BitmapSizeTable::indexSubTableArrayOffset to get offset from beginning of 'EBLC'
     89     }; //indexSubTableArray[BitmapSizeTable::numberOfIndexSubTables];
     90 
     91     struct IndexSubHeader {
     92         SK_OT_USHORT indexFormat; //format of this indexSubTable
     93         SK_OT_USHORT imageFormat; //format of 'EBDT' image data
     94         SK_OT_ULONG imageDataOffset; //offset to image data in 'EBDT' table
     95     };
     96 
     97     // Variable metrics glyphs with 4 byte offsets
     98     struct IndexSubTable1 {
     99         IndexSubHeader header;
    100         //SK_OT_ULONG offsetArray[lastGlyphIndex - firstGlyphIndex + 1 + 1]; //last element points to one past end of last glyph
    101         //glyphData = offsetArray[glyphIndex - firstGlyphIndex] + imageDataOffset
    102     };
    103 
    104     // All Glyphs have identical metrics
    105     struct IndexSubTable2 {
    106         IndexSubHeader header;
    107         SK_OT_ULONG imageSize; // all glyphs are of the same size
    108         SkOTTableEmbeddedBitmapData::BigGlyphMetrics bigMetrics; // all glyphs have the same metrics; glyph data may be compressed, byte-aligned, or bit-aligned
    109     };
    110 
    111     // Variable metrics glyphs with 2 byte offsets
    112     struct IndexSubTable3 {
    113         IndexSubHeader header;
    114         //SK_OT_USHORT offsetArray[lastGlyphIndex - firstGlyphIndex + 1 + 1]; //last element points to one past end of last glyph, may have extra element to force even number of elements
    115         //glyphData = offsetArray[glyphIndex - firstGlyphIndex] + imageDataOffset
    116     };
    117 
    118     // Variable metrics glyphs with sparse glyph codes
    119     struct IndexSubTable4 {
    120         IndexSubHeader header;
    121         SK_OT_ULONG numGlyphs;
    122         struct CodeOffsetPair {
    123             SK_OT_USHORT glyphCode;
    124             SK_OT_USHORT offset; //location in EBDT
    125         }; //glyphArray[numGlyphs+1]
    126     };
    127 
    128     // Constant metrics glyphs with sparse glyph codes
    129     struct IndexSubTable5 {
    130         IndexSubHeader header;
    131         SK_OT_ULONG imageSize; //all glyphs have the same data size
    132         SkOTTableEmbeddedBitmapData::BigGlyphMetrics bigMetrics; //all glyphs have the same metrics
    133         SK_OT_ULONG numGlyphs;
    134         //SK_OT_USHORT glyphCodeArray[numGlyphs] //must have even number of entries (set pad to 0)
    135     };
    136 
    137     union IndexSubTable {
    138         IndexSubHeader header;
    139         IndexSubTable1 format1;
    140         IndexSubTable2 format2;
    141         IndexSubTable3 format3;
    142         IndexSubTable4 format4;
    143         IndexSubTable5 format5;
    144     };
    145 
    146 };
    147 
    148 #pragma pack(pop)
    149 
    150 #endif
    151