~ubuntu-branches/ubuntu/vivid/pango1.0/vivid-proposed

« back to all changes in this revision

Viewing changes to modules/basic/basic-win32.c

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2010-10-19 23:37:45 UTC
  • mfrom: (1.5.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20101019233745-xey8xlf91rpkth51
Tags: 1.28.3-1
* New upstream stable release.
  + Fixes SIGFPE in opentype renderer. Closes: #598166.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "pango-engine.h"
34
34
#include "pango-utils.h"
35
35
 
 
36
extern HFONT _pango_win32_font_get_hfont (PangoFont *font);
 
37
 
36
38
/* No extra fields needed */
37
39
typedef PangoEngineShape      BasicEngineWin32;
38
40
typedef PangoEngineShapeClass BasicEngineWin32Class ;
43
45
 
44
46
#include <usp10.h>
45
47
 
46
 
static gboolean have_uniscribe = FALSE;
47
 
 
48
48
static HDC hdc;
49
49
 
50
 
typedef HRESULT (WINAPI *pScriptGetProperties) (const SCRIPT_PROPERTIES ***,
51
 
                                                int *);
52
 
 
53
 
typedef HRESULT (WINAPI *pScriptItemize) (const WCHAR *,
54
 
                                          int,
55
 
                                          int,
56
 
                                          const SCRIPT_CONTROL *,
57
 
                                          const SCRIPT_STATE *,
58
 
                                          SCRIPT_ITEM *,
59
 
                                          int *);
60
 
 
61
 
typedef HRESULT (WINAPI *pScriptShape) (HDC,
62
 
                                        SCRIPT_CACHE *,
63
 
                                        const WCHAR *,
64
 
                                        int,
65
 
                                        int,
66
 
                                        SCRIPT_ANALYSIS *,
67
 
                                        WORD *,
68
 
                                        WORD *,
69
 
                                        SCRIPT_VISATTR *,
70
 
                                        int *);
71
 
 
72
 
typedef HRESULT (WINAPI *pScriptPlace) (HDC,
73
 
                                        SCRIPT_CACHE *,
74
 
                                        const WORD *,
75
 
                                        int,
76
 
                                        const SCRIPT_VISATTR *,
77
 
                                        SCRIPT_ANALYSIS *,
78
 
                                        int *,
79
 
                                        GOFFSET *,
80
 
                                        ABC *);
81
 
 
82
 
typedef HRESULT (WINAPI *pScriptFreeCache) (SCRIPT_CACHE *);
83
 
 
84
 
typedef HRESULT (WINAPI *pScriptIsComplex) (WCHAR *,
85
 
                                            int,
86
 
                                            DWORD);
87
 
 
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;
94
 
 
95
50
#ifdef BASIC_WIN32_DEBUGGING
96
51
static const SCRIPT_PROPERTIES **scripts;
97
52
static int nscripts;
495
450
                         wchar_t             *wtext,
496
451
                         int                  wlen,
497
452
                         const PangoAnalysis *analysis,
498
 
                         PangoGlyphString    *glyphs,
499
 
                         SCRIPT_CACHE        *script_cache)
 
453
                         PangoGlyphString    *glyphs)
500
454
{
501
455
  int i;
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;
 
464
 
 
465
  if (!script_cache_hash)
 
466
    script_cache_hash = g_hash_table_new (g_int64_hash, g_int64_equal);
508
467
 
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);
519
478
#endif
520
 
  if ((*script_itemize) (wtext, wlen, G_N_ELEMENTS (items), &control, NULL,
521
 
                         items, &nitems))
 
479
  if (ScriptItemize (wtext, wlen, G_N_ELEMENTS (items), &control, NULL,
 
480
                     items, &nitems))
522
481
    {
523
482
#ifdef BASIC_WIN32_DEBUGGING
524
483
      if (pango_win32_debug)
551
510
      int advances[1000];
552
511
      GOFFSET offsets[1000];
553
512
      ABC abc;
554
 
      int script = items[item].a.eScript;
 
513
      gint32 script = items[item].a.eScript;
555
514
      int ng;
556
515
      int char_offset;
 
516
      SCRIPT_CACHE *script_cache;
 
517
      gint64 font_and_script_key;
557
518
 
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);
581
542
#endif
 
543
      /* Create a hash key based on hfont and script engine */
 
544
      font_and_script_key = (((gint64) ((gint32) hfont)) << 32) | script;
 
545
 
 
546
      /* Get the script cache for this hfont and script */
 
547
      script_cache = g_hash_table_lookup (script_cache_hash, &font_and_script_key);
 
548
      if (!script_cache)
 
