ReactOS 0.4.17-dev-934-g091855f
arabic.c
Go to the documentation of this file.
1/*
2 * Copyright HarfBuzz Project authors
3 * Copyright 2020 Nikolay Sivov for CodeWeavers
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20#include "dwrite_private.h"
21#include "scripts.h"
22
23static const unsigned int arabic_features[] =
24{
25 DWRITE_MAKE_OPENTYPE_TAG('i','s','o','l'),
26 DWRITE_MAKE_OPENTYPE_TAG('f','i','n','a'),
27 DWRITE_MAKE_OPENTYPE_TAG('f','i','n','2'),
28 DWRITE_MAKE_OPENTYPE_TAG('f','i','n','3'),
29 DWRITE_MAKE_OPENTYPE_TAG('m','e','d','i'),
30 DWRITE_MAKE_OPENTYPE_TAG('m','e','d','2'),
31 DWRITE_MAKE_OPENTYPE_TAG('i','n','i','t'),
32};
33
35{
45};
46
47static BOOL feature_is_syriac(unsigned int tag)
48{
49 return tag == arabic_features[FIN2] || tag == arabic_features[FIN3] ||
51}
52
54 struct shaping_features *features)
55{
56 unsigned int i;
57
58 shape_enable_feature(features, DWRITE_MAKE_OPENTYPE_TAG('c','c','m','p'), 0);
59 shape_enable_feature(features, DWRITE_MAKE_OPENTYPE_TAG('l','o','c','l'), 0);
61
62 for (i = 0; i < ARRAY_SIZE(arabic_features); ++i)
63 {
64 unsigned int flags = context->script == Script_Arabic && !feature_is_syriac(arabic_features[i]) ?
68 }
69
70 shape_enable_feature(features, DWRITE_MAKE_OPENTYPE_TAG('r','l','i','g'), FEATURE_MANUAL_ZWJ | FEATURE_HAS_FALLBACK);
71
72 shape_enable_feature(features, DWRITE_MAKE_OPENTYPE_TAG('r','c','l','t'), FEATURE_MANUAL_ZWJ);
73 shape_enable_feature(features, DWRITE_MAKE_OPENTYPE_TAG('c','a','l','t'), FEATURE_MANUAL_ZWJ);
75
76 shape_enable_feature(features, DWRITE_MAKE_OPENTYPE_TAG('m','s','e','t'), 0);
77}
78
80{
90};
91
92static const struct arabic_state_table_entry
93{
94 unsigned char prev_action;
95 unsigned char curr_action;
96 unsigned char next_state;
97}
99{
100 /* U, L, R, D, ALAPH, DALATH_RISH */
101 /* State 0: prev was U, not willing to join. */
102 { {NONE,NONE,0}, {NONE,ISOL,2}, {NONE,ISOL,1}, {NONE,ISOL,2}, {NONE,ISOL,1}, {NONE,ISOL,6}, },
103
104 /* State 1: prev was R or ISOL/ALAPH, not willing to join. */
105 { {NONE,NONE,0}, {NONE,ISOL,2}, {NONE,ISOL,1}, {NONE,ISOL,2}, {NONE,FIN2,5}, {NONE,ISOL,6}, },
106
107 /* State 2: prev was D/L in ISOL form, willing to join. */
108 { {NONE,NONE,0}, {NONE,ISOL,2}, {INIT,FINA,1}, {INIT,FINA,3}, {INIT,FINA,4}, {INIT,FINA,6}, },
109
110 /* State 3: prev was D in FINA form, willing to join. */
111 { {NONE,NONE,0}, {NONE,ISOL,2}, {MEDI,FINA,1}, {MEDI,FINA,3}, {MEDI,FINA,4}, {MEDI,FINA,6}, },
112
113 /* State 4: prev was FINA ALAPH, not willing to join. */
114 { {NONE,NONE,0}, {NONE,ISOL,2}, {MED2,ISOL,1}, {MED2,ISOL,2}, {MED2,FIN2,5}, {MED2,ISOL,6}, },
115
116 /* State 5: prev was FIN2/FIN3 ALAPH, not willing to join. */
117 { {NONE,NONE,0}, {NONE,ISOL,2}, {ISOL,ISOL,1}, {ISOL,ISOL,2}, {ISOL,FIN2,5}, {ISOL,ISOL,6}, },
118
119 /* State 6: prev was DALATH/RISH, not willing to join. */
120 { {NONE,NONE,0}, {NONE,ISOL,2}, {NONE,ISOL,1}, {NONE,ISOL,2}, {NONE,FIN3,5}, {NONE,ISOL,6}, }
122
123extern const unsigned short arabic_shaping_table[];
124
125static unsigned short arabic_get_joining_type(UINT ch)
126{
128}
129
131 unsigned int idx, enum arabic_shaping_action action)
132{
133 context->glyph_infos[idx].props &= ~(0xf << 16);
134 context->glyph_infos[idx].props |= (action & 0xf) << 16;
135}
136
138 unsigned int idx)
139{
140 return (context->glyph_infos[idx].props >> 16) & 0xf;
141}
142
144 const struct shaping_features *features)
145{
146 unsigned int i, prev = ~0u, state = 0;
147 unsigned int masks[NUM_FEATURES+1];
148
149 for (i = 0; i < context->glyph_count; ++i)
150 {
151 unsigned short this_type = arabic_get_joining_type(context->glyph_infos[i].codepoint);
152 const struct arabic_state_table_entry *entry;
153
154 if (this_type == JOINING_TYPE_T)
155 {
157 continue;
158 }
159
160 entry = &arabic_state_table[state][this_type];
161
162 if (entry->prev_action != NONE && prev != ~0u)
163 arabic_set_shaping_action(context, prev, entry->prev_action);
164
166
167 prev = i;
168 state = entry->next_state;
169 }
170
171 for (i = 0; i < NUM_FEATURES; ++i)
173 masks[NONE] = 0;
174
175 /* Unaffected glyphs get action NONE with zero mask. */
176 for (i = 0; i < context->glyph_count; ++i)
177 {
179 if (action != NONE)
181 context->glyph_infos[i].mask |= masks[action];
182 }
183}
184
185const struct shaper arabic_shaper =
186{
187 .collect_features = arabic_collect_features,
188 .setup_masks = arabic_setup_masks,
189};
static int state
Definition: maze.c:121
const unsigned short arabic_shaping_table[]
Definition: arabic_table.c:7
const struct shaper arabic_shaper
Definition: arabic.c:185
static unsigned short arabic_get_joining_type(UINT ch)
Definition: arabic.c:125
arabic_joining_type
Definition: arabic.c:80
@ JOINING_GROUP_ALAPH
Definition: arabic.c:86
@ JOINING_TYPES
Definition: arabic.c:88
@ JOINING_TYPE_T
Definition: arabic.c:89
@ JOINING_TYPE_C
Definition: arabic.c:85
@ JOINING_TYPE_D
Definition: arabic.c:84
@ JOINING_TYPE_L
Definition: arabic.c:82
@ JOINING_TYPE_R
Definition: arabic.c:83
@ JOINING_GROUP_DALATH_RISH
Definition: arabic.c:87
@ JOINING_TYPE_U
Definition: arabic.c:81
static void arabic_setup_masks(struct scriptshaping_context *context, const struct shaping_features *features)
Definition: arabic.c:143
static void arabic_collect_features(struct scriptshaping_context *context, struct shaping_features *features)
Definition: arabic.c:53
static const struct arabic_state_table_entry arabic_state_table[][JOINING_TYPES]
static const unsigned int arabic_features[]
Definition: arabic.c:23
static void arabic_set_shaping_action(struct scriptshaping_context *context, unsigned int idx, enum arabic_shaping_action action)
Definition: arabic.c:130
static BOOL feature_is_syriac(unsigned int tag)
Definition: arabic.c:47
static enum arabic_shaping_action arabic_get_shaping_action(const struct scriptshaping_context *context, unsigned int idx)
Definition: arabic.c:137
arabic_shaping_action
Definition: arabic.c:35
@ ISOL
Definition: arabic.c:36
@ INIT
Definition: arabic.c:42
@ NUM_FEATURES
Definition: arabic.c:44
@ FINA
Definition: arabic.c:37
@ MEDI
Definition: arabic.c:40
@ MED2
Definition: arabic.c:41
@ NONE
Definition: arabic.c:43
@ FIN3
Definition: arabic.c:39
@ FIN2
Definition: arabic.c:38
#define ARRAY_SIZE(A)
Definition: main.h:20
#define NULL
Definition: types.h:112
unsigned int idx
Definition: utils.c:40
unsigned char ch[4][2]
Definition: console.c:118
action
Definition: namespace.c:707
void shape_start_next_stage(struct shaping_features *features, stage_func func)
Definition: shape.c:144
@ FEATURE_MANUAL_ZWJ
@ FEATURE_HAS_FALLBACK
void opentype_layout_unsafe_to_break(struct scriptshaping_context *context, unsigned int start, unsigned int end)
Definition: opentype.c:5233
void shape_enable_feature(struct shaping_features *features, unsigned int tag, unsigned int flags)
Definition: shape.c:138
unsigned int shape_get_feature_1_mask(const struct shaping_features *features, unsigned int tag)
Definition: opentype.c:4822
static unsigned short get_table_entry_32(const unsigned short *table, UINT ch)
void shape_add_feature_full(struct shaping_features *features, unsigned int tag, unsigned int flags, unsigned int value)
Definition: shape.c:117
unsigned int BOOL
Definition: ntddk_ex.h:94
GLbitfield flags
Definition: glext.h:7161
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
unsigned int UINT
Definition: sysinfo.c:13
uint32_t entry
Definition: isohybrid.c:63
static const BYTE masks[8]
Definition: dib.c:3008
@ Script_Arabic
Definition: scripts.h:9
Definition: arabic.c:93
unsigned char prev_action
Definition: arabic.c:94
unsigned char next_state
Definition: arabic.c:96
unsigned char curr_action
Definition: arabic.c:95
Definition: http.c:7252
Definition: ecma_167.h:138