TextLayout.h
12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/////////////////////////////////////////////////////////////////////////
/// \file TextLayout.h
/// \brief to support script languages on the basis of FreeType
/// \details
/// <br><br>
/// \author etrump
/// \version 1.00
/// \date 2008/11/27
///
/////////////////////////////////////////////////////////////////////////
#ifndef __TEXT_LAYOUT_H__
#define __TEXT_LAYOUT_H__
/* for OTTB 2012-04-01 */
#define OTTB_OFFSET_SUPPORT
/// The maximun string length.
#define MAX_STR_LENGTH 4096
#include <ft2build.h>
#include FT_FREETYPE_H
/// boundary type
typedef enum
{
Grapheme,
Word,
Line,
Sentence
}FT_Boundary_Type;
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
FT_F26Dot6 x; ///<F26Dot6[26.6]
FT_F26Dot6 y; ///<F26Dot6[26.6]
}OT_Offset;
typedef struct
{
FT_UInt32 num_glyphs; ///< glyphs used
FT_UInt32 *glyph_indices; ///< glyph index
FT_F26Dot6 *advances; ///< glyph advance
OT_Offset *offsets; ///< glyph offset
}FT_ShaperOut;
#define ET_UNICODE_REGION_MAX 8
typedef struct
{
FT_UInt32 count;
FT_UInt16 start[ET_UNICODE_REGION_MAX];
FT_UInt16 end[ET_UNICODE_REGION_MAX];
}FT_UniRegion;
/// The pointer to the text bounary.
typedef struct FT_Boundary *FT_Bound;
/// The pointer to the shape object.
typedef struct FT_ShaperRec *FT_Shaper;
/// The pointer to the layout object.
typedef struct FT_LayoutRec *FT_Layout;
/// The pointer to the text layout.
typedef struct FT_Text_LayoutRec *FT_TextLayout;
// add for mtk
typedef struct MT_OTInfoRec* MT_OTInfo;
typedef struct MT_Cluster_InfoRec* MT_Cluster_Info;
typedef struct ET_OTInfoRec* ET_OTInfo;
/////////////////////////////////////////////////////////////////////////
/// \brief Load Open Type Layout table (GDEF/GPOS/GPOS) from font
/// \param[in] face ::A handle to a face object
/// \param[out] playout ::A handle to a layout object
/// \return 1 means success and 0 means error
///////////////////////////////////////////////////////////////////////
FT_Bool FT_Load_Layout_Table( FT_Face face, FT_Layout *playout );
//////////////////////////////////////////////////////////////////////
/// \brief Destroy a layout object created by FT_Load_Layout_Table
/// \param[in] layout ::A handle to a layout object
/// \return N/A
/////////////////////////////////////////////////////////////////////
void FT_Done_Layout_Table( FT_Layout layout );
/////////////////////////////////////////////////////////////////////
/// \brief Create a shape object used to shape script to glyph item
/// \param[in] layout ::A handle to a layout object
/// \param[out] pshape ::A handle to a shape object
/// \return 1 means success and 0 means error
/////////////////////////////////////////////////////////////////////
FT_Bool FT_Shaper_Create( FT_Shaper *pshaper, FT_Layout layout );
////////////////////////////////////////////////////////////////////
/// \brief Destroy a shape object created by FT_Shaper_Create
/// \param[in] shaper ::A handle to a shape object
/// \return N/A
///////////////////////////////////////////////////////////////////
void FT_Shaper_Delete( FT_Shaper shaper );
//////////////////////////////////////////////////////////////////
/// \brief Create the texts boundary.
/// \param[in] chars ::The string to process.
/// \param[in] length ::The string length.
/// \param[in] type ::Which type of boundary will be created.
/// \return The created text boundary.
///////////////////////////////////////////////////////////////////
FT_Bound FT_Boundary_New( const FT_UInt16 *chars, int length, FT_Boundary_Type type );
///////////////////////////////////////////////////////////////////
/// \brief Get the next text that split by the boundary.
/// \param[in] bound ::A handle to a text boundary.
/// \return The start position of the next text.
///////////////////////////////////////////////////////////////////
int FT_Boundary_Get_Next( FT_Bound bound );
///////////////////////////////////////////////////////////////////
/// \brief Get the previous text that split by the boundary.
/// \param[in] bound ::A handle to a text boundary.
/// \return The start position of the previous text.
///////////////////////////////////////////////////////////////////
int FT_Boundary_Get_Previous( FT_Bound bound );
///////////////////////////////////////////////////////////////////
/// \brief Destroy the text boundary created by the function of FT_Boundary_New.
/// \param[in] bound ::A handle to a text boundary.
/// \return N/A.
///////////////////////////////////////////////////////////////////
void FT_Boundary_Free( FT_Bound bound );
///////////////////////////////////////////////////////////////////
/// \brief Shape a script to glyph item.
/// \param[in] shaper ::A handle to a shape object.
/// \param[in] str ::The string to process.
/// \param[in] length ::The string length.
/// \param[out] shaper ::A handle to a shape object.
/// \return if successful return 1, if failed return 0.
//////////////////////////////////////////////////////////////////
FT_Bool FT_Layout_Shape_Grapheme( FT_Shaper shaper, const FT_UInt16 *str, FT_UInt32 length );
//////////////////////////////////////////////////////////////////
/// \brief Get the result of the function FT_Layout_Shape_Grapheme.
/// \param[in] shaper ::A handle to a shape object.
/// \param[out] shape_result ::A hanldle to a shape result object.
/// \return if successful return 1, if failed return 0.
//////////////////////////////////////////////////////////////////
FT_Bool FT_Shaper_Get_Result( FT_Shaper shaper, FT_ShaperOut *shape_result );
typedef struct FT_GlyphItemRec
{
FT_Face face;
FT_UInt16 glyph; ///< glyph index
FT_Fixed advance; ///< glyph advance
OT_Offset offset; ///< glyph offset
}FT_GlyphItem; ///< Glyph item object.
//////////////////////////////////////////////////////////////////////////
/// \brief Convert the bidi-levels to visual orders.
/// \param[in] levels ::The bidi-levels.
/// \param[in] num_level ::The num levels.
/// \param[out] visual_orders ::The visual order result.
/// \return N/A.
/////////////////////////////////////////////////////////////////////////
void FT_Bidi_Level_To_Visual_Order( const FT_Byte *levels, int num_level, int *visual_orders );
//////////////////////////////////////////////////////////////////
/// \brief Create a text layout object to process string (script analysis/bi-direction).
/// \param[in] bRight2Left ::Align mode is right-to-left or left-to-right.
/// \param[in] text ::The string to process
/// \param[in] length ::The string length.
/// \param[out] text_layout ::A handle to a text layout object
/// \return N/A
/////////////////////////////////////////////////////////////////
void FT_Text_Layout_Create( FT_TextLayout *text_layout, int bRight2Left, FT_UInt16 *text, FT_UInt32 length );
//////////////////////////////////////////////////////////////////
/// \brief Shape the text by shape.
/// Get the glyph information for each script item.
/// \param[in] text_layout ::A handle to a text layout object.
/// \param[out] text_layout ::A handle to a text layout object.
/// \return N/A
////////////////////////////////////////////////////////////////
void FT_Text_Layout_Shape_Text( FT_TextLayout text_layout, FT_Shaper shaper );
////////////////////////////////////////////////////////////////
/// \brief Split text into a number of lines to draw within a given rectangle
/// \param[in] text_layout ::A handle to a layout object.
/// \param[in] shaper ::A handle to a shape object.
/// \param[in] boldWidth ::Specify the added width value if font style is bold.
/// \param[in] tabWidth ::Specify the tab width value if neccessary.
/// \param[in] fontHeight ::Specify the font height.
/// \param[in] rWidth ::The width of the bound rectangle.
/// \param[in] rHeight ::The height of the bound rectangle.
/// \param[in] byWord ::calculate line wrapper by word.
/// \param[out] text_layout ::A handle to a text layout object.
/// \return the line number.
///////////////////////////////////////////////////////////////
int FT_Text_Layout_Text_Lines( FT_TextLayout text_layout, FT_Shaper shaper, int boldWidth, int tabWidth, int fontheight, int rWidth, int rHeight, int widthGap, int heightGap, int byWord );
///////////////////////////////////////////////////////////////
/// \brief Get the line number in a rectangle after FT_Text_Layout_Text_Lines is called.
/// \param[in] text_layout ::A handle to a text layout object.
/// \return The line number.
//////////////////////////////////////////////////////////////
int FT_Text_Layout_Get_Line_Count( FT_TextLayout text_layout );
//////////////////////////////////////////////////////////////
/// \brief Get the first and last item in the current line and return.
/// \param[in] text_layout ::A handle to a text layout object.
/// \param[in] cur_line ::Current line number.
/// \param[out] first_item ::the first item.
/// \param[out] last_item ::the last item.
/// \return The item count.
/////////////////////////////////////////////////////////////
int FT_Text_Layout_Get_Line_Items( FT_TextLayout text_layout, int cur_line, int *first_item, int *last_item );
/////////////////////////////////////////////////////////////
/// \brief Get the bidi-levels array, the range is [from_item, last_item].
/// \param[in] text_layout ::A handle to a text layout object.
/// \param[in] from_item ::The first item.
/// \param[in] last_item ::The last item.
/// \param[out] levels ::The bidi-leves result.
/// \return if successful return (last_item - from_item + 1), if failed return 0.
//////////////////////////////////////////////////////////////
int FT_Text_Layout_Get_Levels( FT_TextLayout text_layout, int from_item, int last_item, FT_Byte *levels );
/////////////////////////////////////////////////////////////
/// \brief Get the glyph item by its index
/// \param[in] text_layout ::A handle to a layout object.
/// \param[in] item ::The given item.
/// \param[in] glyph_item ::A handle to a glyph item.
/// \param[out] glyph_item ::The glyph item result.
/// \return The number of glyph item.
////////////////////////////////////////////////////////////
int FT_Text_Layout_Get_Glyph_Item( FT_TextLayout text_layout, int item, FT_GlyphItem **glyph_item );
////////////////////////////////////////////////////////////
/// \brief Get the flags of the current item.
/// \param[in] text_layout ::A handle to a text layout object.
/// \param[in] item ::The given item.
/// \return The item flag.
///////////////////////////////////////////////////////////
int FT_Text_Layout_Get_Item_Flag( FT_TextLayout text_layout, int item );
//////////////////////////////////////////////////////////
/// \brief Get the level of the current item. This functions has same functions as FT_Text_Layout_Get_Levels.
/// \param[in] text_layout ::A handle to a layout object.
/// \param[in] item ::The given item.
/// \return The bide level.
////////////////////////////////////////////////////////
int FT_Text_Layout_Get_Level( FT_TextLayout text_layout, int item );
////////////////////////////////////////////////////////////////
/// \brief Destroy a text layout created by FT_Text_Layout_Create
/// \param[in] text_layout ::A handle to a layout object.
/// \return N/A
///////////////////////////////////////////////////////////////
void FT_Text_Layout_Delete( FT_TextLayout text_layout );
FT_GlyphItem* FT_Text_Layout_Get_Glyphs (FT_TextLayout layout);
int FT_Text_Layout_Get_Uni_Num(FT_TextLayout layout);
int FT_Text_Layout_Get_Glyph_Num (FT_TextLayout layout);
int FT_Text_Layout_Get_Item_Count( FT_TextLayout text_layout );
int FT_Text_Layout_Get_Item_Text(FT_TextLayout text_layout, int item, int *start);
int FT_Text_Layout_Item_Get_Glyph_Offset(FT_TextLayout layout, int item);
int FT_Text_Layout_Get_Syllable_Info(FT_TextLayout layout, int *glyph_cluster_start);
void FT_Text_Layout_Get_Offset_Info(FT_TextLayout layout, int tabWidth, int widthGap,
int *glyph_start_offset, int *glyph_end_offset, int *glyphLen);
int FT_Text_Layout_Get_Offset( FT_TextLayout layout, int cursor, int tabWidth, int widthGap);
int FT_Text_Layout_Get_Cursor( FT_TextLayout layout, int offset, int tabWidth, int widthGap);
int FT_Text_Layout_Prev_Cursor( FT_TextLayout layout, int cursor );
int FT_Text_Layout_Next_Cursor( FT_TextLayout layout, int cursor );
void FT_Text_Layout_Support_Multiple_Faces(int support);
// add for mtk
int FT_Shape_OpenType_Info( FT_Layout layout, FT_UInt16* text, int len, int bR2L, MT_Cluster_Info cluster );
int FT_Face_Get_Unicode_Region( FT_Face face, FT_UniRegion* region );
// for spreadtrum
int FT_Text_Layout_Paragraph_Direction(FT_UInt16* wstr, int len);
int FT_Text_Layout_Line_Direction(FT_UInt16* wstr, int len);
#ifdef __cplusplus
}
#endif
#endif //< __TEXT_LAYOUT_H__