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