summaryrefslogtreecommitdiffstats
path: root/src/sp-text.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp-text.cpp')
-rw-r--r--src/sp-text.cpp66
1 files changed, 60 insertions, 6 deletions
diff --git a/src/sp-text.cpp b/src/sp-text.cpp
index 1cd690729..755a4f769 100644
--- a/src/sp-text.cpp
+++ b/src/sp-text.cpp
@@ -81,6 +81,10 @@ void SPText::build(SPDocument *doc, Inkscape::XML::Node *repr) {
this->readAttr( "dy" );
this->readAttr( "rotate" );
+ // textLength and friends
+ this->readAttr( "textLength" );
+ this->readAttr( "lengthAdjust" );
+
// SVG 2 Auto wrapped text
this->readAttr( "width" );
this->readAttr( "height" );
@@ -403,6 +407,10 @@ Geom::Affine SPText::set_transform(Geom::Affine const &xform) {
}
}
+ // we cannot optimize text with textLength because it may show different size than specified
+ if (this->attributes.getTextLength()->_set)
+ return xform;
+
/* This function takes care of scaling & translation only, we return whatever parts we can't
handle. */
@@ -466,6 +474,13 @@ unsigned SPText::_buildLayoutInput(SPObject *root, Inkscape::Text::Layout::Optio
if (SP_IS_TEXT(root)) {
SP_TEXT(root)->attributes.mergeInto(&optional_attrs, parent_optional_attrs, parent_attrs_offset, true, true);
+ if (SP_TEXT(root)->attributes.getTextLength()->_set) { // set textLength on the entire layout, see note in TNG-Layout.h
+ layout.textLength._set = true;
+ layout.textLength.value = SP_TEXT(root)->attributes.getTextLength()->value;
+ layout.textLength.computed = SP_TEXT(root)->attributes.getTextLength()->computed;
+ layout.textLength.unit = SP_TEXT(root)->attributes.getTextLength()->unit;
+ layout.lengthAdjust = (Inkscape::Text::Layout::LengthAdjust) SP_TEXT(root)->attributes.getLengthAdjust();
+ }
}
else if (SP_IS_TSPAN(root)) {
SPTSpan *tspan = SP_TSPAN(root);
@@ -611,6 +626,8 @@ void TextTagAttributes::readFrom(Inkscape::XML::Node const *node)
readSingleAttribute(SP_ATTR_DX, node->attribute("dx"));
readSingleAttribute(SP_ATTR_DY, node->attribute("dy"));
readSingleAttribute(SP_ATTR_ROTATE, node->attribute("rotate"));
+ readSingleAttribute(SP_ATTR_TEXTLENGTH, node->attribute("textLength"));
+ readSingleAttribute(SP_ATTR_LENGTHADJUST, node->attribute("lengthAdjust"));
}
bool TextTagAttributes::readSingleAttribute(unsigned key, gchar const *value)
@@ -622,6 +639,16 @@ bool TextTagAttributes::readSingleAttribute(unsigned key, gchar const *value)
case SP_ATTR_DX: attr_vector = &attributes.dx; break;
case SP_ATTR_DY: attr_vector = &attributes.dy; break;
case SP_ATTR_ROTATE: attr_vector = &attributes.rotate; break;
+ case SP_ATTR_TEXTLENGTH:
+ attributes.textLength.readOrUnset(value);
+ return true;
+ break;
+ case SP_ATTR_LENGTHADJUST:
+ attributes.lengthAdjust = (value && !strcmp(value, "spacingAndGlyphs")?
+ Inkscape::Text::Layout::LENGTHADJUST_SPACINGANDGLYPHS :
+ Inkscape::Text::Layout::LENGTHADJUST_SPACING); // default is "spacing"
+ return true;
+ break;
default: return false;
}
@@ -632,14 +659,34 @@ bool TextTagAttributes::readSingleAttribute(unsigned key, gchar const *value)
void TextTagAttributes::writeTo(Inkscape::XML::Node *node) const
{
- writeSingleAttribute(node, "x", attributes.x);
- writeSingleAttribute(node, "y", attributes.y);
- writeSingleAttribute(node, "dx", attributes.dx);
- writeSingleAttribute(node, "dy", attributes.dy);
- writeSingleAttribute(node, "rotate", attributes.rotate);
+ writeSingleAttributeVector(node, "x", attributes.x);
+ writeSingleAttributeVector(node, "y", attributes.y);
+ writeSingleAttributeVector(node, "dx", attributes.dx);
+ writeSingleAttributeVector(node, "dy", attributes.dy);
+ writeSingleAttributeVector(node, "rotate", attributes.rotate);
+
+ writeSingleAttributeLength(node, "textLength", attributes.textLength);
+
+ if (attributes.textLength._set) {
+ if (attributes.lengthAdjust == Inkscape::Text::Layout::LENGTHADJUST_SPACING) {
+ node->setAttribute("lengthAdjust", "spacing");
+ } else if (attributes.lengthAdjust == Inkscape::Text::Layout::LENGTHADJUST_SPACINGANDGLYPHS) {
+ node->setAttribute("lengthAdjust", "spacingAndGlyphs");
+ }
+ }
+}
+
+void TextTagAttributes::writeSingleAttributeLength(Inkscape::XML::Node *node, gchar const *key, const SVGLength &length)
+{
+ if (length._set) {
+ gchar single_value_string[32];
+ g_ascii_formatd(single_value_string, sizeof (single_value_string), "%.8g", length.computed);
+ node->setAttribute(key, single_value_string);
+ } else
+ node->setAttribute(key, NULL);
}
-void TextTagAttributes::writeSingleAttribute(Inkscape::XML::Node *node, gchar const *key, std::vector<SVGLength> const &attr_vector)
+void TextTagAttributes::writeSingleAttributeVector(Inkscape::XML::Node *node, gchar const *key, std::vector<SVGLength> const &attr_vector)
{
if (attr_vector.empty())
node->setAttribute(key, NULL);
@@ -697,6 +744,13 @@ void TextTagAttributes::mergeInto(Inkscape::Text::Layout::OptionalTextTagAttrs *
mergeSingleAttribute(&output->dx, parent_attrs.dx, parent_attrs_offset, copy_dxdyrotate ? &attributes.dx : NULL);
mergeSingleAttribute(&output->dy, parent_attrs.dy, parent_attrs_offset, copy_dxdyrotate ? &attributes.dy : NULL);
mergeSingleAttribute(&output->rotate, parent_attrs.rotate, parent_attrs_offset, copy_dxdyrotate ? &attributes.rotate : NULL);
+ if (attributes.textLength._set) { // only from current node, this is not inherited from parent
+ output->textLength.value = attributes.textLength.value;
+ output->textLength.computed = attributes.textLength.computed;
+ output->textLength.unit = attributes.textLength.unit;
+ output->textLength._set = attributes.textLength._set;
+ output->lengthAdjust = attributes.lengthAdjust;
+ }
}
void TextTagAttributes::mergeSingleAttribute(std::vector<SVGLength> *output_list, std::vector<SVGLength> const &parent_list, unsigned parent_offset, std::vector<SVGLength> const *overlay_list)