2 * Implementation of Uniscribe Script Processor (usp10.dll)
4 * Copyright 2005 Steven Edwards for CodeWeavers
5 * Copyright 2006 Hans Leidekker
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Uniscribe allows for processing of complex scripts such as joining
23 * and filtering characters and bi-directional text with custom line breaks.
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe
);
40 static const SCRIPT_PROPERTIES props
[] =
42 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
43 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
44 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
45 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
46 { 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
47 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
48 { 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
49 { 8, 0, 0, 0, 0, 161, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
50 { 25, 0, 0, 0, 0, 204, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
51 { 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
52 { 55, 0, 0, 0, 0, 0, 0, 0, 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114 { 9, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
115 { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
118 static const SCRIPT_PROPERTIES
*script_props
[] =
120 &props
[0], &props
[1], &props
[2], &props
[3],
121 &props
[4], &props
[5], &props
[6], &props
[7],
122 &props
[8], &props
[9], &props
[11], &props
[12],
123 &props
[13], &props
[14], &props
[15], &props
[16],
124 &props
[17], &props
[18], &props
[19], &props
[20],
125 &props
[21], &props
[22], &props
[23], &props
[24],
126 &props
[25], &props
[26], &props
[27], &props
[28],
127 &props
[29], &props
[30], &props
[31], &props
[32],
128 &props
[33], &props
[34], &props
[35], &props
[36],
129 &props
[37], &props
[38], &props
[39], &props
[40],
130 &props
[41], &props
[42], &props
[43], &props
[44],
131 &props
[45], &props
[46], &props
[47], &props
[48],
132 &props
[49], &props
[50], &props
[51], &props
[52],
133 &props
[53], &props
[54], &props
[55], &props
[56],
134 &props
[57], &props
[58], &props
[59], &props
[60],
135 &props
[61], &props
[62], &props
[63], &props
[64],
136 &props
[65], &props
[66], &props
[67], &props
[68],
137 &props
[69], &props
[70], &props
[71], &props
[72],
141 #define GLYPH_BLOCK_SHIFT 8
142 #define GLYPH_BLOCK_SIZE (1UL << GLYPH_BLOCK_SHIFT)
143 #define GLYPH_BLOCK_MASK (GLYPH_BLOCK_SIZE - 1)
144 #define GLYPH_MAX 65536
149 WORD
*glyphs
[GLYPH_MAX
/ GLYPH_BLOCK_SIZE
];
150 ABC
*widths
[GLYPH_MAX
/ GLYPH_BLOCK_SIZE
];
158 SCRIPT_VISATTR
* psva
;
172 StringGlyphs
* glyphs
;
173 SCRIPT_LOGATTR
* logattrs
;
177 static inline void *heap_alloc(SIZE_T size
)
179 return HeapAlloc(GetProcessHeap(), 0, size
);
182 static inline void *heap_alloc_zero(SIZE_T size
)
184 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
187 static inline void *heap_realloc_zero(LPVOID mem
, SIZE_T size
)
189 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, size
);
192 static inline BOOL
heap_free(LPVOID mem
)
194 return HeapFree(GetProcessHeap(), 0, mem
);
197 static inline WCHAR
get_cache_default_char(SCRIPT_CACHE
*psc
)
199 return ((ScriptCache
*)*psc
)->tm
.tmDefaultChar
;
202 static inline LONG
get_cache_height(SCRIPT_CACHE
*psc
)
204 return ((ScriptCache
*)*psc
)->tm
.tmHeight
;
207 static inline BYTE
get_cache_pitch_family(SCRIPT_CACHE
*psc
)
209 return ((ScriptCache
*)*psc
)->tm
.tmPitchAndFamily
;
212 static inline WORD
get_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
)
214 WORD
*block
= ((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
216 if (!block
) return 0;
217 return block
[c
& GLYPH_BLOCK_MASK
];
220 static inline WORD
set_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
, WORD glyph
)
222 WORD
**block
= &((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
224 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(WORD
) * GLYPH_BLOCK_SIZE
))) return 0;
225 return ((*block
)[c
& GLYPH_BLOCK_MASK
] = glyph
);
228 static inline BOOL
get_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
230 static const ABC nil
;
231 ABC
*block
= ((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
233 if (!block
|| !memcmp(&block
[glyph
& GLYPH_BLOCK_MASK
], &nil
, sizeof(ABC
))) return FALSE
;
234 memcpy(abc
, &block
[glyph
& GLYPH_BLOCK_MASK
], sizeof(ABC
));
238 static inline BOOL
set_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
240 ABC
**block
= &((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
242 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(ABC
) * GLYPH_BLOCK_SIZE
))) return FALSE
;
243 memcpy(&(*block
)[glyph
& GLYPH_BLOCK_MASK
], abc
, sizeof(ABC
));
247 static HRESULT
init_script_cache(const HDC hdc
, SCRIPT_CACHE
*psc
)
251 if (!psc
) return E_INVALIDARG
;
252 if (*psc
) return S_OK
;
253 if (!hdc
) return E_PENDING
;
255 if (!(sc
= heap_alloc_zero(sizeof(ScriptCache
)))) return E_OUTOFMEMORY
;
256 if (!GetTextMetricsW(hdc
, &sc
->tm
))
261 if (!GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(LOGFONTW
), &sc
->lf
))
267 TRACE("<- %p\n", sc
);
271 /***********************************************************************
275 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
279 case DLL_PROCESS_ATTACH
:
280 DisableThreadLibraryCalls(hInstDLL
);
282 case DLL_PROCESS_DETACH
:
288 /***********************************************************************
289 * ScriptFreeCache (USP10.@)
291 * Free a script cache.
294 * psc [I/O] Script cache.
298 * Failure: Non-zero HRESULT value.
300 HRESULT WINAPI
ScriptFreeCache(SCRIPT_CACHE
*psc
)
307 for (i
= 0; i
< GLYPH_MAX
/ GLYPH_BLOCK_SIZE
; i
++)
309 heap_free(((ScriptCache
*)*psc
)->glyphs
[i
]);
310 heap_free(((ScriptCache
*)*psc
)->widths
[i
]);
318 /***********************************************************************
319 * ScriptGetProperties (USP10.@)
321 * Retrieve a list of script properties.
324 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
325 * num [I] Pointer to the number of scripts.
329 * Failure: Non-zero HRESULT value.
332 * Behaviour matches WinXP.
334 HRESULT WINAPI
ScriptGetProperties(const SCRIPT_PROPERTIES
***props
, int *num
)
336 TRACE("(%p,%p)\n", props
, num
);
338 if (!props
&& !num
) return E_INVALIDARG
;
340 if (num
) *num
= sizeof(script_props
)/sizeof(script_props
[0]);
341 if (props
) *props
= script_props
;
346 /***********************************************************************
347 * ScriptGetFontProperties (USP10.@)
349 * Get information on special glyphs.
352 * hdc [I] Device context.
353 * psc [I/O] Opaque pointer to a script cache.
354 * sfp [O] Font properties structure.
356 HRESULT WINAPI
ScriptGetFontProperties(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_FONTPROPERTIES
*sfp
)
360 TRACE("%p,%p,%p\n", hdc
, psc
, sfp
);
362 if (!sfp
) return E_INVALIDARG
;
363 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
365 if (sfp
->cBytes
!= sizeof(SCRIPT_FONTPROPERTIES
))
368 /* return something sensible? */
370 sfp
->wgDefault
= get_cache_default_char(psc
);
372 sfp
->wgKashida
= 0xffff;
373 sfp
->iKashidaWidth
= 0;
378 /***********************************************************************
379 * ScriptRecordDigitSubstitution (USP10.@)
381 * Record digit substitution settings for a given locale.
384 * locale [I] Locale identifier.
385 * sds [I] Structure to record substitution settings.
389 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
392 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
394 HRESULT WINAPI
ScriptRecordDigitSubstitution(LCID locale
, SCRIPT_DIGITSUBSTITUTE
*sds
)
398 TRACE("0x%x, %p\n", locale
, sds
);
400 /* This implementation appears to be correct for all languages, but it's
401 * not clear if sds->DigitSubstitute is ever set to anything except
402 * CONTEXT or NONE in reality */
404 if (!sds
) return E_POINTER
;
406 locale
= ConvertDefaultLocale(locale
);
408 if (!IsValidLocale(locale
, LCID_INSTALLED
))
411 plgid
= PRIMARYLANGID(LANGIDFROMLCID(locale
));
412 sds
->TraditionalDigitLanguage
= plgid
;
414 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
415 sds
->NationalDigitLanguage
= plgid
;
417 sds
->NationalDigitLanguage
= LANG_ENGLISH
;
419 if (!GetLocaleInfoW(locale
, LOCALE_IDIGITSUBSTITUTION
| LOCALE_RETURN_NUMBER
,
420 (LPWSTR
)&sub
, sizeof(sub
)/sizeof(WCHAR
))) return E_INVALIDARG
;
425 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
426 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_CONTEXT
;
428 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
431 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
434 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NATIONAL
;
437 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
;
445 /***********************************************************************
446 * ScriptApplyDigitSubstitution (USP10.@)
448 * Apply digit substitution settings.
451 * sds [I] Structure with recorded substitution settings.
452 * sc [I] Script control structure.
453 * ss [I] Script state structure.
457 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
459 HRESULT WINAPI
ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE
*sds
,
460 SCRIPT_CONTROL
*sc
, SCRIPT_STATE
*ss
)
462 SCRIPT_DIGITSUBSTITUTE psds
;
464 TRACE("%p, %p, %p\n", sds
, sc
, ss
);
466 if (!sc
|| !ss
) return E_POINTER
;
470 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT
, &psds
) != S_OK
)
474 sc
->uDefaultLanguage
= LANG_ENGLISH
;
475 sc
->fContextDigits
= 0;
476 ss
->fDigitSubstitute
= 0;
478 switch (sds
->DigitSubstitute
) {
479 case SCRIPT_DIGITSUBSTITUTE_CONTEXT
:
480 case SCRIPT_DIGITSUBSTITUTE_NATIONAL
:
481 case SCRIPT_DIGITSUBSTITUTE_NONE
:
482 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
:
489 /***********************************************************************
490 * ScriptItemize (USP10.@)
492 * Split a Unicode string into shapeable parts.
495 * pwcInChars [I] String to split.
496 * cInChars [I] Number of characters in pwcInChars.
497 * cMaxItems [I] Maximum number of items to return.
498 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
499 * psState [I] Pointer to a SCRIPT_STATE structure.
500 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
501 * pcItems [O] Number of script items returned.
505 * Failure: Non-zero HRESULT value.
507 HRESULT WINAPI
ScriptItemize(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
508 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
509 SCRIPT_ITEM
*pItems
, int *pcItems
)
512 #define Numeric_start 0x0030
513 #define Numeric_stop 0x0039
514 #define Numeric_space 0x0020
515 #define Arabic_start 0x0600
516 #define Arabic_stop 0x06ff
517 #define Latin_start 0x0001
518 #define Latin_stop 0x024f
519 #define Script_Arabic 6
520 #define Script_Latin 1
521 #define Script_Numeric 5
525 int cnt
= 0, index
= 0;
526 int New_Script
= SCRIPT_UNDEFINED
;
528 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars
, cInChars
), cInChars
, cMaxItems
,
529 psControl
, psState
, pItems
, pcItems
);
531 if (!pwcInChars
|| !cInChars
|| !pItems
|| cMaxItems
< 2)
534 pItems
[index
].iCharPos
= 0;
535 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
537 if (pwcInChars
[cnt
] == '\r')
538 pItems
[index
].a
.eScript
= Script_CR
;
540 if (pwcInChars
[cnt
] == '\n')
541 pItems
[index
].a
.eScript
= Script_LF
;
543 if (pwcInChars
[cnt
] >= Numeric_start
&& pwcInChars
[cnt
] <= Numeric_stop
)
544 pItems
[index
].a
.eScript
= Script_Numeric
;
546 if (pwcInChars
[cnt
] >= Arabic_start
&& pwcInChars
[cnt
] <= Arabic_stop
)
547 pItems
[index
].a
.eScript
= Script_Arabic
;
549 if (pwcInChars
[cnt
] >= Latin_start
&& pwcInChars
[cnt
] <= Latin_stop
)
550 pItems
[index
].a
.eScript
= Script_Latin
;
552 if (pItems
[index
].a
.eScript
== Script_Arabic
)
553 pItems
[index
].a
.s
.uBidiLevel
= 1;
555 TRACE("New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
556 New_Script
, pItems
[index
].a
.eScript
, index
, cnt
,
557 pItems
[index
].iCharPos
);
559 for (cnt
=1; cnt
< cInChars
; cnt
++)
561 if (pwcInChars
[cnt
] == '\r')
562 New_Script
= Script_CR
;
564 if (pwcInChars
[cnt
] == '\n')
565 New_Script
= Script_LF
;
567 if ((pwcInChars
[cnt
] >= Numeric_start
&& pwcInChars
[cnt
] <= Numeric_stop
)
568 || (New_Script
== Script_Numeric
&& pwcInChars
[cnt
] == Numeric_space
))
569 New_Script
= Script_Numeric
;
571 if ((pwcInChars
[cnt
] >= Arabic_start
&& pwcInChars
[cnt
] <= Arabic_stop
)
572 || (New_Script
== Script_Arabic
&& pwcInChars
[cnt
] == Numeric_space
))
573 New_Script
= Script_Arabic
;
575 if ((pwcInChars
[cnt
] >= Latin_start
&& pwcInChars
[cnt
] <= Latin_stop
)
576 || (New_Script
== Script_Latin
&& pwcInChars
[cnt
] == Numeric_space
))
577 New_Script
= Script_Latin
;
579 New_Script
= SCRIPT_UNDEFINED
;
581 if (New_Script
!= pItems
[index
].a
.eScript
)
583 TRACE("New_Script=%d, eScript=%d ", New_Script
, pItems
[index
].a
.eScript
);
585 if (index
+1 > cMaxItems
)
586 return E_OUTOFMEMORY
;
588 pItems
[index
].iCharPos
= cnt
;
589 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
591 if (New_Script
== Script_Arabic
)
592 pItems
[index
].a
.s
.uBidiLevel
= 1;
594 pItems
[index
].a
.eScript
= New_Script
;
595 if (New_Script
== Script_Arabic
)
596 pItems
[index
].a
.s
.uBidiLevel
= 1;
598 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
602 /* While not strictly necessary according to the spec, make sure the n+1
603 * item is set up to prevent random behaviour if the caller erroneously
604 * checks the n+1 structure */
605 memset(&pItems
[index
+1].a
, 0, sizeof(SCRIPT_ANALYSIS
));
607 TRACE("index=%d cnt=%d iCharPos=%d\n", index
+1, cnt
, pItems
[index
+1].iCharPos
= cnt
);
609 /* Set one SCRIPT_STATE item being returned */
610 if (pcItems
) *pcItems
= index
+ 1;
612 /* Set SCRIPT_ITEM */
613 pItems
[index
+1].iCharPos
= cnt
; /* the last + 1 item
614 contains the ptr to the lastchar */
618 /***********************************************************************
619 * ScriptStringAnalyse (USP10.@)
622 HRESULT WINAPI
ScriptStringAnalyse(HDC hdc
, const void *pString
, int cString
,
623 int cGlyphs
, int iCharset
, DWORD dwFlags
,
624 int iReqWidth
, SCRIPT_CONTROL
*psControl
,
625 SCRIPT_STATE
*psState
, const int *piDx
,
626 SCRIPT_TABDEF
*pTabdef
, const BYTE
*pbInClass
,
627 SCRIPT_STRING_ANALYSIS
*pssa
)
629 HRESULT hr
= E_OUTOFMEMORY
;
630 StringAnalysis
*analysis
= NULL
;
631 int i
, num_items
= 255;
633 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
634 hdc
, pString
, cString
, cGlyphs
, iCharset
, dwFlags
, iReqWidth
,
635 psControl
, psState
, piDx
, pTabdef
, pbInClass
, pssa
);
639 FIXME("Only Unicode strings are supported\n");
642 if (cString
< 1 || !pString
) return E_INVALIDARG
;
643 if ((dwFlags
& SSA_GLYPHS
) && !hdc
) return E_PENDING
;
645 if (!(analysis
= heap_alloc_zero(sizeof(StringAnalysis
)))) return E_OUTOFMEMORY
;
646 if (!(analysis
->pItem
= heap_alloc_zero(num_items
* sizeof(SCRIPT_ITEM
) + 1))) goto error
;
648 /* FIXME: handle clipping */
649 analysis
->clip_len
= cString
;
652 hr
= ScriptItemize(pString
, cString
, num_items
, psControl
, psState
, analysis
->pItem
,
653 &analysis
->numItems
);
655 while (hr
== E_OUTOFMEMORY
)
660 if (!(tmp
= heap_realloc_zero(analysis
->pItem
, num_items
* sizeof(SCRIPT_ITEM
) + 1)))
663 analysis
->pItem
= tmp
;
664 hr
= ScriptItemize(pString
, cString
, num_items
, psControl
, psState
, analysis
->pItem
,
665 &analysis
->numItems
);
667 if (hr
!= S_OK
) goto error
;
669 if ((analysis
->logattrs
= heap_alloc(sizeof(SCRIPT_LOGATTR
) * cString
)))
670 ScriptBreak(pString
, cString
, (SCRIPT_STRING_ANALYSIS
)analysis
, analysis
->logattrs
);
674 if (!(analysis
->glyphs
= heap_alloc_zero(sizeof(StringGlyphs
) * analysis
->numItems
)))
677 for (i
= 0; i
< analysis
->numItems
; i
++)
679 SCRIPT_CACHE
*sc
= (SCRIPT_CACHE
*)&analysis
->sc
;
680 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
681 int numGlyphs
= 1.5 * cChar
+ 16;
682 WORD
*glyphs
= heap_alloc_zero(sizeof(WORD
) * numGlyphs
);
683 WORD
*pwLogClust
= heap_alloc_zero(sizeof(WORD
) * cChar
);
684 int *piAdvance
= heap_alloc_zero(sizeof(int) * numGlyphs
);
685 SCRIPT_VISATTR
*psva
= heap_alloc_zero(sizeof(SCRIPT_VISATTR
) * cChar
);
686 GOFFSET
*pGoffset
= heap_alloc_zero(sizeof(GOFFSET
) * numGlyphs
);
687 ABC
*abc
= heap_alloc_zero(sizeof(ABC
));
688 int numGlyphsReturned
;
690 /* FIXME: non unicode strings */
691 WCHAR
* pStr
= (WCHAR
*)pString
;
692 hr
= ScriptShape(hdc
, sc
, &pStr
[analysis
->pItem
[i
].iCharPos
],
693 cChar
, numGlyphs
, &analysis
->pItem
[i
].a
,
694 glyphs
, pwLogClust
, psva
, &numGlyphsReturned
);
695 hr
= ScriptPlace(hdc
, sc
, glyphs
, numGlyphsReturned
, psva
, &analysis
->pItem
[i
].a
,
696 piAdvance
, pGoffset
, abc
);
698 analysis
->glyphs
[i
].numGlyphs
= numGlyphsReturned
;
699 analysis
->glyphs
[i
].glyphs
= glyphs
;
700 analysis
->glyphs
[i
].pwLogClust
= pwLogClust
;
701 analysis
->glyphs
[i
].piAdvance
= piAdvance
;
702 analysis
->glyphs
[i
].psva
= psva
;
703 analysis
->glyphs
[i
].pGoffset
= pGoffset
;
704 analysis
->glyphs
[i
].abc
= abc
;
711 heap_free(analysis
->glyphs
);
712 heap_free(analysis
->logattrs
);
713 heap_free(analysis
->pItem
);
714 heap_free(analysis
->sc
);
719 /***********************************************************************
720 * ScriptStringOut (USP10.@)
722 * This function takes the output of ScriptStringAnalyse and joins the segments
723 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
724 * only processes glyphs.
727 * ssa [I] buffer to hold the analysed string components
728 * iX [I] X axis displacement for output
729 * iY [I] Y axis displacement for output
730 * uOptions [I] flags controling output processing
731 * prc [I] rectangle coordinates
732 * iMinSel [I] starting pos for substringing output string
733 * iMaxSel [I] ending pos for substringing output string
734 * fDisabled [I] controls text highlighting
738 * Failure: is the value returned by ScriptTextOut
740 HRESULT WINAPI
ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa
,
749 StringAnalysis
*analysis
;
754 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
755 ssa
, iX
, iY
, uOptions
, prc
, iMinSel
, iMaxSel
, fDisabled
);
757 if (!(analysis
= ssa
)) return E_INVALIDARG
;
760 * Get storage for the output buffer for the consolidated strings
763 for (item
= 0; item
< analysis
->numItems
; item
++)
765 cnt
+= analysis
->glyphs
[item
].numGlyphs
;
767 if (!(glyphs
= heap_alloc(sizeof(WCHAR
) * cnt
))) return E_OUTOFMEMORY
;
770 * ScriptStringOut only processes glyphs hence set ETO_GLYPH_INDEX
772 uOptions
|= ETO_GLYPH_INDEX
;
773 analysis
->pItem
[0].a
.fNoGlyphIndex
= FALSE
; /* say that we have glyphs */
776 * Copy the string items into the output buffer
779 TRACE("numItems %d\n", analysis
->numItems
);
782 for (item
= 0; item
< analysis
->numItems
; item
++)
784 memcpy(&glyphs
[cnt
], analysis
->glyphs
[item
].glyphs
,
785 sizeof(WCHAR
) * analysis
->glyphs
[item
].numGlyphs
);
787 TRACE("Item %d, Glyphs %d ", item
, analysis
->glyphs
[item
].numGlyphs
);
788 for (x
= cnt
; x
< analysis
->glyphs
[item
].numGlyphs
+ cnt
; x
++)
789 TRACE("%04x", glyphs
[x
]);
792 cnt
+= analysis
->glyphs
[item
].numGlyphs
; /* point to the end of the copied text */
795 hr
= ScriptTextOut(analysis
->hdc
, (SCRIPT_CACHE
*)&analysis
->sc
, iX
, iY
,
796 uOptions
, prc
, &analysis
->pItem
->a
, NULL
, 0, glyphs
, cnt
,
797 analysis
->glyphs
->piAdvance
, NULL
, analysis
->glyphs
->pGoffset
);
798 TRACE("ScriptTextOut hr=%08x\n", hr
);
801 * Free the output buffer and script cache
807 /***********************************************************************
808 * ScriptStringCPtoX (USP10.@)
811 HRESULT WINAPI
ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa
, int icp
, BOOL fTrailing
, int* pX
)
816 StringAnalysis
* analysis
= ssa
;
818 TRACE("(%p), %d, %d, (%p)\n", ssa
, icp
, fTrailing
, pX
);
820 if (!ssa
|| !pX
) return S_FALSE
;
822 /* icp out of range */
825 analysis
->invalid
= TRUE
;
829 for(i
=0; i
<analysis
->numItems
; i
++)
831 for(j
=0; j
<analysis
->glyphs
[i
].numGlyphs
; j
++)
833 if(runningCp
== icp
&& fTrailing
== FALSE
)
838 runningX
+= analysis
->glyphs
[i
].piAdvance
[j
];
839 if(runningCp
== icp
&& fTrailing
== TRUE
)
848 /* icp out of range */
849 analysis
->invalid
= TRUE
;
853 /***********************************************************************
854 * ScriptStringXtoCP (USP10.@)
857 HRESULT WINAPI
ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa
, int iX
, int* piCh
, int* piTrailing
)
859 StringAnalysis
* analysis
= ssa
;
866 TRACE("(%p), %d, (%p), (%p)\n", ssa
, iX
, piCh
, piTrailing
);
868 if (!ssa
|| !piCh
|| !piTrailing
) return S_FALSE
;
878 for(i
=0; i
<analysis
->numItems
; i
++)
880 for(j
=0; j
<analysis
->glyphs
[i
].numGlyphs
; j
++)
882 width
= analysis
->glyphs
[i
].piAdvance
[j
];
883 if(iX
< (runningX
+ width
))
886 if((iX
- runningX
) > width
/2)
898 *piCh
= analysis
->pItem
[analysis
->numItems
].iCharPos
;
905 /***********************************************************************
906 * ScriptStringFree (USP10.@)
908 * Free a string analysis.
911 * pssa [I] string analysis.
915 * Failure: Non-zero HRESULT value.
917 HRESULT WINAPI
ScriptStringFree(SCRIPT_STRING_ANALYSIS
*pssa
)
919 StringAnalysis
* analysis
;
923 TRACE("(%p)\n", pssa
);
925 if (!pssa
|| !(analysis
= *pssa
)) return E_INVALIDARG
;
927 invalid
= analysis
->invalid
;
928 ScriptFreeCache((SCRIPT_CACHE
*)&analysis
->sc
);
930 for (i
= 0; i
< analysis
->numItems
; i
++)
932 heap_free(analysis
->glyphs
[i
].glyphs
);
933 heap_free(analysis
->glyphs
[i
].pwLogClust
);
934 heap_free(analysis
->glyphs
[i
].piAdvance
);
935 heap_free(analysis
->glyphs
[i
].psva
);
936 heap_free(analysis
->glyphs
[i
].pGoffset
);
937 heap_free(analysis
->glyphs
[i
].abc
);
940 heap_free(analysis
->glyphs
);
941 heap_free(analysis
->pItem
);
942 heap_free(analysis
->logattrs
);
943 heap_free(analysis
->sz
);
944 heap_free(analysis
->sc
);
947 if (invalid
) return E_INVALIDARG
;
951 /***********************************************************************
952 * ScriptCPtoX (USP10.@)
955 HRESULT WINAPI
ScriptCPtoX(int iCP
,
959 const WORD
*pwLogClust
,
960 const SCRIPT_VISATTR
*psva
,
961 const int *piAdvance
,
962 const SCRIPT_ANALYSIS
*psa
,
968 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
969 iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
971 for (item
=0; item
< cGlyphs
; item
++) /* total piAdvance */
972 fMaxPosX
+= piAdvance
[item
];
973 iPosX
= (fMaxPosX
/cGlyphs
)*(iCP
+fTrailing
);
974 if (iPosX
> fMaxPosX
)
976 *piX
= iPosX
; /* Return something in range */
978 TRACE("*piX=%d\n", *piX
);
982 /***********************************************************************
983 * ScriptXtoCP (USP10.@)
986 HRESULT WINAPI
ScriptXtoCP(int iX
,
989 const WORD
*pwLogClust
,
990 const SCRIPT_VISATTR
*psva
,
991 const int *piAdvance
,
992 const SCRIPT_ANALYSIS
*psa
,
1000 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
1001 iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
1002 psa
, piCP
, piTrailing
);
1003 if (iX
< 0) /* iX is before start of run */
1010 for (item
=0; item
< cGlyphs
; item
++) /* total piAdvance */
1011 fMaxPosX
+= piAdvance
[item
];
1013 if (iX
>= fMaxPosX
) /* iX too large */
1016 *piTrailing
= FALSE
;
1020 fAvePosX
= fMaxPosX
/ cGlyphs
;
1022 for (item
= 1; item
< cGlyphs
&& iPosX
< iX
; item
++)
1024 if (iPosX
- iX
> fAvePosX
/2)
1027 *piTrailing
= 1; /* yep we are over halfway */
1029 *piCP
= item
-1; /* Return character position */
1030 TRACE("*piCP=%d iPposX=%d\n", *piCP
, iPosX
);
1034 /***********************************************************************
1035 * ScriptBreak (USP10.@)
1037 * Retrieve line break information.
1040 * chars [I] Array of characters.
1041 * sa [I] String analysis.
1042 * la [I] Array of logical attribute structures.
1048 HRESULT WINAPI
ScriptBreak(const WCHAR
*chars
, int count
, const SCRIPT_ANALYSIS
*sa
, SCRIPT_LOGATTR
*la
)
1052 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars
, count
), count
, sa
, la
);
1054 if (!la
) return S_FALSE
;
1056 for (i
= 0; i
< count
; i
++)
1058 memset(&la
[i
], 0, sizeof(SCRIPT_LOGATTR
));
1060 /* FIXME: set the other flags */
1061 la
[i
].fWhiteSpace
= (chars
[i
] == ' ');
1062 la
[i
].fCharStop
= 1;
1064 if (i
> 0 && la
[i
- 1].fWhiteSpace
)
1066 la
[i
].fSoftBreak
= 1;
1067 la
[i
].fWordStop
= 1;
1081 { 0, 0x0b, SIC_COMPLEX
},
1082 { 0x0c, 0x0c, SIC_NEUTRAL
},
1083 { 0x0d, 0x1f, SIC_COMPLEX
},
1084 { 0x20, 0x2f, SIC_NEUTRAL
},
1085 { 0x30, 0x39, SIC_ASCIIDIGIT
},
1086 { 0x3a, 0x40, SIC_NEUTRAL
},
1087 { 0x5b, 0x60, SIC_NEUTRAL
},
1088 { 0x7b, 0x7e, SIC_NEUTRAL
},
1089 { 0x7f, 0x9f, SIC_COMPLEX
},
1090 { 0xa0, 0xa5, SIC_NEUTRAL
},
1091 { 0xa7, 0xa8, SIC_NEUTRAL
},
1092 { 0xab, 0xab, SIC_NEUTRAL
},
1093 { 0xad, 0xad, SIC_NEUTRAL
},
1094 { 0xaf, 0xaf, SIC_NEUTRAL
},
1095 { 0xb0, 0xb1, SIC_NEUTRAL
},
1096 { 0xb4, 0xb4, SIC_NEUTRAL
},
1097 { 0xb6, 0xb8, SIC_NEUTRAL
},
1098 { 0xbb, 0xbf, SIC_NEUTRAL
},
1099 { 0xd7, 0xd7, SIC_NEUTRAL
},
1100 { 0xf7, 0xf7, SIC_NEUTRAL
},
1101 { 0x2b9, 0x2ba, SIC_NEUTRAL
},
1102 { 0x2c2, 0x2cf, SIC_NEUTRAL
},
1103 { 0x2d2, 0x2df, SIC_NEUTRAL
},
1104 { 0x2e5, 0x2e9, SIC_COMPLEX
},
1105 { 0x2ea, 0x2ed, SIC_NEUTRAL
},
1106 { 0x300, 0x362, SIC_COMPLEX
},
1107 { 0x530, 0x60b, SIC_COMPLEX
},
1108 { 0x60c, 0x60d, SIC_NEUTRAL
},
1109 { 0x60e, 0x669, SIC_COMPLEX
},
1110 { 0x66a, 0x66a, SIC_NEUTRAL
},
1111 { 0x66b, 0x6e8, SIC_COMPLEX
},
1112 { 0x6e9, 0x6e9, SIC_NEUTRAL
},
1113 { 0x6ea, 0x7bf, SIC_COMPLEX
},
1114 { 0x900, 0x1360, SIC_COMPLEX
},
1115 { 0x137d, 0x137f, SIC_COMPLEX
},
1116 { 0x1680, 0x1680, SIC_NEUTRAL
},
1117 { 0x1780, 0x18af, SIC_COMPLEX
},
1118 { 0x2000, 0x200a, SIC_NEUTRAL
},
1119 { 0x200b, 0x200f, SIC_COMPLEX
},
1120 { 0x2010, 0x2016, SIC_NEUTRAL
},
1121 { 0x2018, 0x2022, SIC_NEUTRAL
},
1122 { 0x2024, 0x2028, SIC_NEUTRAL
},
1123 { 0x2029, 0x202e, SIC_COMPLEX
},
1124 { 0x202f, 0x2037, SIC_NEUTRAL
},
1125 { 0x2039, 0x203c, SIC_NEUTRAL
},
1126 { 0x2044, 0x2046, SIC_NEUTRAL
},
1127 { 0x206a, 0x206f, SIC_COMPLEX
},
1128 { 0x207a, 0x207e, SIC_NEUTRAL
},
1129 { 0x208a, 0x20aa, SIC_NEUTRAL
},
1130 { 0x20ac, 0x20cf, SIC_NEUTRAL
},
1131 { 0x20d0, 0x20ff, SIC_COMPLEX
},
1132 { 0x2103, 0x2103, SIC_NEUTRAL
},
1133 { 0x2105, 0x2105, SIC_NEUTRAL
},
1134 { 0x2109, 0x2109, SIC_NEUTRAL
},
1135 { 0x2116, 0x2116, SIC_NEUTRAL
},
1136 { 0x2121, 0x2122, SIC_NEUTRAL
},
1137 { 0x212e, 0x212e, SIC_NEUTRAL
},
1138 { 0x2153, 0x2154, SIC_NEUTRAL
},
1139 { 0x215b, 0x215e, SIC_NEUTRAL
},
1140 { 0x2190, 0x2199, SIC_NEUTRAL
},
1141 { 0x21b8, 0x21b9, SIC_NEUTRAL
},
1142 { 0x21d2, 0x21d2, SIC_NEUTRAL
},
1143 { 0x21d4, 0x21d4, SIC_NEUTRAL
},
1144 { 0x21e7, 0x21e7, SIC_NEUTRAL
},
1145 { 0x2200, 0x2200, SIC_NEUTRAL
},
1146 { 0x2202, 0x2203, SIC_NEUTRAL
},
1147 { 0x2207, 0x2208, SIC_NEUTRAL
},
1148 { 0x220b, 0x220b, SIC_NEUTRAL
},
1149 { 0x220f, 0x220f, SIC_NEUTRAL
},
1150 { 0x2211, 0x2213, SIC_NEUTRAL
},
1151 { 0x2215, 0x2215, SIC_NEUTRAL
},
1152 { 0x221a, 0x221a, SIC_NEUTRAL
},
1153 { 0x221d, 0x2220, SIC_NEUTRAL
},
1154 { 0x2223, 0x2223, SIC_NEUTRAL
},
1155 { 0x2225, 0x2225, SIC_NEUTRAL
},
1156 { 0x2227, 0x222c, SIC_NEUTRAL
},
1157 { 0x222e, 0x222e, SIC_NEUTRAL
},
1158 { 0x2234, 0x2237, SIC_NEUTRAL
},
1159 { 0x223c, 0x223d, SIC_NEUTRAL
},
1160 { 0x2248, 0x2248, SIC_NEUTRAL
},
1161 { 0x224c, 0x224c, SIC_NEUTRAL
},
1162 { 0x2252, 0x2252, SIC_NEUTRAL
},
1163 { 0x2260, 0x2261, SIC_NEUTRAL
},
1164 { 0x2264, 0x2267, SIC_NEUTRAL
},
1165 { 0x226a, 0x226b, SIC_NEUTRAL
},
1166 { 0x226e, 0x226f, SIC_NEUTRAL
},
1167 { 0x2282, 0x2283, SIC_NEUTRAL
},
1168 { 0x2286, 0x2287, SIC_NEUTRAL
},
1169 { 0x2295, 0x2295, SIC_NEUTRAL
},
1170 { 0x2299, 0x2299, SIC_NEUTRAL
},
1171 { 0x22a5, 0x22a5, SIC_NEUTRAL
},
1172 { 0x22bf, 0x22bf, SIC_NEUTRAL
},
1173 { 0x2312, 0x2312, SIC_NEUTRAL
},
1174 { 0x24ea, 0x24ea, SIC_COMPLEX
},
1175 { 0x2500, 0x254b, SIC_NEUTRAL
},
1176 { 0x2550, 0x256d, SIC_NEUTRAL
},
1177 { 0x256e, 0x2574, SIC_NEUTRAL
},
1178 { 0x2581, 0x258f, SIC_NEUTRAL
},
1179 { 0x2592, 0x2595, SIC_NEUTRAL
},
1180 { 0x25a0, 0x25a1, SIC_NEUTRAL
},
1181 { 0x25a3, 0x25a9, SIC_NEUTRAL
},
1182 { 0x25b2, 0x25b3, SIC_NEUTRAL
},
1183 { 0x25b6, 0x25b7, SIC_NEUTRAL
},
1184 { 0x25bc, 0x25bd, SIC_NEUTRAL
},
1185 { 0x25c0, 0x25c1, SIC_NEUTRAL
},
1186 { 0x25c6, 0x25c8, SIC_NEUTRAL
},
1187 { 0x25cb, 0x25cb, SIC_NEUTRAL
},
1188 { 0x25ce, 0x25d1, SIC_NEUTRAL
},
1189 { 0x25e2, 0x25e5, SIC_NEUTRAL
},
1190 { 0x25ef, 0x25ef, SIC_NEUTRAL
},
1191 { 0x2605, 0x2606, SIC_NEUTRAL
},
1192 { 0x2609, 0x2609, SIC_NEUTRAL
},
1193 { 0x260e, 0x260f, SIC_NEUTRAL
},
1194 { 0x261c, 0x261c, SIC_NEUTRAL
},
1195 { 0x261e, 0x261e, SIC_NEUTRAL
},
1196 { 0x2640, 0x2640, SIC_NEUTRAL
},
1197 { 0x2642, 0x2642, SIC_NEUTRAL
},
1198 { 0x2660, 0x2661, SIC_NEUTRAL
},
1199 { 0x2663, 0x2665, SIC_NEUTRAL
},
1200 { 0x2667, 0x266a, SIC_NEUTRAL
},
1201 { 0x266c, 0x266d, SIC_NEUTRAL
},
1202 { 0x266f, 0x266f, SIC_NEUTRAL
},
1203 { 0x273d, 0x273d, SIC_NEUTRAL
},
1204 { 0x2e80, 0x312f, SIC_COMPLEX
},
1205 { 0x3190, 0x31bf, SIC_COMPLEX
},
1206 { 0x31f0, 0x31ff, SIC_COMPLEX
},
1207 { 0x3220, 0x325f, SIC_COMPLEX
},
1208 { 0x3280, 0xa4ff, SIC_COMPLEX
},
1209 { 0xd800, 0xdfff, SIC_COMPLEX
},
1210 { 0xe000, 0xf8ff, SIC_NEUTRAL
},
1211 { 0xf900, 0xfaff, SIC_COMPLEX
},
1212 { 0xfb13, 0xfb28, SIC_COMPLEX
},
1213 { 0xfb29, 0xfb29, SIC_NEUTRAL
},
1214 { 0xfb2a, 0xfb4f, SIC_COMPLEX
},
1215 { 0xfd3e, 0xfd3f, SIC_NEUTRAL
},
1216 { 0xfdd0, 0xfdef, SIC_COMPLEX
},
1217 { 0xfe20, 0xfe6f, SIC_COMPLEX
},
1218 { 0xfeff, 0xfeff, SIC_COMPLEX
},
1219 { 0xff01, 0xff5e, SIC_COMPLEX
},
1220 { 0xff61, 0xff9f, SIC_COMPLEX
},
1221 { 0xffe0, 0xffe6, SIC_COMPLEX
},
1222 { 0xffe8, 0xffee, SIC_COMPLEX
},
1223 { 0xfff9, 0xfffb, SIC_COMPLEX
},
1224 { 0xfffe, 0xfffe, SIC_COMPLEX
}
1227 /***********************************************************************
1228 * ScriptIsComplex (USP10.@)
1230 * Determine if a string is complex.
1233 * chars [I] Array of characters to test.
1234 * len [I] Length in characters.
1242 * Behaviour matches that of WinXP.
1244 HRESULT WINAPI
ScriptIsComplex(const WCHAR
*chars
, int len
, DWORD flag
)
1249 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars
, len
), len
, flag
);
1251 for (i
= 0; i
< len
; i
++)
1253 for (j
= 0; j
< sizeof(complex_ranges
)/sizeof(complex_ranges
[0]); j
++)
1255 if (chars
[i
] >= complex_ranges
[j
].start
&&
1256 chars
[i
] <= complex_ranges
[j
].end
&&
1257 (flag
& complex_ranges
[j
].flag
)) return S_OK
;
1263 /***********************************************************************
1264 * ScriptShape (USP10.@)
1266 * Produce glyphs and visual attributes for a run.
1269 * hdc [I] Device context.
1270 * psc [I/O] Opaque pointer to a script cache.
1271 * pwcChars [I] Array of characters specifying the run.
1272 * cChars [I] Number of characters in pwcChars.
1273 * cMaxGlyphs [I] Length of pwOutGlyphs.
1274 * psa [I/O] Script analysis.
1275 * pwOutGlyphs [O] Array of glyphs.
1276 * pwLogClust [O] Array of logical cluster info.
1277 * psva [O] Array of visual attributes.
1278 * pcGlyphs [O] Number of glyphs returned.
1282 * Failure: Non-zero HRESULT value.
1284 HRESULT WINAPI
ScriptShape(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcChars
,
1285 int cChars
, int cMaxGlyphs
,
1286 SCRIPT_ANALYSIS
*psa
, WORD
*pwOutGlyphs
, WORD
*pwLogClust
,
1287 SCRIPT_VISATTR
*psva
, int *pcGlyphs
)
1292 TRACE("(%p, %p, %s, %d, %d, %p, %p, %p, %p, %p)\n", hdc
, psc
, debugstr_wn(pwcChars
, cChars
),
1293 cChars
, cMaxGlyphs
, psa
, pwOutGlyphs
, pwLogClust
, psva
, pcGlyphs
);
1295 if (psa
) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa
->eScript
, psa
->fRTL
, psa
->fLayoutRTL
,
1296 psa
->fLinkBefore
, psa
->fLinkAfter
, psa
->fLogicalOrder
, psa
->fNoGlyphIndex
);
1298 if (!psva
|| !pcGlyphs
) return E_INVALIDARG
;
1299 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
1302 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
1303 if (!pwLogClust
) return E_FAIL
;
1305 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
) && !psa
->fNoGlyphIndex
)
1307 for (i
= 0; i
< cChars
; i
++)
1309 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, pwcChars
[i
])))
1312 if (!hdc
) return E_PENDING
;
1313 if (GetGlyphIndicesW(hdc
, &pwcChars
[i
], 1, &glyph
, GGI_MARK_NONEXISTING_GLYPHS
) == GDI_ERROR
) return S_FALSE
;
1314 pwOutGlyphs
[i
] = set_cache_glyph(psc
, pwcChars
[i
], glyph
);
1320 TRACE("no glyph translation\n");
1321 for (i
= 0; i
< cChars
; i
++) pwOutGlyphs
[i
] = pwcChars
[i
];
1324 /* set up a valid SCRIPT_VISATTR and LogClust for each char in this run */
1325 for (i
= 0; i
< cChars
; i
++)
1327 /* FIXME: set to better values */
1328 psva
[i
].uJustification
= (pwcChars
[i
] == ' ') ? SCRIPT_JUSTIFY_BLANK
: SCRIPT_JUSTIFY_CHARACTER
;
1329 psva
[i
].fClusterStart
= 1;
1330 psva
[i
].fDiacritic
= 0;
1331 psva
[i
].fZeroWidth
= 0;
1332 psva
[i
].fReserved
= 0;
1333 psva
[i
].fShapeReserved
= 0;
1340 /***********************************************************************
1341 * ScriptPlace (USP10.@)
1343 * Produce advance widths for a run.
1346 * hdc [I] Device context.
1347 * psc [I/O] Opaque pointer to a script cache.
1348 * pwGlyphs [I] Array of glyphs.
1349 * cGlyphs [I] Number of glyphs in pwGlyphs.
1350 * psva [I] Array of visual attributes.
1351 * psa [I/O] String analysis.
1352 * piAdvance [O] Array of advance widths.
1353 * pGoffset [O] Glyph offsets.
1354 * pABC [O] Combined ABC width.
1358 * Failure: Non-zero HRESULT value.
1360 HRESULT WINAPI
ScriptPlace(HDC hdc
, SCRIPT_CACHE
*psc
, const WORD
*pwGlyphs
,
1361 int cGlyphs
, const SCRIPT_VISATTR
*psva
,
1362 SCRIPT_ANALYSIS
*psa
, int *piAdvance
, GOFFSET
*pGoffset
, ABC
*pABC
)
1367 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc
, psc
, pwGlyphs
, cGlyphs
, psva
, psa
,
1368 piAdvance
, pGoffset
, pABC
);
1370 if (!psva
) return E_INVALIDARG
;
1371 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
1372 if (!pGoffset
) return E_FAIL
;
1374 if (pABC
) memset(pABC
, 0, sizeof(ABC
));
1375 for (i
= 0; i
< cGlyphs
; i
++)
1378 if (!get_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
))
1380 if (!hdc
) return E_PENDING
;
1381 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
) && !psa
->fNoGlyphIndex
)
1383 if (!GetCharABCWidthsI(hdc
, 0, 1, (WORD
*)&pwGlyphs
[i
], &abc
)) return S_FALSE
;
1388 if (!GetCharWidth32W(hdc
, pwGlyphs
[i
], pwGlyphs
[i
], &width
)) return S_FALSE
;
1390 abc
.abcA
= abc
.abcC
= 0;
1392 set_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
);
1396 pABC
->abcA
+= abc
.abcA
;
1397 pABC
->abcB
+= abc
.abcB
;
1398 pABC
->abcC
+= abc
.abcC
;
1400 /* FIXME: set to more reasonable values */
1401 pGoffset
[i
].du
= pGoffset
[i
].dv
= 0;
1402 if (piAdvance
) piAdvance
[i
] = abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
1405 if (pABC
) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC
->abcA
, pABC
->abcB
, pABC
->abcC
);
1409 /***********************************************************************
1410 * ScriptGetCMap (USP10.@)
1412 * Retrieve glyph indices.
1415 * hdc [I] Device context.
1416 * psc [I/O] Opaque pointer to a script cache.
1417 * pwcInChars [I] Array of Unicode characters.
1418 * cChars [I] Number of characters in pwcInChars.
1419 * dwFlags [I] Flags.
1420 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
1424 * Failure: Non-zero HRESULT value.
1426 HRESULT WINAPI
ScriptGetCMap(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcInChars
,
1427 int cChars
, DWORD dwFlags
, WORD
*pwOutGlyphs
)
1432 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc
, psc
, debugstr_wn(pwcInChars
, cChars
),
1433 cChars
, dwFlags
, pwOutGlyphs
);
1435 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
1437 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
1439 for (i
= 0; i
< cChars
; i
++)
1441 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, pwcInChars
[i
])))
1444 if (!hdc
) return E_PENDING
;
1445 if (GetGlyphIndicesW(hdc
, &pwcInChars
[i
], 1, &glyph
, GGI_MARK_NONEXISTING_GLYPHS
) == GDI_ERROR
) return S_FALSE
;
1446 pwOutGlyphs
[i
] = set_cache_glyph(psc
, pwcInChars
[i
], glyph
);
1452 TRACE("no glyph translation\n");
1453 for (i
= 0; i
< cChars
; i
++) pwOutGlyphs
[i
] = pwcInChars
[i
];
1458 /***********************************************************************
1459 * ScriptTextOut (USP10.@)
1462 HRESULT WINAPI
ScriptTextOut(const HDC hdc
, SCRIPT_CACHE
*psc
, int x
, int y
, UINT fuOptions
,
1463 const RECT
*lprc
, const SCRIPT_ANALYSIS
*psa
, const WCHAR
*pwcReserved
,
1464 int iReserved
, const WORD
*pwGlyphs
, int cGlyphs
, const int *piAdvance
,
1465 const int *piJustify
, const GOFFSET
*pGoffset
)
1469 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
1470 hdc
, psc
, x
, y
, fuOptions
, lprc
, psa
, pwcReserved
, iReserved
, pwGlyphs
, cGlyphs
,
1471 piAdvance
, piJustify
, pGoffset
);
1473 if (!hdc
|| !psc
) return E_INVALIDARG
;
1474 if (!piAdvance
|| !psa
|| !pwGlyphs
) return E_INVALIDARG
;
1476 fuOptions
&= ETO_CLIPPED
+ ETO_OPAQUE
;
1477 if (!psa
->fNoGlyphIndex
) /* Have Glyphs? */
1478 fuOptions
|= ETO_GLYPH_INDEX
; /* Say don't do translation to glyph */
1480 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, pwGlyphs
, cGlyphs
, NULL
))
1486 /***********************************************************************
1487 * ScriptCacheGetHeight (USP10.@)
1489 * Retrieve the height of the font in the cache.
1492 * hdc [I] Device context.
1493 * psc [I/O] Opaque pointer to a script cache.
1494 * height [O] Receives font height.
1498 * Failure: Non-zero HRESULT value.
1500 HRESULT WINAPI
ScriptCacheGetHeight(HDC hdc
, SCRIPT_CACHE
*psc
, LONG
*height
)
1504 TRACE("(%p, %p, %p)\n", hdc
, psc
, height
);
1506 if (!height
) return E_INVALIDARG
;
1507 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
1509 *height
= get_cache_height(psc
);
1513 /***********************************************************************
1514 * ScriptGetGlyphABCWidth (USP10.@)
1516 * Retrieve the width of a glyph.
1519 * hdc [I] Device context.
1520 * psc [I/O] Opaque pointer to a script cache.
1521 * glyph [I] Glyph to retrieve the width for.
1522 * abc [O] ABC widths of the glyph.
1526 * Failure: Non-zero HRESULT value.
1528 HRESULT WINAPI
ScriptGetGlyphABCWidth(HDC hdc
, SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
1532 TRACE("(%p, %p, 0x%04x, %p)\n", hdc
, psc
, glyph
, abc
);
1534 if (!abc
) return E_INVALIDARG
;
1535 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
1537 if (!get_cache_glyph_widths(psc
, glyph
, abc
))
1539 if (!hdc
) return E_PENDING
;
1540 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
1542 if (!GetCharABCWidthsI(hdc
, 0, 1, &glyph
, abc
)) return S_FALSE
;
1547 if (!GetCharWidth32W(hdc
, glyph
, glyph
, &width
)) return S_FALSE
;
1549 abc
->abcA
= abc
->abcC
= 0;
1551 set_cache_glyph_widths(psc
, glyph
, abc
);
1556 /***********************************************************************
1557 * ScriptLayout (USP10.@)
1559 * Map embedding levels to visual and/or logical order.
1562 * runs [I] Size of level array.
1563 * level [I] Array of embedding levels.
1564 * vistolog [O] Map of embedding levels from visual to logical order.
1565 * logtovis [O] Map of embedding levels from logical to visual order.
1569 * Failure: Non-zero HRESULT value.
1572 * This stub works correctly for any sequence of a single
1573 * embedding level but not for sequences of different
1574 * embedding levels, i.e. mixtures of RTL and LTR scripts.
1576 HRESULT WINAPI
ScriptLayout(int runs
, const BYTE
*level
, int *vistolog
, int *logtovis
)
1578 int i
, j
= runs
- 1, k
= 0;
1580 TRACE("(%d, %p, %p, %p)\n", runs
, level
, vistolog
, logtovis
);
1582 if (!level
|| (!vistolog
&& !logtovis
))
1583 return E_INVALIDARG
;
1585 for (i
= 0; i
< runs
; i
++)
1589 if (vistolog
) *vistolog
++ = j
;
1590 if (logtovis
) *logtovis
++ = j
;
1595 if (vistolog
) *vistolog
++ = k
;
1596 if (logtovis
) *logtovis
++ = k
;
1603 /***********************************************************************
1604 * ScriptStringGetLogicalWidths (USP10.@)
1606 * Returns logical widths from a string analysis.
1609 * ssa [I] string analysis.
1610 * piDx [O] logical widths returned.
1614 * Failure: a non-zero HRESULT.
1616 HRESULT WINAPI
ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa
, int *piDx
)
1619 StringAnalysis
*analysis
= ssa
;
1621 TRACE("%p, %p\n", ssa
, piDx
);
1623 if (!analysis
) return S_FALSE
;
1625 for (i
= 0; i
< analysis
->numItems
; i
++)
1627 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
1629 piDx
[next
] = analysis
->glyphs
[i
].piAdvance
[j
];
1636 /***********************************************************************
1637 * ScriptStringValidate (USP10.@)
1639 * Validate a string analysis.
1642 * ssa [I] string analysis.
1646 * Failure: S_FALSE if invalid sequences are found
1647 * or a non-zero HRESULT if it fails.
1649 HRESULT WINAPI
ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa
)
1651 StringAnalysis
*analysis
= ssa
;
1653 TRACE("(%p)\n", ssa
);
1655 if (!analysis
) return E_INVALIDARG
;
1656 return (analysis
->invalid
) ? S_FALSE
: S_OK
;
1659 /***********************************************************************
1660 * ScriptString_pSize (USP10.@)
1662 * Retrieve width and height of an analysed string.
1665 * ssa [I] string analysis.
1668 * Success: Pointer to a SIZE structure.
1671 const SIZE
* WINAPI
ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa
)
1674 StringAnalysis
*analysis
= ssa
;
1676 TRACE("(%p)\n", ssa
);
1678 if (!analysis
) return NULL
;
1682 if (!(analysis
->sz
= heap_alloc(sizeof(SIZE
)))) return NULL
;
1683 analysis
->sz
->cy
= analysis
->sc
->tm
.tmHeight
;
1685 analysis
->sz
->cx
= 0;
1686 for (i
= 0; i
< analysis
->numItems
; i
++)
1687 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
1688 analysis
->sz
->cx
+= analysis
->glyphs
[i
].piAdvance
[j
];
1690 return analysis
->sz
;
1693 /***********************************************************************
1694 * ScriptString_pLogAttr (USP10.@)
1696 * Retrieve logical attributes of an analysed string.
1699 * ssa [I] string analysis.
1702 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
1705 const SCRIPT_LOGATTR
* WINAPI
ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa
)
1707 StringAnalysis
*analysis
= ssa
;
1709 TRACE("(%p)\n", ssa
);
1711 if (!analysis
) return NULL
;
1712 return analysis
->logattrs
;
1715 /***********************************************************************
1716 * ScriptString_pcOutChars (USP10.@)
1718 * Retrieve the length of a string after clipping.
1721 * ssa [I] String analysis.
1724 * Success: Pointer to the length.
1727 const int * WINAPI
ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa
)
1729 StringAnalysis
*analysis
= ssa
;
1731 TRACE("(%p)\n", ssa
);
1733 if (!analysis
) return NULL
;
1734 return &analysis
->clip_len
;
1737 /***********************************************************************
1738 * ScriptStringGetOrder (USP10.@)
1740 * Retrieve a glyph order map.
1743 * ssa [I] String analysis.
1744 * order [I/O] Array of glyph positions.
1748 * Failure: a non-zero HRESULT.
1750 HRESULT WINAPI
ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa
, UINT
*order
)
1754 StringAnalysis
*analysis
= ssa
;
1756 TRACE("(%p)\n", ssa
);
1758 if (!analysis
) return S_FALSE
;
1760 /* FIXME: handle RTL scripts */
1761 for (i
= 0, k
= 0; i
< analysis
->numItems
; i
++)
1762 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++, k
++)
1768 /***********************************************************************
1769 * ScriptGetLogicalWidths (USP10.@)
1771 * Convert advance widths to logical widths.
1774 * sa [I] Script analysis.
1775 * nbchars [I] Number of characters.
1776 * nbglyphs [I] Number of glyphs.
1777 * glyph_width [I] Array of glyph widths.
1778 * log_clust [I] Array of logical clusters.
1779 * sva [I] Visual attributes.
1780 * widths [O] Array of logical widths.
1784 * Failure: a non-zero HRESULT.
1786 HRESULT WINAPI
ScriptGetLogicalWidths(const SCRIPT_ANALYSIS
*sa
, int nbchars
, int nbglyphs
,
1787 const int *glyph_width
, const WORD
*log_clust
,
1788 const SCRIPT_VISATTR
*sva
, int *widths
)
1792 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
1793 sa
, nbchars
, nbglyphs
, glyph_width
, log_clust
, sva
, widths
);
1796 for (i
= 0; i
< nbchars
; i
++) widths
[i
] = glyph_width
[i
];
1800 /***********************************************************************
1801 * ScriptApplyLogicalWidth (USP10.@)
1803 * Generate glyph advance widths.
1806 * dx [I] Array of logical advance widths.
1807 * num_chars [I] Number of characters.
1808 * num_glyphs [I] Number of glyphs.
1809 * log_clust [I] Array of logical clusters.
1810 * sva [I] Visual attributes.
1811 * advance [I] Array of glyph advance widths.
1812 * sa [I] Script analysis.
1813 * abc [I/O] Summed ABC widths.
1814 * justify [O] Array of glyph advance widths.
1818 * Failure: a non-zero HRESULT.
1820 HRESULT WINAPI
ScriptApplyLogicalWidth(const int *dx
, int num_chars
, int num_glyphs
,
1821 const WORD
*log_clust
, const SCRIPT_VISATTR
*sva
,
1822 const int *advance
, const SCRIPT_ANALYSIS
*sa
,
1823 ABC
*abc
, int *justify
)
1827 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
1828 dx
, num_chars
, num_glyphs
, log_clust
, sva
, advance
, sa
, abc
, justify
);
1830 for (i
= 0; i
< num_chars
; i
++) justify
[i
] = advance
[i
];
1834 HRESULT WINAPI
ScriptJustify(const SCRIPT_VISATTR
*sva
, const int *advance
,
1835 int num_glyphs
, int dx
, int min_kashida
, int *justify
)
1839 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva
, advance
, num_glyphs
, dx
, min_kashida
, justify
);
1841 for (i
= 0; i
< num_glyphs
; i
++) justify
[i
] = advance
[i
];