• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_FONT_HEADER_TABLE_H_
18 #define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_FONT_HEADER_TABLE_H_
19 
20 #include "sfntly/table/table.h"
21 #include "sfntly/table/table_based_table_builder.h"
22 
23 namespace sfntly {
24 
25 struct IndexToLocFormat {
26   enum {
27     kInvalidOffset = -1,
28     kShortOffset = 0,
29     kLongOffset = 1
30   };
31 };
32 
33 struct FontDirectionHint {
34   enum {
35     kFullyMixed = 0,
36     kOnlyStrongLTR = 1,
37     kStrongLTRAndNeutral = 2,
38     kOnlyStrongRTL = -1,
39     kStrongRTLAndNeutral = -2
40   };
41 };
42 
43 class FontHeaderTable : public Table, public RefCounted<FontHeaderTable> {
44  public:
45   class Builder : public TableBasedTableBuilder, public RefCounted<Builder> {
46    public:
47     // Constructor scope altered to public because C++ does not allow base
48     // class to instantiate derived class with protected constructors.
49     Builder(Header* header, WritableFontData* data);
50     Builder(Header* header, ReadableFontData* data);
51     virtual ~Builder();
52     virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data);
53 
54     virtual int32_t TableVersion();
55     virtual void SetTableVersion(int32_t version);
56     virtual int32_t FontRevision();
57     virtual void SetFontRevision(int32_t revision);
58     virtual int64_t ChecksumAdjustment();
59     virtual void SetChecksumAdjustment(int64_t adjustment);
60     virtual int64_t MagicNumber();
61     virtual void SetMagicNumber(int64_t magic_number);
62     virtual int32_t FlagsAsInt();
63     virtual void SetFlagsAsInt(int32_t flags);
64     // TODO(arthurhsu): IMPLEMENT EnumSet<Flags> Flags()
65     // TODO(arthurhsu): IMPLEMENT setFlags(EnumSet<Flags> flags)
66     virtual int32_t UnitsPerEm();
67     virtual void SetUnitsPerEm(int32_t units);
68     virtual int64_t Created();
69     virtual void SetCreated(int64_t date);
70     virtual int64_t Modified();
71     virtual void SetModified(int64_t date);
72     virtual int32_t XMin();
73     virtual void SetXMin(int32_t xmin);
74     virtual int32_t YMin();
75     virtual void SetYMin(int32_t ymin);
76     virtual int32_t XMax();
77     virtual void SetXMax(int32_t xmax);
78     virtual int32_t YMax();
79     virtual void SetYMax(int32_t ymax);
80     virtual int32_t MacStyleAsInt();
81     virtual void SetMacStyleAsInt(int32_t style);
82     // TODO(arthurhsu): IMPLEMENT EnumSet<MacStyle> macStyle()
83     // TODO(arthurhsu): IMPLEMENT setMacStyle(EnumSet<MacStyle> style)
84     virtual int32_t LowestRecPPEM();
85     virtual void SetLowestRecPPEM(int32_t size);
86     virtual int32_t FontDirectionHint();
87     virtual void SetFontDirectionHint(int32_t hint);
88     virtual int32_t IndexToLocFormat();
89     virtual void SetIndexToLocFormat(int32_t format);
90     virtual int32_t GlyphDataFormat();
91     virtual void SetGlyphDataFormat(int32_t format);
92 
93     static CALLER_ATTACH Builder* CreateBuilder(Header* header,
94                                                 WritableFontData* data);
95   };
96 
97   virtual ~FontHeaderTable();
98   int32_t TableVersion();
99   int32_t FontRevision();
100 
101   // Get the checksum adjustment. To compute: set it to 0, sum the entire font
102   // as ULONG, then store 0xB1B0AFBA - sum.
103   int64_t ChecksumAdjustment();
104 
105   // Get the magic number. Set to 0x5F0F3CF5.
106   int64_t MagicNumber();
107 
108   // TODO(arthurhsu): IMPLEMENT: EnumSet<Flags>
109   int32_t FlagsAsInt();
110   // TODO(arthurhsu): IMPLEMENT: Flags() returning EnumSet<Flags>
111 
112   int32_t UnitsPerEm();
113 
114   // Get the created date. Number of seconds since 12:00 midnight, January 1,
115   // 1904. 64-bit integer.
116   int64_t Created();
117   // Get the modified date. Number of seconds since 12:00 midnight, January 1,
118   // 1904. 64-bit integer.
119   int64_t Modified();
120 
121   // Get the x min. For all glyph bounding boxes.
122   int32_t XMin();
123   // Get the y min. For all glyph bounding boxes.
124   int32_t YMin();
125   // Get the x max. For all glyph bounding boxes.
126   int32_t XMax();
127   // Get the y max. For all glyph bounding boxes.
128   int32_t YMax();
129 
130   // TODO(arthurhsu): IMPLEMENT: EnumSet<MacStyle>
131   int32_t MacStyleAsInt();
132   // TODO(arthurhsu): IMPLEMENT: macStyle() returning EnumSet<MacStyle>
133 
134   int32_t LowestRecPPEM();
135   int32_t FontDirectionHint();  // Note: no AsInt() form, already int
136   int32_t IndexToLocFormat();  // Note: no AsInt() form, already int
137   int32_t GlyphDataFormat();
138 
139  private:
140   struct Offset {
141     enum {
142       kTableVersion = 0,
143       kFontRevision = 4,
144       kCheckSumAdjustment = 8,
145       kMagicNumber = 12,
146       kFlags = 16,
147       kUnitsPerEm = 18,
148       kCreated = 20,
149       kModified = 28,
150       kXMin = 36,
151       kYMin = 38,
152       kXMax = 40,
153       kYMax = 42,
154       kMacStyle = 44,
155       kLowestRecPPEM = 46,
156       kFontDirectionHint = 48,
157       kIndexToLocFormat = 50,
158       kGlyphDataFormat = 52
159     };
160   };
161 
162   FontHeaderTable(Header* header, ReadableFontData* data);
163 };
164 typedef Ptr<FontHeaderTable> FontHeaderTablePtr;
165 typedef Ptr<FontHeaderTable::Builder> FontHeaderTableBuilderPtr;
166 
167 }  // namespace sfntly
168 
169 #endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_FONT_HEADER_TABLE_H_
170