Code

bug 1495265: css fallback fonts broken on win32
authorcyreve <cyreve@users.sourceforge.net>
Sat, 27 May 2006 16:56:44 +0000 (16:56 +0000)
committercyreve <cyreve@users.sourceforge.net>
Sat, 27 May 2006 16:56:44 +0000 (16:56 +0000)
src/libnrtype/Layout-TNG-Compute.cpp
src/libnrtype/Layout-TNG-Input.cpp
src/libnrtype/Layout-TNG.h

index ca16291d04bcbfd57bc08658f327fea2b231c341..4d83410bb301037a930a853f9cb16341df53e117 100755 (executable)
@@ -832,12 +832,10 @@ void Layout::Calculator::_buildPangoItemizationForPara(ParagraphInfo *para) cons
         } else if (_flow._input_stream[input_index]->Type() == TEXT_SOURCE) {
             Layout::InputStreamTextSource *text_source = static_cast<Layout::InputStreamTextSource *>(_flow._input_stream[input_index]);
 
-            // create the font_instance
-            font_instance *font = text_source->styleGetFontInstance();
-            if (font == NULL)
-                continue;  // bad news: we'll have to ignore all this text because we know of no font to render it
+            PangoFontDescription *temp_descr = text_source->styleGetFontDescription();
+            PangoAttribute *attribute_font_description = pango_attr_font_desc_new(temp_descr);
+            pango_font_description_free(temp_descr);
 
-            PangoAttribute *attribute_font_description = pango_attr_font_desc_new(font->descr);
             attribute_font_description->start_index = para_text.bytes();
             para_text.append(&*text_source->text_begin.base(), text_source->text_length);     // build the combined text
             attribute_font_description->end_index = para_text.bytes();
index 8b695af043cc88de04f7c501abd049e7c097336c..c8dc41e953234d8a5e13d44856e7d02af593edce 100755 (executable)
@@ -252,13 +252,48 @@ static const Layout::EnumConversionItem enum_convert_spstyle_variant_to_pango_va
     {SP_CSS_FONT_VARIANT_SMALL_CAPS, PANGO_VARIANT_SMALL_CAPS}};
 
 font_instance *Layout::InputStreamTextSource::styleGetFontInstance() const
+{
+    PangoFontDescription *descr = styleGetFontDescription();
+    if (descr == NULL) return NULL;
+    font_instance *res = (font_factory::Default())->Face(descr);
+    pango_font_description_free(descr);
+    return res;
+}
+
+PangoFontDescription *Layout::InputStreamTextSource::styleGetFontDescription() const
 {
     if (style->text == NULL) return NULL;
-    return (font_factory::Default())->Face(style->text->font_family.value,
-                                           _enum_converter(style->font_variant.computed, enum_convert_spstyle_variant_to_pango_variant, sizeof(enum_convert_spstyle_variant_to_pango_variant)/sizeof(enum_convert_spstyle_variant_to_pango_variant[0])),
-                                           _enum_converter(style->font_style.computed,   enum_convert_spstyle_style_to_pango_style,     sizeof(enum_convert_spstyle_style_to_pango_style)/sizeof(enum_convert_spstyle_style_to_pango_style[0])),
-                                           _enum_converter(style->font_weight.computed,  enum_convert_spstyle_weight_to_pango_weight,   sizeof(enum_convert_spstyle_weight_to_pango_weight)/sizeof(enum_convert_spstyle_weight_to_pango_weight[0])),
-                                           _enum_converter(style->font_stretch.computed, enum_convert_spstyle_stretch_to_pango_stretch, sizeof(enum_convert_spstyle_stretch_to_pango_stretch)/sizeof(enum_convert_spstyle_stretch_to_pango_stretch[0])));
+    PangoFontDescription *descr = pango_font_description_new();
+    // Pango can't cope with spaces before or after the commas - let's remove them.
+    // this code is not exactly unicode-safe, but it's similar to what's done in
+    // pango, so it's not the limiting factor
+    Glib::ustring family;
+    if (style->text->font_family.value == NULL) {
+        family = "Sans";
+    } else {
+        gchar **families = g_strsplit(style->text->font_family.value, ",", -1);
+        if (families) {
+            for (gchar **f = families ; *f ; ++f) {
+                g_strstrip(*f);
+                if (!family.empty()) family += ',';
+                family += *f;
+            }
+        }
+        g_strfreev(families);
+    }
+
+    pango_font_description_set_family(descr,family.c_str());
+    pango_font_description_set_weight(descr,(PangoWeight)_enum_converter(style->font_weight.computed,  enum_convert_spstyle_weight_to_pango_weight,   sizeof(enum_convert_spstyle_weight_to_pango_weight)/sizeof(enum_convert_spstyle_weight_to_pango_weight[0])));
+    pango_font_description_set_stretch(descr,(PangoStretch)_enum_converter(style->font_stretch.computed, enum_convert_spstyle_stretch_to_pango_stretch, sizeof(enum_convert_spstyle_stretch_to_pango_stretch)/sizeof(enum_convert_spstyle_stretch_to_pango_stretch[0])));
+    pango_font_description_set_style(descr,(PangoStyle)_enum_converter(style->font_style.computed,   enum_convert_spstyle_style_to_pango_style,     sizeof(enum_convert_spstyle_style_to_pango_style)/sizeof(enum_convert_spstyle_style_to_pango_style[0])));
+    pango_font_description_set_variant(descr,(PangoVariant)_enum_converter(style->font_variant.computed, enum_convert_spstyle_variant_to_pango_variant, sizeof(enum_convert_spstyle_variant_to_pango_variant)/sizeof(enum_convert_spstyle_variant_to_pango_variant[0])));
+#ifdef USE_PANGO_WIN32
+    // damn Pango fudges the size, so we need to unfudge. See source of pango_win32_font_map_init()
+    pango_font_description_set_size(descr, (int) ((font_factory::Default())->fontSize*PANGO_SCALE*72/GetDeviceCaps(pango_win32_get_dc(),LOGPIXELSY))); // mandatory huge size (hinting workaround)
+#else
+    pango_font_description_set_size(descr, (int) ((font_factory::Default())->fontSize*PANGO_SCALE)); // mandatory huge size (hinting workaround)
+#endif
+    return descr;
 }
 
 Layout::InputStreamTextSource::~InputStreamTextSource()
index 5c86d3135ac6cd06a4e6d548d8743cb5d8a5b663..072aef8789fcbb305c092ab98d1f60a3622f0b98 100755 (executable)
@@ -27,6 +27,7 @@ class SVGLength;
 class Path;
 class SPCurve;
 class font_instance;
+typedef struct _PangoFontDescription PangoFontDescription;
 
 namespace Inkscape {
 namespace Text {
@@ -579,6 +580,8 @@ private:
         
         // a few functions for some of the more complicated style accesses
         float styleComputeFontSize() const;
+        /// The return value must be freed with pango_font_description_free()
+        PangoFontDescription *styleGetFontDescription() const;
         font_instance *styleGetFontInstance() const;
         Direction styleGetBlockProgression() const;
         Alignment styleGetAlignment(Direction para_direction, bool try_text_align) const;