• 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_OS2_TABLE_H_
18 #define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_OS2_TABLE_H_
19 
20 #include "sfntly/port/refcount.h"
21 #include "sfntly/table/table.h"
22 #include "sfntly/table/table_based_table_builder.h"
23 
24 namespace sfntly {
25 
26 struct WeightClass {
27   enum {
28     kThin = 100,
29     kExtraLight = 200,
30     kUltraLight = 200,
31     kLight = 300,
32     kNormal = 400,
33     kRegular = 400,
34     kMedium = 500,
35     kSemiBold = 600,
36     kDemiBold = 600,
37     kBold = 700,
38     kExtraBold = 800,
39     kUltraBold = 800,
40     kBlack = 900,
41     kHeavy = 900
42   };
43 };
44 
45 struct WidthClass {
46   enum {
47     kUltraCondensed = 1,
48     kExtraCondensed = 2,
49     kCondensed = 3,
50     kSemiCondensed = 4,
51     kMedium = 5,
52     kNormal = 5,
53     kSemiExpanded = 6,
54     kExpanded = 7,
55     kExtraExpanded = 8,
56     kUltraExpanded = 9
57   };
58 };
59 
60 // Flags to indicate the embedding licensing rights for a font.
61 struct EmbeddingFlags {
62   enum {
63     kReserved0 = 1 << 0,
64     kRestrictedLicenseEmbedding = 1 << 1,
65     kPreviewAndPrintEmbedding = 1 << 2,
66     kEditableEmbedding = 1 << 3,
67     kReserved4 = 1 << 4,
68     kReserved5 = 1 << 5,
69     kReserved6 = 1 << 6,
70     kReserved7 = 1 << 7,
71     kNoSubsetting = 1 << 8,
72     kBitmapEmbeddingOnly = 1 << 9,
73     kReserved10 = 1 << 10,
74     kReserved11 = 1 << 11,
75     kReserved12 = 1 << 12,
76     kReserved13 = 1 << 13,
77     kReserved14 = 1 << 14,
78     kReserved15 = 1 << 15
79   };
80 };
81 
82 struct UnicodeRange {
83   enum {
84     // Do NOT reorder. This enum relies on the ordering of the data matching the
85     // ordinal numbers of the properties.
86     kBasicLatin,
87     kLatin1Supplement,
88     kLatinExtendedA,
89     kLatinExtendedB,
90     kIPAExtensions,
91     kSpacingModifierLetters,
92     kCombiningDiacriticalMarks,
93     kGreekAndCoptic,
94     kCoptic,
95     kCyrillic,
96     kArmenian,
97     kHebrew,
98     kVai,
99     kArabic,
100     kNKo,
101     kDevanagari,
102     kBengali,
103     kGurmukhi,
104     kGujarati,
105     kOriya,
106     kTamil,
107     kTelugu,
108     kKannada,
109     kMalayalam,
110     kThai,
111     kLao,
112     kGeorgian,
113     kBalinese,
114     kHangulJamo,
115     kLatinExtendedAdditional,
116     kGreekExtended,
117     kGeneralPunctuation,
118     kSuperscriptsAndSubscripts,
119     kCurrencySymbols,
120     kNumberForms,
121     kArrows,
122     kMathematicalOperators,
123     kMiscTechnical,
124     kControlPictures,
125     kOCR,
126     kEnclosedAlphanumerics,
127     kBoxDrawing,
128     kBlockElements,
129     kGeometricShapes,
130     kMiscSymbols,
131     kDingbats,
132     kCJKSymbolsAndPunctuation,
133     kHiragana,
134     kKatakana,
135     kBopomofo,
136     kHangulCompatibilityJamo,
137     kPhagspa,
138     kEnclosedCJKLettersAndMonths,
139     kCJKCompatibility,
140     kHangulSyllables,
141     kNonPlane0,
142     kPhoenician,
143     kCJKUnifiedIdeographs,
144     kPrivateUseAreaPlane0,
145     kCJKStrokes,
146     kAlphabeticPresentationForms,
147     kArabicPresentationFormsA,
148     kCombiningHalfMarks,
149     kVerticalForms,
150     kSmallFormVariants,
151     kArabicPresentationFormsB,
152     kHalfwidthAndFullwidthForms,
153     kSpecials,
154     kTibetan,
155     kSyriac,
156     kThaana,
157     kSinhala,
158     kMyanmar,
159     kEthiopic,
160     kCherokee,
161     kUnifiedCanadianAboriginalSyllabics,
162     kOgham,
163     kRunic,
164     kKhmer,
165     kMongolian,
166     kBraillePatterns,
167     kYiSyllables,
168     kTagalog,
169     kOldItalic,
170     kGothic,
171     kDeseret,
172     kMusicalSymbols,
173     kMathematicalAlphanumericSymbols,
174     kPrivateUsePlane15And16,
175     kVariationSelectors,
176     kTags,
177     kLimbu,
178     kTaiLe,
179     kNewTaiLue,
180     kBuginese,
181     kGlagolitic,
182     kTifnagh,
183     kYijingHexagramSymbols,
184     kSylotiNagari,
185     kLinearB,
186     kAncientGreekNumbers,
187     kUgaritic,
188     kOldPersian,
189     kShavian,
190     kOsmanya,
191     kCypriotSyllabary,
192     kKharoshthi,
193     kTaiXuanJingSymbols,
194     kCuneiform,
195     kCountingRodNumerals,
196     kSudanese,
197     kLepcha,
198     kOlChiki,
199     kSaurashtra,
200     kKayahLi,
201     kRejang,
202     kCharm,
203     kAncientSymbols,
204     kPhaistosDisc,
205     kCarian,
206     kDominoTiles,
207     kReserved123,
208     kReserved124,
209     kReserved125,
210     kReserved126,
211     kReserved127,
212     kLast = kReserved127
213   };
214 
215   int32_t range(int32_t bit);
216   // UNIMPLEMENTED: EnumSet<UnicodeRange> asSet(long range1, long range2,
217   //                                            long range3, long range4)
218   //                long[] asArray(EnumSet<UnicodeRange> rangeSet)
219 };
220 
221 struct FsSelection {
222   enum {
223     kITALIC = 1 << 0,
224     kUNDERSCORE = 1 << 1,
225     kNEGATIVE = 1 << 2,
226     kOUTLINED = 1 << 3,
227     kSTRIKEOUT = 1 << 4,
228     kBOLD = 1 << 5,
229     kREGULAR = 1 << 6,
230     kUSE_TYPO_METRICS = 1 << 7,
231     kWWS = 1 << 8,
232     kOBLIQUE = 1 << 9
233   };
234   // UNIMPLEMENTED: EnumSet<FsSelection> asSet(long range1, long range2,
235   //                                           long range3, long range4)
236   //                long[] asArray(EnumSet<FsSelection> rangeSet)
237 };
238 
239 // C++ port only: C++ does not support 64-bit enums until C++0x.  For better
240 // portability, we need to use static const int64_t instead.
241 struct CodePageRange {
242   static const int64_t kLatin1_1252;
243   static const int64_t kLatin2_1250;
244   static const int64_t kCyrillic_1251;
245   static const int64_t kGreek_1253;
246   static const int64_t kTurkish_1254;
247   static const int64_t kHebrew_1255;
248   static const int64_t kArabic_1256;
249   static const int64_t kWindowsBaltic_1257;
250   static const int64_t kVietnamese_1258;
251   static const int64_t kAlternateANSI9;
252   static const int64_t kAlternateANSI10;
253   static const int64_t kAlternateANSI11;
254   static const int64_t kAlternateANSI12;
255   static const int64_t kAlternateANSI13;
256   static const int64_t kAlternateANSI14;
257   static const int64_t kAlternateANSI15;
258   static const int64_t kThai_874;
259   static const int64_t kJapanJIS_932;
260   static const int64_t kChineseSimplified_936;
261   static const int64_t kKoreanWansung_949;
262   static const int64_t kChineseTraditional_950;
263   static const int64_t kKoreanJohab_1361;
264   static const int64_t kAlternateANSI22;
265   static const int64_t kAlternateANSI23;
266   static const int64_t kAlternateANSI24;
267   static const int64_t kAlternateANSI25;
268   static const int64_t kAlternateANSI26;
269   static const int64_t kAlternateANSI27;
270   static const int64_t kAlternateANSI28;
271   static const int64_t kMacintoshCharacterSet;
272   static const int64_t kOEMCharacterSet;
273   static const int64_t kSymbolCharacterSet;
274   static const int64_t kReservedForOEM32;
275   static const int64_t kReservedForOEM33;
276   static const int64_t kReservedForOEM34;
277   static const int64_t kReservedForOEM35;
278   static const int64_t kReservedForOEM36;
279   static const int64_t kReservedForOEM37;
280   static const int64_t kReservedForOEM38;
281   static const int64_t kReservedForOEM39;
282   static const int64_t kReservedForOEM40;
283   static const int64_t kReservedForOEM41;
284   static const int64_t kReservedForOEM42;
285   static const int64_t kReservedForOEM43;
286   static const int64_t kReservedForOEM44;
287   static const int64_t kReservedForOEM45;
288   static const int64_t kReservedForOEM46;
289   static const int64_t kReservedForOEM47;
290   static const int64_t kIBMGreek_869;
291   static const int64_t kMSDOSRussion_866;
292   static const int64_t kMSDOSNordic_865;
293   static const int64_t kArabic_864;
294   static const int64_t kMSDOSCanadianFrench_863;
295   static const int64_t kHebrew_862;
296   static const int64_t kMSDOSIcelandic_861;
297   static const int64_t kMSDOSPortugese_860;
298   static const int64_t kIBMTurkish_857;
299   static const int64_t kIBMCyrillic_855;
300   static const int64_t kLatin2_852;
301   static const int64_t kMSDOSBaltic_775;
302   static const int64_t kGreek_737;
303   static const int64_t kArabic_708;
304   static const int64_t kLatin1_850;
305   static const int64_t kUS_437;
306 
307   // UNIMPLEMENTED: EnumSet<CodePageRange> asSet(long range1, long range2,
308   //                                             long range3, long range4)
309   //                long[] asArray(EnumSet<CodePageRange> rangeSet)
310 };
311 
312 // An OS/2 table - 'OS/2'.
313 class OS2Table : public Table, public RefCounted<OS2Table> {
314  public:
315   // A builder for the OS/2 table = 'OS/2'.
316   class Builder : public TableBasedTableBuilder, public RefCounted<Builder> {
317    public:
318     Builder(Header* header, WritableFontData* data);
319     Builder(Header* header, ReadableFontData* data);
320     virtual ~Builder();
321     virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data);
322 
323     static CALLER_ATTACH Builder* CreateBuilder(Header* header,
324                                                 WritableFontData* data);
325 
326     int32_t TableVersion();
327     void SetTableVersion(int32_t version);
328     int32_t XAvgCharWidth();
329     void SetXAvgCharWidth(int32_t width);
330     int32_t UsWeightClass();
331     void SetUsWeightClass(int32_t weight);
332     int32_t UsWidthClass();
333     void SetUsWidthClass(int32_t width);
334     // UNIMPLEMENTED: EnumSet<EmbeddingFlags> fsType()
335     //                void setFsType(EnumSeT<EmbeddingFlags> flagSet)
336     int32_t FsType();
337     void SetFsType(int32_t fs_type);
338     int32_t YSubscriptXSize();
339     void SetYSubscriptXSize(int32_t size);
340     int32_t YSubscriptYSize();
341     void SetYSubscriptYSize(int32_t size);
342     int32_t YSubscriptXOffset();
343     void SetYSubscriptXOffset(int32_t offset);
344     int32_t YSubscriptYOffset();
345     void SetYSubscriptYOffset(int32_t offset);
346     int32_t YSuperscriptXSize();
347     void SetYSuperscriptXSize(int32_t size);
348     int32_t YSuperscriptYSize();
349     void SetYSuperscriptYSize(int32_t size);
350     int32_t YSuperscriptXOffset();
351     void SetYSuperscriptXOffset(int32_t offset);
352     int32_t YSuperscriptYOffset();
353     void SetYSuperscriptYOffset(int32_t offset);
354     int32_t YStrikeoutSize();
355     void SetYStrikeoutSize(int32_t size);
356     int32_t YStrikeoutPosition();
357     void SetYStrikeoutPosition(int32_t position);
358     int32_t SFamilyClass();
359     void SetSFamilyClass(int32_t family);
360     void Panose(ByteVector* value);
361     void SetPanose(ByteVector* panose);
362     int64_t UlUnicodeRange1();
363     void SetUlUnicodeRange1(int64_t range);
364     int64_t UlUnicodeRange2();
365     void SetUlUnicodeRange2(int64_t range);
366     int64_t UlUnicodeRange3();
367     void SetUlUnicodeRange3(int64_t range);
368     int64_t UlUnicodeRange4();
369     void SetUlUnicodeRange4(int64_t range);
370     // UNIMPLEMENTED: EnumSet<UnicodeRange> UlUnicodeRange()
371     //                setUlUnicodeRange(EnumSet<UnicodeRange> rangeSet)
372     void AchVendId(ByteVector* b);
373     // This field is 4 bytes in length and only the first 4 bytes of the byte
374     // array will be written. If the byte array is less than 4 bytes it will be
375     // padded out with space characters (0x20).
376     // @param b ach Vendor Id
377     void SetAchVendId(ByteVector* b);
378     // UNIMPLEMENTED: public EnumSet<FsSelection> fsSelection()
379     int32_t FsSelection();
380     void SetFsSelection(int32_t fs_selection);
381     int32_t UsFirstCharIndex();
382     void SetUsFirstCharIndex(int32_t first_index);
383     int32_t UsLastCharIndex();
384     void SetUsLastCharIndex(int32_t last_index);
385     int32_t STypoAscender();
386     void SetSTypoAscender(int32_t ascender);
387     int32_t STypoDescender();
388     void SetSTypoDescender(int32_t descender);
389     int32_t STypoLineGap();
390     void SetSTypoLineGap(int32_t line_gap);
391     int32_t UsWinAscent();
392     void SetUsWinAscent(int32_t ascent);
393     int32_t UsWinDescent();
394     void SetUsWinDescent(int32_t descent);
395     int64_t UlCodePageRange1();
396     void SetUlCodePageRange1(int64_t range);
397     int64_t UlCodePageRange2();
398     void SetUlCodePageRange2(int64_t range);
399     // UNIMPLEMENTED: EnumSet<CodePageRange> ulCodePageRange()
400     //                void setUlCodePageRange(EnumSet<CodePageRange> rangeSet)
401     int32_t SxHeight();
402     void SetSxHeight(int32_t height);
403     int32_t SCapHeight();
404     void SetSCapHeight(int32_t height);
405     int32_t UsDefaultChar();
406     void SetUsDefaultChar(int32_t default_char);
407     int32_t UsBreakChar();
408     void SetUsBreakChar(int32_t break_char);
409     int32_t UsMaxContext();
410     void SetUsMaxContext(int32_t max_context);
411   };
412 
413   ~OS2Table();
414 
415   int32_t TableVersion();
416   int32_t XAvgCharWidth();
417   int32_t UsWeightClass();
418   int32_t UsWidthClass();
419   // UNIMPLEMENTED: public EnumSet<EmbeddingFlags> fsType()
420   int32_t FsType();
421   int32_t YSubscriptXSize();
422   int32_t YSubscriptYSize();
423   int32_t YSubscriptXOffset();
424   int32_t YSubscriptYOffset();
425   int32_t YSuperscriptXSize();
426   int32_t YSuperscriptYSize();
427   int32_t YSuperscriptXOffset();
428   int32_t YSuperscriptYOffset();
429   int32_t YStrikeoutSize();
430   int32_t YStrikeoutPosition();
431   int32_t SFamilyClass();
432   void Panose(ByteVector* value);
433   int64_t UlUnicodeRange1();
434   int64_t UlUnicodeRange2();
435   int64_t UlUnicodeRange3();
436   int64_t UlUnicodeRange4();
437   // UNIMPLEMENTED: public EnumSet<UnicodeRange> UlUnicodeRange()
438   void AchVendId(ByteVector* b);
439   // UNIMPLEMENTED: public EnumSet<FsSelection> fsSelection()
440   int32_t FsSelection();
441   int32_t UsFirstCharIndex();
442   int32_t UsLastCharIndex();
443   int32_t STypoAscender();
444   int32_t STypoDescender();
445   int32_t STypoLineGap();
446   int32_t UsWinAscent();
447   int32_t UsWinDescent();
448   int64_t UlCodePageRange1();
449   int64_t UlCodePageRange2();
450   // UNIMPLEMENTED: public EnumSet<CodePageRange> ulCodePageRange()
451   int32_t SxHeight();
452   int32_t SCapHeight();
453   int32_t UsDefaultChar();
454   int32_t UsBreakChar();
455   int32_t UsMaxContext();
456 
457  private:
458   struct Offset {
459     enum {
460       kVersion = 0,
461       kXAvgCharWidth = 2,
462       kUsWeightClass = 4,
463       kUsWidthClass = 6,
464       kFsType = 8,
465       kYSubscriptXSize = 10,
466       kYSubscriptYSize = 12,
467       kYSubscriptXOffset = 14,
468       kYSubscriptYOffset = 16,
469       kYSuperscriptXSize = 18,
470       kYSuperscriptYSize = 20,
471       kYSuperscriptXOffset = 22,
472       kYSuperscriptYOffset = 24,
473       kYStrikeoutSize = 26,
474       kYStrikeoutPosition = 28,
475       kSFamilyClass = 30,
476       kPanose = 32,
477       kPanoseLength = 10,  // Length of panose bytes.
478       kUlUnicodeRange1 = 42,
479       kUlUnicodeRange2 = 46,
480       kUlUnicodeRange3 = 50,
481       kUlUnicodeRange4 = 54,
482       kAchVendId = 58,
483       kAchVendIdLength = 4,  // Length of ach vend id bytes.
484       kFsSelection = 62,
485       kUsFirstCharIndex = 64,
486       kUsLastCharIndex = 66,
487       kSTypoAscender = 68,
488       kSTypoDescender = 70,
489       kSTypoLineGap = 72,
490       kUsWinAscent = 74,
491       kUsWinDescent = 76,
492       kUlCodePageRange1 = 78,
493       kUlCodePageRange2 = 82,
494       kSxHeight = 86,
495       kSCapHeight = 88,
496       kUsDefaultChar = 90,
497       kUsBreakChar = 92,
498       kUsMaxContext = 94
499     };
500   };
501 
502   OS2Table(Header* header, ReadableFontData* data);
503 };
504 typedef Ptr<OS2Table> OS2TablePtr;
505 
506 }  // namespace sfntly
507 
508 #endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_OS2_TABLE_H_
509