[dia] Bug 676959 - Respect <text/> attribute font-size during import
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] Bug 676959 - Respect <text/> attribute font-size during import
- Date: Sat, 23 Jun 2012 12:25:40 +0000 (UTC)
commit f4e3e611a409b1fac19b6e1bc74b4823f205d37f
Author: Hans Breuer <hans breuer org>
Date: Sat Jun 23 14:24:14 2012 +0200
Bug 676959 - Respect <text/> attribute font-size during import
The previously committed check does not catch this change but
should have given the reminder to look here too for support
of font-size support.
lib/dia_svg.c | 5 ++++-
objects/custom/shape_info.c | 6 ++++++
plug-ins/svg/svg-import.c | 19 ++++++++++++++++++-
3 files changed, 28 insertions(+), 2 deletions(-)
---
diff --git a/lib/dia_svg.c b/lib/dia_svg.c
index b7f1a04..0e9ebb2 100644
--- a/lib/dia_svg.c
+++ b/lib/dia_svg.c
@@ -400,7 +400,10 @@ dia_svg_parse_style(xmlNodePtr node, DiaSvgStyle *s, real user_scale)
if (family || style || weight) {
if (s->font)
dia_font_unref (s->font);
- s->font = dia_font_new_from_style(DIA_FONT_SANS,s->font_height/*bogus*/);
+ /* given font_height is bogus, especially if not given at all
+ * or without unit ... see bug 665648 about invalid CSS
+ */
+ s->font = dia_font_new_from_style(DIA_FONT_SANS, s->font_height > 0 ? s->font_height : 1.0);
if (family) {
dia_font_set_any_family(s->font,family);
g_free(family);
diff --git a/objects/custom/shape_info.c b/objects/custom/shape_info.c
index 443502a..ae6ec0e 100644
--- a/objects/custom/shape_info.c
+++ b/objects/custom/shape_info.c
@@ -355,6 +355,12 @@ parse_svg_node(ShapeInfo *info, xmlNodePtr node, xmlNsPtr svg_ns,
xmlFree(str);
} else text->anchor.y = 0;
+ str = xmlGetProp(node, (const xmlChar *)"font-size");
+ if (str) {
+ text->s.font_height = g_ascii_strtod((gchar *) str, NULL);
+ xmlFree(str);
+ } else text->s.font_height = 0.8;
+
str = xmlNodeGetContent(node);
if (str) {
text->string = g_strdup((gchar *) str);
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index 0da83cb..cb8d8b6 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -385,6 +385,7 @@ read_text_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GList *list)
DiaSvgStyle *gs;
gboolean any_tspan = FALSE;
DiaMatrix *matrix = NULL;
+ real font_height = 0.0;
str = xmlGetProp(node, (const xmlChar *)"transform");
if (str) {
@@ -410,6 +411,16 @@ read_text_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GList *list)
xmlFree(str);
}
+ /* font-size can be given in the style (with absolute unit) or
+ * with it's own attribute. The latter is preferred - also by
+ * Dia's own export.
+ */
+ str = xmlGetProp(node, (const xmlChar *)"font-size");
+ if (str) {
+ font_height = get_value_as_cm((char *) str, NULL);
+ xmlFree(str);
+ }
+
str = xmlGetProp(node, (const xmlChar *)"text-anchor");
if (str) {
if (xmlStrcmp(str, (const xmlChar*)"middle") == 0)
@@ -469,7 +480,13 @@ read_text_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GList *list)
/* FIXME: looks like a leak but without this an imported svg is
* crashing on release */
prop->attr.font = dia_font_ref (gs->font);
- prop->attr.height = gs->font_height;
+ if (font_height > 0.0) {
+ /* font-size should be the line-height according to SVG spec,
+ * but see node_set_text_style() - round-trip first */
+ real font_scale = dia_font_get_height (prop->attr.font) / dia_font_get_size (prop->attr.font);
+ prop->attr.height = font_height * font_scale;
+ } else
+ prop->attr.height = gs->font_height;
/* when operating with default values foreground and background are intentionally swapped
* to avoid getting white text by default */
switch (gs->fill) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]