• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2010  Red Hat, Inc.
3  * Copyright © 2012  Google, Inc.
4  *
5  *  This is part of HarfBuzz, a text shaping library.
6  *
7  * Permission is hereby granted, without written agreement and without
8  * license or royalty fees, to use, copy, modify, and distribute this
9  * software and its documentation for any purpose, provided that the
10  * above copyright notice and the following two paragraphs appear in
11  * all copies of this software.
12  *
13  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17  * DAMAGE.
18  *
19  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24  *
25  * Red Hat Author(s): Behdad Esfahbod
26  * Google Author(s): Behdad Esfahbod
27  */
28 
29 #ifndef HB_OT_HEAD_TABLE_HH
30 #define HB_OT_HEAD_TABLE_HH
31 
32 #include "hb-open-type.hh"
33 
34 /*
35  * head -- Font Header
36  * https://docs.microsoft.com/en-us/typography/opentype/spec/head
37  */
38 #define HB_OT_TAG_head HB_TAG('h','e','a','d')
39 
40 
41 namespace OT {
42 
43 
44 struct head
45 {
46   friend struct OpenTypeOffsetTable;
47 
48   static constexpr hb_tag_t tableTag = HB_OT_TAG_head;
49 
get_upemOT::head50   unsigned int get_upem () const
51   {
52     unsigned int upem = unitsPerEm;
53     /* If no valid head table found, assume 1000, which matches typical Type1 usage. */
54     return 16 <= upem && upem <= 16384 ? upem : 1000;
55   }
56 
serializeOT::head57   bool serialize (hb_serialize_context_t *c) const
58   {
59     TRACE_SERIALIZE (this);
60     return_trace ((bool) c->embed (this));
61   }
62 
subsetOT::head63   bool subset (hb_subset_context_t *c) const
64   {
65     TRACE_SUBSET (this);
66     head *out = c->serializer->embed (this);
67     if (unlikely (!out)) return_trace (false);
68 
69     if (c->plan->normalized_coords)
70     {
71       if (unlikely (!c->serializer->check_assign (out->xMin, c->plan->head_maxp_info.xMin,
72                                                   HB_SERIALIZE_ERROR_INT_OVERFLOW)))
73         return_trace (false);
74       if (unlikely (!c->serializer->check_assign (out->xMax, c->plan->head_maxp_info.xMax,
75                                                   HB_SERIALIZE_ERROR_INT_OVERFLOW)))
76         return_trace (false);
77       if (unlikely (!c->serializer->check_assign (out->yMin, c->plan->head_maxp_info.yMin,
78                                                   HB_SERIALIZE_ERROR_INT_OVERFLOW)))
79         return_trace (false);
80       if (unlikely (!c->serializer->check_assign (out->yMax, c->plan->head_maxp_info.yMax,
81                                                   HB_SERIALIZE_ERROR_INT_OVERFLOW)))
82         return_trace (false);
83     }
84     return_trace (true);
85   }
86 
87   enum mac_style_flag_t {
88     BOLD	= 1u<<0,
89     ITALIC	= 1u<<1,
90     UNDERLINE	= 1u<<2,
91     OUTLINE	= 1u<<3,
92     SHADOW	= 1u<<4,
93     CONDENSED	= 1u<<5,
94     EXPANDED	= 1u<<6,
95   };
96 
is_boldOT::head97   bool is_bold () const      { return macStyle & BOLD; }
is_italicOT::head98   bool is_italic () const    { return macStyle & ITALIC; }
is_condensedOT::head99   bool is_condensed () const { return macStyle & CONDENSED; }
is_expandedOT::head100   bool is_expanded () const  { return macStyle & EXPANDED; }
101 
sanitizeOT::head102   bool sanitize (hb_sanitize_context_t *c) const
103   {
104     TRACE_SANITIZE (this);
105     return_trace (c->check_struct (this) &&
106 		  version.major == 1 &&
107 		  magicNumber == 0x5F0F3CF5u);
108   }
109 
110   protected:
111   FixedVersion<>version;		/* Version of the head table--currently
112 					 * 0x00010000u for version 1.0. */
113   FixedVersion<>fontRevision;		/* Set by font manufacturer. */
114   HBUINT32	checkSumAdjustment;	/* To compute: set it to 0, sum the
115 					 * entire font as HBUINT32, then store
116 					 * 0xB1B0AFBAu - sum. */
117   HBUINT32	magicNumber;		/* Set to 0x5F0F3CF5u. */
118   public:
119   HBUINT16	flags;			/* Bit 0: Baseline for font at y=0;
120 					 * Bit 1: Left sidebearing point at x=0;
121 					 * Bit 2: Instructions may depend on point size;
122 					 * Bit 3: Force ppem to integer values for all
123 					 *   internal scaler math; may use fractional
124 					 *   ppem sizes if this bit is clear;
125 					 * Bit 4: Instructions may alter advance width
126 					 *   (the advance widths might not scale linearly);
127 					 * Bits 5-10: These should be set according to
128 					 *   Apple's specification. However, they are not
129 					 *   implemented in OpenType.
130 					 * Bit 5: This bit should be set in fonts that are
131 					 *   intended to e laid out vertically, and in
132 					 *   which the glyphs have been drawn such that an
133 					 *   x-coordinate of 0 corresponds to the desired
134 					 *   vertical baseline.
135 					 * Bit 6: This bit must be set to zero.
136 					 * Bit 7: This bit should be set if the font
137 					 *   requires layout for correct linguistic
138 					 *   rendering (e.g. Arabic fonts).
139 					 * Bit 8: This bit should be set for a GX font
140 					 *   which has one or more metamorphosis effects
141 					 *   designated as happening by default.
142 					 * Bit 9: This bit should be set if the font
143 					 *   contains any strong right-to-left glyphs.
144 					 * Bit 10: This bit should be set if the font
145 					 *   contains Indic-style rearrangement effects.
146 					 * Bit 11: Font data is 'lossless,' as a result
147 					 *   of having been compressed and decompressed
148 					 *   with the Agfa MicroType Express engine.
149 					 * Bit 12: Font converted (produce compatible metrics)
150 					 * Bit 13: Font optimized for ClearType™.
151 					 *   Note, fonts that rely on embedded bitmaps (EBDT)
152 					 *   for rendering should not be considered optimized
153 					 *   for ClearType, and therefore should keep this bit
154 					 *   cleared.
155 					 * Bit 14: Last Resort font. If set, indicates that
156 					 * the glyphs encoded in the cmap subtables are simply
157 					 * generic symbolic representations of code point
158 					 * ranges and don’t truly represent support for those
159 					 * code points. If unset, indicates that the glyphs
160 					 * encoded in the cmap subtables represent proper
161 					 * support for those code points.
162 					 * Bit 15: Reserved, set to 0. */
163   protected:
164   HBUINT16	unitsPerEm;		/* Valid range is from 16 to 16384. This value
165 					 * should be a power of 2 for fonts that have
166 					 * TrueType outlines. */
167   LONGDATETIME	created;		/* Number of seconds since 12:00 midnight,
168 					   January 1, 1904. 64-bit integer */
169   LONGDATETIME	modified;		/* Number of seconds since 12:00 midnight,
170 					   January 1, 1904. 64-bit integer */
171   public:
172   HBINT16	xMin;			/* For all glyph bounding boxes. */
173   HBINT16	yMin;			/* For all glyph bounding boxes. */
174   HBINT16	xMax;			/* For all glyph bounding boxes. */
175   HBINT16	yMax;			/* For all glyph bounding boxes. */
176   protected:
177   HBUINT16	macStyle;		/* Bit 0: Bold (if set to 1);
178 					 * Bit 1: Italic (if set to 1)
179 					 * Bit 2: Underline (if set to 1)
180 					 * Bit 3: Outline (if set to 1)
181 					 * Bit 4: Shadow (if set to 1)
182 					 * Bit 5: Condensed (if set to 1)
183 					 * Bit 6: Extended (if set to 1)
184 					 * Bits 7-15: Reserved (set to 0). */
185   HBUINT16	lowestRecPPEM;		/* Smallest readable size in pixels. */
186   HBINT16	fontDirectionHint;	/* Deprecated (Set to 2).
187 					 * 0: Fully mixed directional glyphs;
188 					 * 1: Only strongly left to right;
189 					 * 2: Like 1 but also contains neutrals;
190 					 * -1: Only strongly right to left;
191 					 * -2: Like -1 but also contains neutrals. */
192   public:
193   HBUINT16	indexToLocFormat;	/* 0 for short offsets, 1 for long. */
194   HBUINT16	glyphDataFormat;	/* 0 for current format. */
195 
196   DEFINE_SIZE_STATIC (54);
197 };
198 
199 
200 } /* namespace OT */
201 
202 
203 #endif /* HB_OT_HEAD_TABLE_HH */
204