summaryrefslogtreecommitdiffstats
path: root/src/sp-text.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-03-14 16:37:50 +0000
committerJabiertxof <jtx@jtx.marker.es>2016-03-14 16:37:50 +0000
commitb8d22beef5345210ad27cdc2685083aeae6f8f3b (patch)
treed69b8bfd19d3627a8425a1b265c2abf229b05354 /src/sp-text.cpp
parentfixes for update to trunk (diff)
parent"Relative to" option for node alignment. (diff)
downloadinkscape-b8d22beef5345210ad27cdc2685083aeae6f8f3b.tar.gz
inkscape-b8d22beef5345210ad27cdc2685083aeae6f8f3b.zip
update to trunk
(bzr r13708.1.39)
Diffstat (limited to 'src/sp-text.cpp')
-rw-r--r--src/sp-text.cpp102
1 files changed, 68 insertions, 34 deletions
diff --git a/src/sp-text.cpp b/src/sp-text.cpp
index d351e58e3..4a5b1b1d6 100644
--- a/src/sp-text.cpp
+++ b/src/sp-text.cpp
@@ -93,7 +93,7 @@ void SPText::release() {
void SPText::set(unsigned int key, const gchar* value) {
//std::cout << "SPText::set: " << sp_attribute_name( key ) << ": " << (value?value:"Null") << std::endl;
- if (this->attributes.readSingleAttribute(key, value)) {
+ if (this->attributes.readSingleAttribute(key, value, style, &viewport)) {
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
} else {
switch (key) {
@@ -181,6 +181,16 @@ void SPText::update(SPCtx *ctx, guint flags) {
SP_OBJECT_CHILD_MODIFIED_FLAG |
SP_TEXT_LAYOUT_MODIFIED_FLAG ) )
{
+
+ SPItemCtx const *ictx = reinterpret_cast<SPItemCtx const *>(ctx);
+
+ double const w = ictx->viewport.width();
+ double const h = ictx->viewport.height();
+ double const em = style->font_size.computed;
+ double const ex = 0.5 * em; // fixme: get x height from pango or libnrtype.
+
+ attributes.update( em, ex, w, h );
+
/* fixme: It is not nice to have it here, but otherwise children content changes does not work */
/* fixme: Even now it may not work, as we are delayed */
/* fixme: So check modification flag everywhere immediate state is used */
@@ -292,15 +302,6 @@ Inkscape::XML::Node *SPText::write(Inkscape::XML::Document *xml_doc, Inkscape::X
this->attributes.writeTo(repr);
this->rebuildLayout(); // copied from update(), see LP Bug 1339305
- // deprecated attribute, but keep it around for backwards compatibility
- if (this->style->line_height.set && !this->style->line_height.inherit && !this->style->line_height.normal && this->style->line_height.unit == SP_CSS_UNIT_PERCENT) {
- Inkscape::SVGOStringStream os;
- os << (this->style->line_height.value * 100.0) << "%";
- this->getRepr()->setAttribute("sodipodi:linespacing", os.str().c_str());
- } else {
- this->getRepr()->setAttribute("sodipodi:linespacing", NULL);
- }
-
// SVG 2 Auto-wrapped text
if( this->width.computed > 0.0 ) {
sp_repr_set_svg_double(repr, "width", this->width.computed);
@@ -357,8 +358,11 @@ gchar* SPText::description() const {
char *n = xml_quote_strdup( style->font_family.value );
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
Inkscape::Util::Quantity q = Inkscape::Util::Quantity(style->font_size.computed, "px");
- GString *xs = g_string_new(q.string(SP_ACTIVE_DESKTOP->getNamedView()->display_units).c_str());
+ q.quantity *= this->i2doc_affine().descrim();
+ GString *xs = g_string_new(q.string(sp_style_get_css_unit_string(unit)).c_str());
char const *trunc = "";
Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) this);
@@ -576,7 +580,7 @@ unsigned SPText::_buildLayoutInput(SPObject *root, Inkscape::Text::Layout::Optio
SPString *str = dynamic_cast<SPString *>(child);
if (str) {
Glib::ustring const &string = str->string;
- // std::cout << " Appending: " << string << std::endl;
+ // std::cout << " Appending: >" << string << "<" << std::endl;
layout.appendText(string, root->style, child, &optional_attrs, child_attrs_offset + length);
length += string.length();
} else if (!sp_repr_is_meta_element(child->getRepr())) {
@@ -671,25 +675,30 @@ void SPText::_clearFlow(Inkscape::DrawingGroup *in_arena)
* TextTagAttributes implementation
*/
-void TextTagAttributes::readFrom(Inkscape::XML::Node const *node)
-{
- readSingleAttribute(SP_ATTR_X, node->attribute("x"));
- readSingleAttribute(SP_ATTR_Y, node->attribute("y"));
- 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)
+// Not used.
+// void TextTagAttributes::readFrom(Inkscape::XML::Node const *node)
+// {
+// readSingleAttribute(SP_ATTR_X, node->attribute("x"));
+// readSingleAttribute(SP_ATTR_Y, node->attribute("y"));
+// 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, SPStyle const *style, Geom::Rect const *viewport)
{
+ // std::cout << "TextTagAttributes::readSingleAttribute: key: " << key
+ // << " value: " << (value?value:"Null") << std::endl;
std::vector<SVGLength> *attr_vector;
+ bool update_x = false;
+ bool update_y = false;
switch (key) {
- case SP_ATTR_X: attr_vector = &attributes.x; break;
- case SP_ATTR_Y: attr_vector = &attributes.y; break;
- case SP_ATTR_DX: attr_vector = &attributes.dx; break;
- case SP_ATTR_DY: attr_vector = &attributes.dy; break;
+ case SP_ATTR_X: attr_vector = &attributes.x; update_x = true; break;
+ case SP_ATTR_Y: attr_vector = &attributes.y; update_y = true; break;
+ case SP_ATTR_DX: attr_vector = &attributes.dx; update_x = true; break;
+ case SP_ATTR_DY: attr_vector = &attributes.dy; update_y = true; break;
case SP_ATTR_ROTATE: attr_vector = &attributes.rotate; break;
case SP_ATTR_TEXTLENGTH:
attributes.textLength.readOrUnset(value);
@@ -706,6 +715,19 @@ bool TextTagAttributes::readSingleAttribute(unsigned key, gchar const *value)
// FIXME: sp_svg_length_list_read() amalgamates repeated separators. This prevents unset values.
*attr_vector = sp_svg_length_list_read(value);
+
+ if( (update_x || update_y) && style != NULL && viewport != NULL ) {
+ double const w = viewport->width();
+ double const h = viewport->height();
+ double const em = style->font_size.computed;
+ double const ex = em * 0.5;
+ for(std::vector<SVGLength>::iterator it = attr_vector->begin(); it != attr_vector->end(); ++it) {
+ if( update_x )
+ it->update( em, ex, w );
+ if( update_y )
+ it->update( em, ex, h );
+ }
+ }
return true;
}
@@ -728,12 +750,26 @@ void TextTagAttributes::writeTo(Inkscape::XML::Node *node) const
}
}
+void TextTagAttributes::update( double em, double ex, double w, double h )
+{
+ for(std::vector<SVGLength>::iterator it = attributes.x.begin(); it != attributes.x.end(); ++it) {
+ it->update( em, ex, w );
+ }
+ for(std::vector<SVGLength>::iterator it = attributes.y.begin(); it != attributes.y.end(); ++it) {
+ it->update( em, ex, h );
+ }
+ for(std::vector<SVGLength>::iterator it = attributes.dx.begin(); it != attributes.dx.end(); ++it) {
+ it->update( em, ex, w );
+ }
+ for(std::vector<SVGLength>::iterator it = attributes.dy.begin(); it != attributes.dy.end(); ++it) {
+ it->update( em, ex, h );
+ }
+}
+
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);
+ node->setAttribute(key, length.write().c_str());
} else
node->setAttribute(key, NULL);
}
@@ -744,13 +780,11 @@ void TextTagAttributes::writeSingleAttributeVector(Inkscape::XML::Node *node, gc
node->setAttribute(key, NULL);
else {
Glib::ustring string;
- gchar single_value_string[32];
// FIXME: this has no concept of unset values because sp_svg_length_list_read() can't read them back in
for (std::vector<SVGLength>::const_iterator it = attr_vector.begin() ; it != attr_vector.end() ; ++it) {
- g_ascii_formatd(single_value_string, sizeof (single_value_string), "%.8g", it->computed);
if (!string.empty()) string += ' ';
- string += single_value_string;
+ string += it->write();
}
node->setAttribute(key, string.c_str());
}