pango r2573 - in trunk: . pango



Author: tml
Date: Sun Feb 24 22:04:56 2008
New Revision: 2573
URL: http://svn.gnome.org/viewvc/pango?rev=2573&view=rev

Log:
2008-02-24  Tor Lillqvist  <tml novell com>

	Bug 515484: Pango on Windows is missing Type 1
	font support
	Patch from Adrian Johnson.
	
	* pango/pangowin32-private.h (PangoWin32Face): Add has_cmap field
	that tells whether the font has a cmap or not. A Type 1 font
	doesn't.

	* pango/pangowin32.c (pango_win32_font_get_type1_glyph_index): New
	static function. Uses GetGlyphIndicesW() to get the glyph indices
	for Type 1 fonts. Possibly also TrueType fonts that for some
	reason lack the cmap formats we understand.
	(pango_win32_font_calc_type1_coverage): New static function. Uses
	GetFontUnicodeRanges() to get the coverage for Type 1 fonts, and
	possibly TrueType fonts that lack the cmap formats we understand.
	(pango_win32_font_get_glyph_index): Set has_cmap to false if the
	font doesn't have a cmap. Call
	pango_win32_font_get_type1_glyph_index() in that case.
	(pango_win32_font_calc_coverage): Set has_cmap to false if the
	font doesn't have a cmap. Call
	pango_win32_font_calc_type1_coverage() in that case.
	
	* pango/pangowin32-fontmap.c (pango_win32_enum_proc): Accept also
	Type 1 fonts.
	(pango_win32_insert_font): Initialise has_cmap tentativaly to True.



Modified:
   trunk/ChangeLog
   trunk/pango/pangowin32-fontmap.c
   trunk/pango/pangowin32-private.h
   trunk/pango/pangowin32.c

Modified: trunk/pango/pangowin32-fontmap.c
==============================================================================
--- trunk/pango/pangowin32-fontmap.c	(original)
+++ trunk/pango/pangowin32-fontmap.c	Sun Feb 24 22:04:56 2008
@@ -57,6 +57,10 @@
 # define NTM_PS_OPENTYPE 0x20000
 #endif
 
+#if !defined(NTM_TYPE1)
+# define NTM_TYPE1 0x100000
+#endif
+
 #define PANGO_WIN32_TYPE_FAMILY              (pango_win32_family_get_type ())
 #define PANGO_WIN32_FAMILY(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_WIN32_TYPE_FAMILY, PangoWin32Family))
 #define PANGO_WIN32_IS_FAMILY(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_WIN32_TYPE_FAMILY))
@@ -196,7 +200,7 @@
 
   if (fontType == TRUETYPE_FONTTYPE ||
       (_pango_win32_os_version_info.dwMajorVersion >= 5 &&
-       (metrics->ntmFlags & NTM_PS_OPENTYPE)))
+       ((metrics->ntmFlags & NTM_PS_OPENTYPE) || (metrics->ntmFlags & NTM_TYPE1))))
     {
       lf = *lfp;
 
@@ -1098,6 +1102,7 @@
 
   win32face->is_synthetic = is_synthetic;
 
+  win32face->has_cmap = TRUE;
   win32face->cmap_format = 0;
   win32face->cmap = NULL;
 

Modified: trunk/pango/pangowin32-private.h
==============================================================================
--- trunk/pango/pangowin32-private.h	(original)
+++ trunk/pango/pangowin32-private.h	Sun Feb 24 22:04:56 2008
@@ -165,6 +165,7 @@
   char *face_name;
   gboolean is_synthetic;
 
+  gboolean has_cmap;
   guint16 cmap_format;
   gpointer cmap;
 

Modified: trunk/pango/pangowin32.c
==============================================================================
--- trunk/pango/pangowin32.c	(original)
+++ trunk/pango/pangowin32.c	Sun Feb 24 22:04:56 2008
@@ -1463,6 +1463,26 @@
   return cmap;
 }
 
