static Inkscape::XML::Node * sp_textpath_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPTextPath *textpath = SP_TEXTPATH(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:textPath"); } textpath->attributes.writeTo(repr); if (textpath->startOffset._set) { if (textpath->startOffset.unit == SVGLength::PERCENT) { Inkscape::SVGOStringStream os; os << (textpath->startOffset.computed * 100.0) << "%"; SP_OBJECT_REPR(textpath)->setAttribute("startOffset", os.str().c_str()); } else { /* FIXME: This logic looks rather undesirable if e.g. startOffset is to be in ems. */ sp_repr_set_svg_double(repr, "startOffset", textpath->startOffset.computed); } } if ( textpath->sourcePath->sourceHref ) repr->setAttribute("xlink:href", textpath->sourcePath->sourceHref); if ( flags&SP_OBJECT_WRITE_BUILD ) { GSList *l = NULL; for (SPObject* child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) { Inkscape::XML::Node* c_repr=NULL; if ( SP_IS_TSPAN(child) || SP_IS_TREF(child) ) { c_repr = child->updateRepr(xml_doc, NULL, flags); } else if ( SP_IS_TEXTPATH(child) ) { //c_repr = child->updateRepr(xml_doc, NULL, flags); // shouldn't happen } else if ( SP_IS_STRING(child) ) { c_repr = xml_doc->createTextNode(SP_STRING(child)->string.c_str()); } if ( c_repr ) l = g_slist_prepend(l, c_repr); } while ( l ) { repr->addChild((Inkscape::XML::Node *) l->data, NULL); Inkscape::GC::release((Inkscape::XML::Node *) l->data); l = g_slist_remove(l, l->data); } } else { for (SPObject* child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) { if ( SP_IS_TSPAN(child) || SP_IS_TREF(child) ) { child->updateRepr(flags); } else if ( SP_IS_TEXTPATH(child) ) { //c_repr = child->updateRepr(xml_doc, NULL, flags); // shouldn't happen } else if ( SP_IS_STRING(child) ) { SP_OBJECT_REPR(child)->setContent(SP_STRING(child)->string.c_str()); } } } if (((SPObjectClass *) textpath_parent_class)->write) ((SPObjectClass *) textpath_parent_class)->write(object, xml_doc, repr, flags); return repr; }
Inkscape::XML::Node* SPTSpan::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:tspan"); } this->attributes.writeTo(repr); if ( flags&SP_OBJECT_WRITE_BUILD ) { GSList *l = NULL; for (SPObject* child = this->firstChild() ; child ; child = child->getNext() ) { Inkscape::XML::Node* c_repr=NULL; if ( SP_IS_TSPAN(child) || SP_IS_TREF(child) ) { c_repr = child->updateRepr(xml_doc, NULL, flags); } else if ( SP_IS_TEXTPATH(child) ) { //c_repr = child->updateRepr(xml_doc, NULL, flags); // shouldn't happen } else if ( SP_IS_STRING(child) ) { c_repr = xml_doc->createTextNode(SP_STRING(child)->string.c_str()); } if ( c_repr ) { l = g_slist_prepend(l, c_repr); } } while ( l ) { repr->addChild((Inkscape::XML::Node *) l->data, NULL); Inkscape::GC::release((Inkscape::XML::Node *) l->data); l = g_slist_remove(l, l->data); } } else { for (SPObject* child = this->firstChild() ; child ; child = child->getNext() ) { if ( SP_IS_TSPAN(child) || SP_IS_TREF(child) ) { child->updateRepr(flags); } else if ( SP_IS_TEXTPATH(child) ) { //c_repr = child->updateRepr(xml_doc, NULL, flags); // shouldn't happen } else if ( SP_IS_STRING(child) ) { child->getRepr()->setContent(SP_STRING(child)->string.c_str()); } } } SPItem::write(xml_doc, repr, flags); return repr; }
/** * Returns true if a tref is fully contained in the confines of the given * iterators and layout (or if there is no tref). */ bool sp_tref_fully_contained(SPObject *start_item, Glib::ustring::iterator &start, SPObject *end_item, Glib::ustring::iterator &end) { bool fully_contained = false; if (start_item && end_item) { // If neither the beginning or the end is a tref then we return true (whether there // is a tref in the innards or not, because if there is one then it must be totally // contained) if (!(SP_IS_STRING(start_item) && SP_IS_TREF(start_item->parent)) && !(SP_IS_STRING(end_item) && SP_IS_TREF(end_item->parent))) { fully_contained = true; } // Both the beginning and end are trefs; but in this case, the string iterators // must be at the right places else if ((SP_IS_STRING(start_item) && SP_IS_TREF(start_item->parent)) && (SP_IS_STRING(end_item) && SP_IS_TREF(end_item->parent))) { if (start == SP_STRING(start_item)->string.begin() && end == SP_STRING(start_item)->string.end()) { fully_contained = true; } } // If the beginning is a string that is a child of a tref, the iterator has to be // at the beginning of the item else if ((SP_IS_STRING(start_item) && SP_IS_TREF(start_item->parent)) && !(SP_IS_STRING(end_item) && SP_IS_TREF(end_item->parent))) { if (start == SP_STRING(start_item)->string.begin()) { fully_contained = true; } } // Same, but the for the end else if (!(SP_IS_STRING(start_item) && SP_IS_TREF(start_item->parent)) && (SP_IS_STRING(end_item) && SP_IS_TREF(end_item->parent))) { if (end == SP_STRING(start_item)->string.end()) { fully_contained = true; } } } return fully_contained; }
static Inkscape::XML::Node * sp_tspan_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPTSpan *tspan = SP_TSPAN(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:tspan"); } tspan->attributes.writeTo(repr); if ( flags&SP_OBJECT_WRITE_BUILD ) { GSList *l = NULL; for (SPObject* child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) { Inkscape::XML::Node* c_repr=NULL; if ( SP_IS_TSPAN(child) || SP_IS_TREF(child) ) { c_repr = child->updateRepr(xml_doc, NULL, flags); } else if ( SP_IS_TEXTPATH(child) ) { //c_repr = child->updateRepr(xml_doc, NULL, flags); // shouldn't happen } else if ( SP_IS_STRING(child) ) { c_repr = xml_doc->createTextNode(SP_STRING(child)->string.c_str()); } if ( c_repr ) l = g_slist_prepend(l, c_repr); } while ( l ) { repr->addChild((Inkscape::XML::Node *) l->data, NULL); Inkscape::GC::release((Inkscape::XML::Node *) l->data); l = g_slist_remove(l, l->data); } } else { for (SPObject* child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) { if ( SP_IS_TSPAN(child) || SP_IS_TREF(child) ) { child->updateRepr(flags); } else if ( SP_IS_TEXTPATH(child) ) { //c_repr = child->updateRepr(xml_doc, NULL, flags); // shouldn't happen } else if ( SP_IS_STRING(child) ) { SP_OBJECT_REPR(child)->setContent(SP_STRING(child)->string.c_str()); } } } if (((SPObjectClass *) tspan_parent_class)->write) ((SPObjectClass *) tspan_parent_class)->write(object, xml_doc, repr, flags); return repr; }
static void sp_string_release(SPObject *object) { SPString *string = SP_STRING(object); string->string.~ustring(); if (((SPObjectClass *) string_parent_class)->release) ((SPObjectClass *) string_parent_class)->release(object); }
static Inkscape::XML::Node * sp_flowpara_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { // SPFlowpara *group = SP_FLOWPARA (object); if ( flags&SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) repr = xml_doc->createElement("svg:flowPara"); GSList *l = NULL; for (SPObject* child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) { Inkscape::XML::Node* c_repr=NULL; if ( SP_IS_FLOWTSPAN (child) ) { c_repr = child->updateRepr(xml_doc, NULL, flags); } else if ( SP_IS_FLOWPARA (child) ) { c_repr = child->updateRepr(xml_doc, NULL, flags); } else if ( SP_IS_STRING(child) ) { c_repr = xml_doc->createTextNode(SP_STRING(child)->string.c_str()); } if ( c_repr ) l = g_slist_prepend (l, c_repr); } while ( l ) { repr->addChild((Inkscape::XML::Node *) l->data, NULL); Inkscape::GC::release((Inkscape::XML::Node *) l->data); l = g_slist_remove (l, l->data); } } else { for (SPObject* child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) { if ( SP_IS_FLOWTSPAN (child) ) { child->updateRepr(flags); } else if ( SP_IS_FLOWPARA (child) ) { child->updateRepr(flags); } else if ( SP_IS_STRING(child) ) { SP_OBJECT_REPR (child)->setContent(SP_STRING(child)->string.c_str()); } } } if (((SPObjectClass *) (flowpara_parent_class))->write) ((SPObjectClass *) (flowpara_parent_class))->write (object, xml_doc, repr, flags); return repr; }
void SPString::read_content() { SPString* object = this; SPString *string = SP_STRING(object); string->string.clear(); //XML Tree being used directly here while it shouldn't be. gchar const *xml_string = string->getRepr()->content(); // see algorithms described in svg 1.1 section 10.15 if (object->xml_space.value == SP_XML_SPACE_PRESERVE) { for ( ; *xml_string ; xml_string = g_utf8_next_char(xml_string) ) { gunichar c = g_utf8_get_char(xml_string); if ((c == 0xa) || (c == 0xd) || (c == '\t')) { c = ' '; } string->string += c; } } else { bool whitespace = false; for ( ; *xml_string ; xml_string = g_utf8_next_char(xml_string) ) { gunichar c = g_utf8_get_char(xml_string); if ((c == 0xa) || (c == 0xd)) { continue; } if ((c == ' ') || (c == '\t')) { whitespace = true; } else { if (whitespace && (!string->string.empty() || (object->getPrev() != NULL))) { string->string += ' '; } string->string += c; whitespace = false; } } if (whitespace && object->getRepr()->next() != NULL) { // can't use SPObject::getNext() when the SPObject tree is still being built string->string += ' '; } } object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); }