Inkscape::XML::Node* SPUse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:use"); } SPItem::write(xml_doc, repr, flags); sp_repr_set_svg_double(repr, "x", this->x.computed); sp_repr_set_svg_double(repr, "y", this->y.computed); repr->setAttribute("width", sp_svg_length_write_with_units(this->width).c_str()); repr->setAttribute("height", sp_svg_length_write_with_units(this->height).c_str()); if (this->ref->getURI()) { gchar *uri_string = this->ref->getURI()->toString(); repr->setAttribute("xlink:href", uri_string); g_free(uri_string); } if (SP_IS_SHAPE(this->child)) { SP_SHAPE(this->child)->set_shape(); // evaluate SPCurve of child } else if (SP_IS_TEXT(this->child)) { SP_TEXT(this->child)->rebuildLayout(); // refresh Layout, LP Bug 1339305 } else if (SP_IS_FLOWTEXT(this->child)) { if (SP_IS_FLOWREGION(SP_FLOWTEXT(this->child)->firstChild())) SP_FLOWREGION(SP_FLOWTEXT(this->child)->firstChild())->UpdateComputed(); SP_FLOWTEXT(this->child)->rebuildLayout(); } return repr; }
/** * Writes the object into the repr object, then calls the parent's write routine. */ static Inkscape::XML::Node * sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPRoot *root = SP_ROOT(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:svg"); } if (flags & SP_OBJECT_WRITE_EXT) { repr->setAttribute("inkscape:version", Inkscape::version_string); } if ( !repr->attribute("version") ) { gchar* myversion = sp_version_to_string(root->version.svg); repr->setAttribute("version", myversion); g_free(myversion); } if (fabs(root->x.computed) > 1e-9) sp_repr_set_svg_double(repr, "x", root->x.computed); if (fabs(root->y.computed) > 1e-9) sp_repr_set_svg_double(repr, "y", root->y.computed); /* Unlike all other SPObject, here we want to preserve absolute units too (and only here, * according to the recommendation in http://www.w3.org/TR/SVG11/coords.html#Units). */ repr->setAttribute("width", sp_svg_length_write_with_units(root->width).c_str()); repr->setAttribute("height", sp_svg_length_write_with_units(root->height).c_str()); if (root->viewBox_set) { Inkscape::SVGOStringStream os; os << root->viewBox.left() << " " << root->viewBox.top() << " " << root->viewBox.width() << " " << root->viewBox.height(); repr->setAttribute("viewBox", os.str().c_str()); } if (((SPObjectClass *) (parent_class))->write) ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); return repr; }
Inkscape::XML::Node* SPUse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:use"); } SPItem::write(xml_doc, repr, flags); sp_repr_set_svg_double(repr, "x", this->x.computed); sp_repr_set_svg_double(repr, "y", this->y.computed); repr->setAttribute("width", sp_svg_length_write_with_units(this->width).c_str()); repr->setAttribute("height", sp_svg_length_write_with_units(this->height).c_str()); if (this->ref->getURI()) { gchar *uri_string = this->ref->getURI()->toString(); repr->setAttribute("xlink:href", uri_string); g_free(uri_string); } SPShape *shape = dynamic_cast<SPShape *>(child); if (shape) { shape->set_shape(); // evaluate SPCurve of child } else { SPText *text = dynamic_cast<SPText *>(child); if (text) { text->rebuildLayout(); // refresh Layout, LP Bug 1339305 } else { SPFlowtext *flowtext = dynamic_cast<SPFlowtext *>(child); if (flowtext) { SPFlowregion *flowregion = dynamic_cast<SPFlowregion *>(flowtext->firstChild()); if (flowregion) { flowregion->UpdateComputed(); } flowtext->rebuildLayout(); } } } return repr; }