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