549
        {
 
550
          gint64 *key_n;
 
551
          SCRIPT_CACHE *new_script_cache;
 
552
 
 
553
          key_n = g_new (gint64, 1);
 
554
          *key_n = font_and_script_key;
 
555
 
 
556
          new_script_cache = g_new0 (SCRIPT_CACHE, 1);
 
557
          script_cache = new_script_cache;
 
558
 
 
559
          /* Insert the new value */
 
560
          g_hash_table_insert (script_cache_hash, key_n, new_script_cache);
 
561
 
 
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);
 
565
#endif
 
566
        }
582
567
 
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),
587
 
                           &items[item].a,
588
 
                           iglyphs,
589
 
                           log_clusters,
590
 
                           visattrs,
591
 
                           &nglyphs))
 
569
      if (ScriptShape (hdc, script_cache,
 
570
                       wtext + items[item].iCharPos, itemlen,
 
571
                       G_N_ELEMENTS (iglyphs),
 
572
                       &items[item].a,
 
573
                       iglyphs,
 
574
                       log_clusters,
 
575
                       visattrs,
 
576
                       &nglyphs))
592
577
        {
593
578
#ifdef BASIC_WIN32_DEBUGGING
594
579
          if (pango_win32_debug)
611
596
                                 nglyphs, glyphs->log_clusters + ng,
612
597
                                 char_offset);
613
598
 
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))
617
602
        {
618
603
#ifdef BASIC_WIN32_DEBUGGING
619
604
          if (pango_win32_debug)
671
656
{
672
657
  wchar_t *wtext;
673
658
  long wlen;
674
 
  int i;
675
659
  gboolean retval = TRUE;
676
 
  SCRIPT_CACHE script_cache[100];
677
660
 
678
661
  if (!pango_win32_font_select_font (font, hdc))
679
662
    return FALSE;
684
667
 
685
668
  if (retval)
686
669
    {
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++)
690
 
        if (script_cache[i])
691
 
          (*script_free_cache)(&script_cache[i]);
 
670
      retval = itemize_shape_and_place (font, hdc, wtext, wlen, analysis, glyphs);
692
671
    }
693
672
 
694
673
  if (retval)
726
705
  if (wtext == NULL)
727
706
    return TRUE;
728
707
 
729
 
  retval = ((*script_is_complex) (wtext, wlen, SIC_COMPLEX) == S_FALSE);
 
708
  retval = (ScriptIsComplex (wtext, wlen, SIC_COMPLEX) == S_FALSE);
730
709
 
731
710
  g_free (wtext);
732
711
 
756
735
  g_return_if_fail (length >= 0);
757
736
  g_return_if_fail (analysis != NULL);
758
737
 
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))
762
740
    return;
763
741
 
846
824
static void
847
825
init_uniscribe (void)
848
826
{
849
 
  HMODULE usp10_dll;
850
 
 
851
 
  have_uniscribe = FALSE;
852
 
 
853
 
  if ((usp10_dll = LoadLibrary ("usp10.dll")) != NULL)
854
 
    {
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);
868
 
    }
869
 
  if (have_uniscribe)
870
 
    {
871
827
#ifdef BASIC_WIN32_DEBUGGING
872
 
      (*script_get_properties) (&scripts, &nscripts);
 
828
  ScriptGetProperties (&scripts, &nscripts);
873
829
#endif
874
 
      hdc = pango_win32_get_dc ();
875
 
    }
 
830
  hdc = pango_win32_get_dc ();
876
831
}
877
832
 
878
833
static void
909
864
  script_engines[0].scripts = basic_scripts;
910
865
  script_engines[0].n_scripts = G_N_ELEMENTS (basic_scripts);
911
866
 
912
 
  if (have_uniscribe)
913
 
    {
914
867
#if 0
915
 
      int i;
916
 
      GArray *ranges = g_array_new (FALSE, FALSE, sizeof (PangoEngineRange));
917
 
 
918
 
      /* Walk through scripts supported by the Uniscribe implementation on this
919
 
       * machine, and mark corresponding Unicode ranges.
920
 
       */
921
 
      for (i = 0; i < nscripts; i++)
922
 
        {
923
 
        }
924
 
 
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;
 
868
  int i;
 
869
  GArray *ranges = g_array_new (FALSE, FALSE, sizeof (PangoEngineRange));
 
870
 
 
871
  /* Walk through scripts supported by the Uniscribe implementation on this
 
872
   * machine, and mark corresponding Unicode ranges.
 
873
   */
 
874
  for (i = 0; i < nscripts; i++)
 
875
    {
 
876
    }
 
877
 
 
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;
929
882
#else
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);
932
885
#endif
933
 
    }
934
886
 
935
887
  *engines = script_engines;
936
888
  *n_engines = G_N_ELEMENTS (script_engines);