X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fsp-tspan.cpp;h=0b3be70723fdb5ea22f8071247a63d2917dcb1ba;hb=76db360f5f052775326e6d406b9e1e9e2966e11a;hp=3339b2377e65ecf2d5638be2786593feffaac379;hpb=8d44186af89a0de0591b1cd1e5ec0d81d6c695e7;p=inkscape.git diff --git a/src/sp-tspan.cpp b/src/sp-tspan.cpp index 3339b2377..0b3be7072 100644 --- a/src/sp-tspan.cpp +++ b/src/sp-tspan.cpp @@ -27,11 +27,16 @@ # include "config.h" #endif +#include +#include +#include + #include #include "svg/stringstream.h" #include "attributes.h" #include "sp-use-reference.h" #include "sp-tspan.h" +#include "sp-tref.h" #include "sp-textpath.h" #include "text-editing.h" #include "style.h" @@ -53,7 +58,8 @@ static void sp_tspan_set(SPObject *object, unsigned key, gchar const *value); static void sp_tspan_update(SPObject *object, SPCtx *ctx, guint flags); static void sp_tspan_modified(SPObject *object, unsigned flags); static void sp_tspan_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags); -static Inkscape::XML::Node *sp_tspan_write(SPObject *object, Inkscape::XML::Node *repr, guint flags); +static Inkscape::XML::Node *sp_tspan_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); +static char *sp_tspan_description (SPItem *item); static SPItemClass *tspan_parent_class; @@ -101,6 +107,7 @@ sp_tspan_class_init(SPTSpanClass *classname) sp_object_class->write = sp_tspan_write; item_class->bbox = sp_tspan_bbox; + item_class->description = sp_tspan_description; } static void @@ -143,8 +150,7 @@ sp_tspan_set(SPObject *object, unsigned key, gchar const *value) SPTSpan *tspan = SP_TSPAN(object); if (tspan->attributes.readSingleAttribute(key, value)) { - if (tspan->role != SP_TSPAN_ROLE_LINE) - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } else { switch (key) { case SP_ATTR_SODIPODI_ROLE: @@ -197,7 +203,7 @@ sp_tspan_modified(SPObject *object, unsigned flags) } } -static void sp_tspan_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags) +static void sp_tspan_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const /*flags*/) { // find out the ancestor text which holds our layout SPObject *parent_text = SP_OBJECT(item); @@ -209,7 +215,7 @@ static void sp_tspan_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &tr // Add stroke width SPStyle* style=SP_OBJECT_STYLE (item); - if (style->stroke.type != SP_PAINT_TYPE_NONE) { + if (!style->stroke.isNone()) { double const scale = expansion(transform); if ( fabs(style->stroke_width.computed * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord double const width = MAX(0.125, style->stroke_width.computed * scale); @@ -224,11 +230,10 @@ static void sp_tspan_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &tr } static Inkscape::XML::Node * -sp_tspan_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) +sp_tspan_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPTSpan *tspan = SP_TSPAN(object); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object)); - + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:tspan"); } @@ -239,10 +244,10 @@ sp_tspan_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) 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) ) { - c_repr = child->updateRepr(NULL, flags); + 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(NULL, flags); // shouldn't happen + //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()); } @@ -255,10 +260,10 @@ sp_tspan_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) } } else { for (SPObject* child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) { - if ( SP_IS_TSPAN(child) ) { + if ( SP_IS_TSPAN(child) || SP_IS_TREF(child) ) { child->updateRepr(flags); } else if ( SP_IS_TEXTPATH(child) ) { - //c_repr = child->updateRepr(NULL, flags); // shouldn't happen + //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()); } @@ -266,11 +271,20 @@ sp_tspan_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) } if (((SPObjectClass *) tspan_parent_class)->write) - ((SPObjectClass *) tspan_parent_class)->write(object, repr, flags); + ((SPObjectClass *) tspan_parent_class)->write(object, xml_doc, repr, flags); return repr; } +static char * +sp_tspan_description(SPItem *item) +{ + g_return_val_if_fail(SP_IS_TSPAN(item), NULL); + + return g_strdup(_("Text span")); +} + + /*##################################################### # SPTEXTPATH #####################################################*/ @@ -284,7 +298,7 @@ static void sp_textpath_release(SPObject *object); static void sp_textpath_set(SPObject *object, unsigned key, gchar const *value); static void sp_textpath_update(SPObject *object, SPCtx *ctx, guint flags); static void sp_textpath_modified(SPObject *object, unsigned flags); -static Inkscape::XML::Node *sp_textpath_write(SPObject *object, Inkscape::XML::Node *repr, guint flags); +static Inkscape::XML::Node *sp_textpath_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static SPItemClass *textpath_parent_class; @@ -487,11 +501,10 @@ sp_textpath_modified(SPObject *object, unsigned flags) } } static Inkscape::XML::Node * -sp_textpath_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) +sp_textpath_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPTextPath *textpath = SP_TEXTPATH(object); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object)); - + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:textPath"); } @@ -515,10 +528,10 @@ sp_textpath_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) 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) ) { - c_repr = child->updateRepr(NULL, flags); + 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(NULL, flags); // shouldn't happen + //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()); } @@ -531,10 +544,10 @@ sp_textpath_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) } } else { for (SPObject* child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) { - if ( SP_IS_TSPAN(child) ) { + if ( SP_IS_TSPAN(child) || SP_IS_TREF(child) ) { child->updateRepr(flags); } else if ( SP_IS_TEXTPATH(child) ) { - //c_repr = child->updateRepr(NULL, flags); // shouldn't happen + //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()); } @@ -542,7 +555,7 @@ sp_textpath_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) } if (((SPObjectClass *) textpath_parent_class)->write) - ((SPObjectClass *) textpath_parent_class)->write(object, repr, flags); + ((SPObjectClass *) textpath_parent_class)->write(object, xml_doc, repr, flags); return repr; } @@ -565,7 +578,7 @@ sp_textpath_to_text(SPObject *tp) SPObject *text = SP_OBJECT_PARENT(tp); NRRect bbox; - sp_item_invoke_bbox(SP_ITEM(text), &bbox, sp_item_i2doc_affine(SP_ITEM(text)), TRUE); + sp_item_invoke_bbox(SP_ITEM(text), &bbox, from_2geom(sp_item_i2doc_affine(SP_ITEM(text))), TRUE); NR::Point xy(bbox.x0, bbox.y0); // make a list of textpath children @@ -576,10 +589,10 @@ sp_textpath_to_text(SPObject *tp) for ( GSList *i = tp_reprs ; i ; i = i->next ) { // make a copy of each textpath child - Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) i->data)->duplicate(); + Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) i->data)->duplicate(SP_OBJECT_REPR(text)->document()); // remove the old repr from under textpath SP_OBJECT_REPR(tp)->removeChild((Inkscape::XML::Node *) i->data); - // put its copy into under textPath + // put its copy under text SP_OBJECT_REPR(text)->addChild(copy, NULL); // fixme: copy id }