summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Hughes <cyreve@gmail.com>2006-05-27 16:56:44 +0000
committercyreve <cyreve@users.sourceforge.net>2006-05-27 16:56:44 +0000
commit7afa4e18cef85b197fe438fe15c1c2681265b1ed (patch)
treee68487ca5d8b19a357207d97f6666b3810a50173 /src
parentpatch from bug 1474575 (diff)
downloadinkscape-7afa4e18cef85b197fe438fe15c1c2681265b1ed.tar.gz
inkscape-7afa4e18cef85b197fe438fe15c1c2681265b1ed.zip
bug 1495265: css fallback fonts broken on win32
(bzr r1029)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/libnrtype/Layout-TNG-Compute.cpp8
-rwxr-xr-xsrc/libnrtype/Layout-TNG-Input.cpp45
-rwxr-xr-xsrc/libnrtype/Layout-TNG.h3
3 files changed, 46 insertions, 10 deletions
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<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();
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
@@ -253,12 +253,47 @@ static const Layout::EnumConversionItem enum_convert_spstyle_variant_to_pango_va
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;