diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2019-10-01 10:37:50 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2019-10-01 10:37:50 +0000 |
| commit | a48a5301a4d8912d717dc6e393608b8abb55a086 (patch) | |
| tree | 9db87354f5c2e300b3765efc0d61f71ba694296e /src | |
| parent | Use two bounding box caches instead of one (diff) | |
| download | inkscape-a48a5301a4d8912d717dc6e393608b8abb55a086.tar.gz inkscape-a48a5301a4d8912d717dc6e393608b8abb55a086.zip | |
Support "lang" and "xml:lang" attributes.
Partial fix for https://gitlab.com/inkscape/inbox/issues/951
Diffstat (limited to 'src')
| -rw-r--r-- | src/attributes.cpp | 1 | ||||
| -rw-r--r-- | src/attributes.h | 1 | ||||
| -rw-r--r-- | src/libnrtype/Layout-TNG-Compute.cpp | 8 | ||||
| -rw-r--r-- | src/libnrtype/Layout-TNG.h | 3 | ||||
| -rw-r--r-- | src/object/sp-object.cpp | 29 | ||||
| -rw-r--r-- | src/object/sp-object.h | 1 |
6 files changed, 41 insertions, 2 deletions
diff --git a/src/attributes.cpp b/src/attributes.cpp index 7353c35ed..49ec997ec 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -409,6 +409,7 @@ static SPStyleProp const props[] = { /* XML */ {SP_ATTR_XML_SPACE, "xml:space"}, + {SP_ATTR_XML_LANG, "xml:lang"}, /* typeset */ {SP_ATTR_TEXT_NOMARKUP, "inkscape:srcNoMarkup"}, diff --git a/src/attributes.h b/src/attributes.h index 7a49e2808..d1d4c5aa7 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -415,6 +415,7 @@ enum SPAttributeEnum : unsigned { /* XML */ SP_ATTR_XML_SPACE, + SP_ATTR_XML_LANG, /* typeset */ SP_ATTR_TEXT_NOMARKUP, diff --git a/src/libnrtype/Layout-TNG-Compute.cpp b/src/libnrtype/Layout-TNG-Compute.cpp index 03ccc62d7..aad2744b5 100644 --- a/src/libnrtype/Layout-TNG-Compute.cpp +++ b/src/libnrtype/Layout-TNG-Compute.cpp @@ -1148,6 +1148,14 @@ void Layout::Calculator::_buildPangoItemizationForPara(ParagraphInfo *para) con pango_attr_list_insert(attributes_list, attribute_font_features); #endif + // Set language + SPObject * object = static_cast<SPObject *>(text_source->source_cookie); + if (!object->lang.empty()) { + PangoLanguage* language = pango_language_from_string(object->lang.c_str()); + PangoAttribute *attribute_language = pango_attr_language_new( language ); + pango_attr_list_insert(attributes_list, attribute_language); + } + // ownership of attribute is assumed by the list font->Unref(); } diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h index 4f096abab..596e112b3 100644 --- a/src/libnrtype/Layout-TNG.h +++ b/src/libnrtype/Layout-TNG.h @@ -718,7 +718,8 @@ private: std::vector<SVGLength> rotate; SVGLength textLength; LengthAdjust lengthAdjust; - + Glib::ustring lang; + // a few functions for some of the more complicated style accesses /// The return value must be freed with pango_font_description_free() PangoFontDescription *styleGetFontDescription() const; diff --git a/src/object/sp-object.cpp b/src/object/sp-object.cpp index 1d7ae6396..dabf5219a 100644 --- a/src/object/sp-object.cpp +++ b/src/object/sp-object.cpp @@ -657,8 +657,16 @@ void SPObject::build(SPDocument *document, Inkscape::XML::Node *repr) { debug("id=%p, typename=%s", object, g_type_name_from_instance((GTypeInstance*)object)); object->readAttr("xml:space"); + object->readAttr("lang"); + object->readAttr("xml:lang"); // "xml:lang" overrides "lang" per spec, read it last. object->readAttr("inkscape:label"); object->readAttr("inkscape:collect"); + + // Inherit if not set + if (lang.empty() && object->parent) { + lang = object->parent->lang; + } + if(object->cloned && (repr->attribute("id")) ) // The cases where this happens are when the "original" has no id. This happens // if it is a SPString (a TextNode, e.g. in a <title>), or when importing // stuff externally modified to have no id. @@ -888,6 +896,7 @@ void SPObject::set(SPAttributeEnum key, gchar const* value) { SPObject* object = this; switch (key) { + case SP_ATTR_ID: //XML Tree being used here. @@ -928,6 +937,7 @@ void SPObject::set(SPAttributeEnum key, gchar const* value) { object->_default_label = nullptr; } break; + case SP_ATTR_INKSCAPE_LABEL: g_free(object->_label); if (value) { @@ -938,6 +948,7 @@ void SPObject::set(SPAttributeEnum key, gchar const* value) { g_free(object->_default_label); object->_default_label = nullptr; break; + case SP_ATTR_INKSCAPE_COLLECT: if ( value && !std::strcmp(value, "always") ) { object->setCollectionPolicy(SPObject::ALWAYS_COLLECT); @@ -945,6 +956,7 @@ void SPObject::set(SPAttributeEnum key, gchar const* value) { object->setCollectionPolicy(SPObject::COLLECT_WITH_PARENT); } break; + case SP_ATTR_XML_SPACE: if (value && !std::strcmp(value, "preserve")) { object->xml_space.value = SP_XML_SPACE_PRESERVE; @@ -959,10 +971,26 @@ void SPObject::set(SPAttributeEnum key, gchar const* value) { } object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); break; + + case SP_ATTR_LANG: + if (value) { + lang = value; + // To do: sanity check + } + break; + + case SP_ATTR_XML_LANG: + if (value) { + lang = value; + // To do: sanity check + } + break; + case SP_ATTR_STYLE: object->style->readFromObject( object ); object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); break; + default: break; } @@ -1373,7 +1401,6 @@ void SPObject::setAttribute(Glib::ustring const &key, Glib::ustring const &value value.empty() ? nullptr : value.c_str(), ex); } - void SPObject::removeAttribute(gchar const *key, SPException *ex) { /* If exception is not clear, return */ diff --git a/src/object/sp-object.h b/src/object/sp-object.h index baa2bf9c7..190f24253 100644 --- a/src/object/sp-object.h +++ b/src/object/sp-object.h @@ -210,6 +210,7 @@ public: unsigned int uflags : 8; unsigned int mflags : 8; SPIXmlSpace xml_space; + Glib::ustring lang; unsigned int hrefcount; /* number of xlink:href references */ unsigned int _total_hrefcount; /* our hrefcount + total descendants */ SPDocument *document; /* Document we are part of */ |
