[pango] Bug 611033 - Layout using ATSUI fontmap treats absolute font sizes a...



commit f4201009d192300442e76d25a83c0dab8022d0d6
Author: Kristian Rietveld <kris gtk org>
Date:   Sun Mar 21 21:23:56 2010 +0100

    Bug 611033 - Layout using ATSUI fontmap treats absolute font sizes a...
    
    pango_atsui_font_map_load_font() has been corrected to take into account
    whether the size retrieved from the given font description is absolute
    when setting this size again on best_description.
    
    _pango_cairo_atsui_font_new() has been cleaned up with regard to size
    conversion and usage.  The code now properly takes the absolute property
    into account and is more clear.

 pango/pangoatsui-fontmap.c   |    8 ++++++-
 pango/pangocairo-atsuifont.c |   47 ++++++++++++++++++++---------------------
 2 files changed, 30 insertions(+), 25 deletions(-)
---
diff --git a/pango/pangoatsui-fontmap.c b/pango/pangoatsui-fontmap.c
index f433440..12b86bb 100644
--- a/pango/pangoatsui-fontmap.c
+++ b/pango/pangoatsui-fontmap.c
@@ -672,11 +672,14 @@ pango_atsui_font_map_load_font (PangoFontMap               *fontmap,
   const gchar *family;
   gchar *name;
   gint size;
+  gboolean is_absolute;
 
   size = pango_font_description_get_size (description);
   if (size < 0)
     return NULL;
 
+  is_absolute = pango_font_description_get_size_is_absolute (description);
+
   family = pango_font_description_get_family (description);
   family = family ? family : "";
   name = g_utf8_casefold (family, -1);
@@ -695,7 +698,10 @@ pango_atsui_font_map_load_font (PangoFontMap               *fontmap,
       if (!find_best_match (font_family, description, &best_description, &best_face))
 	return NULL;
       
-      pango_font_description_set_size (best_description, size);
+      if (is_absolute)
+        pango_font_description_set_absolute_size (best_description, size);
+      else
+        pango_font_description_set_size (best_description, size);
 
       best_font = pango_atsui_font_map_lookup (atsuifontmap, 
 					       context, 
diff --git a/pango/pangocairo-atsuifont.c b/pango/pangocairo-atsuifont.c
index 057cc76..3abafff 100644
--- a/pango/pangocairo-atsuifont.c
+++ b/pango/pangocairo-atsuifont.c
@@ -36,8 +36,7 @@ struct _PangoCairoATSUIFont
   PangoATSUIFont font;
   PangoCairoFontPrivate cf_priv;
 
-  double size;
-  int absolute_size;
+  double size; /* Absolute size */
 };
 
 struct _PangoCairoATSUIFontClass
@@ -166,7 +165,8 @@ pango_cairo_atsui_font_describe_absolute (PangoFont *font)
   PangoCairoATSUIFont *cafont = (PangoCairoATSUIFont *) font;
 
   desc = pango_font_describe (font);
-  pango_font_description_set_absolute_size (desc, cafont->absolute_size);
+  pango_font_description_set_absolute_size (desc,
+                                            cafont->size * PANGO_SCALE);
 
   return desc;
 }
@@ -212,7 +212,7 @@ _pango_cairo_atsui_font_new (PangoCairoATSUIFontMap     *cafontmap,
   CFStringRef cfstr;
   ATSFontRef font_ref;
   CGFontRef font_id;
-  double size;
+  double size, abs_size;
   double dpi;
   double m;
   cairo_matrix_t font_matrix;
@@ -224,6 +224,23 @@ _pango_cairo_atsui_font_new (PangoCairoATSUIFontMap     *cafontmap,
   font_ref = ATSFontFindFromPostScriptName (cfstr, kATSOptionFlagsDefault);
   CFRelease (cfstr);
 
+  abs_size = size = pango_units_to_double (pango_font_description_get_size (desc));
+
+  if (context)
+    {
+      dpi = pango_cairo_context_get_resolution (context);
+
+      if (dpi <= 0)
+	dpi = cafontmap->dpi;
+    }
+  else
+    dpi = cafontmap->dpi;
+
+  if (pango_font_description_get_size_is_absolute (desc))
+    size *= 72. / dpi;
+  else
+    abs_size *= dpi / 72.;
+
   /* We synthesize italic in two cases. The first is when
    * NSFontManager has handed out a face that it claims has italic but
    * it doesn't. The other is when an italic face is requested that
@@ -236,8 +253,6 @@ _pango_cairo_atsui_font_new (PangoCairoATSUIFontMap     *cafontmap,
       NSString *nsname;
       NSFont *nsfont, *converted_font;
 
-      size = (double) pango_font_description_get_size (desc) / PANGO_SCALE;
-
       nsname = [NSString stringWithUTF8String:postscript_name];
       nsfont = [NSFont fontWithName:nsname size:size];
 
@@ -266,26 +281,10 @@ _pango_cairo_atsui_font_new (PangoCairoATSUIFontMap     *cafontmap,
   _pango_atsui_font_set_font_description (afont, desc);
   _pango_atsui_font_set_face (afont, face);
 
-  size = (double) pango_font_description_get_size (desc) / PANGO_SCALE;
   _pango_atsui_font_set_cgfont (afont, font_id);
   _pango_atsui_font_set_atsfont (afont, font_ref);
 
-  if (context)
-    {
-      dpi = pango_cairo_context_get_resolution (context);
-
-      if (dpi <= 0)
-	dpi = cafontmap->dpi;
-    }
-  else
-    dpi = cafontmap->dpi;
-
-  cafont->absolute_size = pango_font_description_get_size (desc);
-
-  if (!pango_font_description_get_size_is_absolute (desc))
-    size *= dpi / 72.;
-
-  cafont->size = size;
+  cafont->size = abs_size;
 
   /* When synthesizing italics, apply a shear matrix matching what Cocoa
    * does. Cairo quartz had transformed text wrong before 1.5.13, stay
@@ -304,7 +303,7 @@ _pango_cairo_atsui_font_new (PangoCairoATSUIFontMap     *cafontmap,
   else
     cairo_matrix_init_identity (&font_matrix);
 
-  cairo_matrix_scale (&font_matrix, size, size);
+  cairo_matrix_scale (&font_matrix, abs_size, abs_size);
 
   _pango_cairo_font_private_initialize (&cafont->cf_priv,
 					(PangoCairoFont *) cafont,



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