Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Implementation of Uniscribe Script Processor (usp10.dll) |
| 3 | * |
| 4 | * Copyright 2005 Steven Edwards for CodeWeavers |
Hans Leidekker | 960372f | 2006-12-23 15:19:30 +0100 | [diff] [blame] | 5 | * Copyright 2006 Hans Leidekker |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 6 | * Copyright 2010 CodeWeavers, Aric Stewart |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 21 | * |
| 22 | * Notes: |
| 23 | * Uniscribe allows for processing of complex scripts such as joining |
| 24 | * and filtering characters and bi-directional text with custom line breaks. |
| 25 | */ |
| 26 | |
| 27 | #include <stdarg.h> |
| 28 | |
Vincent Béron | 56da0c3 | 2005-08-10 09:51:40 +0000 | [diff] [blame] | 29 | #include "windef.h" |
| 30 | #include "winbase.h" |
Vijay Kiran Kamuju | a1eeaf9 | 2005-11-28 11:52:55 +0100 | [diff] [blame] | 31 | #include "wingdi.h" |
Vincent Béron | 56da0c3 | 2005-08-10 09:51:40 +0000 | [diff] [blame] | 32 | #include "winuser.h" |
Albert Lee | b2182f9 | 2006-09-07 02:42:56 -0400 | [diff] [blame] | 33 | #include "winnls.h" |
Vincent Béron | 56da0c3 | 2005-08-10 09:51:40 +0000 | [diff] [blame] | 34 | #include "usp10.h" |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 35 | |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 36 | #include "usp10_internal.h" |
| 37 | |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 38 | #include "wine/debug.h" |
Hans Leidekker | 02d30df | 2006-12-23 11:50:47 +0100 | [diff] [blame] | 39 | #include "wine/unicode.h" |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 40 | |
| 41 | WINE_DEFAULT_DEBUG_CHANNEL(uniscribe); |
| 42 | |
Hans Leidekker | 960372f | 2006-12-23 15:19:30 +0100 | [diff] [blame] | 43 | static const SCRIPT_PROPERTIES props[] = |
| 44 | { |
| 45 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 46 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 47 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 48 | { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 49 | { 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 50 | { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 51 | { 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 52 | { 8, 0, 0, 0, 0, 161, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 53 | { 25, 0, 0, 0, 0, 204, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 54 | { 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 55 | { 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 56 | { 42, 0, 0, 0, 0, 163, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 57 | { 9, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 58 | { 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0 }, |
| 59 | { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 60 | { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 61 | { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 62 | { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 63 | { 18, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 64 | { 18, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 65 | { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 66 | { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 67 | { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 68 | { 9, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 69 | { 13, 0, 1, 0, 1, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 70 | { 13, 0, 1, 0, 0, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 71 | { 1, 0, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 1, 1, 0 }, |
| 72 | { 1, 1, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
| 73 | { 41, 1, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 74 | { 32, 1, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 75 | { 90, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0 }, |
| 76 | { 30, 0, 1, 1, 1, 222, 0, 0, 1, 0, 1, 0, 0, 0, 1 }, |
| 77 | { 30, 1, 1, 0, 0, 222, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 78 | { 30, 0, 1, 0, 0, 222, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 79 | { 57, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
| 80 | { 57, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 81 | { 73, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
| 82 | { 73, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 83 | { 69, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
| 84 | { 69, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 85 | { 69, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 86 | { 70, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
| 87 | { 70, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 88 | { 71, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
| 89 | { 71, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 90 | { 72, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
| 91 | { 72, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 92 | { 74, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
| 93 | { 74, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 94 | { 75, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
| 95 | { 75, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 96 | { 76, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
| 97 | { 76, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 98 | { 81, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0 }, |
| 99 | { 81, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 100 | { 84, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0 }, |
| 101 | { 84, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 102 | { 83, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
| 103 | { 83, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 104 | { 85, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
| 105 | { 85, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 106 | { 80, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 107 | { 80, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 108 | { 94, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 109 | { 94, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 110 | { 101, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 111 | { 93, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 112 | { 92, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 113 | { 9, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 114 | { 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 115 | { 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 116 | { 91, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 117 | { 9, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 }, |
| 118 | { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 119 | }; |
Jeff Latimer | 0ba307d | 2006-02-16 12:06:18 +0100 | [diff] [blame] | 120 | |
Hans Leidekker | 960372f | 2006-12-23 15:19:30 +0100 | [diff] [blame] | 121 | static const SCRIPT_PROPERTIES *script_props[] = |
| 122 | { |
| 123 | &props[0], &props[1], &props[2], &props[3], |
| 124 | &props[4], &props[5], &props[6], &props[7], |
| 125 | &props[8], &props[9], &props[11], &props[12], |
| 126 | &props[13], &props[14], &props[15], &props[16], |
| 127 | &props[17], &props[18], &props[19], &props[20], |
| 128 | &props[21], &props[22], &props[23], &props[24], |
| 129 | &props[25], &props[26], &props[27], &props[28], |
| 130 | &props[29], &props[30], &props[31], &props[32], |
| 131 | &props[33], &props[34], &props[35], &props[36], |
| 132 | &props[37], &props[38], &props[39], &props[40], |
| 133 | &props[41], &props[42], &props[43], &props[44], |
| 134 | &props[45], &props[46], &props[47], &props[48], |
| 135 | &props[49], &props[50], &props[51], &props[52], |
| 136 | &props[53], &props[54], &props[55], &props[56], |
| 137 | &props[57], &props[58], &props[59], &props[60], |
| 138 | &props[61], &props[62], &props[63], &props[64], |
| 139 | &props[65], &props[66], &props[67], &props[68], |
| 140 | &props[69], &props[70], &props[71], &props[72], |
| 141 | &props[73] |
| 142 | }; |
Jeff Latimer | 0ba307d | 2006-02-16 12:06:18 +0100 | [diff] [blame] | 143 | |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 144 | typedef struct { |
| 145 | int numGlyphs; |
| 146 | WORD* glyphs; |
| 147 | WORD* pwLogClust; |
| 148 | int* piAdvance; |
| 149 | SCRIPT_VISATTR* psva; |
| 150 | GOFFSET* pGoffset; |
| 151 | ABC* abc; |
| 152 | } StringGlyphs; |
| 153 | |
| 154 | typedef struct { |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 155 | HDC hdc; |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 156 | BOOL invalid; |
Hans Leidekker | f152153 | 2007-01-03 12:12:29 +0100 | [diff] [blame] | 157 | int clip_len; |
Hans Leidekker | 23b3299 | 2007-01-03 12:12:03 +0100 | [diff] [blame] | 158 | ScriptCache *sc; |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 159 | int cItems; |
| 160 | int cMaxGlyphs; |
| 161 | SCRIPT_ITEM* pItem; |
| 162 | int numItems; |
| 163 | StringGlyphs* glyphs; |
Hans Leidekker | cd6fe7d | 2006-12-23 17:19:31 +0100 | [diff] [blame] | 164 | SCRIPT_LOGATTR* logattrs; |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 165 | SIZE* sz; |
| 166 | } StringAnalysis; |
| 167 | |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 168 | static inline void *heap_alloc(SIZE_T size) |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 169 | { |
| 170 | return HeapAlloc(GetProcessHeap(), 0, size); |
| 171 | } |
| 172 | |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 173 | static inline void *heap_alloc_zero(SIZE_T size) |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 174 | { |
| 175 | return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size); |
| 176 | } |
| 177 | |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 178 | static inline void *heap_realloc_zero(LPVOID mem, SIZE_T size) |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 179 | { |
| 180 | return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size); |
| 181 | } |
| 182 | |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 183 | static inline BOOL heap_free(LPVOID mem) |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 184 | { |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 185 | return HeapFree(GetProcessHeap(), 0, mem); |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 186 | } |
| 187 | |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 188 | static inline WCHAR get_cache_default_char(SCRIPT_CACHE *psc) |
Hans Leidekker | 06ed81e | 2007-01-23 11:03:12 +0100 | [diff] [blame] | 189 | { |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 190 | return ((ScriptCache *)*psc)->tm.tmDefaultChar; |
Hans Leidekker | 06ed81e | 2007-01-23 11:03:12 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 193 | static inline LONG get_cache_height(SCRIPT_CACHE *psc) |
Hans Leidekker | 06ed81e | 2007-01-23 11:03:12 +0100 | [diff] [blame] | 194 | { |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 195 | return ((ScriptCache *)*psc)->tm.tmHeight; |
| 196 | } |
| 197 | |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 198 | static inline BYTE get_cache_pitch_family(SCRIPT_CACHE *psc) |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 199 | { |
| 200 | return ((ScriptCache *)*psc)->tm.tmPitchAndFamily; |
Hans Leidekker | 06ed81e | 2007-01-23 11:03:12 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 203 | static inline WORD get_cache_glyph(SCRIPT_CACHE *psc, WCHAR c) |
Hans Leidekker | 06ed81e | 2007-01-23 11:03:12 +0100 | [diff] [blame] | 204 | { |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 205 | WORD *block = ((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT]; |
| 206 | |
| 207 | if (!block) return 0; |
| 208 | return block[c & GLYPH_BLOCK_MASK]; |
Hans Leidekker | 06ed81e | 2007-01-23 11:03:12 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 211 | static inline WORD set_cache_glyph(SCRIPT_CACHE *psc, WCHAR c, WORD glyph) |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 212 | { |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 213 | WORD **block = &((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT]; |
| 214 | |
| 215 | if (!*block && !(*block = heap_alloc_zero(sizeof(WORD) * GLYPH_BLOCK_SIZE))) return 0; |
| 216 | return ((*block)[c & GLYPH_BLOCK_MASK] = glyph); |
| 217 | } |
| 218 | |
| 219 | static inline BOOL get_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc) |
| 220 | { |
| 221 | static const ABC nil; |
| 222 | ABC *block = ((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT]; |
| 223 | |
| 224 | if (!block || !memcmp(&block[glyph & GLYPH_BLOCK_MASK], &nil, sizeof(ABC))) return FALSE; |
| 225 | memcpy(abc, &block[glyph & GLYPH_BLOCK_MASK], sizeof(ABC)); |
| 226 | return TRUE; |
| 227 | } |
| 228 | |
| 229 | static inline BOOL set_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc) |
| 230 | { |
| 231 | ABC **block = &((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT]; |
| 232 | |
| 233 | if (!*block && !(*block = heap_alloc_zero(sizeof(ABC) * GLYPH_BLOCK_SIZE))) return FALSE; |
| 234 | memcpy(&(*block)[glyph & GLYPH_BLOCK_MASK], abc, sizeof(ABC)); |
| 235 | return TRUE; |
| 236 | } |
| 237 | |
| 238 | static HRESULT init_script_cache(const HDC hdc, SCRIPT_CACHE *psc) |
| 239 | { |
| 240 | ScriptCache *sc; |
| 241 | |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 242 | if (!psc) return E_INVALIDARG; |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 243 | if (*psc) return S_OK; |
| 244 | if (!hdc) return E_PENDING; |
| 245 | |
| 246 | if (!(sc = heap_alloc_zero(sizeof(ScriptCache)))) return E_OUTOFMEMORY; |
| 247 | if (!GetTextMetricsW(hdc, &sc->tm)) |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 248 | { |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 249 | heap_free(sc); |
| 250 | return E_INVALIDARG; |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 251 | } |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 252 | if (!GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(LOGFONTW), &sc->lf)) |
| 253 | { |
| 254 | heap_free(sc); |
| 255 | return E_INVALIDARG; |
| 256 | } |
| 257 | *psc = sc; |
| 258 | TRACE("<- %p\n", sc); |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 259 | return S_OK; |
| 260 | } |
| 261 | |
Aric Stewart | 4377cc6 | 2010-05-06 08:28:57 -0500 | [diff] [blame] | 262 | static WCHAR mirror_char( WCHAR ch ) |
| 263 | { |
| 264 | extern const WCHAR wine_mirror_map[]; |
| 265 | return ch + wine_mirror_map[wine_mirror_map[ch >> 8] + (ch & 0xff)]; |
| 266 | } |
| 267 | |
Francois Gouget | 17689c0 | 2006-05-12 00:34:55 +0200 | [diff] [blame] | 268 | /*********************************************************************** |
| 269 | * DllMain |
| 270 | * |
| 271 | */ |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 272 | BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv) |
| 273 | { |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 274 | switch(fdwReason) |
| 275 | { |
| 276 | case DLL_PROCESS_ATTACH: |
| 277 | DisableThreadLibraryCalls(hInstDLL); |
| 278 | break; |
| 279 | case DLL_PROCESS_DETACH: |
| 280 | break; |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 281 | } |
| 282 | return TRUE; |
| 283 | } |
| 284 | |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 285 | /*********************************************************************** |
Hans Leidekker | c0a223b | 2006-01-09 17:16:57 +0100 | [diff] [blame] | 286 | * ScriptFreeCache (USP10.@) |
| 287 | * |
Hans Leidekker | 44fd9a2 | 2007-01-02 16:11:10 +0100 | [diff] [blame] | 288 | * Free a script cache. |
| 289 | * |
| 290 | * PARAMS |
| 291 | * psc [I/O] Script cache. |
| 292 | * |
| 293 | * RETURNS |
| 294 | * Success: S_OK |
| 295 | * Failure: Non-zero HRESULT value. |
Hans Leidekker | c0a223b | 2006-01-09 17:16:57 +0100 | [diff] [blame] | 296 | */ |
| 297 | HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc) |
| 298 | { |
Jeff Latimer | 334e191 | 2006-02-20 20:19:32 +1100 | [diff] [blame] | 299 | TRACE("%p\n", psc); |
Hans Leidekker | c0a223b | 2006-01-09 17:16:57 +0100 | [diff] [blame] | 300 | |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 301 | if (psc && *psc) |
Hans Leidekker | 44fd9a2 | 2007-01-02 16:11:10 +0100 | [diff] [blame] | 302 | { |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 303 | unsigned int i; |
| 304 | for (i = 0; i < GLYPH_MAX / GLYPH_BLOCK_SIZE; i++) |
| 305 | { |
| 306 | heap_free(((ScriptCache *)*psc)->glyphs[i]); |
| 307 | heap_free(((ScriptCache *)*psc)->widths[i]); |
| 308 | } |
Aric Stewart | 8412028 | 2010-05-19 09:16:45 -0500 | [diff] [blame] | 309 | heap_free(((ScriptCache *)*psc)->GSUB_Table); |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 310 | heap_free(*psc); |
| 311 | *psc = NULL; |
Jeff Latimer | 334e191 | 2006-02-20 20:19:32 +1100 | [diff] [blame] | 312 | } |
Hans Leidekker | 44fd9a2 | 2007-01-02 16:11:10 +0100 | [diff] [blame] | 313 | return S_OK; |
Hans Leidekker | c0a223b | 2006-01-09 17:16:57 +0100 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /*********************************************************************** |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 317 | * ScriptGetProperties (USP10.@) |
| 318 | * |
Hans Leidekker | 960372f | 2006-12-23 15:19:30 +0100 | [diff] [blame] | 319 | * Retrieve a list of script properties. |
| 320 | * |
| 321 | * PARAMS |
| 322 | * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers. |
| 323 | * num [I] Pointer to the number of scripts. |
| 324 | * |
| 325 | * RETURNS |
| 326 | * Success: S_OK |
| 327 | * Failure: Non-zero HRESULT value. |
| 328 | * |
| 329 | * NOTES |
| 330 | * Behaviour matches WinXP. |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 331 | */ |
Hans Leidekker | 960372f | 2006-12-23 15:19:30 +0100 | [diff] [blame] | 332 | HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***props, int *num) |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 333 | { |
Hans Leidekker | 960372f | 2006-12-23 15:19:30 +0100 | [diff] [blame] | 334 | TRACE("(%p,%p)\n", props, num); |
Hans Leidekker | c0a223b | 2006-01-09 17:16:57 +0100 | [diff] [blame] | 335 | |
Hans Leidekker | 960372f | 2006-12-23 15:19:30 +0100 | [diff] [blame] | 336 | if (!props && !num) return E_INVALIDARG; |
Eric Pouech | 766530d | 2006-05-16 21:12:16 +0200 | [diff] [blame] | 337 | |
Hans Leidekker | 960372f | 2006-12-23 15:19:30 +0100 | [diff] [blame] | 338 | if (num) *num = sizeof(script_props)/sizeof(script_props[0]); |
| 339 | if (props) *props = script_props; |
| 340 | |
| 341 | return S_OK; |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 344 | /*********************************************************************** |
| 345 | * ScriptGetFontProperties (USP10.@) |
| 346 | * |
Hans Leidekker | 44fd9a2 | 2007-01-02 16:11:10 +0100 | [diff] [blame] | 347 | * Get information on special glyphs. |
| 348 | * |
| 349 | * PARAMS |
| 350 | * hdc [I] Device context. |
| 351 | * psc [I/O] Opaque pointer to a script cache. |
| 352 | * sfp [O] Font properties structure. |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 353 | */ |
Oliver Stieber | b671180 | 2005-08-01 09:18:53 +0000 | [diff] [blame] | 354 | HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp) |
| 355 | { |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 356 | HRESULT hr; |
Jeff Latimer | ca55584 | 2006-04-13 18:38:31 +1000 | [diff] [blame] | 357 | |
Jeff Latimer | 9c6c83e | 2006-04-20 21:50:44 +1000 | [diff] [blame] | 358 | TRACE("%p,%p,%p\n", hdc, psc, sfp); |
Paul Vriens | e56f6a3 | 2006-04-21 08:00:14 +0200 | [diff] [blame] | 359 | |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 360 | if (!sfp) return E_INVALIDARG; |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 361 | if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr; |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 362 | |
Jeff Latimer | ca55584 | 2006-04-13 18:38:31 +1000 | [diff] [blame] | 363 | if (sfp->cBytes != sizeof(SCRIPT_FONTPROPERTIES)) |
| 364 | return E_INVALIDARG; |
| 365 | |
Oliver Stieber | b671180 | 2005-08-01 09:18:53 +0000 | [diff] [blame] | 366 | /* return something sensible? */ |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 367 | sfp->wgBlank = 0; |
Hans Leidekker | 06ed81e | 2007-01-23 11:03:12 +0100 | [diff] [blame] | 368 | sfp->wgDefault = get_cache_default_char(psc); |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 369 | sfp->wgInvalid = 0; |
| 370 | sfp->wgKashida = 0xffff; |
Paul Vriens | e56f6a3 | 2006-04-21 08:00:14 +0200 | [diff] [blame] | 371 | sfp->iKashidaWidth = 0; |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 372 | |
| 373 | return S_OK; |
Oliver Stieber | b671180 | 2005-08-01 09:18:53 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 376 | /*********************************************************************** |
| 377 | * ScriptRecordDigitSubstitution (USP10.@) |
| 378 | * |
Albert Lee | b2182f9 | 2006-09-07 02:42:56 -0400 | [diff] [blame] | 379 | * Record digit substitution settings for a given locale. |
| 380 | * |
| 381 | * PARAMS |
| 382 | * locale [I] Locale identifier. |
| 383 | * sds [I] Structure to record substitution settings. |
| 384 | * |
| 385 | * RETURNS |
| 386 | * Success: S_OK |
| 387 | * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise. |
| 388 | * |
| 389 | * SEE ALSO |
| 390 | * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 391 | */ |
Albert Lee | b2182f9 | 2006-09-07 02:42:56 -0400 | [diff] [blame] | 392 | HRESULT WINAPI ScriptRecordDigitSubstitution(LCID locale, SCRIPT_DIGITSUBSTITUTE *sds) |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 393 | { |
Albert Lee | b2182f9 | 2006-09-07 02:42:56 -0400 | [diff] [blame] | 394 | DWORD plgid, sub; |
| 395 | |
Michael Stefaniuc | f3cfb89 | 2006-10-05 00:58:37 +0200 | [diff] [blame] | 396 | TRACE("0x%x, %p\n", locale, sds); |
Albert Lee | b2182f9 | 2006-09-07 02:42:56 -0400 | [diff] [blame] | 397 | |
| 398 | /* This implementation appears to be correct for all languages, but it's |
| 399 | * not clear if sds->DigitSubstitute is ever set to anything except |
| 400 | * CONTEXT or NONE in reality */ |
| 401 | |
| 402 | if (!sds) return E_POINTER; |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 403 | |
Albert Lee | b2182f9 | 2006-09-07 02:42:56 -0400 | [diff] [blame] | 404 | locale = ConvertDefaultLocale(locale); |
| 405 | |
| 406 | if (!IsValidLocale(locale, LCID_INSTALLED)) |
| 407 | return E_INVALIDARG; |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 408 | |
Albert Lee | b2182f9 | 2006-09-07 02:42:56 -0400 | [diff] [blame] | 409 | plgid = PRIMARYLANGID(LANGIDFROMLCID(locale)); |
| 410 | sds->TraditionalDigitLanguage = plgid; |
| 411 | |
| 412 | if (plgid == LANG_ARABIC || plgid == LANG_FARSI) |
| 413 | sds->NationalDigitLanguage = plgid; |
| 414 | else |
| 415 | sds->NationalDigitLanguage = LANG_ENGLISH; |
| 416 | |
| 417 | if (!GetLocaleInfoW(locale, LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER, |
| 418 | (LPWSTR)&sub, sizeof(sub)/sizeof(WCHAR))) return E_INVALIDARG; |
| 419 | |
| 420 | switch (sub) |
| 421 | { |
| 422 | case 0: |
| 423 | if (plgid == LANG_ARABIC || plgid == LANG_FARSI) |
| 424 | sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_CONTEXT; |
| 425 | else |
| 426 | sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE; |
| 427 | break; |
| 428 | case 1: |
| 429 | sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE; |
| 430 | break; |
| 431 | case 2: |
| 432 | sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NATIONAL; |
| 433 | break; |
| 434 | default: |
| 435 | sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_TRADITIONAL; |
| 436 | break; |
| 437 | } |
| 438 | |
| 439 | sds->dwReserved = 0; |
| 440 | return S_OK; |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 443 | /*********************************************************************** |
| 444 | * ScriptApplyDigitSubstitution (USP10.@) |
| 445 | * |
Albert Lee | b2182f9 | 2006-09-07 02:42:56 -0400 | [diff] [blame] | 446 | * Apply digit substitution settings. |
| 447 | * |
| 448 | * PARAMS |
| 449 | * sds [I] Structure with recorded substitution settings. |
| 450 | * sc [I] Script control structure. |
| 451 | * ss [I] Script state structure. |
| 452 | * |
| 453 | * RETURNS |
| 454 | * Success: S_OK |
| 455 | * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT. |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 456 | */ |
Albert Lee | b2182f9 | 2006-09-07 02:42:56 -0400 | [diff] [blame] | 457 | HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE *sds, |
| 458 | SCRIPT_CONTROL *sc, SCRIPT_STATE *ss) |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 459 | { |
Albert Lee | b2182f9 | 2006-09-07 02:42:56 -0400 | [diff] [blame] | 460 | SCRIPT_DIGITSUBSTITUTE psds; |
| 461 | |
| 462 | TRACE("%p, %p, %p\n", sds, sc, ss); |
| 463 | |
| 464 | if (!sc || !ss) return E_POINTER; |
| 465 | if (!sds) |
| 466 | { |
| 467 | sds = &psds; |
| 468 | if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &psds) != S_OK) |
| 469 | return E_INVALIDARG; |
| 470 | } |
| 471 | |
| 472 | sc->uDefaultLanguage = LANG_ENGLISH; |
| 473 | sc->fContextDigits = 0; |
| 474 | ss->fDigitSubstitute = 0; |
| 475 | |
| 476 | switch (sds->DigitSubstitute) { |
| 477 | case SCRIPT_DIGITSUBSTITUTE_CONTEXT: |
| 478 | case SCRIPT_DIGITSUBSTITUTE_NATIONAL: |
| 479 | case SCRIPT_DIGITSUBSTITUTE_NONE: |
| 480 | case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL: |
| 481 | return S_OK; |
| 482 | default: |
| 483 | return E_INVALIDARG; |
| 484 | } |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 487 | /*********************************************************************** |
| 488 | * ScriptItemize (USP10.@) |
| 489 | * |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 490 | * Split a Unicode string into shapeable parts. |
| 491 | * |
| 492 | * PARAMS |
| 493 | * pwcInChars [I] String to split. |
| 494 | * cInChars [I] Number of characters in pwcInChars. |
| 495 | * cMaxItems [I] Maximum number of items to return. |
| 496 | * psControl [I] Pointer to a SCRIPT_CONTROL structure. |
| 497 | * psState [I] Pointer to a SCRIPT_STATE structure. |
| 498 | * pItems [O] Buffer to receive SCRIPT_ITEM structures. |
| 499 | * pcItems [O] Number of script items returned. |
| 500 | * |
| 501 | * RETURNS |
| 502 | * Success: S_OK |
| 503 | * Failure: Non-zero HRESULT value. |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 504 | */ |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 505 | HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems, |
| 506 | const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState, |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 507 | SCRIPT_ITEM *pItems, int *pcItems) |
| 508 | { |
Jeff Latimer | e4a154c | 2006-02-18 16:00:29 +0100 | [diff] [blame] | 509 | |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 510 | #define Numeric_start 0x0030 |
| 511 | #define Numeric_stop 0x0039 |
| 512 | #define Numeric_space 0x0020 |
| 513 | #define Arabic_start 0x0600 |
| 514 | #define Arabic_stop 0x06ff |
Aric Stewart | 4459c5b | 2010-04-19 07:31:16 -0500 | [diff] [blame] | 515 | #define Hebrew_start 0x0590 |
| 516 | #define Hebrew_stop 0x05ff |
Aric Stewart | af3dfc1 | 2010-04-19 07:31:28 -0500 | [diff] [blame] | 517 | #define Syriac_start 0x0700 |
| 518 | #define Syriac_stop 0x074f |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 519 | #define Latin_start 0x0001 |
| 520 | #define Latin_stop 0x024f |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 521 | |
| 522 | int cnt = 0, index = 0; |
| 523 | int New_Script = SCRIPT_UNDEFINED; |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 524 | WORD *levels = NULL; |
Aric Stewart | d5672fe | 2010-04-29 07:32:03 -0500 | [diff] [blame] | 525 | WORD baselevel = 0; |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 526 | |
| 527 | TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems, |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 528 | psControl, psState, pItems, pcItems); |
Hans Leidekker | c0a223b | 2006-01-09 17:16:57 +0100 | [diff] [blame] | 529 | |
| 530 | if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2) |
| 531 | return E_INVALIDARG; |
| 532 | |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 533 | if (psState && psControl) |
| 534 | { |
| 535 | int i; |
| 536 | levels = heap_alloc_zero(cInChars * sizeof(WORD)); |
| 537 | if (!levels) |
| 538 | return E_OUTOFMEMORY; |
| 539 | |
| 540 | BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels); |
Aric Stewart | d5672fe | 2010-04-29 07:32:03 -0500 | [diff] [blame] | 541 | baselevel = levels[0]; |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 542 | for (i = 0; i < cInChars; i++) |
| 543 | if (levels[i]!=levels[0]) |
| 544 | break; |
| 545 | if (i >= cInChars) |
| 546 | { |
| 547 | heap_free(levels); |
| 548 | levels = NULL; |
| 549 | } |
| 550 | } |
| 551 | |
Hans Leidekker | d2f2130 | 2006-12-24 12:37:36 +0100 | [diff] [blame] | 552 | pItems[index].iCharPos = 0; |
| 553 | memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS)); |
| 554 | |
Hans Leidekker | 8a5eae2 | 2009-01-06 11:20:41 +0100 | [diff] [blame] | 555 | if (pwcInChars[cnt] == '\r') |
| 556 | pItems[index].a.eScript = Script_CR; |
| 557 | else |
| 558 | if (pwcInChars[cnt] == '\n') |
| 559 | pItems[index].a.eScript = Script_LF; |
| 560 | else |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 561 | if (pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop) |
| 562 | pItems[index].a.eScript = Script_Numeric; |
| 563 | else |
| 564 | if (pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop) |
| 565 | pItems[index].a.eScript = Script_Arabic; |
| 566 | else |
Aric Stewart | 4459c5b | 2010-04-19 07:31:16 -0500 | [diff] [blame] | 567 | if (pwcInChars[cnt] >= Hebrew_start && pwcInChars[cnt] <= Hebrew_stop) |
| 568 | pItems[index].a.eScript = Script_Hebrew; |
| 569 | else |
Aric Stewart | af3dfc1 | 2010-04-19 07:31:28 -0500 | [diff] [blame] | 570 | if (pwcInChars[cnt] >= Syriac_start && pwcInChars[cnt] <= Syriac_stop) |
| 571 | pItems[index].a.eScript = Script_Syriac; |
| 572 | else |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 573 | if (pwcInChars[cnt] >= Latin_start && pwcInChars[cnt] <= Latin_stop) |
| 574 | pItems[index].a.eScript = Script_Latin; |
Hans Leidekker | d2f2130 | 2006-12-24 12:37:36 +0100 | [diff] [blame] | 575 | |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 576 | if (levels) |
| 577 | { |
| 578 | pItems[index].a.fRTL = odd(levels[cnt]); |
| 579 | pItems[index].a.fLayoutRTL = odd(levels[cnt]); |
| 580 | pItems[index].a.s.uBidiLevel = levels[cnt]; |
| 581 | } |
Aric Stewart | 4459c5b | 2010-04-19 07:31:16 -0500 | [diff] [blame] | 582 | else if ((pItems[index].a.eScript == Script_Arabic) || |
Aric Stewart | af3dfc1 | 2010-04-19 07:31:28 -0500 | [diff] [blame] | 583 | (pItems[index].a.eScript == Script_Hebrew) || |
| 584 | (pItems[index].a.eScript == Script_Syriac)) |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 585 | { |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 586 | pItems[index].a.s.uBidiLevel = 1; |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 587 | pItems[index].a.fRTL = 1; |
| 588 | pItems[index].a.fLayoutRTL = 1; |
| 589 | } |
Aric Stewart | d5672fe | 2010-04-29 07:32:03 -0500 | [diff] [blame] | 590 | else |
| 591 | { |
| 592 | pItems[index].a.s.uBidiLevel = baselevel; |
| 593 | pItems[index].a.fLayoutRTL = odd(baselevel); |
| 594 | pItems[index].a.fRTL = odd(baselevel); |
| 595 | } |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 596 | |
| 597 | TRACE("New_Level=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n", |
| 598 | levels?levels[cnt]:-1, New_Script, pItems[index].a.eScript, index, cnt, |
Hans Leidekker | 8a5eae2 | 2009-01-06 11:20:41 +0100 | [diff] [blame] | 599 | pItems[index].iCharPos); |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 600 | |
Hans Leidekker | 8a5eae2 | 2009-01-06 11:20:41 +0100 | [diff] [blame] | 601 | for (cnt=1; cnt < cInChars; cnt++) |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 602 | { |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 603 | if (levels && (levels[cnt] == pItems[index].a.s.uBidiLevel)) |
| 604 | continue; |
| 605 | |
Hans Leidekker | 8a5eae2 | 2009-01-06 11:20:41 +0100 | [diff] [blame] | 606 | if (pwcInChars[cnt] == '\r') |
| 607 | New_Script = Script_CR; |
| 608 | else |
| 609 | if (pwcInChars[cnt] == '\n') |
| 610 | New_Script = Script_LF; |
| 611 | else |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 612 | if ((pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop) |
| 613 | || (New_Script == Script_Numeric && pwcInChars[cnt] == Numeric_space)) |
| 614 | New_Script = Script_Numeric; |
| 615 | else |
| 616 | if ((pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop) |
| 617 | || (New_Script == Script_Arabic && pwcInChars[cnt] == Numeric_space)) |
| 618 | New_Script = Script_Arabic; |
| 619 | else |
Aric Stewart | 4459c5b | 2010-04-19 07:31:16 -0500 | [diff] [blame] | 620 | if ((pwcInChars[cnt] >= Hebrew_start && pwcInChars[cnt] <= Hebrew_stop) |
| 621 | || (New_Script == Script_Hebrew && pwcInChars[cnt] == Numeric_space)) |
| 622 | New_Script = Script_Hebrew; |
| 623 | else |
Aric Stewart | af3dfc1 | 2010-04-19 07:31:28 -0500 | [diff] [blame] | 624 | if ((pwcInChars[cnt] >= Syriac_start && pwcInChars[cnt] <= Syriac_stop) |
| 625 | || (New_Script == Script_Syriac && pwcInChars[cnt] == Numeric_space)) |
| 626 | New_Script = Script_Syriac; |
| 627 | else |
Hans Leidekker | 8a5eae2 | 2009-01-06 11:20:41 +0100 | [diff] [blame] | 628 | if ((pwcInChars[cnt] >= Latin_start && pwcInChars[cnt] <= Latin_stop) |
| 629 | || (New_Script == Script_Latin && pwcInChars[cnt] == Numeric_space)) |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 630 | New_Script = Script_Latin; |
| 631 | else |
| 632 | New_Script = SCRIPT_UNDEFINED; |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 633 | |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 634 | if ((levels && (levels[cnt] != pItems[index].a.s.uBidiLevel)) || New_Script != pItems[index].a.eScript) |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 635 | { |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 636 | TRACE("New_Level = %i, New_Script=%d, eScript=%d ", levels?levels[cnt]:-1, New_Script, pItems[index].a.eScript); |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 637 | index++; |
| 638 | if (index+1 > cMaxItems) |
| 639 | return E_OUTOFMEMORY; |
Hans Leidekker | d2f2130 | 2006-12-24 12:37:36 +0100 | [diff] [blame] | 640 | |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 641 | pItems[index].iCharPos = cnt; |
Hans Leidekker | d2f2130 | 2006-12-24 12:37:36 +0100 | [diff] [blame] | 642 | memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS)); |
| 643 | |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 644 | if (levels) |
| 645 | { |
| 646 | pItems[index].a.fRTL = odd(levels[cnt]); |
| 647 | pItems[index].a.fLayoutRTL = odd(levels[cnt]); |
| 648 | pItems[index].a.s.uBidiLevel = levels[cnt]; |
| 649 | } |
Aric Stewart | 4459c5b | 2010-04-19 07:31:16 -0500 | [diff] [blame] | 650 | else if ((New_Script == Script_Arabic) || |
Aric Stewart | af3dfc1 | 2010-04-19 07:31:28 -0500 | [diff] [blame] | 651 | (New_Script == Script_Hebrew) || |
| 652 | (New_Script == Script_Syriac)) |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 653 | { |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 654 | pItems[index].a.s.uBidiLevel = 1; |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 655 | pItems[index].a.fRTL = 1; |
| 656 | pItems[index].a.fLayoutRTL = 1; |
| 657 | } |
Aric Stewart | d5672fe | 2010-04-29 07:32:03 -0500 | [diff] [blame] | 658 | else |
| 659 | { |
| 660 | pItems[index].a.s.uBidiLevel = baselevel; |
| 661 | pItems[index].a.fLayoutRTL = odd(baselevel); |
| 662 | pItems[index].a.fRTL = odd(baselevel); |
| 663 | } |
| 664 | |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 665 | pItems[index].a.eScript = New_Script; |
Hans Leidekker | d2f2130 | 2006-12-24 12:37:36 +0100 | [diff] [blame] | 666 | |
Hans Leidekker | 8a5eae2 | 2009-01-06 11:20:41 +0100 | [diff] [blame] | 667 | TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos); |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 668 | } |
| 669 | } |
Jeff Latimer | e4a154c | 2006-02-18 16:00:29 +0100 | [diff] [blame] | 670 | |
Francois Gouget | 58162f8 | 2006-10-13 02:19:42 +0200 | [diff] [blame] | 671 | /* While not strictly necessary according to the spec, make sure the n+1 |
| 672 | * item is set up to prevent random behaviour if the caller erroneously |
Jeff Latimer | e4a154c | 2006-02-18 16:00:29 +0100 | [diff] [blame] | 673 | * checks the n+1 structure */ |
Jeff Latimer | b367e90 | 2010-04-27 22:43:34 +1000 | [diff] [blame] | 674 | index++; |
| 675 | memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS)); |
Hans Leidekker | d2f2130 | 2006-12-24 12:37:36 +0100 | [diff] [blame] | 676 | |
Jeff Latimer | b367e90 | 2010-04-27 22:43:34 +1000 | [diff] [blame] | 677 | TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos); |
Jeff Latimer | e4a154c | 2006-02-18 16:00:29 +0100 | [diff] [blame] | 678 | |
| 679 | /* Set one SCRIPT_STATE item being returned */ |
Jeff Latimer | b367e90 | 2010-04-27 22:43:34 +1000 | [diff] [blame] | 680 | if (index + 1 > cMaxItems) return E_OUTOFMEMORY; |
| 681 | if (pcItems) *pcItems = index; |
Jeff Latimer | e4a154c | 2006-02-18 16:00:29 +0100 | [diff] [blame] | 682 | |
| 683 | /* Set SCRIPT_ITEM */ |
Jeff Latimer | b367e90 | 2010-04-27 22:43:34 +1000 | [diff] [blame] | 684 | pItems[index].iCharPos = cnt; /* the last item contains the ptr to the lastchar */ |
Aric Stewart | 6c3659c | 2010-04-13 14:49:07 -0500 | [diff] [blame] | 685 | heap_free(levels); |
Jeff Latimer | ff421fd | 2006-08-08 18:57:37 +1000 | [diff] [blame] | 686 | return S_OK; |
Steven Edwards | 54508df | 2005-07-27 11:02:52 +0000 | [diff] [blame] | 687 | } |
Raphael Junqueira | 8f554aa | 2005-11-15 12:02:16 +0000 | [diff] [blame] | 688 | |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 689 | /*********************************************************************** |
| 690 | * ScriptStringAnalyse (USP10.@) |
| 691 | * |
| 692 | */ |
Hans Leidekker | f152153 | 2007-01-03 12:12:29 +0100 | [diff] [blame] | 693 | HRESULT WINAPI ScriptStringAnalyse(HDC hdc, const void *pString, int cString, |
| 694 | int cGlyphs, int iCharset, DWORD dwFlags, |
| 695 | int iReqWidth, SCRIPT_CONTROL *psControl, |
| 696 | SCRIPT_STATE *psState, const int *piDx, |
| 697 | SCRIPT_TABDEF *pTabdef, const BYTE *pbInClass, |
| 698 | SCRIPT_STRING_ANALYSIS *pssa) |
Raphael Junqueira | 8f554aa | 2005-11-15 12:02:16 +0000 | [diff] [blame] | 699 | { |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 700 | HRESULT hr = E_OUTOFMEMORY; |
| 701 | StringAnalysis *analysis = NULL; |
| 702 | int i, num_items = 255; |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 703 | |
| 704 | TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n", |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 705 | hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, |
| 706 | psControl, psState, piDx, pTabdef, pbInClass, pssa); |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 707 | |
Hans Leidekker | f152153 | 2007-01-03 12:12:29 +0100 | [diff] [blame] | 708 | if (iCharset != -1) |
| 709 | { |
| 710 | FIXME("Only Unicode strings are supported\n"); |
| 711 | return E_INVALIDARG; |
| 712 | } |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 713 | if (cString < 1 || !pString) return E_INVALIDARG; |
| 714 | if ((dwFlags & SSA_GLYPHS) && !hdc) return E_PENDING; |
Hans Leidekker | 55f385c | 2006-12-24 12:39:27 +0100 | [diff] [blame] | 715 | |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 716 | if (!(analysis = heap_alloc_zero(sizeof(StringAnalysis)))) return E_OUTOFMEMORY; |
| 717 | if (!(analysis->pItem = heap_alloc_zero(num_items * sizeof(SCRIPT_ITEM) + 1))) goto error; |
Raphael Junqueira | 8f554aa | 2005-11-15 12:02:16 +0000 | [diff] [blame] | 718 | |
Hans Leidekker | f152153 | 2007-01-03 12:12:29 +0100 | [diff] [blame] | 719 | /* FIXME: handle clipping */ |
| 720 | analysis->clip_len = cString; |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 721 | analysis->hdc = hdc; |
Hans Leidekker | f152153 | 2007-01-03 12:12:29 +0100 | [diff] [blame] | 722 | |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 723 | hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem, |
| 724 | &analysis->numItems); |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 725 | |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 726 | while (hr == E_OUTOFMEMORY) |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 727 | { |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 728 | SCRIPT_ITEM *tmp; |
| 729 | |
| 730 | num_items *= 2; |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 731 | if (!(tmp = heap_realloc_zero(analysis->pItem, num_items * sizeof(SCRIPT_ITEM) + 1))) |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 732 | goto error; |
| 733 | |
| 734 | analysis->pItem = tmp; |
| 735 | hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem, |
| 736 | &analysis->numItems); |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 737 | } |
Rob Shearman | 89a3ad7 | 2008-09-12 13:02:12 +0100 | [diff] [blame] | 738 | if (hr != S_OK) goto error; |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 739 | |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 740 | if ((analysis->logattrs = heap_alloc(sizeof(SCRIPT_LOGATTR) * cString))) |
Hans Leidekker | cd6fe7d | 2006-12-23 17:19:31 +0100 | [diff] [blame] | 741 | ScriptBreak(pString, cString, (SCRIPT_STRING_ANALYSIS)analysis, analysis->logattrs); |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 742 | else |
| 743 | goto error; |
Hans Leidekker | cd6fe7d | 2006-12-23 17:19:31 +0100 | [diff] [blame] | 744 | |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 745 | if (!(analysis->glyphs = heap_alloc_zero(sizeof(StringGlyphs) * analysis->numItems))) |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 746 | goto error; |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 747 | |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 748 | for (i = 0; i < analysis->numItems; i++) |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 749 | { |
Hans Leidekker | 23b3299 | 2007-01-03 12:12:03 +0100 | [diff] [blame] | 750 | SCRIPT_CACHE *sc = (SCRIPT_CACHE *)&analysis->sc; |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 751 | int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos; |
| 752 | int numGlyphs = 1.5 * cChar + 16; |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 753 | WORD *glyphs = heap_alloc_zero(sizeof(WORD) * numGlyphs); |
| 754 | WORD *pwLogClust = heap_alloc_zero(sizeof(WORD) * cChar); |
| 755 | int *piAdvance = heap_alloc_zero(sizeof(int) * numGlyphs); |
| 756 | SCRIPT_VISATTR *psva = heap_alloc_zero(sizeof(SCRIPT_VISATTR) * cChar); |
| 757 | GOFFSET *pGoffset = heap_alloc_zero(sizeof(GOFFSET) * numGlyphs); |
| 758 | ABC *abc = heap_alloc_zero(sizeof(ABC)); |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 759 | int numGlyphsReturned; |
| 760 | |
| 761 | /* FIXME: non unicode strings */ |
Mikhail Maroukhine | 2a89723 | 2010-03-28 16:28:31 +0700 | [diff] [blame] | 762 | const WCHAR* pStr = (const WCHAR*)pString; |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 763 | hr = ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos], |
| 764 | cChar, numGlyphs, &analysis->pItem[i].a, |
| 765 | glyphs, pwLogClust, psva, &numGlyphsReturned); |
| 766 | hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a, |
| 767 | piAdvance, pGoffset, abc); |
| 768 | |
| 769 | analysis->glyphs[i].numGlyphs = numGlyphsReturned; |
| 770 | analysis->glyphs[i].glyphs = glyphs; |
| 771 | analysis->glyphs[i].pwLogClust = pwLogClust; |
| 772 | analysis->glyphs[i].piAdvance = piAdvance; |
| 773 | analysis->glyphs[i].psva = psva; |
| 774 | analysis->glyphs[i].pGoffset = pGoffset; |
| 775 | analysis->glyphs[i].abc = abc; |
| 776 | } |
| 777 | |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 778 | *pssa = analysis; |
Clinton Stimpson | b91eb5a | 2006-12-15 19:28:07 -0700 | [diff] [blame] | 779 | return S_OK; |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 780 | |
| 781 | error: |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 782 | heap_free(analysis->glyphs); |
| 783 | heap_free(analysis->logattrs); |
| 784 | heap_free(analysis->pItem); |
| 785 | heap_free(analysis->sc); |
| 786 | heap_free(analysis); |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 787 | return hr; |
Raphael Junqueira | 8f554aa | 2005-11-15 12:02:16 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 790 | /*********************************************************************** |
Jeff Latimer | 42b576e | 2006-05-23 22:15:15 +1000 | [diff] [blame] | 791 | * ScriptStringOut (USP10.@) |
| 792 | * |
Jeff Latimer | c2680ed | 2006-12-29 22:37:16 +1100 | [diff] [blame] | 793 | * This function takes the output of ScriptStringAnalyse and joins the segments |
| 794 | * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut |
| 795 | * only processes glyphs. |
| 796 | * |
| 797 | * Parameters: |
| 798 | * ssa [I] buffer to hold the analysed string components |
| 799 | * iX [I] X axis displacement for output |
| 800 | * iY [I] Y axis displacement for output |
| 801 | * uOptions [I] flags controling output processing |
| 802 | * prc [I] rectangle coordinates |
| 803 | * iMinSel [I] starting pos for substringing output string |
| 804 | * iMaxSel [I] ending pos for substringing output string |
| 805 | * fDisabled [I] controls text highlighting |
| 806 | * |
| 807 | * RETURNS |
| 808 | * Success: S_OK |
| 809 | * Failure: is the value returned by ScriptTextOut |
Jeff Latimer | 42b576e | 2006-05-23 22:15:15 +1000 | [diff] [blame] | 810 | */ |
Jeff Latimer | c2680ed | 2006-12-29 22:37:16 +1100 | [diff] [blame] | 811 | HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa, |
| 812 | int iX, |
Jeff Latimer | 42b576e | 2006-05-23 22:15:15 +1000 | [diff] [blame] | 813 | int iY, |
| 814 | UINT uOptions, |
| 815 | const RECT *prc, |
| 816 | int iMinSel, |
Jeff Latimer | c2680ed | 2006-12-29 22:37:16 +1100 | [diff] [blame] | 817 | int iMaxSel, |
Jeff Latimer | 42b576e | 2006-05-23 22:15:15 +1000 | [diff] [blame] | 818 | BOOL fDisabled) |
| 819 | { |
Jeff Latimer | c2680ed | 2006-12-29 22:37:16 +1100 | [diff] [blame] | 820 | StringAnalysis *analysis; |
| 821 | WORD *glyphs; |
| 822 | int item, cnt, x; |
| 823 | HRESULT hr; |
Jeff Latimer | c2680ed | 2006-12-29 22:37:16 +1100 | [diff] [blame] | 824 | |
| 825 | TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n", |
Jeff Latimer | 42b576e | 2006-05-23 22:15:15 +1000 | [diff] [blame] | 826 | ssa, iX, iY, uOptions, prc, iMinSel, iMaxSel, fDisabled); |
Jeff Latimer | c2680ed | 2006-12-29 22:37:16 +1100 | [diff] [blame] | 827 | |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 828 | if (!(analysis = ssa)) return E_INVALIDARG; |
Jeff Latimer | c2680ed | 2006-12-29 22:37:16 +1100 | [diff] [blame] | 829 | |
| 830 | /* |
| 831 | * Get storage for the output buffer for the consolidated strings |
| 832 | */ |
| 833 | cnt = 0; |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 834 | for (item = 0; item < analysis->numItems; item++) |
Jeff Latimer | c2680ed | 2006-12-29 22:37:16 +1100 | [diff] [blame] | 835 | { |
| 836 | cnt += analysis->glyphs[item].numGlyphs; |
| 837 | } |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 838 | if (!(glyphs = heap_alloc(sizeof(WCHAR) * cnt))) return E_OUTOFMEMORY; |
Jeff Latimer | c2680ed | 2006-12-29 22:37:16 +1100 | [diff] [blame] | 839 | |
| 840 | /* |
| 841 | * ScriptStringOut only processes glyphs hence set ETO_GLYPH_INDEX |
| 842 | */ |
| 843 | uOptions |= ETO_GLYPH_INDEX; |
| 844 | analysis->pItem[0].a.fNoGlyphIndex = FALSE; /* say that we have glyphs */ |
| 845 | |
| 846 | /* |
| 847 | * Copy the string items into the output buffer |
| 848 | */ |
| 849 | |
| 850 | TRACE("numItems %d\n", analysis->numItems); |
| 851 | |
| 852 | cnt = 0; |
| 853 | for (item = 0; item < analysis->numItems; item++) |
| 854 | { |
| 855 | memcpy(&glyphs[cnt], analysis->glyphs[item].glyphs, |
| 856 | sizeof(WCHAR) * analysis->glyphs[item].numGlyphs); |
| 857 | |
| 858 | TRACE("Item %d, Glyphs %d ", item, analysis->glyphs[item].numGlyphs); |
| 859 | for (x = cnt; x < analysis->glyphs[item].numGlyphs + cnt; x ++) |
| 860 | TRACE("%04x", glyphs[x]); |
| 861 | TRACE("\n"); |
| 862 | |
| 863 | cnt += analysis->glyphs[item].numGlyphs; /* point to the end of the copied text */ |
Jeff Latimer | 42b576e | 2006-05-23 22:15:15 +1000 | [diff] [blame] | 864 | } |
| 865 | |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 866 | hr = ScriptTextOut(analysis->hdc, (SCRIPT_CACHE *)&analysis->sc, iX, iY, |
Hans Leidekker | 23b3299 | 2007-01-03 12:12:03 +0100 | [diff] [blame] | 867 | uOptions, prc, &analysis->pItem->a, NULL, 0, glyphs, cnt, |
| 868 | analysis->glyphs->piAdvance, NULL, analysis->glyphs->pGoffset); |
Jeff Latimer | c2680ed | 2006-12-29 22:37:16 +1100 | [diff] [blame] | 869 | TRACE("ScriptTextOut hr=%08x\n", hr); |
| 870 | |
| 871 | /* |
| 872 | * Free the output buffer and script cache |
| 873 | */ |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 874 | heap_free(glyphs); |
Jeff Latimer | c2680ed | 2006-12-29 22:37:16 +1100 | [diff] [blame] | 875 | return hr; |
Jeff Latimer | 42b576e | 2006-05-23 22:15:15 +1000 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | /*********************************************************************** |
Jeff Latimer | ac40feb | 2006-07-18 19:35:07 +1000 | [diff] [blame] | 879 | * ScriptStringCPtoX (USP10.@) |
| 880 | * |
| 881 | */ |
| 882 | HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX) |
| 883 | { |
Clinton Stimpson | e0829eb | 2006-12-15 19:28:25 -0700 | [diff] [blame] | 884 | int i, j; |
| 885 | int runningX = 0; |
| 886 | int runningCp = 0; |
| 887 | StringAnalysis* analysis = ssa; |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 888 | |
Clinton Stimpson | e0829eb | 2006-12-15 19:28:25 -0700 | [diff] [blame] | 889 | TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX); |
| 890 | |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 891 | if (!ssa || !pX) return S_FALSE; |
Clinton Stimpson | e0829eb | 2006-12-15 19:28:25 -0700 | [diff] [blame] | 892 | |
| 893 | /* icp out of range */ |
| 894 | if(icp < 0) |
| 895 | { |
| 896 | analysis->invalid = TRUE; |
| 897 | return E_INVALIDARG; |
| 898 | } |
| 899 | |
| 900 | for(i=0; i<analysis->numItems; i++) |
| 901 | { |
| 902 | for(j=0; j<analysis->glyphs[i].numGlyphs; j++) |
| 903 | { |
| 904 | if(runningCp == icp && fTrailing == FALSE) |
| 905 | { |
| 906 | *pX = runningX; |
| 907 | return S_OK; |
| 908 | } |
| 909 | runningX += analysis->glyphs[i].piAdvance[j]; |
| 910 | if(runningCp == icp && fTrailing == TRUE) |
| 911 | { |
| 912 | *pX = runningX; |
| 913 | return S_OK; |
| 914 | } |
| 915 | runningCp++; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | /* icp out of range */ |
| 920 | analysis->invalid = TRUE; |
| 921 | return E_INVALIDARG; |
Jeff Latimer | ac40feb | 2006-07-18 19:35:07 +1000 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | /*********************************************************************** |
| 925 | * ScriptStringXtoCP (USP10.@) |
| 926 | * |
| 927 | */ |
| 928 | HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing) |
| 929 | { |
Clinton Stimpson | bdbab21 | 2006-12-15 19:28:17 -0700 | [diff] [blame] | 930 | StringAnalysis* analysis = ssa; |
| 931 | int i; |
| 932 | int j; |
| 933 | int runningX = 0; |
| 934 | int runningCp = 0; |
| 935 | int width; |
| 936 | |
| 937 | TRACE("(%p), %d, (%p), (%p)\n", ssa, iX, piCh, piTrailing); |
| 938 | |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 939 | if (!ssa || !piCh || !piTrailing) return S_FALSE; |
Clinton Stimpson | bdbab21 | 2006-12-15 19:28:17 -0700 | [diff] [blame] | 940 | |
| 941 | /* out of range */ |
| 942 | if(iX < 0) |
| 943 | { |
| 944 | *piCh = -1; |
| 945 | *piTrailing = TRUE; |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 946 | return S_OK; |
Clinton Stimpson | bdbab21 | 2006-12-15 19:28:17 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | for(i=0; i<analysis->numItems; i++) |
| 950 | { |
| 951 | for(j=0; j<analysis->glyphs[i].numGlyphs; j++) |
| 952 | { |
| 953 | width = analysis->glyphs[i].piAdvance[j]; |
| 954 | if(iX < (runningX + width)) |
| 955 | { |
| 956 | *piCh = runningCp; |
| 957 | if((iX - runningX) > width/2) |
| 958 | *piTrailing = TRUE; |
| 959 | else |
| 960 | *piTrailing = FALSE; |
| 961 | return S_OK; |
| 962 | } |
| 963 | runningX += width; |
| 964 | runningCp++; |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | /* out of range */ |
| 969 | *piCh = analysis->pItem[analysis->numItems].iCharPos; |
| 970 | *piTrailing = FALSE; |
| 971 | |
Jeff Latimer | ac40feb | 2006-07-18 19:35:07 +1000 | [diff] [blame] | 972 | return S_OK; |
| 973 | } |
| 974 | |
Clinton Stimpson | bdbab21 | 2006-12-15 19:28:17 -0700 | [diff] [blame] | 975 | |
Jeff Latimer | ac40feb | 2006-07-18 19:35:07 +1000 | [diff] [blame] | 976 | /*********************************************************************** |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 977 | * ScriptStringFree (USP10.@) |
| 978 | * |
Hans Leidekker | 44fd9a2 | 2007-01-02 16:11:10 +0100 | [diff] [blame] | 979 | * Free a string analysis. |
| 980 | * |
| 981 | * PARAMS |
| 982 | * pssa [I] string analysis. |
| 983 | * |
| 984 | * RETURNS |
| 985 | * Success: S_OK |
| 986 | * Failure: Non-zero HRESULT value. |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 987 | */ |
Clinton Stimpson | 857e330 | 2006-12-15 19:28:11 -0700 | [diff] [blame] | 988 | HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa) |
| 989 | { |
| 990 | StringAnalysis* analysis; |
| 991 | BOOL invalid; |
| 992 | int i; |
Hans Leidekker | 44fd9a2 | 2007-01-02 16:11:10 +0100 | [diff] [blame] | 993 | |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 994 | TRACE("(%p)\n", pssa); |
Clinton Stimpson | 857e330 | 2006-12-15 19:28:11 -0700 | [diff] [blame] | 995 | |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 996 | if (!pssa || !(analysis = *pssa)) return E_INVALIDARG; |
Hans Leidekker | 7d3f37f | 2009-12-07 09:18:58 +0100 | [diff] [blame] | 997 | |
Clinton Stimpson | 857e330 | 2006-12-15 19:28:11 -0700 | [diff] [blame] | 998 | invalid = analysis->invalid; |
Hans Leidekker | 7d3f37f | 2009-12-07 09:18:58 +0100 | [diff] [blame] | 999 | ScriptFreeCache((SCRIPT_CACHE *)&analysis->sc); |
Clinton Stimpson | 857e330 | 2006-12-15 19:28:11 -0700 | [diff] [blame] | 1000 | |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 1001 | for (i = 0; i < analysis->numItems; i++) |
Clinton Stimpson | 857e330 | 2006-12-15 19:28:11 -0700 | [diff] [blame] | 1002 | { |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 1003 | heap_free(analysis->glyphs[i].glyphs); |
| 1004 | heap_free(analysis->glyphs[i].pwLogClust); |
| 1005 | heap_free(analysis->glyphs[i].piAdvance); |
| 1006 | heap_free(analysis->glyphs[i].psva); |
| 1007 | heap_free(analysis->glyphs[i].pGoffset); |
| 1008 | heap_free(analysis->glyphs[i].abc); |
Clinton Stimpson | 857e330 | 2006-12-15 19:28:11 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 1011 | heap_free(analysis->glyphs); |
| 1012 | heap_free(analysis->pItem); |
| 1013 | heap_free(analysis->logattrs); |
| 1014 | heap_free(analysis->sz); |
| 1015 | heap_free(analysis->sc); |
| 1016 | heap_free(analysis); |
Clinton Stimpson | 857e330 | 2006-12-15 19:28:11 -0700 | [diff] [blame] | 1017 | |
Hans Leidekker | e0c38fd | 2007-01-03 12:12:17 +0100 | [diff] [blame] | 1018 | if (invalid) return E_INVALIDARG; |
Jeff Latimer | 5f529fe0d | 2006-06-07 23:05:14 +1000 | [diff] [blame] | 1019 | return S_OK; |
| 1020 | } |
| 1021 | |
| 1022 | /*********************************************************************** |
| 1023 | * ScriptCPtoX (USP10.@) |
| 1024 | * |
| 1025 | */ |
| 1026 | HRESULT WINAPI ScriptCPtoX(int iCP, |
| 1027 | BOOL fTrailing, |
| 1028 | int cChars, |
| 1029 | int cGlyphs, |
| 1030 | const WORD *pwLogClust, |
| 1031 | const SCRIPT_VISATTR *psva, |
| 1032 | const int *piAdvance, |
| 1033 | const SCRIPT_ANALYSIS *psa, |
| 1034 | int *piX) |
| 1035 | { |
Jeff Latimer | 8d139c8 | 2006-07-20 22:16:50 +1000 | [diff] [blame] | 1036 | int item; |
| 1037 | int iPosX; |
| 1038 | float fMaxPosX = 0; |
| 1039 | TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n", |
Jeff Latimer | 5f529fe0d | 2006-06-07 23:05:14 +1000 | [diff] [blame] | 1040 | iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, |
| 1041 | psa, piX); |
Jeff Latimer | 8d139c8 | 2006-07-20 22:16:50 +1000 | [diff] [blame] | 1042 | for (item=0; item < cGlyphs; item++) /* total piAdvance */ |
| 1043 | fMaxPosX += piAdvance[item]; |
| 1044 | iPosX = (fMaxPosX/cGlyphs)*(iCP+fTrailing); |
| 1045 | if (iPosX > fMaxPosX) |
| 1046 | iPosX = fMaxPosX; |
| 1047 | *piX = iPosX; /* Return something in range */ |
Jeff Latimer | 5f529fe0d | 2006-06-07 23:05:14 +1000 | [diff] [blame] | 1048 | |
Jeff Latimer | 8d139c8 | 2006-07-20 22:16:50 +1000 | [diff] [blame] | 1049 | TRACE("*piX=%d\n", *piX); |
Jeff Latimer | 5f529fe0d | 2006-06-07 23:05:14 +1000 | [diff] [blame] | 1050 | return S_OK; |
| 1051 | } |
| 1052 | |
| 1053 | /*********************************************************************** |
| 1054 | * ScriptXtoCP (USP10.@) |
| 1055 | * |
| 1056 | */ |
| 1057 | HRESULT WINAPI ScriptXtoCP(int iX, |
| 1058 | int cChars, |
| 1059 | int cGlyphs, |
| 1060 | const WORD *pwLogClust, |
| 1061 | const SCRIPT_VISATTR *psva, |
| 1062 | const int *piAdvance, |
| 1063 | const SCRIPT_ANALYSIS *psa, |
| 1064 | int *piCP, |
| 1065 | int *piTrailing) |
| 1066 | { |
Jeff Latimer | 8d139c8 | 2006-07-20 22:16:50 +1000 | [diff] [blame] | 1067 | int item; |
Clinton Stimpson | 39a5b07 | 2006-12-11 22:23:53 -0700 | [diff] [blame] | 1068 | int iPosX; |
Jeff Latimer | 8d139c8 | 2006-07-20 22:16:50 +1000 | [diff] [blame] | 1069 | float fMaxPosX = 1; |
| 1070 | float fAvePosX; |
| 1071 | TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n", |
Jeff Latimer | 5f529fe0d | 2006-06-07 23:05:14 +1000 | [diff] [blame] | 1072 | iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, |
| 1073 | psa, piCP, piTrailing); |
Jeff Latimer | 8d139c8 | 2006-07-20 22:16:50 +1000 | [diff] [blame] | 1074 | if (iX < 0) /* iX is before start of run */ |
| 1075 | { |
| 1076 | *piCP = -1; |
| 1077 | *piTrailing = TRUE; |
| 1078 | return S_OK; |
| 1079 | } |
Jeff Latimer | 5f529fe0d | 2006-06-07 23:05:14 +1000 | [diff] [blame] | 1080 | |
Jeff Latimer | 8d139c8 | 2006-07-20 22:16:50 +1000 | [diff] [blame] | 1081 | for (item=0; item < cGlyphs; item++) /* total piAdvance */ |
| 1082 | fMaxPosX += piAdvance[item]; |
| 1083 | |
| 1084 | if (iX >= fMaxPosX) /* iX too large */ |
| 1085 | { |
| 1086 | *piCP = cChars; |
| 1087 | *piTrailing = FALSE; |
| 1088 | return S_OK; |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 1089 | } |
Jeff Latimer | 8d139c8 | 2006-07-20 22:16:50 +1000 | [diff] [blame] | 1090 | |
| 1091 | fAvePosX = fMaxPosX / cGlyphs; |
Clinton Stimpson | 39a5b07 | 2006-12-11 22:23:53 -0700 | [diff] [blame] | 1092 | iPosX = fAvePosX; |
| 1093 | for (item = 1; item < cGlyphs && iPosX < iX; item++) |
| 1094 | iPosX += fAvePosX; |
Jeff Latimer | 8d139c8 | 2006-07-20 22:16:50 +1000 | [diff] [blame] | 1095 | if (iPosX - iX > fAvePosX/2) |
| 1096 | *piTrailing = 0; |
| 1097 | else |
Francois Gouget | 367f91f | 2006-12-14 17:59:46 +0100 | [diff] [blame] | 1098 | *piTrailing = 1; /* yep we are over halfway */ |
Hans Leidekker | 586e16d | 2007-01-03 12:12:43 +0100 | [diff] [blame] | 1099 | |
Jeff Latimer | 8d139c8 | 2006-07-20 22:16:50 +1000 | [diff] [blame] | 1100 | *piCP = item -1; /* Return character position */ |
| 1101 | TRACE("*piCP=%d iPposX=%d\n", *piCP, iPosX); |
Jeff Latimer | 5f529fe0d | 2006-06-07 23:05:14 +1000 | [diff] [blame] | 1102 | return S_OK; |
| 1103 | } |
| 1104 | |
| 1105 | /*********************************************************************** |
| 1106 | * ScriptBreak (USP10.@) |
| 1107 | * |
Hans Leidekker | 02d30df | 2006-12-23 11:50:47 +0100 | [diff] [blame] | 1108 | * Retrieve line break information. |
| 1109 | * |
| 1110 | * PARAMS |
| 1111 | * chars [I] Array of characters. |
| 1112 | * sa [I] String analysis. |
| 1113 | * la [I] Array of logical attribute structures. |
| 1114 | * |
| 1115 | * RETURNS |
| 1116 | * Success: S_OK |
| 1117 | * Failure: S_FALSE |
Jeff Latimer | 5f529fe0d | 2006-06-07 23:05:14 +1000 | [diff] [blame] | 1118 | */ |
Hans Leidekker | 02d30df | 2006-12-23 11:50:47 +0100 | [diff] [blame] | 1119 | HRESULT WINAPI ScriptBreak(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la) |
Jeff Latimer | 5f529fe0d | 2006-06-07 23:05:14 +1000 | [diff] [blame] | 1120 | { |
Andrew Talbot | bf92d68 | 2008-11-19 21:28:04 +0000 | [diff] [blame] | 1121 | int i; |
Jeff Latimer | 5f529fe0d | 2006-06-07 23:05:14 +1000 | [diff] [blame] | 1122 | |
Hans Leidekker | 21987d3 | 2007-01-02 15:31:34 +0100 | [diff] [blame] | 1123 | TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars, count), count, sa, la); |
Hans Leidekker | 02d30df | 2006-12-23 11:50:47 +0100 | [diff] [blame] | 1124 | |
| 1125 | if (!la) return S_FALSE; |
| 1126 | |
| 1127 | for (i = 0; i < count; i++) |
| 1128 | { |
| 1129 | memset(&la[i], 0, sizeof(SCRIPT_LOGATTR)); |
| 1130 | |
Clinton Stimpson | fd21610 | 2006-12-27 18:23:45 -0700 | [diff] [blame] | 1131 | /* FIXME: set the other flags */ |
Hans Leidekker | 020456f | 2009-01-06 11:20:26 +0100 | [diff] [blame] | 1132 | la[i].fWhiteSpace = (chars[i] == ' '); |
Hans Leidekker | 02d30df | 2006-12-23 11:50:47 +0100 | [diff] [blame] | 1133 | la[i].fCharStop = 1; |
Hans Leidekker | 020456f | 2009-01-06 11:20:26 +0100 | [diff] [blame] | 1134 | |
| 1135 | if (i > 0 && la[i - 1].fWhiteSpace) |
| 1136 | { |
| 1137 | la[i].fSoftBreak = 1; |
| 1138 | la[i].fWordStop = 1; |
| 1139 | } |
Hans Leidekker | 02d30df | 2006-12-23 11:50:47 +0100 | [diff] [blame] | 1140 | } |
Jeff Latimer | 5f529fe0d | 2006-06-07 23:05:14 +1000 | [diff] [blame] | 1141 | return S_OK; |
Raphael Junqueira | 8f554aa | 2005-11-15 12:02:16 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
Hans Leidekker | c340ddd | 2006-08-04 11:41:58 +0200 | [diff] [blame] | 1144 | static const struct |
| 1145 | { |
| 1146 | WCHAR start; |
| 1147 | WCHAR end; |
| 1148 | DWORD flag; |
| 1149 | } |
| 1150 | complex_ranges[] = |
| 1151 | { |
| 1152 | { 0, 0x0b, SIC_COMPLEX }, |
| 1153 | { 0x0c, 0x0c, SIC_NEUTRAL }, |
| 1154 | { 0x0d, 0x1f, SIC_COMPLEX }, |
| 1155 | { 0x20, 0x2f, SIC_NEUTRAL }, |
| 1156 | { 0x30, 0x39, SIC_ASCIIDIGIT }, |
| 1157 | { 0x3a, 0x40, SIC_NEUTRAL }, |
| 1158 | { 0x5b, 0x60, SIC_NEUTRAL }, |
| 1159 | { 0x7b, 0x7e, SIC_NEUTRAL }, |
| 1160 | { 0x7f, 0x9f, SIC_COMPLEX }, |
| 1161 | { 0xa0, 0xa5, SIC_NEUTRAL }, |
| 1162 | { 0xa7, 0xa8, SIC_NEUTRAL }, |
| 1163 | { 0xab, 0xab, SIC_NEUTRAL }, |
| 1164 | { 0xad, 0xad, SIC_NEUTRAL }, |
| 1165 | { 0xaf, 0xaf, SIC_NEUTRAL }, |
| 1166 | { 0xb0, 0xb1, SIC_NEUTRAL }, |
| 1167 | { 0xb4, 0xb4, SIC_NEUTRAL }, |
| 1168 | { 0xb6, 0xb8, SIC_NEUTRAL }, |
| 1169 | { 0xbb, 0xbf, SIC_NEUTRAL }, |
| 1170 | { 0xd7, 0xd7, SIC_NEUTRAL }, |
| 1171 | { 0xf7, 0xf7, SIC_NEUTRAL }, |
| 1172 | { 0x2b9, 0x2ba, SIC_NEUTRAL }, |
| 1173 | { 0x2c2, 0x2cf, SIC_NEUTRAL }, |
| 1174 | { 0x2d2, 0x2df, SIC_NEUTRAL }, |
| 1175 | { 0x2e5, 0x2e9, SIC_COMPLEX }, |
| 1176 | { 0x2ea, 0x2ed, SIC_NEUTRAL }, |
| 1177 | { 0x300, 0x362, SIC_COMPLEX }, |
| 1178 | { 0x530, 0x60b, SIC_COMPLEX }, |
| 1179 | { 0x60c, 0x60d, SIC_NEUTRAL }, |
| 1180 | { 0x60e, 0x669, SIC_COMPLEX }, |
| 1181 | { 0x66a, 0x66a, SIC_NEUTRAL }, |
| 1182 | { 0x66b, 0x6e8, SIC_COMPLEX }, |
| 1183 | { 0x6e9, 0x6e9, SIC_NEUTRAL }, |
| 1184 | { 0x6ea, 0x7bf, SIC_COMPLEX }, |
| 1185 | { 0x900, 0x1360, SIC_COMPLEX }, |
| 1186 | { 0x137d, 0x137f, SIC_COMPLEX }, |
| 1187 | { 0x1680, 0x1680, SIC_NEUTRAL }, |
| 1188 | { 0x1780, 0x18af, SIC_COMPLEX }, |
| 1189 | { 0x2000, 0x200a, SIC_NEUTRAL }, |
| 1190 | { 0x200b, 0x200f, SIC_COMPLEX }, |
| 1191 | { 0x2010, 0x2016, SIC_NEUTRAL }, |
| 1192 | { 0x2018, 0x2022, SIC_NEUTRAL }, |
| 1193 | { 0x2024, 0x2028, SIC_NEUTRAL }, |
| 1194 | { 0x2029, 0x202e, SIC_COMPLEX }, |
| 1195 | { 0x202f, 0x2037, SIC_NEUTRAL }, |
| 1196 | { 0x2039, 0x203c, SIC_NEUTRAL }, |
| 1197 | { 0x2044, 0x2046, SIC_NEUTRAL }, |
| 1198 | { 0x206a, 0x206f, SIC_COMPLEX }, |
| 1199 | { 0x207a, 0x207e, SIC_NEUTRAL }, |
| 1200 | { 0x208a, 0x20aa, SIC_NEUTRAL }, |
| 1201 | { 0x20ac, 0x20cf, SIC_NEUTRAL }, |
| 1202 | { 0x20d0, 0x20ff, SIC_COMPLEX }, |
| 1203 | { 0x2103, 0x2103, SIC_NEUTRAL }, |
| 1204 | { 0x2105, 0x2105, SIC_NEUTRAL }, |
| 1205 | { 0x2109, 0x2109, SIC_NEUTRAL }, |
| 1206 | { 0x2116, 0x2116, SIC_NEUTRAL }, |
| 1207 | { 0x2121, 0x2122, SIC_NEUTRAL }, |
| 1208 | { 0x212e, 0x212e, SIC_NEUTRAL }, |
| 1209 | { 0x2153, 0x2154, SIC_NEUTRAL }, |
| 1210 | { 0x215b, 0x215e, SIC_NEUTRAL }, |
| 1211 | { 0x2190, 0x2199, SIC_NEUTRAL }, |
| 1212 | { 0x21b8, 0x21b9, SIC_NEUTRAL }, |
| 1213 | { 0x21d2, 0x21d2, SIC_NEUTRAL }, |
| 1214 | { 0x21d4, 0x21d4, SIC_NEUTRAL }, |
| 1215 | { 0x21e7, 0x21e7, SIC_NEUTRAL }, |
| 1216 | { 0x2200, 0x2200, SIC_NEUTRAL }, |
| 1217 | { 0x2202, 0x2203, SIC_NEUTRAL }, |
| 1218 | { 0x2207, 0x2208, SIC_NEUTRAL }, |
| 1219 | { 0x220b, 0x220b, SIC_NEUTRAL }, |
| 1220 | { 0x220f, 0x220f, SIC_NEUTRAL }, |
| 1221 | { 0x2211, 0x2213, SIC_NEUTRAL }, |
| 1222 | { 0x2215, 0x2215, SIC_NEUTRAL }, |
| 1223 | { 0x221a, 0x221a, SIC_NEUTRAL }, |
| 1224 | { 0x221d, 0x2220, SIC_NEUTRAL }, |
| 1225 | { 0x2223, 0x2223, SIC_NEUTRAL }, |
| 1226 | { 0x2225, 0x2225, SIC_NEUTRAL }, |
| 1227 | { 0x2227, 0x222c, SIC_NEUTRAL }, |
| 1228 | { 0x222e, 0x222e, SIC_NEUTRAL }, |
| 1229 | { 0x2234, 0x2237, SIC_NEUTRAL }, |
| 1230 | { 0x223c, 0x223d, SIC_NEUTRAL }, |
| 1231 | { 0x2248, 0x2248, SIC_NEUTRAL }, |
| 1232 | { 0x224c, 0x224c, SIC_NEUTRAL }, |
| 1233 | { 0x2252, 0x2252, SIC_NEUTRAL }, |
| 1234 | { 0x2260, 0x2261, SIC_NEUTRAL }, |
| 1235 | { 0x2264, 0x2267, SIC_NEUTRAL }, |
| 1236 | { 0x226a, 0x226b, SIC_NEUTRAL }, |
| 1237 | { 0x226e, 0x226f, SIC_NEUTRAL }, |
| 1238 | { 0x2282, 0x2283, SIC_NEUTRAL }, |
| 1239 | { 0x2286, 0x2287, SIC_NEUTRAL }, |
| 1240 | { 0x2295, 0x2295, SIC_NEUTRAL }, |
| 1241 | { 0x2299, 0x2299, SIC_NEUTRAL }, |
| 1242 | { 0x22a5, 0x22a5, SIC_NEUTRAL }, |
| 1243 | { 0x22bf, 0x22bf, SIC_NEUTRAL }, |
| 1244 | { 0x2312, 0x2312, SIC_NEUTRAL }, |
| 1245 | { 0x24ea, 0x24ea, SIC_COMPLEX }, |
| 1246 | { 0x2500, 0x254b, SIC_NEUTRAL }, |
| 1247 | { 0x2550, 0x256d, SIC_NEUTRAL }, |
| 1248 | { 0x256e, 0x2574, SIC_NEUTRAL }, |
| 1249 | { 0x2581, 0x258f, SIC_NEUTRAL }, |
| 1250 | { 0x2592, 0x2595, SIC_NEUTRAL }, |
| 1251 | { 0x25a0, 0x25a1, SIC_NEUTRAL }, |
| 1252 | { 0x25a3, 0x25a9, SIC_NEUTRAL }, |
| 1253 | { 0x25b2, 0x25b3, SIC_NEUTRAL }, |
| 1254 | { 0x25b6, 0x25b7, SIC_NEUTRAL }, |
| 1255 | { 0x25bc, 0x25bd, SIC_NEUTRAL }, |
| 1256 | { 0x25c0, 0x25c1, SIC_NEUTRAL }, |
| 1257 | { 0x25c6, 0x25c8, SIC_NEUTRAL }, |
| 1258 | { 0x25cb, 0x25cb, SIC_NEUTRAL }, |
| 1259 | { 0x25ce, 0x25d1, SIC_NEUTRAL }, |
| 1260 | { 0x25e2, 0x25e5, SIC_NEUTRAL }, |
| 1261 | { 0x25ef, 0x25ef, SIC_NEUTRAL }, |
| 1262 | { 0x2605, 0x2606, SIC_NEUTRAL }, |
| 1263 | { 0x2609, 0x2609, SIC_NEUTRAL }, |
| 1264 | { 0x260e, 0x260f, SIC_NEUTRAL }, |
| 1265 | { 0x261c, 0x261c, SIC_NEUTRAL }, |
| 1266 | { 0x261e, 0x261e, SIC_NEUTRAL }, |
| 1267 | { 0x2640, 0x2640, SIC_NEUTRAL }, |
| 1268 | { 0x2642, 0x2642, SIC_NEUTRAL }, |
| 1269 | { 0x2660, 0x2661, SIC_NEUTRAL }, |
| 1270 | { 0x2663, 0x2665, SIC_NEUTRAL }, |
| 1271 | { 0x2667, 0x266a, SIC_NEUTRAL }, |
| 1272 | { 0x266c, 0x266d, SIC_NEUTRAL }, |
| 1273 | { 0x266f, 0x266f, SIC_NEUTRAL }, |
| 1274 | { 0x273d, 0x273d, SIC_NEUTRAL }, |
| 1275 | { 0x2e80, 0x312f, SIC_COMPLEX }, |
| 1276 | { 0x3190, 0x31bf, SIC_COMPLEX }, |
| 1277 | { 0x31f0, 0x31ff, SIC_COMPLEX }, |
| 1278 | { 0x3220, 0x325f, SIC_COMPLEX }, |
| 1279 | { 0x3280, 0xa4ff, SIC_COMPLEX }, |
| 1280 | { 0xd800, 0xdfff, SIC_COMPLEX }, |
| 1281 | { 0xe000, 0xf8ff, SIC_NEUTRAL }, |
| 1282 | { 0xf900, 0xfaff, SIC_COMPLEX }, |
| 1283 | { 0xfb13, 0xfb28, SIC_COMPLEX }, |
| 1284 | { 0xfb29, 0xfb29, SIC_NEUTRAL }, |
| 1285 | { 0xfb2a, 0xfb4f, SIC_COMPLEX }, |
| 1286 | { 0xfd3e, 0xfd3f, SIC_NEUTRAL }, |
| 1287 | { 0xfdd0, 0xfdef, SIC_COMPLEX }, |
| 1288 | { 0xfe20, 0xfe6f, SIC_COMPLEX }, |
| 1289 | { 0xfeff, 0xfeff, SIC_COMPLEX }, |
| 1290 | { 0xff01, 0xff5e, SIC_COMPLEX }, |
| 1291 | { 0xff61, 0xff9f, SIC_COMPLEX }, |
| 1292 | { 0xffe0, 0xffe6, SIC_COMPLEX }, |
| 1293 | { 0xffe8, 0xffee, SIC_COMPLEX }, |
| 1294 | { 0xfff9, 0xfffb, SIC_COMPLEX }, |
| 1295 | { 0xfffe, 0xfffe, SIC_COMPLEX } |
| 1296 | }; |
| 1297 | |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 1298 | /*********************************************************************** |
| 1299 | * ScriptIsComplex (USP10.@) |
Hans Leidekker | c340ddd | 2006-08-04 11:41:58 +0200 | [diff] [blame] | 1300 | * |
| 1301 | * Determine if a string is complex. |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 1302 | * |
Hans Leidekker | c340ddd | 2006-08-04 11:41:58 +0200 | [diff] [blame] | 1303 | * PARAMS |
| 1304 | * chars [I] Array of characters to test. |
| 1305 | * len [I] Length in characters. |
| 1306 | * flag [I] Flag. |
| 1307 | * |
| 1308 | * RETURNS |
| 1309 | * Success: S_OK |
| 1310 | * Failure: S_FALSE |
| 1311 | * |
| 1312 | * NOTES |
| 1313 | * Behaviour matches that of WinXP. |
Francois Gouget | d69268e | 2005-11-23 20:14:04 +0100 | [diff] [blame] | 1314 | */ |
Hans Leidekker | c340ddd | 2006-08-04 11:41:58 +0200 | [diff] [blame] | 1315 | HRESULT WINAPI ScriptIsComplex(const WCHAR *chars, int len, DWORD flag) |
| 1316 | { |
Andrew Talbot | bf92d68 | 2008-11-19 21:28:04 +0000 | [diff] [blame] | 1317 | int i; |
| 1318 | unsigned int j; |
Hans Leidekker | c340ddd | 2006-08-04 11:41:58 +0200 | [diff] [blame] | 1319 | |
Michael Stefaniuc | f3cfb89 | 2006-10-05 00:58:37 +0200 | [diff] [blame] | 1320 | TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars, len), len, flag); |
Hans Leidekker | c340ddd | 2006-08-04 11:41:58 +0200 | [diff] [blame] | 1321 | |
| 1322 | for (i = 0; i < len; i++) |
| 1323 | { |
| 1324 | for (j = 0; j < sizeof(complex_ranges)/sizeof(complex_ranges[0]); j++) |
| 1325 | { |
| 1326 | if (chars[i] >= complex_ranges[j].start && |
| 1327 | chars[i] <= complex_ranges[j].end && |
| 1328 | (flag & complex_ranges[j].flag)) return S_OK; |
| 1329 | } |
| 1330 | } |
| 1331 | return S_FALSE; |
Raphael Junqueira | 8f554aa | 2005-11-15 12:02:16 +0000 | [diff] [blame] | 1332 | } |
Jeff Latimer | 9c6c83e | 2006-04-20 21:50:44 +1000 | [diff] [blame] | 1333 | |
Jeff Latimer | 29ff53c | 2006-02-14 17:38:20 +0100 | [diff] [blame] | 1334 | /*********************************************************************** |
| 1335 | * ScriptShape (USP10.@) |
| 1336 | * |
Hans Leidekker | dfcdbba | 2007-01-23 11:03:26 +0100 | [diff] [blame] | 1337 | * Produce glyphs and visual attributes for a run. |
| 1338 | * |
| 1339 | * PARAMS |
| 1340 | * hdc [I] Device context. |
| 1341 | * psc [I/O] Opaque pointer to a script cache. |
| 1342 | * pwcChars [I] Array of characters specifying the run. |
| 1343 | * cChars [I] Number of characters in pwcChars. |
| 1344 | * cMaxGlyphs [I] Length of pwOutGlyphs. |
Hans Leidekker | d5e7604 | 2007-12-12 10:44:42 +0100 | [diff] [blame] | 1345 | * psa [I/O] Script analysis. |
Hans Leidekker | dfcdbba | 2007-01-23 11:03:26 +0100 | [diff] [blame] | 1346 | * pwOutGlyphs [O] Array of glyphs. |
| 1347 | * pwLogClust [O] Array of logical cluster info. |
| 1348 | * psva [O] Array of visual attributes. |
| 1349 | * pcGlyphs [O] Number of glyphs returned. |
| 1350 | * |
| 1351 | * RETURNS |
| 1352 | * Success: S_OK |
| 1353 | * Failure: Non-zero HRESULT value. |
Jeff Latimer | 29ff53c | 2006-02-14 17:38:20 +0100 | [diff] [blame] | 1354 | */ |
| 1355 | HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars, |
| 1356 | int cChars, int cMaxGlyphs, |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1357 | SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust, |
Jeff Latimer | 29ff53c | 2006-02-14 17:38:20 +0100 | [diff] [blame] | 1358 | SCRIPT_VISATTR *psva, int *pcGlyphs) |
| 1359 | { |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1360 | HRESULT hr; |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1361 | unsigned int i; |
Aric Stewart | 51bbd92 | 2010-04-14 10:00:37 -0500 | [diff] [blame] | 1362 | BOOL rtl; |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1363 | |
Hans Leidekker | 9a847b3 | 2009-01-06 11:21:07 +0100 | [diff] [blame] | 1364 | TRACE("(%p, %p, %s, %d, %d, %p, %p, %p, %p, %p)\n", hdc, psc, debugstr_wn(pwcChars, cChars), |
| 1365 | cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs); |
| 1366 | |
Jeff Latimer | ec67444 | 2006-02-24 20:13:51 +1100 | [diff] [blame] | 1367 | if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL, |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1368 | psa->fLinkBefore, psa->fLinkAfter, psa->fLogicalOrder, psa->fNoGlyphIndex); |
Jeff Latimer | 334e191 | 2006-02-20 20:19:32 +1100 | [diff] [blame] | 1369 | |
Hans Leidekker | d5e7604 | 2007-12-12 10:44:42 +0100 | [diff] [blame] | 1370 | if (!psva || !pcGlyphs) return E_INVALIDARG; |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1371 | if (cChars > cMaxGlyphs) return E_OUTOFMEMORY; |
Aric Stewart | 51bbd92 | 2010-04-14 10:00:37 -0500 | [diff] [blame] | 1372 | rtl = (!psa->fLogicalOrder && psa->fRTL); |
Rob Shearman | 89a3ad7 | 2008-09-12 13:02:12 +0100 | [diff] [blame] | 1373 | |
Hans Leidekker | d5e7604 | 2007-12-12 10:44:42 +0100 | [diff] [blame] | 1374 | *pcGlyphs = cChars; |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1375 | if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr; |
Hans Leidekker | f7a4936 | 2009-09-03 14:50:17 +0200 | [diff] [blame] | 1376 | if (!pwLogClust) return E_FAIL; |
Hans Leidekker | 68efae1 | 2007-12-09 21:39:19 +0100 | [diff] [blame] | 1377 | |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 1378 | if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex) |
| 1379 | { |
Aric Stewart | 32b9b63 | 2010-05-19 09:17:00 -0500 | [diff] [blame] | 1380 | WCHAR *rChars = heap_alloc(sizeof(WCHAR) * cChars); |
Marcus Meissner | 163c702 | 2010-05-21 21:11:30 +0200 | [diff] [blame] | 1381 | if (!rChars) return E_OUTOFMEMORY; |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1382 | for (i = 0; i < cChars; i++) |
| 1383 | { |
Aric Stewart | 51bbd92 | 2010-04-14 10:00:37 -0500 | [diff] [blame] | 1384 | int idx = i; |
Aric Stewart | 4377cc6 | 2010-05-06 08:28:57 -0500 | [diff] [blame] | 1385 | WCHAR chInput; |
Aric Stewart | 51bbd92 | 2010-04-14 10:00:37 -0500 | [diff] [blame] | 1386 | if (rtl) idx = cChars - 1 - i; |
Aric Stewart | 4377cc6 | 2010-05-06 08:28:57 -0500 | [diff] [blame] | 1387 | if (psa->fRTL) |
| 1388 | chInput = mirror_char(pwcChars[idx]); |
| 1389 | else |
| 1390 | chInput = pwcChars[idx]; |
| 1391 | if (!(pwOutGlyphs[i] = get_cache_glyph(psc, chInput))) |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1392 | { |
| 1393 | WORD glyph; |
| 1394 | if (!hdc) return E_PENDING; |
Aric Stewart | 4377cc6 | 2010-05-06 08:28:57 -0500 | [diff] [blame] | 1395 | if (GetGlyphIndicesW(hdc, &chInput, 1, &glyph, 0) == GDI_ERROR) return S_FALSE; |
| 1396 | pwOutGlyphs[i] = set_cache_glyph(psc, chInput, glyph); |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1397 | } |
Aric Stewart | 32b9b63 | 2010-05-19 09:17:00 -0500 | [diff] [blame] | 1398 | rChars[i] = chInput; |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1399 | } |
Aric Stewart | 6c73258 | 2010-05-21 15:12:03 -0500 | [diff] [blame] | 1400 | SHAPE_ShapeArabicGlyphs(hdc, (ScriptCache *)*psc, psa, rChars, cChars, pwOutGlyphs, pcGlyphs, cMaxGlyphs); |
Aric Stewart | 32b9b63 | 2010-05-19 09:17:00 -0500 | [diff] [blame] | 1401 | heap_free(rChars); |
Jeff Latimer | 334e191 | 2006-02-20 20:19:32 +1100 | [diff] [blame] | 1402 | } |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 1403 | else |
| 1404 | { |
| 1405 | TRACE("no glyph translation\n"); |
Aric Stewart | 51bbd92 | 2010-04-14 10:00:37 -0500 | [diff] [blame] | 1406 | for (i = 0; i < cChars; i++) |
| 1407 | { |
| 1408 | int idx = i; |
Aric Stewart | 4377cc6 | 2010-05-06 08:28:57 -0500 | [diff] [blame] | 1409 | /* No mirroring done here */ |
Aric Stewart | 51bbd92 | 2010-04-14 10:00:37 -0500 | [diff] [blame] | 1410 | if (rtl) idx = cChars - 1 - i; |
| 1411 | pwOutGlyphs[i] = pwcChars[idx]; |
| 1412 | } |
Jeff Latimer | 334e191 | 2006-02-20 20:19:32 +1100 | [diff] [blame] | 1413 | } |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 1414 | |
Paul Vriens | 0af0baf | 2009-04-09 21:31:07 +0200 | [diff] [blame] | 1415 | /* set up a valid SCRIPT_VISATTR and LogClust for each char in this run */ |
| 1416 | for (i = 0; i < cChars; i++) |
Hans Leidekker | d5e7604 | 2007-12-12 10:44:42 +0100 | [diff] [blame] | 1417 | { |
Aric Stewart | 51bbd92 | 2010-04-14 10:00:37 -0500 | [diff] [blame] | 1418 | int idx = i; |
| 1419 | if (rtl) idx = cChars - 1 - i; |
Paul Vriens | 0af0baf | 2009-04-09 21:31:07 +0200 | [diff] [blame] | 1420 | /* FIXME: set to better values */ |
Aric Stewart | 51bbd92 | 2010-04-14 10:00:37 -0500 | [diff] [blame] | 1421 | psva[i].uJustification = (pwcChars[idx] == ' ') ? SCRIPT_JUSTIFY_BLANK : SCRIPT_JUSTIFY_CHARACTER; |
Paul Vriens | 0af0baf | 2009-04-09 21:31:07 +0200 | [diff] [blame] | 1422 | psva[i].fClusterStart = 1; |
| 1423 | psva[i].fDiacritic = 0; |
| 1424 | psva[i].fZeroWidth = 0; |
| 1425 | psva[i].fReserved = 0; |
| 1426 | psva[i].fShapeReserved = 0; |
Jeff Latimer | 334e191 | 2006-02-20 20:19:32 +1100 | [diff] [blame] | 1427 | |
Aric Stewart | 51bbd92 | 2010-04-14 10:00:37 -0500 | [diff] [blame] | 1428 | pwLogClust[i] = idx; |
Jeff Latimer | 334e191 | 2006-02-20 20:19:32 +1100 | [diff] [blame] | 1429 | } |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1430 | return S_OK; |
Jeff Latimer | 29ff53c | 2006-02-14 17:38:20 +0100 | [diff] [blame] | 1431 | } |
Jeff Latimer | 334e191 | 2006-02-20 20:19:32 +1100 | [diff] [blame] | 1432 | |
Jeff Latimer | 29ff53c | 2006-02-14 17:38:20 +0100 | [diff] [blame] | 1433 | /*********************************************************************** |
| 1434 | * ScriptPlace (USP10.@) |
| 1435 | * |
Hans Leidekker | dfcdbba | 2007-01-23 11:03:26 +0100 | [diff] [blame] | 1436 | * Produce advance widths for a run. |
| 1437 | * |
| 1438 | * PARAMS |
| 1439 | * hdc [I] Device context. |
| 1440 | * psc [I/O] Opaque pointer to a script cache. |
| 1441 | * pwGlyphs [I] Array of glyphs. |
| 1442 | * cGlyphs [I] Number of glyphs in pwGlyphs. |
| 1443 | * psva [I] Array of visual attributes. |
| 1444 | * psa [I/O] String analysis. |
| 1445 | * piAdvance [O] Array of advance widths. |
| 1446 | * pGoffset [O] Glyph offsets. |
| 1447 | * pABC [O] Combined ABC width. |
| 1448 | * |
| 1449 | * RETURNS |
| 1450 | * Success: S_OK |
| 1451 | * Failure: Non-zero HRESULT value. |
Jeff Latimer | 29ff53c | 2006-02-14 17:38:20 +0100 | [diff] [blame] | 1452 | */ |
| 1453 | HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs, |
| 1454 | int cGlyphs, const SCRIPT_VISATTR *psva, |
| 1455 | SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC ) |
| 1456 | { |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1457 | HRESULT hr; |
Andrew Talbot | bf92d68 | 2008-11-19 21:28:04 +0000 | [diff] [blame] | 1458 | int i; |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1459 | |
Hans Leidekker | 9a847b3 | 2009-01-06 11:21:07 +0100 | [diff] [blame] | 1460 | TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc, psc, pwGlyphs, cGlyphs, psva, psa, |
| 1461 | piAdvance, pGoffset, pABC); |
Jeff Latimer | 29ff53c | 2006-02-14 17:38:20 +0100 | [diff] [blame] | 1462 | |
Hans Leidekker | d5e7604 | 2007-12-12 10:44:42 +0100 | [diff] [blame] | 1463 | if (!psva) return E_INVALIDARG; |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1464 | if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr; |
Hans Leidekker | f7a4936 | 2009-09-03 14:50:17 +0200 | [diff] [blame] | 1465 | if (!pGoffset) return E_FAIL; |
Rob Shearman | 89a3ad7 | 2008-09-12 13:02:12 +0100 | [diff] [blame] | 1466 | |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 1467 | if (pABC) memset(pABC, 0, sizeof(ABC)); |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 1468 | for (i = 0; i < cGlyphs; i++) |
| 1469 | { |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1470 | ABC abc; |
| 1471 | if (!get_cache_glyph_widths(psc, pwGlyphs[i], &abc)) |
| 1472 | { |
| 1473 | if (!hdc) return E_PENDING; |
| 1474 | if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex) |
| 1475 | { |
| 1476 | if (!GetCharABCWidthsI(hdc, 0, 1, (WORD *)&pwGlyphs[i], &abc)) return S_FALSE; |
| 1477 | } |
| 1478 | else |
| 1479 | { |
| 1480 | INT width; |
| 1481 | if (!GetCharWidth32W(hdc, pwGlyphs[i], pwGlyphs[i], &width)) return S_FALSE; |
| 1482 | abc.abcB = width; |
| 1483 | abc.abcA = abc.abcC = 0; |
| 1484 | } |
| 1485 | set_cache_glyph_widths(psc, pwGlyphs[i], &abc); |
| 1486 | } |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 1487 | if (pABC) |
| 1488 | { |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1489 | pABC->abcA += abc.abcA; |
| 1490 | pABC->abcB += abc.abcB; |
| 1491 | pABC->abcC += abc.abcC; |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 1492 | } |
| 1493 | /* FIXME: set to more reasonable values */ |
Hans Leidekker | f7a4936 | 2009-09-03 14:50:17 +0200 | [diff] [blame] | 1494 | pGoffset[i].du = pGoffset[i].dv = 0; |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1495 | if (piAdvance) piAdvance[i] = abc.abcA + abc.abcB + abc.abcC; |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 1496 | } |
Jeff Latimer | 9c6c83e | 2006-04-20 21:50:44 +1000 | [diff] [blame] | 1497 | |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1498 | if (pABC) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC->abcA, pABC->abcB, pABC->abcC); |
Hans Leidekker | 68efae1 | 2007-12-09 21:39:19 +0100 | [diff] [blame] | 1499 | return S_OK; |
Jeff Latimer | 29ff53c | 2006-02-14 17:38:20 +0100 | [diff] [blame] | 1500 | } |
Louis Lenders | 9acfd6b | 2006-02-14 17:38:47 +0100 | [diff] [blame] | 1501 | |
| 1502 | /*********************************************************************** |
| 1503 | * ScriptGetCMap (USP10.@) |
| 1504 | * |
Hans Leidekker | 44fd9a2 | 2007-01-02 16:11:10 +0100 | [diff] [blame] | 1505 | * Retrieve glyph indices. |
| 1506 | * |
| 1507 | * PARAMS |
| 1508 | * hdc [I] Device context. |
| 1509 | * psc [I/O] Opaque pointer to a script cache. |
| 1510 | * pwcInChars [I] Array of Unicode characters. |
| 1511 | * cChars [I] Number of characters in pwcInChars. |
| 1512 | * dwFlags [I] Flags. |
| 1513 | * pwOutGlyphs [O] Buffer to receive the array of glyph indices. |
| 1514 | * |
| 1515 | * RETURNS |
| 1516 | * Success: S_OK |
| 1517 | * Failure: Non-zero HRESULT value. |
Louis Lenders | 9acfd6b | 2006-02-14 17:38:47 +0100 | [diff] [blame] | 1518 | */ |
| 1519 | HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars, |
Hans Leidekker | 44fd9a2 | 2007-01-02 16:11:10 +0100 | [diff] [blame] | 1520 | int cChars, DWORD dwFlags, WORD *pwOutGlyphs) |
Louis Lenders | 9acfd6b | 2006-02-14 17:38:47 +0100 | [diff] [blame] | 1521 | { |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1522 | HRESULT hr; |
Andrew Talbot | bf92d68 | 2008-11-19 21:28:04 +0000 | [diff] [blame] | 1523 | int i; |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1524 | |
Hans Leidekker | 21987d3 | 2007-01-02 15:31:34 +0100 | [diff] [blame] | 1525 | TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc, psc, debugstr_wn(pwcInChars, cChars), |
| 1526 | cChars, dwFlags, pwOutGlyphs); |
Jeff Latimer | af67bc8 | 2006-04-30 23:44:30 +1000 | [diff] [blame] | 1527 | |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1528 | if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr; |
Jeff Latimer | 4241adb | 2006-02-22 23:24:52 +1100 | [diff] [blame] | 1529 | |
Aric Stewart | abae85b | 2010-05-05 11:51:52 -0500 | [diff] [blame] | 1530 | hr = S_OK; |
| 1531 | |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1532 | if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE)) |
| 1533 | { |
| 1534 | for (i = 0; i < cChars; i++) |
| 1535 | { |
Aric Stewart | 4377cc6 | 2010-05-06 08:28:57 -0500 | [diff] [blame] | 1536 | WCHAR inChar; |
| 1537 | if (dwFlags == SGCM_RTL) |
| 1538 | inChar = mirror_char(pwcInChars[i]); |
| 1539 | else |
| 1540 | inChar = pwcInChars[i]; |
| 1541 | if (!(pwOutGlyphs[i] = get_cache_glyph(psc, inChar))) |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1542 | { |
| 1543 | WORD glyph; |
| 1544 | if (!hdc) return E_PENDING; |
Aric Stewart | 4377cc6 | 2010-05-06 08:28:57 -0500 | [diff] [blame] | 1545 | if (GetGlyphIndicesW(hdc, &inChar, 1, &glyph, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR) return S_FALSE; |
Aric Stewart | abae85b | 2010-05-05 11:51:52 -0500 | [diff] [blame] | 1546 | if (glyph == 0xffff) |
| 1547 | { |
| 1548 | hr = S_FALSE; |
| 1549 | glyph = 0x0; |
| 1550 | } |
Aric Stewart | 4377cc6 | 2010-05-06 08:28:57 -0500 | [diff] [blame] | 1551 | pwOutGlyphs[i] = set_cache_glyph(psc, inChar, glyph); |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | } |
| 1555 | else |
| 1556 | { |
| 1557 | TRACE("no glyph translation\n"); |
Aric Stewart | 4377cc6 | 2010-05-06 08:28:57 -0500 | [diff] [blame] | 1558 | for (i = 0; i < cChars; i++) |
| 1559 | { |
| 1560 | WCHAR inChar; |
| 1561 | if (dwFlags == SGCM_RTL) |
| 1562 | inChar = mirror_char(pwcInChars[i]); |
| 1563 | else |
| 1564 | inChar = pwcInChars[i]; |
| 1565 | pwOutGlyphs[i] = inChar; |
| 1566 | } |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1567 | } |
Aric Stewart | abae85b | 2010-05-05 11:51:52 -0500 | [diff] [blame] | 1568 | return hr; |
Louis Lenders | 9acfd6b | 2006-02-14 17:38:47 +0100 | [diff] [blame] | 1569 | } |
Jeff Latimer | 044a6f8 | 2006-02-21 20:47:39 +1100 | [diff] [blame] | 1570 | |
| 1571 | /*********************************************************************** |
| 1572 | * ScriptTextOut (USP10.@) |
| 1573 | * |
| 1574 | */ |
| 1575 | HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UINT fuOptions, |
| 1576 | const RECT *lprc, const SCRIPT_ANALYSIS *psa, const WCHAR *pwcReserved, |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1577 | int iReserved, const WORD *pwGlyphs, int cGlyphs, const int *piAdvance, |
Jeff Latimer | 044a6f8 | 2006-02-21 20:47:39 +1100 | [diff] [blame] | 1578 | const int *piJustify, const GOFFSET *pGoffset) |
| 1579 | { |
Hans Leidekker | 68efae1 | 2007-12-09 21:39:19 +0100 | [diff] [blame] | 1580 | HRESULT hr = S_OK; |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1581 | |
Hans Leidekker | 21987d3 | 2007-01-02 15:31:34 +0100 | [diff] [blame] | 1582 | TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n", |
Jeff Latimer | af67bc8 | 2006-04-30 23:44:30 +1000 | [diff] [blame] | 1583 | hdc, psc, x, y, fuOptions, lprc, psa, pwcReserved, iReserved, pwGlyphs, cGlyphs, |
| 1584 | piAdvance, piJustify, pGoffset); |
| 1585 | |
Hans Leidekker | c1e6864 | 2008-05-01 17:42:03 +0200 | [diff] [blame] | 1586 | if (!hdc || !psc) return E_INVALIDARG; |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1587 | if (!piAdvance || !psa || !pwGlyphs) return E_INVALIDARG; |
Hans Leidekker | 68efae1 | 2007-12-09 21:39:19 +0100 | [diff] [blame] | 1588 | |
Jeff Latimer | af67bc8 | 2006-04-30 23:44:30 +1000 | [diff] [blame] | 1589 | fuOptions &= ETO_CLIPPED + ETO_OPAQUE; |
Aric Stewart | 421a997 | 2010-05-07 22:10:26 -0500 | [diff] [blame] | 1590 | fuOptions |= ETO_IGNORELANGUAGE; |
Jeff Latimer | af67bc8 | 2006-04-30 23:44:30 +1000 | [diff] [blame] | 1591 | if (!psa->fNoGlyphIndex) /* Have Glyphs? */ |
Francois Gouget | 58162f8 | 2006-10-13 02:19:42 +0200 | [diff] [blame] | 1592 | fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */ |
Jeff Latimer | af67bc8 | 2006-04-30 23:44:30 +1000 | [diff] [blame] | 1593 | |
Aric Stewart | 2ba0048 | 2010-05-05 13:30:33 -0500 | [diff] [blame] | 1594 | if (psa->fRTL && psa->fLogicalOrder) |
| 1595 | { |
| 1596 | int i; |
| 1597 | WORD *rtlGlyphs; |
| 1598 | |
| 1599 | rtlGlyphs = heap_alloc(cGlyphs * sizeof(WORD)); |
| 1600 | if (!rtlGlyphs) |
| 1601 | return E_OUTOFMEMORY; |
| 1602 | |
| 1603 | for (i = 0; i < cGlyphs; i++) |
| 1604 | rtlGlyphs[i] = pwGlyphs[cGlyphs-1-i]; |
| 1605 | |
| 1606 | if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, rtlGlyphs, cGlyphs, NULL)) |
| 1607 | hr = S_FALSE; |
| 1608 | heap_free(rtlGlyphs); |
| 1609 | } |
| 1610 | else |
| 1611 | if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL)) |
| 1612 | hr = S_FALSE; |
Jeff Latimer | af67bc8 | 2006-04-30 23:44:30 +1000 | [diff] [blame] | 1613 | |
Hans Leidekker | 68efae1 | 2007-12-09 21:39:19 +0100 | [diff] [blame] | 1614 | return hr; |
Jeff Latimer | 044a6f8 | 2006-02-21 20:47:39 +1100 | [diff] [blame] | 1615 | } |
Hans Leidekker | 401e32e | 2006-07-19 21:45:24 +0200 | [diff] [blame] | 1616 | |
| 1617 | /*********************************************************************** |
| 1618 | * ScriptCacheGetHeight (USP10.@) |
| 1619 | * |
| 1620 | * Retrieve the height of the font in the cache. |
| 1621 | * |
| 1622 | * PARAMS |
| 1623 | * hdc [I] Device context. |
| 1624 | * psc [I/O] Opaque pointer to a script cache. |
| 1625 | * height [O] Receives font height. |
| 1626 | * |
| 1627 | * RETURNS |
| 1628 | * Success: S_OK |
| 1629 | * Failure: Non-zero HRESULT value. |
| 1630 | */ |
Hans Leidekker | 092edd8 | 2006-12-23 11:07:55 +0100 | [diff] [blame] | 1631 | HRESULT WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, LONG *height) |
Hans Leidekker | 401e32e | 2006-07-19 21:45:24 +0200 | [diff] [blame] | 1632 | { |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1633 | HRESULT hr; |
Hans Leidekker | 401e32e | 2006-07-19 21:45:24 +0200 | [diff] [blame] | 1634 | |
| 1635 | TRACE("(%p, %p, %p)\n", hdc, psc, height); |
| 1636 | |
Hans Leidekker | 7d37e8e | 2006-12-28 16:12:45 +0100 | [diff] [blame] | 1637 | if (!height) return E_INVALIDARG; |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1638 | if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr; |
Hans Leidekker | 401e32e | 2006-07-19 21:45:24 +0200 | [diff] [blame] | 1639 | |
Hans Leidekker | 06ed81e | 2007-01-23 11:03:12 +0100 | [diff] [blame] | 1640 | *height = get_cache_height(psc); |
Hans Leidekker | 401e32e | 2006-07-19 21:45:24 +0200 | [diff] [blame] | 1641 | return S_OK; |
| 1642 | } |
Hans Leidekker | 0c0ab50 | 2006-08-04 14:55:30 +0200 | [diff] [blame] | 1643 | |
| 1644 | /*********************************************************************** |
| 1645 | * ScriptGetGlyphABCWidth (USP10.@) |
| 1646 | * |
| 1647 | * Retrieve the width of a glyph. |
| 1648 | * |
| 1649 | * PARAMS |
| 1650 | * hdc [I] Device context. |
| 1651 | * psc [I/O] Opaque pointer to a script cache. |
| 1652 | * glyph [I] Glyph to retrieve the width for. |
| 1653 | * abc [O] ABC widths of the glyph. |
| 1654 | * |
| 1655 | * RETURNS |
| 1656 | * Success: S_OK |
| 1657 | * Failure: Non-zero HRESULT value. |
| 1658 | */ |
| 1659 | HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, ABC *abc) |
| 1660 | { |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1661 | HRESULT hr; |
Hans Leidekker | 0c0ab50 | 2006-08-04 14:55:30 +0200 | [diff] [blame] | 1662 | |
| 1663 | TRACE("(%p, %p, 0x%04x, %p)\n", hdc, psc, glyph, abc); |
| 1664 | |
Hans Leidekker | f7a4936 | 2009-09-03 14:50:17 +0200 | [diff] [blame] | 1665 | if (!abc) return E_INVALIDARG; |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1666 | if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr; |
Hans Leidekker | 0c0ab50 | 2006-08-04 14:55:30 +0200 | [diff] [blame] | 1667 | |
Hans Leidekker | addcf86 | 2008-10-09 15:17:29 +0200 | [diff] [blame] | 1668 | if (!get_cache_glyph_widths(psc, glyph, abc)) |
| 1669 | { |
| 1670 | if (!hdc) return E_PENDING; |
| 1671 | if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE)) |
| 1672 | { |
| 1673 | if (!GetCharABCWidthsI(hdc, 0, 1, &glyph, abc)) return S_FALSE; |
| 1674 | } |
| 1675 | else |
| 1676 | { |
| 1677 | INT width; |
| 1678 | if (!GetCharWidth32W(hdc, glyph, glyph, &width)) return S_FALSE; |
| 1679 | abc->abcB = width; |
| 1680 | abc->abcA = abc->abcC = 0; |
| 1681 | } |
| 1682 | set_cache_glyph_widths(psc, glyph, abc); |
| 1683 | } |
| 1684 | return S_OK; |
Hans Leidekker | 0c0ab50 | 2006-08-04 14:55:30 +0200 | [diff] [blame] | 1685 | } |
Hans Leidekker | 5782607 | 2006-09-28 17:00:19 +0200 | [diff] [blame] | 1686 | |
| 1687 | /*********************************************************************** |
| 1688 | * ScriptLayout (USP10.@) |
| 1689 | * |
| 1690 | * Map embedding levels to visual and/or logical order. |
| 1691 | * |
| 1692 | * PARAMS |
| 1693 | * runs [I] Size of level array. |
| 1694 | * level [I] Array of embedding levels. |
| 1695 | * vistolog [O] Map of embedding levels from visual to logical order. |
| 1696 | * logtovis [O] Map of embedding levels from logical to visual order. |
| 1697 | * |
| 1698 | * RETURNS |
| 1699 | * Success: S_OK |
| 1700 | * Failure: Non-zero HRESULT value. |
| 1701 | * |
| 1702 | * BUGS |
| 1703 | * This stub works correctly for any sequence of a single |
| 1704 | * embedding level but not for sequences of different |
| 1705 | * embedding levels, i.e. mixtures of RTL and LTR scripts. |
| 1706 | */ |
| 1707 | HRESULT WINAPI ScriptLayout(int runs, const BYTE *level, int *vistolog, int *logtovis) |
| 1708 | { |
Aric Stewart | b9c3044 | 2010-04-13 14:49:20 -0500 | [diff] [blame] | 1709 | int* indexs; |
| 1710 | int ich; |
Hans Leidekker | 5782607 | 2006-09-28 17:00:19 +0200 | [diff] [blame] | 1711 | |
Hans Leidekker | 21987d3 | 2007-01-02 15:31:34 +0100 | [diff] [blame] | 1712 | TRACE("(%d, %p, %p, %p)\n", runs, level, vistolog, logtovis); |
Hans Leidekker | 5782607 | 2006-09-28 17:00:19 +0200 | [diff] [blame] | 1713 | |
| 1714 | if (!level || (!vistolog && !logtovis)) |
| 1715 | return E_INVALIDARG; |
| 1716 | |
Aric Stewart | b9c3044 | 2010-04-13 14:49:20 -0500 | [diff] [blame] | 1717 | indexs = heap_alloc(sizeof(int) * runs); |
| 1718 | if (!indexs) |
| 1719 | return E_OUTOFMEMORY; |
| 1720 | |
| 1721 | |
| 1722 | if (vistolog) |
Hans Leidekker | 5782607 | 2006-09-28 17:00:19 +0200 | [diff] [blame] | 1723 | { |
Aric Stewart | b9c3044 | 2010-04-13 14:49:20 -0500 | [diff] [blame] | 1724 | for( ich = 0; ich < runs; ich++) |
| 1725 | indexs[ich] = ich; |
| 1726 | |
| 1727 | ich = 0; |
| 1728 | while (ich < runs) |
| 1729 | ich += BIDI_ReorderV2lLevel(0, indexs+ich, level+ich, runs - ich, FALSE); |
| 1730 | for (ich = 0; ich < runs; ich++) |
| 1731 | vistolog[ich] = indexs[ich]; |
Hans Leidekker | 5782607 | 2006-09-28 17:00:19 +0200 | [diff] [blame] | 1732 | } |
Aric Stewart | b9c3044 | 2010-04-13 14:49:20 -0500 | [diff] [blame] | 1733 | |
| 1734 | |
| 1735 | if (logtovis) |
| 1736 | { |
| 1737 | for( ich = 0; ich < runs; ich++) |
| 1738 | indexs[ich] = ich; |
| 1739 | |
| 1740 | ich = 0; |
| 1741 | while (ich < runs) |
| 1742 | ich += BIDI_ReorderL2vLevel(0, indexs+ich, level+ich, runs - ich, FALSE); |
| 1743 | for (ich = 0; ich < runs; ich++) |
| 1744 | logtovis[ich] = indexs[ich]; |
| 1745 | } |
| 1746 | heap_free(indexs); |
| 1747 | |
Hans Leidekker | 5782607 | 2006-09-28 17:00:19 +0200 | [diff] [blame] | 1748 | return S_OK; |
| 1749 | } |
Hans Leidekker | 539a962 | 2006-10-06 12:43:49 +0200 | [diff] [blame] | 1750 | |
| 1751 | /*********************************************************************** |
Clinton Stimpson | 46bb89e | 2006-12-24 12:47:15 +0100 | [diff] [blame] | 1752 | * ScriptStringGetLogicalWidths (USP10.@) |
| 1753 | * |
| 1754 | * Returns logical widths from a string analysis. |
| 1755 | * |
| 1756 | * PARAMS |
| 1757 | * ssa [I] string analysis. |
| 1758 | * piDx [O] logical widths returned. |
| 1759 | * |
| 1760 | * RETURNS |
| 1761 | * Success: S_OK |
| 1762 | * Failure: a non-zero HRESULT. |
| 1763 | */ |
| 1764 | HRESULT WINAPI ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa, int *piDx) |
| 1765 | { |
| 1766 | int i, j, next = 0; |
| 1767 | StringAnalysis *analysis = ssa; |
| 1768 | |
| 1769 | TRACE("%p, %p\n", ssa, piDx); |
| 1770 | |
| 1771 | if (!analysis) return S_FALSE; |
| 1772 | |
| 1773 | for (i = 0; i < analysis->numItems; i++) |
| 1774 | { |
| 1775 | for (j = 0; j < analysis->glyphs[i].numGlyphs; j++) |
| 1776 | { |
| 1777 | piDx[next] = analysis->glyphs[i].piAdvance[j]; |
| 1778 | next++; |
| 1779 | } |
| 1780 | } |
| 1781 | return S_OK; |
| 1782 | } |
| 1783 | |
| 1784 | /*********************************************************************** |
Hans Leidekker | 539a962 | 2006-10-06 12:43:49 +0200 | [diff] [blame] | 1785 | * ScriptStringValidate (USP10.@) |
| 1786 | * |
| 1787 | * Validate a string analysis. |
| 1788 | * |
| 1789 | * PARAMS |
| 1790 | * ssa [I] string analysis. |
| 1791 | * |
| 1792 | * RETURNS |
| 1793 | * Success: S_OK |
| 1794 | * Failure: S_FALSE if invalid sequences are found |
| 1795 | * or a non-zero HRESULT if it fails. |
| 1796 | */ |
| 1797 | HRESULT WINAPI ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa) |
| 1798 | { |
Hans Leidekker | bb3a903 | 2007-01-02 15:26:32 +0100 | [diff] [blame] | 1799 | StringAnalysis *analysis = ssa; |
| 1800 | |
| 1801 | TRACE("(%p)\n", ssa); |
| 1802 | |
| 1803 | if (!analysis) return E_INVALIDARG; |
| 1804 | return (analysis->invalid) ? S_FALSE : S_OK; |
Hans Leidekker | 539a962 | 2006-10-06 12:43:49 +0200 | [diff] [blame] | 1805 | } |
Hans Leidekker | 092edd8 | 2006-12-23 11:07:55 +0100 | [diff] [blame] | 1806 | |
| 1807 | /*********************************************************************** |
| 1808 | * ScriptString_pSize (USP10.@) |
| 1809 | * |
| 1810 | * Retrieve width and height of an analysed string. |
| 1811 | * |
| 1812 | * PARAMS |
| 1813 | * ssa [I] string analysis. |
| 1814 | * |
| 1815 | * RETURNS |
| 1816 | * Success: Pointer to a SIZE structure. |
| 1817 | * Failure: NULL |
| 1818 | */ |
| 1819 | const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa) |
| 1820 | { |
Andrew Talbot | bf92d68 | 2008-11-19 21:28:04 +0000 | [diff] [blame] | 1821 | int i, j; |
Hans Leidekker | 092edd8 | 2006-12-23 11:07:55 +0100 | [diff] [blame] | 1822 | StringAnalysis *analysis = ssa; |
Hans Leidekker | 092edd8 | 2006-12-23 11:07:55 +0100 | [diff] [blame] | 1823 | |
| 1824 | TRACE("(%p)\n", ssa); |
| 1825 | |
| 1826 | if (!analysis) return NULL; |
| 1827 | |
| 1828 | if (!analysis->sz) |
| 1829 | { |
Michael Stefaniuc | 8f1b74a | 2007-12-10 23:53:07 +0100 | [diff] [blame] | 1830 | if (!(analysis->sz = heap_alloc(sizeof(SIZE)))) return NULL; |
Hans Leidekker | 25e836e | 2007-12-12 19:11:28 +0100 | [diff] [blame] | 1831 | analysis->sz->cy = analysis->sc->tm.tmHeight; |
Hans Leidekker | 092edd8 | 2006-12-23 11:07:55 +0100 | [diff] [blame] | 1832 | |
| 1833 | analysis->sz->cx = 0; |
| 1834 | for (i = 0; i < analysis->numItems; i++) |
| 1835 | for (j = 0; j < analysis->glyphs[i].numGlyphs; j++) |
| 1836 | analysis->sz->cx += analysis->glyphs[i].piAdvance[j]; |
| 1837 | } |
| 1838 | return analysis->sz; |
| 1839 | } |
Hans Leidekker | cd6fe7d | 2006-12-23 17:19:31 +0100 | [diff] [blame] | 1840 | |
| 1841 | /*********************************************************************** |
| 1842 | * ScriptString_pLogAttr (USP10.@) |
| 1843 | * |
| 1844 | * Retrieve logical attributes of an analysed string. |
| 1845 | * |
| 1846 | * PARAMS |
| 1847 | * ssa [I] string analysis. |
| 1848 | * |
| 1849 | * RETURNS |
| 1850 | * Success: Pointer to an array of SCRIPT_LOGATTR structures. |
| 1851 | * Failure: NULL |
| 1852 | */ |
| 1853 | const SCRIPT_LOGATTR * WINAPI ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa) |
| 1854 | { |
| 1855 | StringAnalysis *analysis = ssa; |
| 1856 | |
| 1857 | TRACE("(%p)\n", ssa); |
| 1858 | |
| 1859 | if (!analysis) return NULL; |
| 1860 | return analysis->logattrs; |
| 1861 | } |
Hans Leidekker | f152153 | 2007-01-03 12:12:29 +0100 | [diff] [blame] | 1862 | |
| 1863 | /*********************************************************************** |
| 1864 | * ScriptString_pcOutChars (USP10.@) |
| 1865 | * |
| 1866 | * Retrieve the length of a string after clipping. |
| 1867 | * |
| 1868 | * PARAMS |
| 1869 | * ssa [I] String analysis. |
| 1870 | * |
| 1871 | * RETURNS |
| 1872 | * Success: Pointer to the length. |
| 1873 | * Failure: NULL |
| 1874 | */ |
| 1875 | const int * WINAPI ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa) |
| 1876 | { |
| 1877 | StringAnalysis *analysis = ssa; |
| 1878 | |
| 1879 | TRACE("(%p)\n", ssa); |
| 1880 | |
| 1881 | if (!analysis) return NULL; |
| 1882 | return &analysis->clip_len; |
| 1883 | } |
| 1884 | |
| 1885 | /*********************************************************************** |
| 1886 | * ScriptStringGetOrder (USP10.@) |
| 1887 | * |
| 1888 | * Retrieve a glyph order map. |
| 1889 | * |
| 1890 | * PARAMS |
| 1891 | * ssa [I] String analysis. |
| 1892 | * order [I/O] Array of glyph positions. |
| 1893 | * |
| 1894 | * RETURNS |
| 1895 | * Success: S_OK |
| 1896 | * Failure: a non-zero HRESULT. |
| 1897 | */ |
| 1898 | HRESULT WINAPI ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa, UINT *order) |
| 1899 | { |
Andrew Talbot | bf92d68 | 2008-11-19 21:28:04 +0000 | [diff] [blame] | 1900 | int i, j; |
| 1901 | unsigned int k; |
Hans Leidekker | f152153 | 2007-01-03 12:12:29 +0100 | [diff] [blame] | 1902 | StringAnalysis *analysis = ssa; |
| 1903 | |
| 1904 | TRACE("(%p)\n", ssa); |
| 1905 | |
| 1906 | if (!analysis) return S_FALSE; |
| 1907 | |
| 1908 | /* FIXME: handle RTL scripts */ |
| 1909 | for (i = 0, k = 0; i < analysis->numItems; i++) |
| 1910 | for (j = 0; j < analysis->glyphs[i].numGlyphs; j++, k++) |
| 1911 | order[k] = k; |
| 1912 | |
| 1913 | return S_OK; |
| 1914 | } |
Hans Leidekker | df2c8a2 | 2007-02-18 19:38:07 +0100 | [diff] [blame] | 1915 | |
| 1916 | /*********************************************************************** |
| 1917 | * ScriptGetLogicalWidths (USP10.@) |
| 1918 | * |
| 1919 | * Convert advance widths to logical widths. |
| 1920 | * |
| 1921 | * PARAMS |
| 1922 | * sa [I] Script analysis. |
| 1923 | * nbchars [I] Number of characters. |
| 1924 | * nbglyphs [I] Number of glyphs. |
| 1925 | * glyph_width [I] Array of glyph widths. |
| 1926 | * log_clust [I] Array of logical clusters. |
| 1927 | * sva [I] Visual attributes. |
| 1928 | * widths [O] Array of logical widths. |
| 1929 | * |
| 1930 | * RETURNS |
| 1931 | * Success: S_OK |
| 1932 | * Failure: a non-zero HRESULT. |
| 1933 | */ |
| 1934 | HRESULT WINAPI ScriptGetLogicalWidths(const SCRIPT_ANALYSIS *sa, int nbchars, int nbglyphs, |
| 1935 | const int *glyph_width, const WORD *log_clust, |
| 1936 | const SCRIPT_VISATTR *sva, int *widths) |
| 1937 | { |
| 1938 | int i; |
| 1939 | |
| 1940 | TRACE("(%p, %d, %d, %p, %p, %p, %p)\n", |
| 1941 | sa, nbchars, nbglyphs, glyph_width, log_clust, sva, widths); |
| 1942 | |
| 1943 | /* FIXME */ |
| 1944 | for (i = 0; i < nbchars; i++) widths[i] = glyph_width[i]; |
| 1945 | return S_OK; |
| 1946 | } |
Hans Leidekker | 7714a3f | 2009-11-21 13:07:36 +0100 | [diff] [blame] | 1947 | |
| 1948 | /*********************************************************************** |
| 1949 | * ScriptApplyLogicalWidth (USP10.@) |
| 1950 | * |
| 1951 | * Generate glyph advance widths. |
| 1952 | * |
| 1953 | * PARAMS |
| 1954 | * dx [I] Array of logical advance widths. |
| 1955 | * num_chars [I] Number of characters. |
| 1956 | * num_glyphs [I] Number of glyphs. |
| 1957 | * log_clust [I] Array of logical clusters. |
| 1958 | * sva [I] Visual attributes. |
| 1959 | * advance [I] Array of glyph advance widths. |
| 1960 | * sa [I] Script analysis. |
| 1961 | * abc [I/O] Summed ABC widths. |
| 1962 | * justify [O] Array of glyph advance widths. |
| 1963 | * |
| 1964 | * RETURNS |
| 1965 | * Success: S_OK |
| 1966 | * Failure: a non-zero HRESULT. |
| 1967 | */ |
| 1968 | HRESULT WINAPI ScriptApplyLogicalWidth(const int *dx, int num_chars, int num_glyphs, |
| 1969 | const WORD *log_clust, const SCRIPT_VISATTR *sva, |
| 1970 | const int *advance, const SCRIPT_ANALYSIS *sa, |
| 1971 | ABC *abc, int *justify) |
| 1972 | { |
| 1973 | int i; |
| 1974 | |
| 1975 | FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n", |
| 1976 | dx, num_chars, num_glyphs, log_clust, sva, advance, sa, abc, justify); |
| 1977 | |
| 1978 | for (i = 0; i < num_chars; i++) justify[i] = advance[i]; |
| 1979 | return S_OK; |
| 1980 | } |
Hans Leidekker | d974a4b | 2009-11-21 13:08:08 +0100 | [diff] [blame] | 1981 | |
| 1982 | HRESULT WINAPI ScriptJustify(const SCRIPT_VISATTR *sva, const int *advance, |
| 1983 | int num_glyphs, int dx, int min_kashida, int *justify) |
| 1984 | { |
| 1985 | int i; |
| 1986 | |
| 1987 | FIXME("(%p, %p, %d, %d, %d, %p)\n", sva, advance, num_glyphs, dx, min_kashida, justify); |
| 1988 | |
| 1989 | for (i = 0; i < num_glyphs; i++) justify[i] = advance[i]; |
| 1990 | return S_OK; |
| 1991 | } |