+static gint
+pango_win32_font_get_type1_glyph_index (PangoFont *font,
+                                        gunichar   wc)
+{
+  wchar_t unicode[2];
+  WORD glyph_index;
+  gint32 res;
+
+  unicode[0] = wc;
+  unicode[1] = 0;
+  pango_win32_font_select_font (font, _pango_win32_hdc);
+  res = GetGlyphIndicesW (_pango_win32_hdc, unicode, 1, &glyph_index, 0);
+  pango_win32_font_done_font (font);
+
+  if (res == 1)
+      return glyph_index;
+  else
+      return 0;
+}
+
 /**
  * pango_win32_font_get_glyph_index:
  * @font: a #PangoFont.
@@ -1481,11 +1501,16 @@
   gpointer cmap;
   guint16 glyph;
 
-  /* Do GetFontData magic on font->hfont here. */
-  cmap = font_get_cmap (font);
+  if (win32font->win32face->has_cmap)
+    {
+      /* Do GetFontData magic on font->hfont here. */
+      cmap = font_get_cmap (font);
+      if (cmap == NULL)
+	win32font->win32face->has_cmap = FALSE;
+    }
 
-  if (cmap == NULL)
-    return 0;
+  if (!win32font->win32face->has_cmap)
+    return pango_win32_font_get_type1_glyph_index (font, wc);
 
   if (win32font->win32face->cmap_format == 4)
     {
@@ -1636,6 +1661,44 @@
 }
 
 static void
+pango_win32_font_calc_type1_coverage (PangoFont     *font,
+				      PangoCoverage *coverage,
+				      PangoLanguage *lang)
+{
+  GLYPHSET *glyph_set;
+  gint32 res;
+  guint32 ch;
+  guint32 i;
+  
+  pango_win32_font_select_font (font, _pango_win32_hdc);
+  res = GetFontUnicodeRanges(_pango_win32_hdc, NULL);
+  if (res == 0)
+    goto fail1;
+
+  glyph_set = g_malloc (res);
+  res = GetFontUnicodeRanges(_pango_win32_hdc, glyph_set);
+  if (res == 0)
+    goto fail2;
+  
+  for (i = 0; i < glyph_set->cRanges; i++) 
+    {
+      guint32 end = glyph_set->ranges[i].wcLow + glyph_set->ranges[i].cGlyphs;
+
+      for (ch = glyph_set->ranges[i].wcLow; ch < end; ch++)
+	  if (CH_IS_UNIHAN_BMP (ch))
+	      pango_coverage_set (coverage, ch, PANGO_COVERAGE_APPROXIMATE);
+	  else
+	      pango_coverage_set (coverage, ch, PANGO_COVERAGE_EXACT);
+    }
+
+ fail2:
+  g_free (glyph_set);
+
+ fail1:
+  pango_win32_font_done_font (font);
+}
+
+static void
 pango_win32_font_calc_coverage (PangoFont     *font,
 				PangoCoverage *coverage,
 				PangoLanguage *lang)
@@ -1651,6 +1714,20 @@
 	pango_font_description_to_string (pango_font_describe (font)),
 	pango_language_to_string (lang)));
 
+  if (win32font->win32face->has_cmap)
+    {
+      /* Do GetFontData magic on font->hfont here. */
+      cmap = font_get_cmap (font);
+      if (cmap == NULL)
+	win32font->win32face->has_cmap = FALSE;
+    }
+
+  if (!win32font->win32face->has_cmap)
+    {
+      pango_win32_font_calc_type1_coverage (font, coverage, lang);
+      return;
+    }
+
   cjkv = pango_win32_coverage_language_classify (lang);
 
   if (cjkv != PANGO_WIN32_COVERAGE_UNSPEC && !font_has_name_in (font, cjkv))
@@ -1659,14 +1736,6 @@
       hide_unihan = TRUE;
     }
 
-  /* Do GetFontData magic on font->hfont here. */
-  cmap = font_get_cmap (font);
-  if (cmap == NULL)
-    {
-      PING(("no table"));
-      return;
-    }
-
   PING (("coverage:"));
   if (win32font->win32face->cmap_format == 4)
     {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]