• 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     kShortOffset = 0,
28     kLongOffset = 1
29   };
30 };
31 
32 struct FontDirectionHint {
33   enum {
34     kFullyMixed = 0,
35     kOnlyStrongLTR = 1,
36     kStrongLTRAndNeutral = 2,
37     kOnlyStrongRTL = -1,
38     kStrongRTLAndNeutral = -2
39   };
40 };
41 
42 class FontHeaderTable : public Table, public RefCounted<FontHeaderTable> {
43  public:
44   class Builder : public TableBasedTableBuilder, public RefCounted<Builder> {
45    public:
46     // Constructor scope altered to public because C++ does not allow base
47     // class to instantiate derived class with protected constructors.
48     Builder(Header* header, WritableFontData* data);
49     Builder(Header* header, ReadableFontData* data);
50     virtual ~Builder();
51     virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data);
52 
53     virtual int32_t TableVersion();
54     virtual void SetTableVersion(int32_t version);
55     virtual int32_t FontRevision();
56     virtual void SetFontRevision(int32_t revision);
57     virtual int64_t ChecksumAdjustment();
58     virtual void SetChecksumAdjustment(int64_t adjustment);
59     virtual int64_t MagicNumber();
60     virtual void SetMagicNumber(int64_t magic_number);
61     virtual int32_t FlagsAsInt();
62     virtual void SetFlagsAsInt(int32_t flags);
63     // TODO(arthurhsu): IMPLEMENT EnumSet<Flags> Flags()
64     // TODO(arthurhsu): IMPLEMENT setFlags(EnumSet<Flags> flags)
65     virtual int32_t UnitsPerEm();
66     virtual void SetUnitsPerEm(int32_t units);
67     virtual int64_t Created();
68     virtual void SetCreated(int64_t date);
69     virtual int64_t Modified();
70     virtual void SetModified(int64_t date);
71     virtual int32_t XMin();
72     virtual void SetXMin(int32_t xmin);
73     virtual int32_t YMin();
74     virtual void SetYMin(int32_t ymin);
75     virtual int32_t XMax();
76     virtual void SetXMax(int32_t xmax);
77     virtual int32_t YMax();
78     virtual void SetYMax(int32_t ymax);
79     virtual int32_t MacStyleAsInt();
80     virtual void SetMacStyleAsInt(int32_t style);
81     // TODO(arthurhsu): IMPLEMENT EnumSet<MacStyle> macStyle()
82     // TODO(arthurhsu): IMPLEMENT setMacStyle(EnumSet<MacStyle> style)
83     virtual int32_t LowestRecPPEM();
84     virtual void SetLowestRecPPEM(int32_t size);
85     virtual int32_t FontDirectionHint();
86     virtual void SetFontDirectionHint(int32_t hint);
87     virtual int32_t IndexToLocFormat();
88     virtual void SetIndexToLocFormat(int32_t format);
89     virtual int32_t GlyphDataFormat();
90     virtual void SetGlyphDataFormat(int32_t format);
91 
92     static CALLER_ATTACH Builder* CreateBuilder(Header* header,
93                                                 WritableFontData* data);
94   };
95 
96   virtual ~FontHeaderTable();
97   int32_t TableVersion();
98   int32_t FontRevision();
99 
100   // Get the checksum adjustment. To compute: set it to 0, sum the entire font
101   // as ULONG, then store 0xB1B0AFBA - sum.
102   int64_t ChecksumAdjustment();
103 
104   // Get the magic number. Set to 0x5F0F3CF5.
105   int64_t MagicNumber();
106 
107   // TODO(arthurhsu): IMPLEMENT: EnumSet<Flags>
108   int32_t FlagsAsInt();
109   // TODO(arthurhsu): IMPLEMENT: Flags() returning EnumSet<Flags>
110 
111   int32_t UnitsPerEm();
112 
113   // Get the created date. Number of seconds since 12:00 midnight, January 1,
114   // 1904. 64-bit integer.
115   int64_t Created();
116   // Get the modified date. Number of seconds since 12:00 midnight, January 1,
117   // 1904. 64-bit integer.
118   int64_t Modified();
119 
120   // Get the x min. For all glyph bounding boxes.
121   int32_t XMin();
122   // Get the y min. For all glyph bounding boxes.
123   int32_t YMin();
124   // Get the x max. For all glyph bounding boxes.
125   int32_t XMax();
126   // Get the y max. For all glyph bounding boxes.
127   int32_t YMax();
128 
129   // TODO(arthurhsu): IMPLEMENT: EnumSet<MacStyle>
130   int32_t MacStyleAsInt();
131   // TODO(arthurhsu): IMPLEMENT: macStyle() returning EnumSet<MacStyle>
132 
133   int32_t LowestRecPPEM();
134   int32_t FontDirectionHint();  // Note: no AsInt() form, already int
135   int32_t IndexToLocFormat();  // Note: no AsInt() form, already int
136   int32_t GlyphDataFormat();
137 
138  private:
139   struct Offset {
140     enum {
141       kTableVersion = 0,
142       kFontRevision = 4,
143       kCheckSumAdjustment = 8,
144       kMagicNumber = 12,
145       kFlags = 16,
146       kUnitsPerEm = 18,
147       kCreated = 20,
148       kModified = 28,
149       kXMin = 36,
150       kYMin = 38,
151       kXMax = 40,
152       kYMax = 42,
153       kMacStyle = 44,
154       kLowestRecPPEM = 46,
155       kFontDirectionHint = 48,
156       kIndexToLocFormat = 50,
157       kGlyphDataFormat = 52
158     };
159   };
160 
161   FontHeaderTable(Header* header, ReadableFontData* data);
162 };
163 typedef Ptr<FontHeaderTable> FontHeaderTablePtr;
164 typedef Ptr<FontHeaderTable::Builder> FontHeaderTableBuilderPtr;
165 
166 }  // namespace sfntly
167 
168 #endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_FONT_HEADER_TABLE_H_
169