From: cyreve Date: Sat, 27 May 2006 16:56:44 +0000 (+0000) Subject: bug 1495265: css fallback fonts broken on win32 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4ffc73d2f7ced0101455af195be98c7f45d9efb2;p=inkscape.git bug 1495265: css fallback fonts broken on win32 --- diff --git a/src/libnrtype/Layout-TNG-Compute.cpp b/src/libnrtype/Layout-TNG-Compute.cpp index ca16291d0..4d83410bb 100755 --- a/src/libnrtype/Layout-TNG-Compute.cpp +++ b/src/libnrtype/Layout-TNG-Compute.cpp @@ -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(_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(); diff --git a/src/libnrtype/Layout-TNG-Input.cpp b/src/libnrtype/Layout-TNG-Input.cpp index 8b695af04..c8dc41e95 100755 --- a/src/libnrtype/Layout-TNG-Input.cpp +++ b/src/libnrtype/Layout-TNG-Input.cpp @@ -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() diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h index 5c86d3135..072aef878 100755 --- a/src/libnrtype/Layout-TNG.h +++ b/src/libnrtype/Layout-TNG.h @@ -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;