xref: /aosp_15_r20/external/skia/src/sfnt/SkOTTable_sbix.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2024 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_sbix_DEFINED
9 #define SkOTTable_sbix_DEFINED
10 
11 #include "include/private/base/SkTemplates.h"
12 #include "src/base/SkUtils.h"
13 #include "src/sfnt/SkOTTableTypes.h"
14 
15 #pragma pack(push, 1)
16 
17 struct SkOTTableGlyphData;
18 
19 struct SkOTTableStandardBitmapGraphics {
20     static const SK_OT_CHAR TAG0 = 's';
21     static const SK_OT_CHAR TAG1 = 'b';
22     static const SK_OT_CHAR TAG2 = 'i';
23     static const SK_OT_CHAR TAG3 = 'x';
24     static const SK_OT_ULONG TAG = SkOTTableTAG<SkOTTableStandardBitmapGraphics>::value;
25 
26     SK_OT_USHORT version; // 1
27     SK_OT_USHORT flags;	// Bit 0: 1. Bit 1: Draw outlines. Bits 2 to 15: reserved (set to 0)
28     SK_OT_ULONG numStrikes;
29     //SK_OT_ULONG strikeOffsets[/*numStrikes*/]; // offset from sbix table to Strike
strikeOffsetSkOTTableStandardBitmapGraphics30     SK_OT_ULONG strikeOffset(int strikeIndex) {
31         return sk_unaligned_load<SK_OT_ULONG>(
32             SkTAddOffset<void*>(&numStrikes, sizeof(numStrikes)+sizeof(SK_OT_ULONG)*strikeIndex));
33     }
34 
35     struct Strike {
36         SK_OT_USHORT ppem; // pixels for em
37         SK_OT_USHORT ppi; // design pixel density
38         //SK_OT_ULONG glyphDataOffsets[/*numGlyphs+1*/]; // offset from Strike to GlyphData
glyphDataOffsetSkOTTableStandardBitmapGraphics::Strike39         SK_OT_ULONG glyphDataOffset(int glyphId) {
40             return sk_unaligned_load<SK_OT_ULONG>(
41                 SkTAddOffset<void*>(&ppi, sizeof(ppi)+sizeof(SK_OT_ULONG)*glyphId));
42         }
43     };
44 
45     struct GlyphData {
46         SK_OT_SHORT originOffsetX; // x offset of bitmap in pixels
47         SK_OT_SHORT originOffsetY; // y offset of bitmap in pixels (y-up)
48         SK_OT_ULONG graphicType; // 'jpg ', 'png ', 'tiff', or 'dupe'
49         //SK_OT_BYTE data[]; // length is to next glyphDataOffsets entry
dataSkOTTableStandardBitmapGraphics::GlyphData50         SK_OT_BYTE* data() { return SkTAfter<SK_OT_BYTE>(&graphicType); }
dataSkOTTableStandardBitmapGraphics::GlyphData51         const SK_OT_BYTE* data() const { return SkTAfter<const SK_OT_BYTE>(&graphicType); }
52     };
53 };
54 
55 #pragma pack(pop)
56 
57 #endif
58