33
33
#include "pango-engine.h"
34
34
#include "pango-utils.h"
36
extern HFONT _pango_win32_font_get_hfont (PangoFont *font);
36
38
/* No extra fields needed */
37
39
typedef PangoEngineShape BasicEngineWin32;
38
40
typedef PangoEngineShapeClass BasicEngineWin32Class ;
46
static gboolean have_uniscribe = FALSE;
50
typedef HRESULT (WINAPI *pScriptGetProperties) (const SCRIPT_PROPERTIES ***,
53
typedef HRESULT (WINAPI *pScriptItemize) (const WCHAR *,
56
const SCRIPT_CONTROL *,
61
typedef HRESULT (WINAPI *pScriptShape) (HDC,
72
typedef HRESULT (WINAPI *pScriptPlace) (HDC,
76
const SCRIPT_VISATTR *,
82
typedef HRESULT (WINAPI *pScriptFreeCache) (SCRIPT_CACHE *);
84
typedef HRESULT (WINAPI *pScriptIsComplex) (WCHAR *,
88
static pScriptGetProperties script_get_properties;
89
static pScriptItemize script_itemize;
90
static pScriptShape script_shape;
91
static pScriptPlace script_place;
92
static pScriptFreeCache script_free_cache;
93
static pScriptIsComplex script_is_complex;
95
50
#ifdef BASIC_WIN32_DEBUGGING
96
51
static const SCRIPT_PROPERTIES **scripts;
97
52
static int nscripts;
497
452
const PangoAnalysis *analysis,
498
PangoGlyphString *glyphs,
499
SCRIPT_CACHE *script_cache)
453
PangoGlyphString *glyphs)
502
456
int item, nitems, item_step;
505
459
SCRIPT_STATE state;
506
460
SCRIPT_ITEM items[100];
507
461
double scale = pango_win32_font_get_metrics_factor (font);
462
HFONT hfont = _pango_win32_font_get_hfont (font);
463
static GHashTable *script_cache_hash = NULL;
465
if (!script_cache_hash)
466
script_cache_hash = g_hash_table_new (g_int64_hash, g_int64_equal);
509
468
memset (&control, 0, sizeof (control));
510
469
memset (&state, 0, sizeof (state));
517
476
g_print (G_STRLOC ": ScriptItemize: uDefaultLanguage:%04x uBidiLevel:%d\n",
518
477
control.uDefaultLanguage, state.uBidiLevel);
520
if ((*script_itemize) (wtext, wlen, G_N_ELEMENTS (items), &control, NULL,
479
if (ScriptItemize (wtext, wlen, G_N_ELEMENTS (items), &control, NULL,
523
482
#ifdef BASIC_WIN32_DEBUGGING
524
483
if (pango_win32_debug)
551
510
int advances[1000];
552
511
GOFFSET offsets[1000];
554
int script = items[item].a.eScript;
513
gint32 script = items[item].a.eScript;
516
SCRIPT_CACHE *script_cache;
517
gint64 font_and_script_key;
558
519
memset (advances, 0, sizeof (advances));
559
520
memset (offsets, 0, sizeof (offsets));
579
540
items[item].a.fNoGlyphIndex ? " fNoGlyphIndex" : "",
580
541
items[item].iCharPos, items[item+1].iCharPos-1, itemlen);
543
/* Create a hash key based on hfont and script engine */
544
font_and_script_key = (((gint64) ((gint32) hfont)) << 32) | script;
546
/* Get the script cache for this hfont and script */
547
script_cache = g_hash_table_lookup (script_cache_hash, &font_and_script_key);
551
SCRIPT_CACHE *new_script_cache;
553
key_n = g_new (gint64, 1);
554
*key_n = font_and_script_key;
556
new_script_cache = g_new0 (SCRIPT_CACHE, 1);
557
script_cache = new_script_cache;
559
/* Insert the new value */
560
g_hash_table_insert (script_cache_hash, key_n, new_script_cache);
562
#ifdef BASIC_WIN32_DEBUGGING
563
if (pango_win32_debug)
564
g_print (" New SCRIPT_CACHE for font %p and script %d\n", hfont, script);
583
568
items[item].a.fRTL = analysis->level % 2;
584
if ((*script_shape) (hdc, &script_cache[script],
585
wtext + items[item].iCharPos, itemlen,
586
G_N_ELEMENTS (iglyphs),
569
if (ScriptShape (hdc, script_cache,
570
wtext + items[item].iCharPos, itemlen,
571
G_N_ELEMENTS (iglyphs),
593
578
#ifdef BASIC_WIN32_DEBUGGING
594
579
if (pango_win32_debug)
611
596
nglyphs, glyphs->log_clusters + ng,
614
if ((*script_place) (hdc, &script_cache[script], iglyphs, nglyphs,
615
visattrs, &items[item].a,
616
advances, offsets, &abc))
599
if (ScriptPlace (hdc, script_cache, iglyphs, nglyphs,
600
visattrs, &items[item].a,
601
advances, offsets, &abc))
618
603
#ifdef BASIC_WIN32_DEBUGGING
619
604
if (pango_win32_debug)
687
memset (script_cache, 0, sizeof (script_cache));
688
retval = itemize_shape_and_place (font, hdc, wtext, wlen, analysis, glyphs, script_cache);
689
for (i = 0; i < G_N_ELEMENTS (script_cache); i++)
691
(*script_free_cache)(&script_cache[i]);
670
retval = itemize_shape_and_place (font, hdc, wtext, wlen, analysis, glyphs);
756
735
g_return_if_fail (length >= 0);
757
736
g_return_if_fail (analysis != NULL);
759
if (have_uniscribe &&
760
!text_is_simple (text, length) &&
738
if (!text_is_simple (text, length) &&
761
739
uniscribe_shape (font, text, length, analysis, glyphs))
847
825
init_uniscribe (void)
851
have_uniscribe = FALSE;
853
if ((usp10_dll = LoadLibrary ("usp10.dll")) != NULL)
855
(script_get_properties = (pScriptGetProperties)
856
GetProcAddress (usp10_dll, "ScriptGetProperties")) &&
857
(script_itemize = (pScriptItemize)
858
GetProcAddress (usp10_dll, "ScriptItemize")) &&
859
(script_shape = (pScriptShape)
860
GetProcAddress (usp10_dll, "ScriptShape")) &&
861
(script_place = (pScriptPlace)
862
GetProcAddress (usp10_dll, "ScriptPlace")) &&
863
(script_free_cache = (pScriptFreeCache)
864
GetProcAddress (usp10_dll, "ScriptFreeCache")) &&
865
(script_is_complex = (pScriptIsComplex)
866
GetProcAddress (usp10_dll, "ScriptIsComplex")) &&
867
(have_uniscribe = TRUE);
871
827
#ifdef BASIC_WIN32_DEBUGGING
872
(*script_get_properties) (&scripts, &nscripts);
828
ScriptGetProperties (&scripts, &nscripts);
874
hdc = pango_win32_get_dc ();
830
hdc = pango_win32_get_dc ();
909
864
script_engines[0].scripts = basic_scripts;
910
865
script_engines[0].n_scripts = G_N_ELEMENTS (basic_scripts);
916
GArray *ranges = g_array_new (FALSE, FALSE, sizeof (PangoEngineRange));
918
/* Walk through scripts supported by the Uniscribe implementation on this
919
* machine, and mark corresponding Unicode ranges.
921
for (i = 0; i < nscripts; i++)
925
/* Sort range array */
926
g_array_sort (ranges, compare_range);
927
script_engines[0].ranges = ranges;
928
script_engines[0].n_ranges = ranges->len;
869
GArray *ranges = g_array_new (FALSE, FALSE, sizeof (PangoEngineRange));
871
/* Walk through scripts supported by the Uniscribe implementation on this
872
* machine, and mark corresponding Unicode ranges.
874
for (i = 0; i < nscripts; i++)
878
/* Sort range array */
879
g_array_sort (ranges, compare_range);
880
script_engines[0].ranges = ranges;
881
script_engines[0].n_ranges = ranges->len;
930
script_engines[0].scripts = uniscribe_scripts;
931
script_engines[0].n_scripts = G_N_ELEMENTS (uniscribe_scripts);
883
script_engines[0].scripts = uniscribe_scripts;
884
script_engines[0].n_scripts = G_N_ELEMENTS (uniscribe_scripts);
935
887
*engines = script_engines;
936
888
*n_engines = G_N_ELEMENTS (script_engines);