2 * Copyright © 2018 Ebrahim Byagowi
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.
25 #ifndef HB_AAT_LAYOUT_JUST_TABLE_HH
26 #define HB_AAT_LAYOUT_JUST_TABLE_HH
28 #include "hb-aat-layout-common.hh"
29 #include "hb-ot-layout.hh"
30 #include "hb-open-type.hh"
32 #include "hb-aat-layout-morx-table.hh"
35 * just -- Justification
36 * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6just.html
38 #define HB_AAT_TAG_just HB_TAG('j','u','s','t')
46 struct ActionSubrecordHeader
48 bool sanitize (hb_sanitize_context_t *c) const
50 TRACE_SANITIZE (this);
51 return_trace (likely (c->check_struct (this)));
54 HBUINT16 actionClass; /* The JustClass value associated with this
56 HBUINT16 actionType; /* The type of postcompensation action. */
57 HBUINT16 actionLength; /* Length of this ActionSubrecord record, which
58 * must be a multiple of 4. */
60 DEFINE_SIZE_STATIC (6);
63 struct DecompositionAction
65 bool sanitize (hb_sanitize_context_t *c) const
67 TRACE_SANITIZE (this);
68 return_trace (likely (c->check_struct (this)));
73 HBFixed lowerLimit; /* If the distance factor is less than this value,
74 * then the ligature is decomposed. */
75 HBFixed upperLimit; /* If the distance factor is greater than this value,
76 * then the ligature is decomposed. */
77 HBUINT16 order; /* Numerical order in which this ligature will
78 * be decomposed; you may want infrequent ligatures
79 * to decompose before more frequent ones. The ligatures
80 * on the line of text will decompose in increasing
81 * value of this field. */
84 /* Number of 16-bit glyph indexes that follow;
85 * the ligature will be decomposed into these glyphs.
87 * Array of decomposed glyphs. */
89 DEFINE_SIZE_ARRAY (18, decomposedglyphs);
92 struct UnconditionalAddGlyphAction
94 bool sanitize (hb_sanitize_context_t *c) const
96 TRACE_SANITIZE (this);
97 return_trace (c->check_struct (this));
101 ActionSubrecordHeader
103 HBGlyphID addGlyph; /* Glyph that should be added if the distance factor
107 DEFINE_SIZE_STATIC (8);
110 struct ConditionalAddGlyphAction
112 bool sanitize (hb_sanitize_context_t *c) const
114 TRACE_SANITIZE (this);
115 return_trace (likely (c->check_struct (this)));
119 ActionSubrecordHeader
121 HBFixed substThreshold; /* Distance growth factor (in ems) at which
122 * this glyph is replaced and the growth factor
124 HBGlyphID addGlyph; /* Glyph to be added as kashida. If this value is
125 * 0xFFFF, no extra glyph will be added. Note that
126 * generally when a glyph is added, justification
127 * will need to be redone. */
128 HBGlyphID substGlyph; /* Glyph to be substituted for this glyph if the
129 * growth factor equals or exceeds the value of
132 DEFINE_SIZE_STATIC (14);
135 struct DuctileGlyphAction
137 bool sanitize (hb_sanitize_context_t *c) const
139 TRACE_SANITIZE (this);
140 return_trace (likely (c->check_struct (this)));
144 ActionSubrecordHeader
146 HBUINT32 variationAxis; /* The 4-byte tag identifying the ductile axis.
147 * This would normally be 0x64756374 ('duct'),
148 * but you may use any axis the font contains. */
149 HBFixed minimumLimit; /* The lowest value for the ductility axis tha
150 * still yields an acceptable appearance. Normally
151 * this will be 1.0. */
152 HBFixed noStretchValue; /* This is the default value that corresponds to
153 * no change in appearance. Normally, this will
155 HBFixed maximumLimit; /* The highest value for the ductility axis that
156 * still yields an acceptable appearance. */
158 DEFINE_SIZE_STATIC (22);
161 struct RepeatedAddGlyphAction
163 bool sanitize (hb_sanitize_context_t *c) const
165 TRACE_SANITIZE (this);
166 return_trace (likely (c->check_struct (this)));
170 ActionSubrecordHeader
172 HBUINT16 flags; /* Currently unused; set to 0. */
173 HBGlyphID glyph; /* Glyph that should be added if the distance factor
176 DEFINE_SIZE_STATIC (10);
179 struct ActionSubrecord
181 unsigned int get_length () const { return u.header.actionLength; }
183 bool sanitize (hb_sanitize_context_t *c) const
185 TRACE_SANITIZE (this);
186 if (unlikely (!c->check_struct (this)))
187 return_trace (false);
189 switch (u.header.actionType)
191 case 0: return_trace (u.decompositionAction.sanitize (c));
192 case 1: return_trace (u.unconditionalAddGlyphAction.sanitize (c));
193 case 2: return_trace (u.conditionalAddGlyphAction.sanitize (c));
194 // case 3: return_trace (u.stretchGlyphAction.sanitize (c));
195 case 4: return_trace (u.decompositionAction.sanitize (c));
196 case 5: return_trace (u.decompositionAction.sanitize (c));
197 default: return_trace (true);
203 ActionSubrecordHeader header;
204 DecompositionAction decompositionAction;
205 UnconditionalAddGlyphAction unconditionalAddGlyphAction;
206 ConditionalAddGlyphAction conditionalAddGlyphAction;
207 /* StretchGlyphAction stretchGlyphAction; -- Not supported by CoreText */
208 DuctileGlyphAction ductileGlyphAction;
209 RepeatedAddGlyphAction repeatedAddGlyphAction;
210 } u; /* Data. The format of this data depends on
211 * the value of the actionType field. */
213 DEFINE_SIZE_UNION (6, header);
216 struct PostcompensationActionChain
218 bool sanitize (hb_sanitize_context_t *c) const
220 TRACE_SANITIZE (this);
221 if (unlikely (!c->check_struct (this)))
222 return_trace (false);
224 unsigned int offset = min_size;
225 for (unsigned int i = 0; i < count; i++)
227 const ActionSubrecord& subrecord = StructAtOffset<ActionSubrecord> (this, offset);
228 if (unlikely (!subrecord.sanitize (c))) return_trace (false);
229 offset += subrecord.get_length ();
239 DEFINE_SIZE_STATIC (4);
242 struct JustWidthDeltaEntry
246 Reserved1 =0xE000,/* Reserved. You should set these bits to zero. */
247 UnlimiteGap =0x1000,/* The glyph can take unlimited gap. When this
248 * glyph participates in the justification process,
249 * it and any other glyphs on the line having this
250 * bit set absorb all the remaining gap. */
251 Reserved2 =0x0FF0,/* Reserved. You should set these bits to zero. */
252 Priority =0x000F /* The justification priority of the glyph. */
257 Kashida = 0, /* Kashida priority. This is the highest priority
258 * during justification. */
259 Whitespace = 1, /* Whitespace priority. Any whitespace glyphs (as
260 * identified in the glyph properties table) will
261 * get this priority. */
262 InterCharacter = 2, /* Inter-character priority. Give this to any
263 * remaining glyphs. */
264 NullPriority = 3 /* Null priority. You should set this priority for
265 * glyphs that only participate in justification
266 * after the above priorities. Normally all glyphs
267 * have one of the previous three values. If you
268 * don't want a glyph to participate in justification,
269 * and you don't want to set its factors to zero,
270 * you may instead assign it to the null priority. */
274 HBFixed beforeGrowLimit;/* The ratio by which the advance width of the
275 * glyph is permitted to grow on the left or top side. */
276 HBFixed beforeShrinkLimit;
277 /* The ratio by which the advance width of the
278 * glyph is permitted to shrink on the left or top side. */
279 HBFixed afterGrowLimit; /* The ratio by which the advance width of the glyph
280 * is permitted to shrink on the left or top side. */
281 HBFixed afterShrinkLimit;
282 /* The ratio by which the advance width of the glyph
283 * is at most permitted to shrink on the right or
285 HBUINT16 growFlags; /* Flags controlling the grow case. */
286 HBUINT16 shrinkFlags; /* Flags controlling the shrink case. */
289 DEFINE_SIZE_STATIC (20);
292 struct WidthDeltaPair
294 bool sanitize (hb_sanitize_context_t *c) const
296 TRACE_SANITIZE (this);
297 return_trace (likely (c->check_struct (this)));
301 HBUINT32 justClass; /* The justification category associated
302 * with the wdRecord field. Only 7 bits of
303 * this field are used. (The other bits are
304 * used as padding to guarantee longword
305 * alignment of the following record). */
307 wdRecord; /* The actual width delta record. */
310 DEFINE_SIZE_STATIC (24);
313 typedef OT::LArrayOf<WidthDeltaPair> WidthDeltaCluster;
315 struct JustificationCategory
317 typedef void EntryData;
321 SetMark =0x8000,/* If set, make the current glyph the marked
323 DontAdvance =0x4000,/* If set, don't advance to the next glyph before
324 * going to the new state. */
325 MarkCategory =0x3F80,/* The justification category for the marked
326 * glyph if nonzero. */
327 CurrentCategory =0x007F /* The justification category for the current
328 * glyph if nonzero. */
331 bool sanitize (hb_sanitize_context_t *c, const void *base) const
333 TRACE_SANITIZE (this);
334 return_trace (likely (c->check_struct (this) &&
335 morphHeader.sanitize (c) &&
336 stHeader.sanitize (c)));
340 ChainSubtable<ObsoleteTypes>
341 morphHeader; /* Metamorphosis-style subtable header. */
342 StateTable<ObsoleteTypes, EntryData>
343 stHeader; /* The justification insertion state table header */
345 DEFINE_SIZE_STATIC (30);
348 struct JustificationHeader
350 bool sanitize (hb_sanitize_context_t *c, const void *base) const
352 TRACE_SANITIZE (this);
353 return_trace (likely (c->check_struct (this) &&
354 justClassTable.sanitize (c, base, base) &&
355 wdcTable.sanitize (c, base) &&
356 pcTable.sanitize (c, base) &&
357 lookupTable.sanitize (c, base)));
361 OffsetTo<JustificationCategory>
362 justClassTable; /* Offset to the justification category state table. */
363 OffsetTo<WidthDeltaCluster>
364 wdcTable; /* Offset from start of justification table to start
365 * of the subtable containing the width delta factors
366 * for the glyphs in your font.
368 * The width delta clusters table. */
369 OffsetTo<PostcompensationActionChain>
370 pcTable; /* Offset from start of justification table to start
371 * of postcompensation subtable (set to zero if none).
373 * The postcompensation subtable, if present in the font. */
374 Lookup<OffsetTo<WidthDeltaCluster>>
375 lookupTable; /* Lookup table associating glyphs with width delta
376 * clusters. See the description of Width Delta Clusters
377 * table for details on how to interpret the lookup values. */
385 static constexpr hb_tag_t tableTag = HB_AAT_TAG_just;
387 bool sanitize (hb_sanitize_context_t *c) const
389 TRACE_SANITIZE (this);
391 return_trace (likely (c->check_struct (this) &&
392 version.major == 1 &&
393 horizData.sanitize (c, this, this) &&
394 vertData.sanitize (c, this, this)));
398 FixedVersion<>version; /* Version of the justification table
399 * (0x00010000u for version 1.0). */
400 HBUINT16 format; /* Format of the justification table (set to 0). */
401 OffsetTo<JustificationHeader>
402 horizData; /* Byte offset from the start of the justification table
403 * to the header for tables that contain justification
404 * information for horizontal text.
405 * If you are not including this information,
407 OffsetTo<JustificationHeader>
408 vertData; /* ditto, vertical */
411 DEFINE_SIZE_STATIC (10);
414 } /* namespace AAT */
417 #endif /* HB_AAT_LAYOUT_JUST_TABLE_HH */