2 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * This is part of HarfBuzz, an OpenType Layout engine 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 HARFBUZZ_SHAPER_H
26 #define HARFBUZZ_SHAPER_H
28 #include "harfbuzz-global.h"
29 #include "harfbuzz-gdef.h"
30 #include "harfbuzz-gpos.h"
31 #include "harfbuzz-gsub.h"
32 #include "harfbuzz-external.h"
33 #include "harfbuzz-stream-private.h"
67 HB_ScriptCount = HB_Script_Inherited
69 HB_Script_Latin = Common,
70 HB_Script_Ethiopic = Common,
71 HB_Script_Cherokee = Common,
72 HB_Script_CanadianAboriginal = Common,
73 HB_Script_Mongolian = Common,
74 HB_Script_Hiragana = Common,
75 HB_Script_Katakana = Common,
76 HB_Script_Bopomofo = Common,
77 HB_Script_Han = Common,
78 HB_Script_Yi = Common,
79 HB_Script_OldItalic = Common,
80 HB_Script_Gothic = Common,
81 HB_Script_Deseret = Common,
82 HB_Script_Tagalog = Common,
83 HB_Script_Hanunoo = Common,
84 HB_Script_Buhid = Common,
85 HB_Script_Tagbanwa = Common,
86 HB_Script_Limbu = Common,
87 HB_Script_TaiLe = Common,
88 HB_Script_LinearB = Common,
89 HB_Script_Ugaritic = Common,
90 HB_Script_Shavian = Common,
91 HB_Script_Osmanya = Common,
92 HB_Script_Cypriot = Common,
93 HB_Script_Braille = Common,
94 HB_Script_Buginese = Common,
95 HB_Script_Coptic = Common,
96 HB_Script_NewTaiLue = Common,
97 HB_Script_Glagolitic = Common,
98 HB_Script_Tifinagh = Common,
99 HB_Script_SylotiNagri = Common,
100 HB_Script_OldPersian = Common,
101 HB_Script_Kharoshthi = Common,
102 HB_Script_Balinese = Common,
103 HB_Script_Cuneiform = Common,
104 HB_Script_Phoenician = Common,
105 HB_Script_PhagsPa = Common,
126 /*HB_LineBreakType*/ unsigned lineBreakType :2;
127 /*HB_Bool*/ unsigned whiteSpace :1; /* A unicode whitespace character, except NBSP, ZWNBSP */
128 /*HB_Bool*/ unsigned charStop :1; /* Valid cursor position (for left/right arrow) */
129 /*HB_Bool*/ unsigned wordBoundary :1;
130 /*HB_Bool*/ unsigned sentenceBoundary :1;
134 void HB_GetCharAttributes(const HB_UChar16 *string, hb_uint32 stringLength,
135 const HB_ScriptItem *items, hb_uint32 numItems,
136 HB_CharAttributes *attributes);
138 /* requires HB_GetCharAttributes to be called before */
139 void HB_GetWordBoundaries(const HB_UChar16 *string, hb_uint32 stringLength,
140 const HB_ScriptItem *items, hb_uint32 numItems,
141 HB_CharAttributes *attributes);
143 /* requires HB_GetCharAttributes to be called before */
144 void HB_GetSentenceBoundaries(const HB_UChar16 *string, hb_uint32 stringLength,
145 const HB_ScriptItem *items, hb_uint32 numItems,
146 HB_CharAttributes *attributes);
152 } HB_StringToGlyphsFlags;
155 HB_ShaperFlag_Default = 0,
156 HB_ShaperFlag_NoKerning = 1,
157 HB_ShaperFlag_UseDesignMetrics = 2
161 highest value means highest priority for justification. Justification is done by first inserting kashidas
162 starting with the highest priority positions, then stretching spaces, afterwards extending inter char
163 spacing, and last spacing between arabic words.
164 NoJustification is for example set for arabic where no Kashida can be inserted or for diacritics.
167 HB_NoJustification= 0, /* Justification can't be applied after this glyph */
168 HB_Arabic_Space = 1, /* This glyph represents a space inside arabic text */
169 HB_Character = 2, /* Inter-character justification point follows this glyph */
170 HB_Space = 4, /* This glyph represents a blank outside an Arabic run */
171 HB_Arabic_Normal = 7, /* Normal Middle-Of-Word glyph that connects to the right (begin) */
172 HB_Arabic_Waw = 8, /* Next character is final form of Waw/Ain/Qaf/Fa */
173 HB_Arabic_BaRa = 9, /* Next two chars are Ba + Ra/Ya/AlefMaksura */
174 HB_Arabic_Alef = 10, /* Next character is final form of Alef/Tah/Lam/Kaf/Gaf */
175 HB_Arabic_HaaDal = 11, /* Next character is final form of Haa/Dal/Taa Marbutah */
176 HB_Arabic_Seen = 12, /* Initial or Medial form Of Seen/Sad */
177 HB_Arabic_Kashida = 13 /* Kashida(U+640) in middle of word */
178 } HB_JustificationClass;
180 /* This structure is binary compatible with Uniscribe's SCRIPT_VISATTR. Would be nice to keep
181 * it like that. If this is a problem please tell Trolltech :)
184 unsigned justification :4; /* Justification class */
185 unsigned clusterStart :1; /* First glyph of representation of cluster */
186 unsigned mark :1; /* needs to be positioned around base char */
187 unsigned zeroWidth :1; /* ZWJ, ZWNJ etc, with no width */
188 unsigned dontPrint :1;
189 unsigned combiningClass :8;
190 } HB_GlyphAttributes;
192 typedef struct HB_FaceRec_ {
193 HB_Bool isSymbolFont;
198 HB_Bool supported_scripts[HB_ScriptCount];
200 HB_Script current_script;
201 int current_flags; /* HB_ShaperFlags */
202 HB_Bool has_opentype_kerning;
203 HB_Bool glyphs_substituted;
204 HB_GlyphAttributes *tmpAttributes;
205 unsigned int *tmpLogClusters;
210 typedef HB_Error (*HB_GetFontTableFunc)(void *font, HB_Tag tag, HB_Byte *buffer, HB_UInt *length);
212 HB_Face HB_NewFace(void *font, HB_GetFontTableFunc tableFunc);
213 void HB_FreeFace(HB_Face face);
217 HB_Fixed width, height;
218 HB_Fixed xOffset, yOffset;
226 HB_Bool (*convertStringToGlyphIndices)(HB_Font font, const HB_UChar16 *string, hb_uint32 length, HB_Glyph *glyphs, hb_uint32 *numGlyphs, HB_Bool rightToLeft);
227 void (*getGlyphAdvances)(HB_Font font, const HB_Glyph *glyphs, hb_uint32 numGlyphs, HB_Fixed *advances, int flags /*HB_ShaperFlag*/);
228 HB_Bool (*canRender)(HB_Font font, const HB_UChar16 *string, hb_uint32 length);
229 /* implementation needs to make sure to load a scaled glyph, so /no/ FT_LOAD_NO_SCALE */
230 HB_Error (*getPointInOutline)(HB_Font font, HB_Glyph glyph, int flags /*HB_ShaperFlag*/, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints);
231 void (*getGlyphMetrics)(HB_Font font, HB_Glyph glyph, HB_GlyphMetrics *metrics);
232 HB_Fixed (*getFontMetric)(HB_Font font, HB_FontMetric metric);
235 typedef struct HB_Font_ {
236 const HB_FontClass *klass;
239 HB_UShort x_ppem, y_ppem;
240 HB_16Dot16 x_scale, y_scale;
245 typedef struct HB_ShaperItem_ HB_ShaperItem;
247 struct HB_ShaperItem_ {
248 const HB_UChar16 *string; /* input: the Unicode UTF16 text to be shaped */
249 hb_uint32 stringLength; /* input: the length of the input in 16-bit words */
250 HB_ScriptItem item; /* input: the current run to be shaped: a run of text all in the same script that is a substring of <string> */
251 HB_Font font; /* input: the font: scale, units and function pointers supplying glyph indices and metrics */
252 HB_Face face; /* input: the shaper state; current script, access to the OpenType tables , etc. */
253 int shaperFlags; /* input (unused) should be set to 0; intended to support flags defined in HB_ShaperFlag */
254 HB_Bool glyphIndicesPresent; /* input: true if the <glyphs> array contains glyph indices ready to be shaped */
255 hb_uint32 initialGlyphCount; /* input: if glyphIndicesPresent is true, the number of glyph indices in the <glyphs> array */
257 hb_uint32 num_glyphs; /* input: capacity of output arrays <glyphs>, <attributes>, <advances>, <offsets>, and <log_clusters>; */
258 /* output: required capacity (may be larger than actual capacity) */
260 HB_Glyph *glyphs; /* output: <num_glyphs> indices of shaped glyphs */
261 HB_GlyphAttributes *attributes; /* output: <num_glyphs> glyph attributes */
262 HB_Fixed *advances; /* output: <num_glyphs> advances */
263 HB_FixedPoint *offsets; /* output: <num_glyphs> offsets */
264 unsigned short *log_clusters; /* output: for each output glyph, the index in the input of the start of its logical cluster */
267 HB_Bool kerning_applied; /* output: true if kerning was applied by the shaper */
270 HB_Bool HB_ShapeItem(HB_ShaperItem *item);
273 extern int tibetan_nextSyllableBoundary(const HB_UChar16 *s, int start, int end, HB_Bool *invalid) ;
274 extern int myanmar_nextSyllableBoundary(const HB_UChar16 *s, int start, int end, HB_Bool *invalid) ;
275 extern int khmer_nextSyllableBoundary(const HB_UChar16 *s, int start, int end, HB_Bool *invalid) ;
277 //extern "C" //{ int indic_nextSyllableBoundary(HB_Script script, const HB_UChar16 *s, int start, int end, bool *invalid) ;
280 extern int indic_nextSyllableBoundary(HB_Script script, const HB_UChar16 *s, int start, int end, HB_Bool *invalid) ;