2 * Copyright © 2011,2012 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Behdad Esfahbod
27 #ifndef HB_OT_OS2_TABLE_HH
28 #define HB_OT_OS2_TABLE_HH
30 #include "hb-open-type-private.hh"
31 #include "hb-ot-os2-unicode-ranges.hh"
36 * OS/2 and Windows Metrics
37 * http://www.microsoft.com/typography/otspec/os2.htm
40 #define HB_OT_TAG_os2 HB_TAG('O','S','/','2')
44 static const hb_tag_t tableTag = HB_OT_TAG_os2;
46 inline bool sanitize (hb_sanitize_context_t *c) const
48 TRACE_SANITIZE (this);
49 return_trace (c->check_struct (this));
52 inline bool subset (hb_subset_plan_t *plan) const
54 hb_blob_t *os2_blob = OT::Sanitizer<OT::os2>().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_os2));
55 hb_blob_t *os2_prime_blob = hb_blob_create_sub_blob (os2_blob, 0, -1);
56 // TODO(grieger): move to hb_blob_copy_writable_or_fail
57 hb_blob_destroy (os2_blob);
59 OT::os2 *os2_prime = (OT::os2 *) hb_blob_get_data_writable (os2_prime_blob, nullptr);
60 if (unlikely (!os2_prime)) {
61 hb_blob_destroy (os2_prime_blob);
65 uint16_t min_cp, max_cp;
66 find_min_and_max_codepoint (plan->codepoints, &min_cp, &max_cp);
67 os2_prime->usFirstCharIndex.set (min_cp);
68 os2_prime->usLastCharIndex.set (max_cp);
70 _update_unicode_ranges (plan->codepoints, os2_prime->ulUnicodeRange);
71 bool result = hb_subset_plan_add_table(plan, HB_OT_TAG_os2, os2_prime_blob);
73 hb_blob_destroy (os2_prime_blob);
77 inline void _update_unicode_ranges (const hb_prealloced_array_t<hb_codepoint_t> &codepoints,
78 HBUINT32 ulUnicodeRange[4]) const
80 for (unsigned int i = 0; i < 4; i++)
81 ulUnicodeRange[i].set (0);
83 for (unsigned int i = 0; i < codepoints.len; i++)
85 hb_codepoint_t cp = codepoints[i];
86 unsigned int bit = hb_get_unicode_range_bit (cp);
89 unsigned int block = bit / 32;
90 unsigned int bit_in_block = bit % 32;
91 unsigned int mask = 1 << bit_in_block;
92 ulUnicodeRange[block].set (ulUnicodeRange[block] | mask);
94 if (cp >= 0x10000 && cp <= 0x110000)
96 /* the spec says that bit 57 ("Non Plane 0") implies that there's
97 at least one codepoint beyond the BMP; so I also include all
98 the non-BMP codepoints here */
99 ulUnicodeRange[1].set (ulUnicodeRange[1] | (1 << 25));
104 static inline void find_min_and_max_codepoint (const hb_prealloced_array_t<hb_codepoint_t> &codepoints,
105 uint16_t *min_cp, /* OUT */
106 uint16_t *max_cp /* OUT */)
108 hb_codepoint_t min = -1, max = 0;
110 for (unsigned int i = 0; i < codepoints.len; i++)
112 hb_codepoint_t cp = codepoints[i];
132 HBINT16 xAvgCharWidth;
133 HBUINT16 usWeightClass;
134 HBUINT16 usWidthClass;
136 HBINT16 ySubscriptXSize;
137 HBINT16 ySubscriptYSize;
138 HBINT16 ySubscriptXOffset;
139 HBINT16 ySubscriptYOffset;
140 HBINT16 ySuperscriptXSize;
141 HBINT16 ySuperscriptYSize;
142 HBINT16 ySuperscriptXOffset;
143 HBINT16 ySuperscriptYOffset;
144 HBINT16 yStrikeoutSize;
145 HBINT16 yStrikeoutPosition;
146 HBINT16 sFamilyClass;
148 HBUINT32 ulUnicodeRange[4];
150 HBUINT16 fsSelection;
151 HBUINT16 usFirstCharIndex;
152 HBUINT16 usLastCharIndex;
153 HBINT16 sTypoAscender;
154 HBINT16 sTypoDescender;
155 HBINT16 sTypoLineGap;
156 HBUINT16 usWinAscent;
157 HBUINT16 usWinDescent;
160 //HBUINT32 ulCodePageRange1;
161 //HBUINT32 ulCodePageRange2;
165 //HBINT16 sCapHeight;
166 //HBUINT16 usDefaultChar;
167 //HBUINT16 usBreakChar;
168 //HBUINT16 usMaxContext;
171 //HBUINT16 usLowerOpticalPointSize;
172 //HBUINT16 usUpperOpticalPointSize;
175 DEFINE_SIZE_STATIC (78);
181 #endif /* HB_OT_OS2_TABLE_HH */