1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49//
50
51#include <QtCore/private/qglobal_p.h>
52
53#ifndef QHARFBUZZ_P_H
54#define QHARFBUZZ_P_H
55
56#include <QtCore/qchar.h>
57
58#if defined(QT_BUILD_CORE_LIB)
59# include <harfbuzz-shaper.h>
60#else
61// a minimal set of HB types required for Qt libs other than Core
62extern "C" {
63
64typedef enum {
65 /* no error */
66 HB_Err_Ok = 0x0000,
67 HB_Err_Not_Covered = 0xFFFF,
68
69 /* _hb_err() is called whenever returning the following errors,
70 * and in a couple places for HB_Err_Not_Covered too. */
71
72 /* programmer error */
73 HB_Err_Invalid_Argument = 0x1A66,
74
75 /* font error */
76 HB_Err_Invalid_SubTable_Format = 0x157F,
77 HB_Err_Invalid_SubTable = 0x1570,
78 HB_Err_Read_Error = 0x6EAD,
79
80 /* system error */
81 HB_Err_Out_Of_Memory = 0xDEAD
82} HB_Error;
83
84typedef QT_PREPEND_NAMESPACE(qint8) hb_int8;
85typedef QT_PREPEND_NAMESPACE(quint8) hb_uint8;
86typedef QT_PREPEND_NAMESPACE(qint16) hb_int16;
87typedef QT_PREPEND_NAMESPACE(quint16) hb_uint16;
88typedef QT_PREPEND_NAMESPACE(qint32) hb_int32;
89typedef QT_PREPEND_NAMESPACE(quint32) hb_uint32;
90
91typedef hb_uint8 HB_Bool;
92typedef hb_uint8 HB_Byte;
93typedef hb_uint16 HB_UShort;
94typedef hb_uint32 HB_UInt;
95typedef hb_int8 HB_Char;
96typedef hb_int16 HB_Short;
97typedef hb_int32 HB_Int;
98typedef hb_uint16 HB_UChar16;
99typedef hb_uint32 HB_UChar32;
100typedef hb_uint32 HB_Glyph;
101typedef hb_int32 HB_Fixed; /* 26.6 */
102typedef hb_int32 HB_16Dot16; /* 16.16 */
103typedef hb_uint32 HB_Tag;
104
105typedef struct {
106 HB_Fixed x;
107 HB_Fixed y;
108} HB_FixedPoint;
109
110typedef enum {
111 HB_Script_Common,
112 HB_Script_Greek,
113 HB_Script_Cyrillic,
114 HB_Script_Armenian,
115 HB_Script_Hebrew,
116 HB_Script_Arabic,
117 HB_Script_Syriac,
118 HB_Script_Thaana,
119 HB_Script_Devanagari,
120 HB_Script_Bengali,
121 HB_Script_Gurmukhi,
122 HB_Script_Gujarati,
123 HB_Script_Oriya,
124 HB_Script_Tamil,
125 HB_Script_Telugu,
126 HB_Script_Kannada,
127 HB_Script_Malayalam,
128 HB_Script_Sinhala,
129 HB_Script_Thai,
130 HB_Script_Lao,
131 HB_Script_Tibetan,
132 HB_Script_Myanmar,
133 HB_Script_Georgian,
134 HB_Script_Hangul,
135 HB_Script_Ogham,
136 HB_Script_Runic,
137 HB_Script_Khmer,
138 HB_Script_Nko,
139 HB_Script_Inherited,
140 HB_ScriptCount = HB_Script_Inherited
141} HB_Script;
142
143#ifdef __xlC__
144typedef unsigned hb_bitfield;
145#else
146typedef hb_uint8 hb_bitfield;
147#endif
148
149typedef struct {
150 hb_bitfield justification :4; /* Justification class */
151 hb_bitfield clusterStart :1; /* First glyph of representation of cluster */
152 hb_bitfield mark :1; /* needs to be positioned around base char */
153 hb_bitfield zeroWidth :1; /* ZWJ, ZWNJ etc, with no width */
154 hb_bitfield dontPrint :1;
155 hb_bitfield combiningClass :8;
156} HB_GlyphAttributes;
157
158typedef void * HB_GDEF;
159typedef void * HB_GSUB;
160typedef void * HB_GPOS;
161typedef void * HB_Buffer;
162
163typedef HB_Error (*HB_GetFontTableFunc)(void *font, HB_Tag tag, HB_Byte *buffer, HB_UInt *length);
164
165typedef struct HB_FaceRec_ {
166 HB_Bool isSymbolFont;
167
168 HB_GDEF gdef;
169 HB_GSUB gsub;
170 HB_GPOS gpos;
171 HB_Bool supported_scripts[HB_ScriptCount];
172 HB_Buffer buffer;
173 HB_Script current_script;
174 int current_flags; /* HB_ShaperFlags */
175 HB_Bool has_opentype_kerning;
176 HB_Bool glyphs_substituted;
177 HB_GlyphAttributes *tmpAttributes;
178 unsigned int *tmpLogClusters;
179 int length;
180 int orig_nglyphs;
181 void *font_for_init;
182 HB_GetFontTableFunc get_font_table_func;
183} HB_FaceRec;
184
185typedef struct {
186 HB_Fixed x, y;
187 HB_Fixed width, height;
188 HB_Fixed xOffset, yOffset;
189} HB_GlyphMetrics;
190
191typedef enum {
192 HB_FontAscent
193} HB_FontMetric;
194
195struct HB_Font_;
196typedef struct HB_Font_ *HB_Font;
197typedef struct HB_FaceRec_ *HB_Face;
198
199typedef struct {
200 HB_Bool (*convertStringToGlyphIndices)(HB_Font font, const HB_UChar16 *string, hb_uint32 length, HB_Glyph *glyphs, hb_uint32 *numGlyphs, HB_Bool rightToLeft);
201 void (*getGlyphAdvances)(HB_Font font, const HB_Glyph *glyphs, hb_uint32 numGlyphs, HB_Fixed *advances, int flags /*HB_ShaperFlag*/);
202 HB_Bool (*canRender)(HB_Font font, const HB_UChar16 *string, hb_uint32 length);
203 /* implementation needs to make sure to load a scaled glyph, so /no/ FT_LOAD_NO_SCALE */
204 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);
205 void (*getGlyphMetrics)(HB_Font font, HB_Glyph glyph, HB_GlyphMetrics *metrics);
206 HB_Fixed (*getFontMetric)(HB_Font font, HB_FontMetric metric);
207} HB_FontClass;
208
209typedef struct HB_Font_ {
210 const HB_FontClass *klass;
211
212 /* Metrics */
213 HB_UShort x_ppem, y_ppem;
214 HB_16Dot16 x_scale, y_scale;
215
216 void *userData;
217} HB_FontRec;
218
219typedef enum {
220 HB_LeftToRight = 0,
221 HB_RightToLeft = 1
222} HB_StringToGlyphsFlags;
223
224typedef enum {
225 HB_ShaperFlag_Default = 0,
226 HB_ShaperFlag_NoKerning = 1,
227 HB_ShaperFlag_UseDesignMetrics = 2
228} HB_ShaperFlag;
229
230typedef struct
231{
232 hb_uint32 pos;
233 hb_uint32 length;
234 HB_Script script;
235 hb_uint8 bidiLevel;
236} HB_ScriptItem;
237
238typedef struct HB_ShaperItem_ HB_ShaperItem;
239
240struct HB_ShaperItem_ {
241 const HB_UChar16 *string; /* input: the Unicode UTF16 text to be shaped */
242 hb_uint32 stringLength; /* input: the length of the input in 16-bit words */
243 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> */
244 HB_Font font; /* input: the font: scale, units and function pointers supplying glyph indices and metrics */
245 HB_Face face; /* input: the shaper state; current script, access to the OpenType tables , etc. */
246 int shaperFlags; /* input (unused) should be set to 0; intended to support flags defined in HB_ShaperFlag */
247 HB_Bool glyphIndicesPresent; /* input: true if the <glyphs> array contains glyph indices ready to be shaped */
248 hb_uint32 initialGlyphCount; /* input: if glyphIndicesPresent is true, the number of glyph indices in the <glyphs> array */
249
250 hb_uint32 num_glyphs; /* input: capacity of output arrays <glyphs>, <attributes>, <advances>, <offsets>, and <log_clusters>; */
251 /* output: required capacity (may be larger than actual capacity) */
252
253 HB_Glyph *glyphs; /* output: <num_glyphs> indices of shaped glyphs */
254 HB_GlyphAttributes *attributes; /* output: <num_glyphs> glyph attributes */
255 HB_Fixed *advances; /* output: <num_glyphs> advances */
256 HB_FixedPoint *offsets; /* output: <num_glyphs> offsets */
257 unsigned short *log_clusters; /* output: for each output glyph, the index in the input of the start of its logical cluster */
258
259 /* internal */
260 HB_Bool kerning_applied; /* output: true if kerning was applied by the shaper */
261};
262
263}
264
265#endif // QT_BUILD_CORE_LIB
266
267
268QT_BEGIN_NAMESPACE
269
270static inline HB_Script script_to_hbscript(uchar script)
271{
272 switch (script) {
273 case QChar::Script_Inherited: return HB_Script_Inherited;
274 case QChar::Script_Common: return HB_Script_Common;
275 case QChar::Script_Arabic: return HB_Script_Arabic;
276 case QChar::Script_Armenian: return HB_Script_Armenian;
277 case QChar::Script_Bengali: return HB_Script_Bengali;
278 case QChar::Script_Cyrillic: return HB_Script_Cyrillic;
279 case QChar::Script_Devanagari: return HB_Script_Devanagari;
280 case QChar::Script_Georgian: return HB_Script_Georgian;
281 case QChar::Script_Greek: return HB_Script_Greek;
282 case QChar::Script_Gujarati: return HB_Script_Gujarati;
283 case QChar::Script_Gurmukhi: return HB_Script_Gurmukhi;
284 case QChar::Script_Hangul: return HB_Script_Hangul;
285 case QChar::Script_Hebrew: return HB_Script_Hebrew;
286 case QChar::Script_Kannada: return HB_Script_Kannada;
287 case QChar::Script_Khmer: return HB_Script_Khmer;
288 case QChar::Script_Lao: return HB_Script_Lao;
289 case QChar::Script_Malayalam: return HB_Script_Malayalam;
290 case QChar::Script_Myanmar: return HB_Script_Myanmar;
291 case QChar::Script_Ogham: return HB_Script_Ogham;
292 case QChar::Script_Oriya: return HB_Script_Oriya;
293 case QChar::Script_Runic: return HB_Script_Runic;
294 case QChar::Script_Sinhala: return HB_Script_Sinhala;
295 case QChar::Script_Syriac: return HB_Script_Syriac;
296 case QChar::Script_Tamil: return HB_Script_Tamil;
297 case QChar::Script_Telugu: return HB_Script_Telugu;
298 case QChar::Script_Thaana: return HB_Script_Thaana;
299 case QChar::Script_Thai: return HB_Script_Thai;
300 case QChar::Script_Tibetan: return HB_Script_Tibetan;
301 case QChar::Script_Nko: return HB_Script_Nko;
302 default: break;
303 };
304 return HB_Script_Common;
305}
306
307static inline uchar hbscript_to_script(uchar script)
308{
309 switch (script) {
310 case HB_Script_Inherited: return QChar::Script_Inherited;
311 case HB_Script_Common: return QChar::Script_Common;
312 case HB_Script_Arabic: return QChar::Script_Arabic;
313 case HB_Script_Armenian: return QChar::Script_Armenian;
314 case HB_Script_Bengali: return QChar::Script_Bengali;
315 case HB_Script_Cyrillic: return QChar::Script_Cyrillic;
316 case HB_Script_Devanagari: return QChar::Script_Devanagari;
317 case HB_Script_Georgian: return QChar::Script_Georgian;
318 case HB_Script_Greek: return QChar::Script_Greek;
319 case HB_Script_Gujarati: return QChar::Script_Gujarati;
320 case HB_Script_Gurmukhi: return QChar::Script_Gurmukhi;
321 case HB_Script_Hangul: return QChar::Script_Hangul;
322 case HB_Script_Hebrew: return QChar::Script_Hebrew;
323 case HB_Script_Kannada: return QChar::Script_Kannada;
324 case HB_Script_Khmer: return QChar::Script_Khmer;
325 case HB_Script_Lao: return QChar::Script_Lao;
326 case HB_Script_Malayalam: return QChar::Script_Malayalam;
327 case HB_Script_Myanmar: return QChar::Script_Myanmar;
328 case HB_Script_Ogham: return QChar::Script_Ogham;
329 case HB_Script_Oriya: return QChar::Script_Oriya;
330 case HB_Script_Runic: return QChar::Script_Runic;
331 case HB_Script_Sinhala: return QChar::Script_Sinhala;
332 case HB_Script_Syriac: return QChar::Script_Syriac;
333 case HB_Script_Tamil: return QChar::Script_Tamil;
334 case HB_Script_Telugu: return QChar::Script_Telugu;
335 case HB_Script_Thaana: return QChar::Script_Thaana;
336 case HB_Script_Thai: return QChar::Script_Thai;
337 case HB_Script_Tibetan: return QChar::Script_Tibetan;
338 case HB_Script_Nko: return QChar::Script_Nko;
339 default: break;
340 };
341 return QChar::Script_Common;
342}
343
344Q_CORE_EXPORT HB_Bool qShapeItem(HB_ShaperItem *item);
345
346// ### temporary
347Q_CORE_EXPORT HB_Face qHBNewFace(void *font, HB_GetFontTableFunc tableFunc);
348Q_CORE_EXPORT void qHBFreeFace(HB_Face);
349Q_CORE_EXPORT HB_Face qHBLoadFace(HB_Face face);
350
351Q_DECLARE_TYPEINFO(HB_GlyphAttributes, Q_PRIMITIVE_TYPE);
352Q_DECLARE_TYPEINFO(HB_FixedPoint, Q_PRIMITIVE_TYPE);
353Q_DECLARE_TYPEINFO(HB_ScriptItem, Q_PRIMITIVE_TYPE);
354
355QT_END_NAMESPACE
356
357#endif // QHARFBUZZ_P_H
358

source code of qtbase/src/corelib/text/qharfbuzz_p.h