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"
39 * some documentation here:
40 * http://www.microsoft.com/typography/developers/uniscribe/uniscribe.htm
43 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe
);
45 static const SCRIPT_PROPERTIES props
[] =
47 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
48 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
49 { 0, 0, 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, 0, 0, 0 },
51 { 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
52 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
53 { 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
54 { 8, 0, 0, 0, 0, 161, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
55 { 25, 0, 0, 0, 0, 204, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
56 { 43, 0, 0, 0, 0, 0, 0, 0, 0, 0,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, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
119 { 9, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
120 { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
123 static const SCRIPT_PROPERTIES
*script_props
[] =
125 &props
[0], &props
[1], &props
[2], &props
[3],
126 &props
[4], &props
[5], &props
[6], &props
[7],
127 &props
[8], &props
[9], &props
[11], &props
[12],
128 &props
[13], &props
[14], &props
[15], &props
[16],
129 &props
[17], &props
[18], &props
[19], &props
[20],
130 &props
[21], &props
[22], &props
[23], &props
[24],
131 &props
[25], &props
[26], &props
[27], &props
[28],
132 &props
[29], &props
[30], &props
[31], &props
[32],
133 &props
[33], &props
[34], &props
[35], &props
[36],
134 &props
[37], &props
[38], &props
[39], &props
[40],
135 &props
[41], &props
[42], &props
[43], &props
[44],
136 &props
[45], &props
[46], &props
[47], &props
[48],
137 &props
[49], &props
[50], &props
[51], &props
[52],
138 &props
[53], &props
[54], &props
[55], &props
[56],
139 &props
[57], &props
[58], &props
[59], &props
[60],
140 &props
[61], &props
[62], &props
[63], &props
[64],
141 &props
[65], &props
[66], &props
[67], &props
[68],
142 &props
[69], &props
[70], &props
[71], &props
[72],
155 SCRIPT_VISATTR
* psva
;
167 StringGlyphs
* glyphs
;
168 SCRIPT_LOGATTR
* logattrs
;
172 static HRESULT
get_script_cache(const HDC hdc
, SCRIPT_CACHE
*psc
)
174 if (!psc
) return E_INVALIDARG
;
177 if (!hdc
) return E_PENDING
;
178 if (!(*psc
= HeapAlloc(GetProcessHeap(), 0, sizeof(ScriptCache
))))
179 return E_OUTOFMEMORY
;
180 ((ScriptCache
*)*psc
)->hdc
= hdc
;
185 /***********************************************************************
189 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
192 case DLL_PROCESS_ATTACH
:
193 DisableThreadLibraryCalls(hInstDLL
);
195 case DLL_PROCESS_DETACH
:
201 /***********************************************************************
202 * ScriptFreeCache (USP10.@)
204 * Free a script cache.
207 * psc [I/O] Script cache.
211 * Failure: Non-zero HRESULT value.
213 HRESULT WINAPI
ScriptFreeCache(SCRIPT_CACHE
*psc
)
219 HeapFree(GetProcessHeap(), 0, *psc
);
225 /***********************************************************************
226 * ScriptGetProperties (USP10.@)
228 * Retrieve a list of script properties.
231 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
232 * num [I] Pointer to the number of scripts.
236 * Failure: Non-zero HRESULT value.
239 * Behaviour matches WinXP.
241 HRESULT WINAPI
ScriptGetProperties(const SCRIPT_PROPERTIES
***props
, int *num
)
243 TRACE("(%p,%p)\n", props
, num
);
245 if (!props
&& !num
) return E_INVALIDARG
;
247 if (num
) *num
= sizeof(script_props
)/sizeof(script_props
[0]);
248 if (props
) *props
= script_props
;
253 /***********************************************************************
254 * ScriptGetFontProperties (USP10.@)
256 * Get information on special glyphs.
259 * hdc [I] Device context.
260 * psc [I/O] Opaque pointer to a script cache.
261 * sfp [O] Font properties structure.
263 HRESULT WINAPI
ScriptGetFontProperties(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_FONTPROPERTIES
*sfp
)
268 TRACE("%p,%p,%p\n", hdc
, psc
, sfp
);
270 if (!sfp
) return E_INVALIDARG
;
271 if ((hr
= get_script_cache(hdc
, psc
))) return hr
;
273 if (sfp
->cBytes
!= sizeof(SCRIPT_FONTPROPERTIES
))
276 /* return something sensible? */
278 if (GetTextMetricsW(((ScriptCache
*)*psc
)->hdc
, &ptm
))
279 sfp
->wgDefault
= ptm
.tmDefaultChar
;
283 sfp
->wgKashida
= 0xffff;
284 sfp
->iKashidaWidth
= 0;
289 /***********************************************************************
290 * ScriptRecordDigitSubstitution (USP10.@)
292 * Record digit substitution settings for a given locale.
295 * locale [I] Locale identifier.
296 * sds [I] Structure to record substitution settings.
300 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
303 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
305 HRESULT WINAPI
ScriptRecordDigitSubstitution(LCID locale
, SCRIPT_DIGITSUBSTITUTE
*sds
)
309 TRACE("0x%x, %p\n", locale
, sds
);
311 /* This implementation appears to be correct for all languages, but it's
312 * not clear if sds->DigitSubstitute is ever set to anything except
313 * CONTEXT or NONE in reality */
315 if (!sds
) return E_POINTER
;
317 locale
= ConvertDefaultLocale(locale
);
319 if (!IsValidLocale(locale
, LCID_INSTALLED
))
322 plgid
= PRIMARYLANGID(LANGIDFROMLCID(locale
));
323 sds
->TraditionalDigitLanguage
= plgid
;
325 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
326 sds
->NationalDigitLanguage
= plgid
;
328 sds
->NationalDigitLanguage
= LANG_ENGLISH
;
330 if (!GetLocaleInfoW(locale
, LOCALE_IDIGITSUBSTITUTION
| LOCALE_RETURN_NUMBER
,
331 (LPWSTR
)&sub
, sizeof(sub
)/sizeof(WCHAR
))) return E_INVALIDARG
;
336 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
337 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_CONTEXT
;
339 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
342 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
345 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NATIONAL
;
348 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
;
356 /***********************************************************************
357 * ScriptApplyDigitSubstitution (USP10.@)
359 * Apply digit substitution settings.
362 * sds [I] Structure with recorded substitution settings.
363 * sc [I] Script control structure.
364 * ss [I] Script state structure.
368 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
370 HRESULT WINAPI
ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE
*sds
,
371 SCRIPT_CONTROL
*sc
, SCRIPT_STATE
*ss
)
373 SCRIPT_DIGITSUBSTITUTE psds
;
375 TRACE("%p, %p, %p\n", sds
, sc
, ss
);
377 if (!sc
|| !ss
) return E_POINTER
;
381 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT
, &psds
) != S_OK
)
385 sc
->uDefaultLanguage
= LANG_ENGLISH
;
386 sc
->fContextDigits
= 0;
387 ss
->fDigitSubstitute
= 0;
389 switch (sds
->DigitSubstitute
) {
390 case SCRIPT_DIGITSUBSTITUTE_CONTEXT
:
391 case SCRIPT_DIGITSUBSTITUTE_NATIONAL
:
392 case SCRIPT_DIGITSUBSTITUTE_NONE
:
393 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
:
400 /***********************************************************************
401 * ScriptItemize (USP10.@)
404 HRESULT WINAPI
ScriptItemize(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
405 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
406 SCRIPT_ITEM
*pItems
, int *pcItems
)
409 #define Numeric_start 0x0030
410 #define Numeric_stop 0x0039
411 #define Numeric_space 0x0020
412 #define Arabic_start 0x0600
413 #define Arabic_stop 0x06ff
414 #define Latin_start 0x0001
415 #define Latin_stop 0x024f
416 #define Script_Arabic 6
417 #define Script_Latin 1
418 #define Script_Numeric 5
420 int cnt
= 0, index
= 0;
421 int New_Script
= SCRIPT_UNDEFINED
;
423 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars
, cInChars
), cInChars
, cMaxItems
,
424 psControl
, psState
, pItems
, pcItems
);
426 if (!pwcInChars
|| !cInChars
|| !pItems
|| cMaxItems
< 2)
429 pItems
[index
].iCharPos
= 0;
430 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
432 if (pwcInChars
[cnt
] >= Numeric_start
&& pwcInChars
[cnt
] <= Numeric_stop
)
433 pItems
[index
].a
.eScript
= Script_Numeric
;
435 if (pwcInChars
[cnt
] >= Arabic_start
&& pwcInChars
[cnt
] <= Arabic_stop
)
436 pItems
[index
].a
.eScript
= Script_Arabic
;
438 if (pwcInChars
[cnt
] >= Latin_start
&& pwcInChars
[cnt
] <= Latin_stop
)
439 pItems
[index
].a
.eScript
= Script_Latin
;
441 if (pItems
[index
].a
.eScript
== Script_Arabic
)
442 pItems
[index
].a
.s
.uBidiLevel
= 1;
444 TRACE("New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
445 New_Script
, pItems
[index
].a
.eScript
, index
, cnt
,
446 pItems
[index
].iCharPos
= cnt
);
448 for (cnt
=0; cnt
< cInChars
; cnt
++)
450 if ((pwcInChars
[cnt
] >= Numeric_start
&& pwcInChars
[cnt
] <= Numeric_stop
)
451 || (New_Script
== Script_Numeric
&& pwcInChars
[cnt
] == Numeric_space
))
452 New_Script
= Script_Numeric
;
454 if ((pwcInChars
[cnt
] >= Arabic_start
&& pwcInChars
[cnt
] <= Arabic_stop
)
455 || (New_Script
== Script_Arabic
&& pwcInChars
[cnt
] == Numeric_space
))
456 New_Script
= Script_Arabic
;
458 if ((WCHAR
) pwcInChars
[cnt
] >= Latin_start
&& (WCHAR
) pwcInChars
[cnt
] <= Latin_stop
)
459 New_Script
= Script_Latin
;
461 New_Script
= SCRIPT_UNDEFINED
;
463 if (New_Script
!= pItems
[index
].a
.eScript
)
465 TRACE("New_Script=%d, eScript=%d ", New_Script
, pItems
[index
].a
.eScript
);
467 if (index
+1 > cMaxItems
)
468 return E_OUTOFMEMORY
;
470 pItems
[index
].iCharPos
= cnt
;
471 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
473 if (New_Script
== Script_Arabic
)
474 pItems
[index
].a
.s
.uBidiLevel
= 1;
476 pItems
[index
].a
.eScript
= New_Script
;
477 if (New_Script
== Script_Arabic
)
478 pItems
[index
].a
.s
.uBidiLevel
= 1;
480 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
= cnt
);
484 /* While not strictly necessary according to the spec, make sure the n+1
485 * item is set up to prevent random behaviour if the caller erroneously
486 * checks the n+1 structure */
487 memset(&pItems
[index
+1].a
, 0, sizeof(SCRIPT_ANALYSIS
));
489 TRACE("index=%d cnt=%d iCharPos=%d\n", index
+1, cnt
, pItems
[index
+1].iCharPos
= cnt
);
491 /* Set one SCRIPT_STATE item being returned */
492 *pcItems
= index
+ 1;
494 /* Set SCRIPT_ITEM */
495 pItems
[index
+1].iCharPos
= cnt
; /* the last + 1 item
496 contains the ptr to the lastchar */
500 /***********************************************************************
501 * ScriptStringAnalyse (USP10.@)
504 HRESULT WINAPI
ScriptStringAnalyse(HDC hdc
,
511 SCRIPT_CONTROL
*psControl
,
512 SCRIPT_STATE
*psState
,
514 SCRIPT_TABDEF
*pTabdef
,
515 const BYTE
*pbInClass
,
516 SCRIPT_STRING_ANALYSIS
*pssa
)
519 StringAnalysis
* analysis
;
520 int numItemizedItems
;
522 SCRIPT_CACHE
* sc
= 0;
524 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
525 hdc
, pString
, cString
, cGlyphs
, iCharset
, dwFlags
,
526 iReqWidth
, psControl
, psState
, piDx
, pTabdef
, pbInClass
, pssa
);
528 if (cString
< 1 || !pString
)
531 if ((dwFlags
& SSA_GLYPHS
) && !hdc
)
534 analysis
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
535 sizeof(StringAnalysis
));
538 numItemizedItems
= 255;
539 analysis
->pItem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
540 numItemizedItems
*sizeof(SCRIPT_ITEM
)+1);
542 hr
= ScriptItemize(pString
, cString
, numItemizedItems
, psControl
,
543 psState
, analysis
->pItem
, &analysis
->numItems
);
545 while(hr
== E_OUTOFMEMORY
)
547 numItemizedItems
*= 2;
548 HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, analysis
->pItem
,
549 numItemizedItems
*sizeof(SCRIPT_ITEM
)+1);
550 hr
= ScriptItemize(pString
, cString
, numItemizedItems
, psControl
,
551 psState
, analysis
->pItem
, &analysis
->numItems
);
554 if ((analysis
->logattrs
= HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_LOGATTR
) * cString
)))
555 ScriptBreak(pString
, cString
, (SCRIPT_STRING_ANALYSIS
)analysis
, analysis
->logattrs
);
557 analysis
->glyphs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
558 sizeof(StringGlyphs
)*analysis
->numItems
);
559 sc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SCRIPT_CACHE
));
561 for(i
=0; i
<analysis
->numItems
; i
++)
563 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
564 int numGlyphs
= 1.5 * cChar
+ 16;
565 WORD
* glyphs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WORD
)*numGlyphs
);
566 WORD
* pwLogClust
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WORD
)*cChar
);
567 int* piAdvance
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(int)*numGlyphs
);
568 SCRIPT_VISATTR
* psva
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SCRIPT_VISATTR
)*cChar
);
569 GOFFSET
* pGoffset
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(GOFFSET
)*numGlyphs
);
570 ABC
* abc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ABC
));
571 int numGlyphsReturned
;
573 /* FIXME: non unicode strings */
574 WCHAR
* pStr
= (WCHAR
*)pString
;
575 hr
= ScriptShape(hdc
, sc
, &pStr
[analysis
->pItem
[i
].iCharPos
],
576 cChar
, numGlyphs
, &analysis
->pItem
[i
].a
,
577 glyphs
, pwLogClust
, psva
, &numGlyphsReturned
);
578 hr
= ScriptPlace(hdc
, sc
, glyphs
, numGlyphsReturned
, psva
, &analysis
->pItem
[i
].a
,
579 piAdvance
, pGoffset
, abc
);
581 analysis
->glyphs
[i
].numGlyphs
= numGlyphsReturned
;
582 analysis
->glyphs
[i
].glyphs
= glyphs
;
583 analysis
->glyphs
[i
].pwLogClust
= pwLogClust
;
584 analysis
->glyphs
[i
].piAdvance
= piAdvance
;
585 analysis
->glyphs
[i
].psva
= psva
;
586 analysis
->glyphs
[i
].pGoffset
= pGoffset
;
587 analysis
->glyphs
[i
].abc
= abc
;
590 HeapFree(GetProcessHeap(), 0, sc
);
597 /***********************************************************************
598 * ScriptStringOut (USP10.@)
600 * This function takes the output of ScriptStringAnalyse and joins the segments
601 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
602 * only processes glyphs.
605 * ssa [I] buffer to hold the analysed string components
606 * iX [I] X axis displacement for output
607 * iY [I] Y axis displacement for output
608 * uOptions [I] flags controling output processing
609 * prc [I] rectangle coordinates
610 * iMinSel [I] starting pos for substringing output string
611 * iMaxSel [I] ending pos for substringing output string
612 * fDisabled [I] controls text highlighting
616 * Failure: is the value returned by ScriptTextOut
618 HRESULT WINAPI
ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa
,
627 StringAnalysis
*analysis
;
633 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
634 ssa
, iX
, iY
, uOptions
, prc
, iMinSel
, iMaxSel
, fDisabled
);
636 analysis
= ssa
; /* map ptr to string_analysis struct */
639 * Get storage for the output buffer for the consolidated strings
642 for(item
= 0; item
< analysis
->numItems
; item
++)
644 cnt
+= analysis
->glyphs
[item
].numGlyphs
;
646 glyphs
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
) * cnt
);
649 * ScriptStringOut only processes glyphs hence set ETO_GLYPH_INDEX
651 uOptions
|= ETO_GLYPH_INDEX
;
652 analysis
->pItem
[0].a
.fNoGlyphIndex
= FALSE
; /* say that we have glyphs */
655 * Copy the string items into the output buffer
658 TRACE("numItems %d\n", analysis
->numItems
);
661 for (item
= 0; item
< analysis
->numItems
; item
++)
663 memcpy(&glyphs
[cnt
], analysis
->glyphs
[item
].glyphs
,
664 sizeof(WCHAR
) * analysis
->glyphs
[item
].numGlyphs
);
666 TRACE("Item %d, Glyphs %d ", item
, analysis
->glyphs
[item
].numGlyphs
);
667 for (x
= cnt
; x
< analysis
->glyphs
[item
].numGlyphs
+ cnt
; x
++)
668 TRACE("%04x", glyphs
[x
]);
671 cnt
+= analysis
->glyphs
[item
].numGlyphs
; /* point to the end of the copied text */
674 hr
= ScriptTextOut(analysis
->hdc
, &sc
, iX
, iY
, uOptions
, prc
, &analysis
->pItem
->a
,
675 NULL
, 0, glyphs
, cnt
, analysis
->glyphs
->piAdvance
, NULL
,
676 analysis
->glyphs
->pGoffset
);
677 TRACE("ScriptTextOut hr=%08x\n", hr
);
680 * Free the output buffer and script cache
682 HeapFree(GetProcessHeap(), 0, glyphs
);
683 ScriptFreeCache(&sc
);
688 /***********************************************************************
689 * ScriptStringCPtoX (USP10.@)
692 HRESULT WINAPI
ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa
, int icp
, BOOL fTrailing
, int* pX
)
697 StringAnalysis
* analysis
= ssa
;
698 TRACE("(%p), %d, %d, (%p)\n", ssa
, icp
, fTrailing
, pX
);
705 /* icp out of range */
708 analysis
->invalid
= TRUE
;
712 for(i
=0; i
<analysis
->numItems
; i
++)
714 for(j
=0; j
<analysis
->glyphs
[i
].numGlyphs
; j
++)
716 if(runningCp
== icp
&& fTrailing
== FALSE
)
721 runningX
+= analysis
->glyphs
[i
].piAdvance
[j
];
722 if(runningCp
== icp
&& fTrailing
== TRUE
)
731 /* icp out of range */
732 analysis
->invalid
= TRUE
;
736 /***********************************************************************
737 * ScriptStringXtoCP (USP10.@)
740 HRESULT WINAPI
ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa
, int iX
, int* piCh
, int* piTrailing
)
742 StringAnalysis
* analysis
= ssa
;
749 TRACE("(%p), %d, (%p), (%p)\n", ssa
, iX
, piCh
, piTrailing
);
751 if(!ssa
|| !piCh
|| !piTrailing
)
764 for(i
=0; i
<analysis
->numItems
; i
++)
766 for(j
=0; j
<analysis
->glyphs
[i
].numGlyphs
; j
++)
768 width
= analysis
->glyphs
[i
].piAdvance
[j
];
769 if(iX
< (runningX
+ width
))
772 if((iX
- runningX
) > width
/2)
784 *piCh
= analysis
->pItem
[analysis
->numItems
].iCharPos
;
791 /***********************************************************************
792 * ScriptStringFree (USP10.@)
794 * Free a string analysis.
797 * pssa [I] string analysis.
801 * Failure: Non-zero HRESULT value.
803 HRESULT WINAPI
ScriptStringFree(SCRIPT_STRING_ANALYSIS
*pssa
)
805 StringAnalysis
* analysis
;
809 TRACE("(%p)\n",pssa
);
818 invalid
= analysis
->invalid
;
820 for(i
=0; i
<analysis
->numItems
; i
++)
822 HeapFree(GetProcessHeap(), 0, analysis
->glyphs
[i
].glyphs
);
823 HeapFree(GetProcessHeap(), 0, analysis
->glyphs
[i
].pwLogClust
);
824 HeapFree(GetProcessHeap(), 0, analysis
->glyphs
[i
].piAdvance
);
825 HeapFree(GetProcessHeap(), 0, analysis
->glyphs
[i
].psva
);
826 HeapFree(GetProcessHeap(), 0, analysis
->glyphs
[i
].pGoffset
);
827 HeapFree(GetProcessHeap(), 0, analysis
->glyphs
[i
].abc
);
830 HeapFree(GetProcessHeap(), 0, analysis
->glyphs
);
831 HeapFree(GetProcessHeap(), 0, analysis
->pItem
);
832 HeapFree(GetProcessHeap(), 0, analysis
->logattrs
);
833 HeapFree(GetProcessHeap(), 0, analysis
->sz
);
834 HeapFree(GetProcessHeap(), 0, analysis
);
842 /***********************************************************************
843 * ScriptCPtoX (USP10.@)
846 HRESULT WINAPI
ScriptCPtoX(int iCP
,
850 const WORD
*pwLogClust
,
851 const SCRIPT_VISATTR
*psva
,
852 const int *piAdvance
,
853 const SCRIPT_ANALYSIS
*psa
,
859 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
860 iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
862 for (item
=0; item
< cGlyphs
; item
++) /* total piAdvance */
863 fMaxPosX
+= piAdvance
[item
];
864 iPosX
= (fMaxPosX
/cGlyphs
)*(iCP
+fTrailing
);
865 if (iPosX
> fMaxPosX
)
867 *piX
= iPosX
; /* Return something in range */
869 TRACE("*piX=%d\n", *piX
);
873 /***********************************************************************
874 * ScriptXtoCP (USP10.@)
877 HRESULT WINAPI
ScriptXtoCP(int iX
,
880 const WORD
*pwLogClust
,
881 const SCRIPT_VISATTR
*psva
,
882 const int *piAdvance
,
883 const SCRIPT_ANALYSIS
*psa
,
891 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
892 iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
893 psa
, piCP
, piTrailing
);
894 if (iX
< 0) /* iX is before start of run */
901 for (item
=0; item
< cGlyphs
; item
++) /* total piAdvance */
902 fMaxPosX
+= piAdvance
[item
];
904 if (iX
>= fMaxPosX
) /* iX too large */
911 fAvePosX
= fMaxPosX
/ cGlyphs
;
913 for (item
= 1; item
< cGlyphs
&& iPosX
< iX
; item
++)
915 if (iPosX
- iX
> fAvePosX
/2)
918 *piTrailing
= 1; /* yep we are over halfway */
920 *piCP
= item
-1; /* Return character position */
921 TRACE("*piCP=%d iPposX=%d\n", *piCP
, iPosX
);
925 /***********************************************************************
926 * ScriptBreak (USP10.@)
928 * Retrieve line break information.
931 * chars [I] Array of characters.
932 * sa [I] String analysis.
933 * la [I] Array of logical attribute structures.
939 HRESULT WINAPI
ScriptBreak(const WCHAR
*chars
, int count
, const SCRIPT_ANALYSIS
*sa
, SCRIPT_LOGATTR
*la
)
943 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars
, count
), count
, sa
, la
);
945 if (!la
) return S_FALSE
;
947 for (i
= 0; i
< count
; i
++)
949 memset(&la
[i
], 0, sizeof(SCRIPT_LOGATTR
));
951 /* FIXME: set the other flags */
952 la
[i
].fWhiteSpace
= isspaceW(chars
[i
]);
966 { 0, 0x0b, SIC_COMPLEX
},
967 { 0x0c, 0x0c, SIC_NEUTRAL
},
968 { 0x0d, 0x1f, SIC_COMPLEX
},
969 { 0x20, 0x2f, SIC_NEUTRAL
},
970 { 0x30, 0x39, SIC_ASCIIDIGIT
},
971 { 0x3a, 0x40, SIC_NEUTRAL
},
972 { 0x5b, 0x60, SIC_NEUTRAL
},
973 { 0x7b, 0x7e, SIC_NEUTRAL
},
974 { 0x7f, 0x9f, SIC_COMPLEX
},
975 { 0xa0, 0xa5, SIC_NEUTRAL
},
976 { 0xa7, 0xa8, SIC_NEUTRAL
},
977 { 0xab, 0xab, SIC_NEUTRAL
},
978 { 0xad, 0xad, SIC_NEUTRAL
},
979 { 0xaf, 0xaf, SIC_NEUTRAL
},
980 { 0xb0, 0xb1, SIC_NEUTRAL
},
981 { 0xb4, 0xb4, SIC_NEUTRAL
},
982 { 0xb6, 0xb8, SIC_NEUTRAL
},
983 { 0xbb, 0xbf, SIC_NEUTRAL
},
984 { 0xd7, 0xd7, SIC_NEUTRAL
},
985 { 0xf7, 0xf7, SIC_NEUTRAL
},
986 { 0x2b9, 0x2ba, SIC_NEUTRAL
},
987 { 0x2c2, 0x2cf, SIC_NEUTRAL
},
988 { 0x2d2, 0x2df, SIC_NEUTRAL
},
989 { 0x2e5, 0x2e9, SIC_COMPLEX
},
990 { 0x2ea, 0x2ed, SIC_NEUTRAL
},
991 { 0x300, 0x362, SIC_COMPLEX
},
992 { 0x530, 0x60b, SIC_COMPLEX
},
993 { 0x60c, 0x60d, SIC_NEUTRAL
},
994 { 0x60e, 0x669, SIC_COMPLEX
},
995 { 0x66a, 0x66a, SIC_NEUTRAL
},
996 { 0x66b, 0x6e8, SIC_COMPLEX
},
997 { 0x6e9, 0x6e9, SIC_NEUTRAL
},
998 { 0x6ea, 0x7bf, SIC_COMPLEX
},
999 { 0x900, 0x1360, SIC_COMPLEX
},
1000 { 0x137d, 0x137f, SIC_COMPLEX
},
1001 { 0x1680, 0x1680, SIC_NEUTRAL
},
1002 { 0x1780, 0x18af, SIC_COMPLEX
},
1003 { 0x2000, 0x200a, SIC_NEUTRAL
},
1004 { 0x200b, 0x200f, SIC_COMPLEX
},
1005 { 0x2010, 0x2016, SIC_NEUTRAL
},
1006 { 0x2018, 0x2022, SIC_NEUTRAL
},
1007 { 0x2024, 0x2028, SIC_NEUTRAL
},
1008 { 0x2029, 0x202e, SIC_COMPLEX
},
1009 { 0x202f, 0x2037, SIC_NEUTRAL
},
1010 { 0x2039, 0x203c, SIC_NEUTRAL
},
1011 { 0x2044, 0x2046, SIC_NEUTRAL
},
1012 { 0x206a, 0x206f, SIC_COMPLEX
},
1013 { 0x207a, 0x207e, SIC_NEUTRAL
},
1014 { 0x208a, 0x20aa, SIC_NEUTRAL
},
1015 { 0x20ac, 0x20cf, SIC_NEUTRAL
},
1016 { 0x20d0, 0x20ff, SIC_COMPLEX
},
1017 { 0x2103, 0x2103, SIC_NEUTRAL
},
1018 { 0x2105, 0x2105, SIC_NEUTRAL
},
1019 { 0x2109, 0x2109, SIC_NEUTRAL
},
1020 { 0x2116, 0x2116, SIC_NEUTRAL
},
1021 { 0x2121, 0x2122, SIC_NEUTRAL
},
1022 { 0x212e, 0x212e, SIC_NEUTRAL
},
1023 { 0x2153, 0x2154, SIC_NEUTRAL
},
1024 { 0x215b, 0x215e, SIC_NEUTRAL
},
1025 { 0x2190, 0x2199, SIC_NEUTRAL
},
1026 { 0x21b8, 0x21b9, SIC_NEUTRAL
},
1027 { 0x21d2, 0x21d2, SIC_NEUTRAL
},
1028 { 0x21d4, 0x21d4, SIC_NEUTRAL
},
1029 { 0x21e7, 0x21e7, SIC_NEUTRAL
},
1030 { 0x2200, 0x2200, SIC_NEUTRAL
},
1031 { 0x2202, 0x2203, SIC_NEUTRAL
},
1032 { 0x2207, 0x2208, SIC_NEUTRAL
},
1033 { 0x220b, 0x220b, SIC_NEUTRAL
},
1034 { 0x220f, 0x220f, SIC_NEUTRAL
},
1035 { 0x2211, 0x2213, SIC_NEUTRAL
},
1036 { 0x2215, 0x2215, SIC_NEUTRAL
},
1037 { 0x221a, 0x221a, SIC_NEUTRAL
},
1038 { 0x221d, 0x2220, SIC_NEUTRAL
},
1039 { 0x2223, 0x2223, SIC_NEUTRAL
},
1040 { 0x2225, 0x2225, SIC_NEUTRAL
},
1041 { 0x2227, 0x222c, SIC_NEUTRAL
},
1042 { 0x222e, 0x222e, SIC_NEUTRAL
},
1043 { 0x2234, 0x2237, SIC_NEUTRAL
},
1044 { 0x223c, 0x223d, SIC_NEUTRAL
},
1045 { 0x2248, 0x2248, SIC_NEUTRAL
},
1046 { 0x224c, 0x224c, SIC_NEUTRAL
},
1047 { 0x2252, 0x2252, SIC_NEUTRAL
},
1048 { 0x2260, 0x2261, SIC_NEUTRAL
},
1049 { 0x2264, 0x2267, SIC_NEUTRAL
},
1050 { 0x226a, 0x226b, SIC_NEUTRAL
},
1051 { 0x226e, 0x226f, SIC_NEUTRAL
},
1052 { 0x2282, 0x2283, SIC_NEUTRAL
},
1053 { 0x2286, 0x2287, SIC_NEUTRAL
},
1054 { 0x2295, 0x2295, SIC_NEUTRAL
},
1055 { 0x2299, 0x2299, SIC_NEUTRAL
},
1056 { 0x22a5, 0x22a5, SIC_NEUTRAL
},
1057 { 0x22bf, 0x22bf, SIC_NEUTRAL
},
1058 { 0x2312, 0x2312, SIC_NEUTRAL
},
1059 { 0x24ea, 0x24ea, SIC_COMPLEX
},
1060 { 0x2500, 0x254b, SIC_NEUTRAL
},
1061 { 0x2550, 0x256d, SIC_NEUTRAL
},
1062 { 0x256e, 0x2574, SIC_NEUTRAL
},
1063 { 0x2581, 0x258f, SIC_NEUTRAL
},
1064 { 0x2592, 0x2595, SIC_NEUTRAL
},
1065 { 0x25a0, 0x25a1, SIC_NEUTRAL
},
1066 { 0x25a3, 0x25a9, SIC_NEUTRAL
},
1067 { 0x25b2, 0x25b3, SIC_NEUTRAL
},
1068 { 0x25b6, 0x25b7, SIC_NEUTRAL
},
1069 { 0x25bc, 0x25bd, SIC_NEUTRAL
},
1070 { 0x25c0, 0x25c1, SIC_NEUTRAL
},
1071 { 0x25c6, 0x25c8, SIC_NEUTRAL
},
1072 { 0x25cb, 0x25cb, SIC_NEUTRAL
},
1073 { 0x25ce, 0x25d1, SIC_NEUTRAL
},
1074 { 0x25e2, 0x25e5, SIC_NEUTRAL
},
1075 { 0x25ef, 0x25ef, SIC_NEUTRAL
},
1076 { 0x2605, 0x2606, SIC_NEUTRAL
},
1077 { 0x2609, 0x2609, SIC_NEUTRAL
},
1078 { 0x260e, 0x260f, SIC_NEUTRAL
},
1079 { 0x261c, 0x261c, SIC_NEUTRAL
},
1080 { 0x261e, 0x261e, SIC_NEUTRAL
},
1081 { 0x2640, 0x2640, SIC_NEUTRAL
},
1082 { 0x2642, 0x2642, SIC_NEUTRAL
},
1083 { 0x2660, 0x2661, SIC_NEUTRAL
},
1084 { 0x2663, 0x2665, SIC_NEUTRAL
},
1085 { 0x2667, 0x266a, SIC_NEUTRAL
},
1086 { 0x266c, 0x266d, SIC_NEUTRAL
},
1087 { 0x266f, 0x266f, SIC_NEUTRAL
},
1088 { 0x273d, 0x273d, SIC_NEUTRAL
},
1089 { 0x2e80, 0x312f, SIC_COMPLEX
},
1090 { 0x3190, 0x31bf, SIC_COMPLEX
},
1091 { 0x31f0, 0x31ff, SIC_COMPLEX
},
1092 { 0x3220, 0x325f, SIC_COMPLEX
},
1093 { 0x3280, 0xa4ff, SIC_COMPLEX
},
1094 { 0xd800, 0xdfff, SIC_COMPLEX
},
1095 { 0xe000, 0xf8ff, SIC_NEUTRAL
},
1096 { 0xf900, 0xfaff, SIC_COMPLEX
},
1097 { 0xfb13, 0xfb28, SIC_COMPLEX
},
1098 { 0xfb29, 0xfb29, SIC_NEUTRAL
},
1099 { 0xfb2a, 0xfb4f, SIC_COMPLEX
},
1100 { 0xfd3e, 0xfd3f, SIC_NEUTRAL
},
1101 { 0xfdd0, 0xfdef, SIC_COMPLEX
},
1102 { 0xfe20, 0xfe6f, SIC_COMPLEX
},
1103 { 0xfeff, 0xfeff, SIC_COMPLEX
},
1104 { 0xff01, 0xff5e, SIC_COMPLEX
},
1105 { 0xff61, 0xff9f, SIC_COMPLEX
},
1106 { 0xffe0, 0xffe6, SIC_COMPLEX
},
1107 { 0xffe8, 0xffee, SIC_COMPLEX
},
1108 { 0xfff9, 0xfffb, SIC_COMPLEX
},
1109 { 0xfffe, 0xfffe, SIC_COMPLEX
}
1112 /***********************************************************************
1113 * ScriptIsComplex (USP10.@)
1115 * Determine if a string is complex.
1118 * chars [I] Array of characters to test.
1119 * len [I] Length in characters.
1127 * Behaviour matches that of WinXP.
1129 HRESULT WINAPI
ScriptIsComplex(const WCHAR
*chars
, int len
, DWORD flag
)
1133 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars
, len
), len
, flag
);
1135 for (i
= 0; i
< len
; i
++)
1137 for (j
= 0; j
< sizeof(complex_ranges
)/sizeof(complex_ranges
[0]); j
++)
1139 if (chars
[i
] >= complex_ranges
[j
].start
&&
1140 chars
[i
] <= complex_ranges
[j
].end
&&
1141 (flag
& complex_ranges
[j
].flag
)) return S_OK
;
1147 /***********************************************************************
1148 * ScriptShape (USP10.@)
1151 HRESULT WINAPI
ScriptShape(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcChars
,
1152 int cChars
, int cMaxGlyphs
,
1153 SCRIPT_ANALYSIS
*psa
, WORD
*pwOutGlyphs
, WORD
*pwLogClust
,
1154 SCRIPT_VISATTR
*psva
, int *pcGlyphs
)
1160 TRACE("(%p, %p, %p, %d, %d, %p)\n", hdc
, psc
, pwcChars
, cChars
, cMaxGlyphs
, psa
);
1161 if (psa
) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa
->eScript
, psa
->fRTL
, psa
->fLayoutRTL
,
1162 psa
->fLinkBefore
, psa
->fLinkAfter
, psa
->fLogicalOrder
, psa
->fNoGlyphIndex
);
1164 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
1165 if ((hr
= get_script_cache(hdc
, psc
))) return hr
;
1168 for (cnt
= 0; cnt
< cChars
; cnt
++)
1169 TRACE("%4x",pwcChars
[cnt
]);
1172 if (!psa
->fNoGlyphIndex
) { /* Glyph translate */
1173 if (!(GetGlyphIndicesW(((ScriptCache
*)*psc
)->hdc
, pwcChars
, cChars
, pwOutGlyphs
, 0)))
1177 for (cnt
= 0; cnt
< cChars
; cnt
++) {
1178 TRACE("%04x",pwOutGlyphs
[cnt
]);
1184 for (cnt
= 0; cnt
< cChars
; cnt
++) { /* no translate so set up */
1185 pwOutGlyphs
[cnt
] = pwcChars
[cnt
]; /* copy in to out and */
1186 TRACE("%04x",pwOutGlyphs
[cnt
]);
1191 /* Set up a valid SCRIPT_VISATTR and LogClust for each char in this run */
1192 for (cnt
= 0; cnt
< cChars
; cnt
++) {
1193 /* FIXME: set to better values */
1194 psva
[cnt
].uJustification
= 2;
1195 psva
[cnt
].fClusterStart
= 1;
1196 psva
[cnt
].fDiacritic
= 0;
1197 psva
[cnt
].fZeroWidth
= 0;
1198 pwLogClust
[cnt
] = cnt
;
1203 /***********************************************************************
1204 * ScriptPlace (USP10.@)
1207 HRESULT WINAPI
ScriptPlace(HDC hdc
, SCRIPT_CACHE
*psc
, const WORD
*pwGlyphs
,
1208 int cGlyphs
, const SCRIPT_VISATTR
*psva
,
1209 SCRIPT_ANALYSIS
*psa
, int *piAdvance
, GOFFSET
*pGoffset
, ABC
*pABC
)
1215 TRACE("(%p, %p, %p, %s, %d, %p, %p, %p)\n", hdc
, psc
, pwGlyphs
,
1216 debugstr_wn(pwGlyphs
, cGlyphs
), cGlyphs
, psva
, psa
, piAdvance
);
1218 if ((hr
= get_script_cache(hdc
, psc
))) return hr
;
1220 /* Here we need to calculate the width of the run unit. At this point the input string
1221 * has been converted to glyphs and we still need to translate back to the original chars
1222 * to get the correct ABC widths. */
1224 /* FIXME: set pGoffset to more reasonable values */
1226 lpABC
= HeapAlloc(GetProcessHeap(), 0 , sizeof(ABC
)*cGlyphs
);
1230 if (!GetCharABCWidthsI(((ScriptCache
*)*psc
)->hdc
, 0, cGlyphs
, (WORD
*) pwGlyphs
, lpABC
))
1232 WARN("Could not get ABC values\n");
1233 for (wcnt
= 0; wcnt
< cGlyphs
; wcnt
++) {
1234 piAdvance
[wcnt
] = 0;
1235 pGoffset
[wcnt
].du
= 0;
1236 pGoffset
[wcnt
].dv
= 0;
1241 for (wcnt
= 0; wcnt
< cGlyphs
; wcnt
++) { /* add up the char lengths */
1242 TRACE(" Glyph=%04x, abcA=%d, abcB=%d, abcC=%d wcnt=%d\n",
1246 lpABC
[wcnt
].abcC
, wcnt
);
1247 pABC
->abcA
+= lpABC
[wcnt
].abcA
;
1248 pABC
->abcB
+= lpABC
[wcnt
].abcB
;
1249 pABC
->abcC
+= lpABC
[wcnt
].abcC
;
1250 piAdvance
[wcnt
] = lpABC
[wcnt
].abcA
+ lpABC
[wcnt
].abcB
+ lpABC
[wcnt
].abcC
;
1251 pGoffset
[wcnt
].du
= 0;
1252 pGoffset
[wcnt
].dv
= 0;
1255 TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC
->abcA
, pABC
->abcB
, pABC
->abcC
);
1256 HeapFree(GetProcessHeap(), 0, lpABC
);
1261 /***********************************************************************
1262 * ScriptGetCMap (USP10.@)
1264 * Retrieve glyph indices.
1267 * hdc [I] Device context.
1268 * psc [I/O] Opaque pointer to a script cache.
1269 * pwcInChars [I] Array of Unicode characters.
1270 * cChars [I] Number of characters in pwcInChars.
1271 * dwFlags [I] Flags.
1272 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
1276 * Failure: Non-zero HRESULT value.
1278 HRESULT WINAPI
ScriptGetCMap(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcInChars
,
1279 int cChars
, DWORD dwFlags
, WORD
*pwOutGlyphs
)
1284 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc
, psc
, debugstr_wn(pwcInChars
, cChars
),
1285 cChars
, dwFlags
, pwOutGlyphs
);
1287 if ((hr
= get_script_cache(hdc
, psc
))) return hr
;
1290 for (cnt
= 0; cnt
< cChars
; cnt
++)
1291 TRACE("%4x",pwcInChars
[cnt
]);
1294 GetGlyphIndicesW(((ScriptCache
*)*psc
)->hdc
, pwcInChars
, cChars
, pwOutGlyphs
, 0);
1297 for (cnt
= 0; cnt
< cChars
; cnt
++) {
1298 TRACE("%04x",pwOutGlyphs
[cnt
]);
1305 /***********************************************************************
1306 * ScriptTextOut (USP10.@)
1309 HRESULT WINAPI
ScriptTextOut(const HDC hdc
, SCRIPT_CACHE
*psc
, int x
, int y
, UINT fuOptions
,
1310 const RECT
*lprc
, const SCRIPT_ANALYSIS
*psa
, const WCHAR
*pwcReserved
,
1311 int iReserved
, const WORD
*pwGlyphs
, int cGlyphs
, const int *piAdvance
,
1312 const int *piJustify
, const GOFFSET
*pGoffset
)
1316 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
1317 hdc
, psc
, x
, y
, fuOptions
, lprc
, psa
, pwcReserved
, iReserved
, pwGlyphs
, cGlyphs
,
1318 piAdvance
, piJustify
, pGoffset
);
1320 if (!hdc
&& psc
&& !*psc
) return E_INVALIDARG
;
1321 if (!piAdvance
|| !psa
|| !pwGlyphs
) return E_INVALIDARG
;
1322 if ((hr
= get_script_cache(hdc
, psc
))) return hr
;
1324 fuOptions
&= ETO_CLIPPED
+ ETO_OPAQUE
;
1325 if (!psa
->fNoGlyphIndex
) /* Have Glyphs? */
1326 fuOptions
|= ETO_GLYPH_INDEX
; /* Say don't do translation to glyph */
1328 if (!ExtTextOutW(((ScriptCache
*)*psc
)->hdc
, x
, y
, fuOptions
, lprc
, pwGlyphs
, cGlyphs
, NULL
))
1334 /***********************************************************************
1335 * ScriptCacheGetHeight (USP10.@)
1337 * Retrieve the height of the font in the cache.
1340 * hdc [I] Device context.
1341 * psc [I/O] Opaque pointer to a script cache.
1342 * height [O] Receives font height.
1346 * Failure: Non-zero HRESULT value.
1348 HRESULT WINAPI
ScriptCacheGetHeight(HDC hdc
, SCRIPT_CACHE
*psc
, LONG
*height
)
1353 TRACE("(%p, %p, %p)\n", hdc
, psc
, height
);
1355 if (!height
) return E_INVALIDARG
;
1356 if ((hr
= get_script_cache(hdc
, psc
))) return hr
;
1358 /* FIXME: get this from the cache */
1359 if (!GetTextMetricsW(((ScriptCache
*)*psc
)->hdc
, &metric
)) return E_INVALIDARG
;
1361 *height
= metric
.tmHeight
;
1365 /***********************************************************************
1366 * ScriptGetGlyphABCWidth (USP10.@)
1368 * Retrieve the width of a glyph.
1371 * hdc [I] Device context.
1372 * psc [I/O] Opaque pointer to a script cache.
1373 * glyph [I] Glyph to retrieve the width for.
1374 * abc [O] ABC widths of the glyph.
1378 * Failure: Non-zero HRESULT value.
1380 HRESULT WINAPI
ScriptGetGlyphABCWidth(HDC hdc
, SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
1384 TRACE("(%p, %p, 0x%04x, %p)\n", hdc
, psc
, glyph
, abc
);
1386 if ((hr
= get_script_cache(hdc
, psc
))) return hr
;
1388 /* FIXME: get this from the cache */
1389 if (!GetCharABCWidthsW(((ScriptCache
*)*psc
)->hdc
, glyph
, glyph
, abc
)) return E_HANDLE
;
1393 /***********************************************************************
1394 * ScriptLayout (USP10.@)
1396 * Map embedding levels to visual and/or logical order.
1399 * runs [I] Size of level array.
1400 * level [I] Array of embedding levels.
1401 * vistolog [O] Map of embedding levels from visual to logical order.
1402 * logtovis [O] Map of embedding levels from logical to visual order.
1406 * Failure: Non-zero HRESULT value.
1409 * This stub works correctly for any sequence of a single
1410 * embedding level but not for sequences of different
1411 * embedding levels, i.e. mixtures of RTL and LTR scripts.
1413 HRESULT WINAPI
ScriptLayout(int runs
, const BYTE
*level
, int *vistolog
, int *logtovis
)
1415 int i
, j
= runs
- 1, k
= 0;
1417 TRACE("(%d, %p, %p, %p)\n", runs
, level
, vistolog
, logtovis
);
1419 if (!level
|| (!vistolog
&& !logtovis
))
1420 return E_INVALIDARG
;
1422 for (i
= 0; i
< runs
; i
++)
1426 if (vistolog
) *vistolog
++ = j
;
1427 if (logtovis
) *logtovis
++ = j
;
1432 if (vistolog
) *vistolog
++ = k
;
1433 if (logtovis
) *logtovis
++ = k
;
1440 /***********************************************************************
1441 * ScriptStringGetLogicalWidths (USP10.@)
1443 * Returns logical widths from a string analysis.
1446 * ssa [I] string analysis.
1447 * piDx [O] logical widths returned.
1451 * Failure: a non-zero HRESULT.
1453 HRESULT WINAPI
ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa
, int *piDx
)
1456 StringAnalysis
*analysis
= ssa
;
1458 TRACE("%p, %p\n", ssa
, piDx
);
1460 if (!analysis
) return S_FALSE
;
1462 for (i
= 0; i
< analysis
->numItems
; i
++)
1464 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
1466 piDx
[next
] = analysis
->glyphs
[i
].piAdvance
[j
];
1473 /***********************************************************************
1474 * ScriptStringValidate (USP10.@)
1476 * Validate a string analysis.
1479 * ssa [I] string analysis.
1483 * Failure: S_FALSE if invalid sequences are found
1484 * or a non-zero HRESULT if it fails.
1486 HRESULT WINAPI
ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa
)
1488 StringAnalysis
*analysis
= ssa
;
1490 TRACE("(%p)\n", ssa
);
1492 if (!analysis
) return E_INVALIDARG
;
1493 return (analysis
->invalid
) ? S_FALSE
: S_OK
;
1496 /***********************************************************************
1497 * ScriptString_pSize (USP10.@)
1499 * Retrieve width and height of an analysed string.
1502 * ssa [I] string analysis.
1505 * Success: Pointer to a SIZE structure.
1508 const SIZE
* WINAPI
ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa
)
1511 StringAnalysis
*analysis
= ssa
;
1514 TRACE("(%p)\n", ssa
);
1516 if (!analysis
) return NULL
;
1520 if (!(analysis
->sz
= HeapAlloc(GetProcessHeap(), 0, sizeof(SIZE
))))
1523 /* FIXME: These values should be calculated at a more
1524 * appropriate place so that we can just pass cached
1527 if (!GetTextMetricsW(analysis
->hdc
, &metric
))
1529 HeapFree(GetProcessHeap(), 0, analysis
->sz
);
1530 analysis
->sz
= NULL
;
1533 analysis
->sz
->cy
= metric
.tmHeight
;
1535 analysis
->sz
->cx
= 0;
1536 for (i
= 0; i
< analysis
->numItems
; i
++)
1537 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
1538 analysis
->sz
->cx
+= analysis
->glyphs
[i
].piAdvance
[j
];
1540 return analysis
->sz
;
1543 /***********************************************************************
1544 * ScriptString_pLogAttr (USP10.@)
1546 * Retrieve logical attributes of an analysed string.
1549 * ssa [I] string analysis.
1552 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
1555 const SCRIPT_LOGATTR
* WINAPI
ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa
)
1557 StringAnalysis
*analysis
= ssa
;
1559 TRACE("(%p)\n", ssa
);
1561 if (!analysis
) return NULL
;
1562 return analysis
->logattrs
;