From ab143333746e25648b253f13c0539adff089b1b6 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Fri, 24 Jun 2011 00:22:07 +0200 Subject: Remove more of libnr (bzr r10347.1.2) --- src/sp-flowtext.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/sp-flowtext.cpp') diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index d7bc0053f..9db0d29b2 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -361,7 +361,10 @@ sp_flowtext_print(SPItem *item, SPPrintContext *ctx) if (!bbox_maybe) { return; } - bbox = NRRect(from_2geom(*bbox_maybe)); + bbox.x0 = bbox_maybe->min()[Geom::X]; + bbox.y0 = bbox_maybe->min()[Geom::Y]; + bbox.x1 = bbox_maybe->max()[Geom::X]; + bbox.y1 = bbox_maybe->max()[Geom::Y]; NRRect dbox; dbox.x0 = 0.0; -- cgit v1.2.3 From 8911d9a8ca0c7f4ef1476b2f056adf2afa4e99cd Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Thu, 30 Jun 2011 22:46:15 +0200 Subject: Implement decent snapping to text (baseline & anchor), and provide a toggle button for this (as requested in LP bug #727281 ) (bzr r10392) --- src/sp-flowtext.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/sp-flowtext.cpp') diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index d7bc0053f..3413999a9 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -388,15 +388,17 @@ static gchar *sp_flowtext_description(SPItem *item) } } -static void sp_flowtext_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const */*snapprefs*/) +static void sp_flowtext_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) { - // Choose a point on the baseline for snapping from or to, with the horizontal position - // of this point depending on the text alignment (left vs. right) - Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item); - if (layout != NULL && layout->outputExists()) { - boost::optional pt = layout->baselineAnchorPoint(); - if (pt) { - p.push_back(Inkscape::SnapCandidatePoint((*pt) * item->i2d_affine(), Inkscape::SNAPSOURCE_TEXT_BASELINE, Inkscape::SNAPTARGET_TEXT_BASELINE)); + if (snapprefs->getSnapTextBaseline()) { + // Choose a point on the baseline for snapping from or to, with the horizontal position + // of this point depending on the text alignment (left vs. right) + Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item); + if (layout != NULL && layout->outputExists()) { + boost::optional pt = layout->baselineAnchorPoint(); + if (pt) { + p.push_back(Inkscape::SnapCandidatePoint((*pt) * item->i2d_affine(), Inkscape::SNAPSOURCE_TEXT_ANCHOR, Inkscape::SNAPTARGET_TEXT_ANCHOR)); + } } } } -- cgit v1.2.3 From 2be2cf32db0668dc64512a98f6c2394152bd10cc Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 16 Jul 2011 00:42:39 -0700 Subject: Cleanup of oudated/redundant SP_ITEM() macro use. (bzr r10461) --- src/sp-flowtext.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/sp-flowtext.cpp') diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index ab545919f..694e21dbd 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -554,12 +554,11 @@ void SPFlowtext::_clearFlow(NRArenaGroup *in_arena) } } -Inkscape::XML::Node * -SPFlowtext::getAsText() +Inkscape::XML::Node *SPFlowtext::getAsText() { - if (!this->layout.outputExists()) return NULL; - - SPItem *item = SP_ITEM(this); + if (!this->layout.outputExists()) { + return NULL; + } Inkscape::XML::Document *xml_doc = this->document->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("svg:text"); @@ -588,7 +587,7 @@ SPFlowtext::getAsText() // set x,y attributes only when we need to bool set_x = false; bool set_y = false; - if (!item->transform.isIdentity()) { + if (!this->transform.isIdentity()) { set_x = set_y = true; } else { Inkscape::Text::Layout::iterator it_chunk_start = it; -- cgit v1.2.3 From eed6e9c2c229b10911a23976c47da79fc70a5b87 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 17 Jul 2011 21:47:09 +0200 Subject: - rename SPItem::i2d_affine to i2dt_affine, to clarify that it is item-to-desktop, not item-to-document. This should make it easier to spot bugs. - tag some instances where the document-to-desktop transform has been hardcoded (bzr r10466) --- src/sp-flowtext.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/sp-flowtext.cpp') diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index 694e21dbd..87266464c 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -371,7 +371,7 @@ sp_flowtext_print(SPItem *item, SPPrintContext *ctx) dbox.y0 = 0.0; dbox.x1 = item->document->getWidth(); dbox.y1 = item->document->getHeight(); - Geom::Affine const ctm (item->i2d_affine()); + Geom::Affine const ctm (item->i2dt_affine()); group->layout.print(ctx, &pbox, &dbox, &bbox, ctm); } @@ -400,7 +400,7 @@ static void sp_flowtext_snappoints(SPItem const *item, std::vectoroutputExists()) { boost::optional pt = layout->baselineAnchorPoint(); if (pt) { - p.push_back(Inkscape::SnapCandidatePoint((*pt) * item->i2d_affine(), Inkscape::SNAPSOURCE_TEXT_ANCHOR, Inkscape::SNAPTARGET_TEXT_ANCHOR)); + p.push_back(Inkscape::SnapCandidatePoint((*pt) * item->i2dt_affine(), Inkscape::SNAPSOURCE_TEXT_ANCHOR, Inkscape::SNAPTARGET_TEXT_ANCHOR)); } } } -- cgit v1.2.3 From 4dd33aa4d5c57706c7f64f63391174954160a308 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 6 Aug 2011 14:18:32 +0200 Subject: Rewrite NRArenaItem hierarchy into C++ (bzr r10347.1.21) --- src/sp-flowtext.cpp | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'src/sp-flowtext.cpp') diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index 87266464c..cbdc8684b 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -31,7 +31,7 @@ #include "livarot/Shape.h" -#include "display/nr-arena-glyphs.h" +#include "display/drawing-text.h" static void sp_flowtext_class_init(SPFlowtextClass *klass); @@ -50,7 +50,7 @@ static void sp_flowtext_bbox(SPItem const *item, NRRect *bbox, Geom::Affine cons static void sp_flowtext_print(SPItem *item, SPPrintContext *ctx); static gchar *sp_flowtext_description(SPItem *item); static void sp_flowtext_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs); -static NRArenaItem *sp_flowtext_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags); +static Inkscape::DrawingItem *sp_flowtext_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags); static void sp_flowtext_hide(SPItem *item, unsigned key); static SPItemClass *parent_class; @@ -179,10 +179,11 @@ static void sp_flowtext_update(SPObject *object, SPCtx *ctx, unsigned flags) NRRect paintbox; group->invoke_bbox( &paintbox, Geom::identity(), TRUE); for (SPItemView *v = group->display; v != NULL; v = v->next) { - group->_clearFlow(NR_ARENA_GROUP(v->arenaitem)); - nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), object->style); + Inkscape::DrawingGroup *g = dynamic_cast(v->arenaitem); + group->_clearFlow(g); + g->setStyle(object->style); // pass the bbox of the flowtext object as paintbox (used for paintserver fills) - group->layout.show(NR_ARENA_GROUP(v->arenaitem), &paintbox); + group->layout.show(g, &paintbox); } } @@ -200,9 +201,10 @@ static void sp_flowtext_modified(SPObject *object, guint flags) NRRect paintbox; text->invoke_bbox( &paintbox, Geom::identity(), TRUE); for (SPItemView* v = text->display; v != NULL; v = v->next) { - text->_clearFlow(NR_ARENA_GROUP(v->arenaitem)); - nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), object->style); - text->layout.show(NR_ARENA_GROUP(v->arenaitem), &paintbox); + Inkscape::DrawingGroup *g = dynamic_cast(v->arenaitem); + text->_clearFlow(g); + g->setStyle(object->style); + text->layout.show(g, &paintbox); } } @@ -406,14 +408,13 @@ static void sp_flowtext_snappoints(SPItem const *item, std::vectorstyle); + Inkscape::DrawingGroup *flowed = new Inkscape::DrawingGroup(arena); + flowed->setPickChildren(false); + flowed->setStyle(group->style); // pass the bbox of the flowtext object as paintbox (used for paintserver fills) NRRect paintbox; @@ -541,17 +542,9 @@ void SPFlowtext::rebuildLayout() //g_print(layout.dumpAsText().c_str()); } -void SPFlowtext::_clearFlow(NRArenaGroup *in_arena) +void SPFlowtext::_clearFlow(Inkscape::DrawingGroup *in_arena) { - nr_arena_item_request_render(NR_ARENA_ITEM(in_arena)); - for (NRArenaItem *child = in_arena->children; child != NULL; ) { - NRArenaItem *nchild = child->next; - - nr_arena_glyphs_group_clear(NR_ARENA_GLYPHS_GROUP(child)); - nr_arena_item_remove_child(NR_ARENA_ITEM(in_arena), child); - - child = nchild; - } + in_arena->clearChildren(); } Inkscape::XML::Node *SPFlowtext::getAsText() -- cgit v1.2.3 From 75976ea07dba9b97186667524d0a76603de416af Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 7 Aug 2011 12:53:12 +0200 Subject: Rewrite NRArena -> Inkscape::Drawing. Call render and update methods on the Drawing rather than on the root DrawingItem. (bzr r10347.1.25) --- src/sp-flowtext.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/sp-flowtext.cpp') diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index cbdc8684b..710f799a5 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -50,7 +50,7 @@ static void sp_flowtext_bbox(SPItem const *item, NRRect *bbox, Geom::Affine cons static void sp_flowtext_print(SPItem *item, SPPrintContext *ctx); static gchar *sp_flowtext_description(SPItem *item); static void sp_flowtext_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs); -static Inkscape::DrawingItem *sp_flowtext_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags); +static Inkscape::DrawingItem *sp_flowtext_show(SPItem *item, Inkscape::Drawing &drawing, unsigned key, unsigned flags); static void sp_flowtext_hide(SPItem *item, unsigned key); static SPItemClass *parent_class; @@ -409,10 +409,10 @@ static void sp_flowtext_snappoints(SPItem const *item, std::vectorsetPickChildren(false); flowed->setStyle(group->style); -- cgit v1.2.3 From babb7a67749cb691674bdd9758f0568d4b094b56 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Mon, 22 Aug 2011 20:27:53 +0200 Subject: Refactoring of the snapping preferences; mainly about storing all toggles in a single array, instead of each having its own member variable (bzr r10569) --- src/sp-flowtext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-flowtext.cpp') diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index 87266464c..bb931a869 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -393,7 +393,7 @@ static gchar *sp_flowtext_description(SPItem *item) static void sp_flowtext_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) { - if (snapprefs->getSnapTextBaseline()) { + if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_TEXT_BASELINE)) { // Choose a point on the baseline for snapping from or to, with the horizontal position // of this point depending on the text alignment (left vs. right) Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item); -- cgit v1.2.3 From 72cc39b9f0b340548f395c7f61ca9662b34aea09 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 27 Aug 2011 11:04:37 +0200 Subject: Refactor SPItem bounding box methods: remove NRRect usage and make code using them more obvious. Fix filter region computation. (bzr r10582.1.1) --- src/sp-flowtext.cpp | 65 +++++++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 44 deletions(-) (limited to 'src/sp-flowtext.cpp') diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index ea8079bba..bd73a65c9 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -46,7 +46,7 @@ static Inkscape::XML::Node *sp_flowtext_write(SPObject *object, Inkscape::XML::D static void sp_flowtext_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_flowtext_set(SPObject *object, unsigned key, gchar const *value); -static void sp_flowtext_bbox(SPItem const *item, NRRect *bbox, Geom::Affine const &transform, unsigned const flags); +static Geom::OptRect sp_flowtext_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type); static void sp_flowtext_print(SPItem *item, SPPrintContext *ctx); static gchar *sp_flowtext_description(SPItem *item); static void sp_flowtext_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs); @@ -176,20 +176,19 @@ static void sp_flowtext_update(SPObject *object, SPCtx *ctx, unsigned flags) group->rebuildLayout(); - NRRect paintbox; - group->invoke_bbox( &paintbox, Geom::identity(), TRUE); + Geom::OptRect pbox = group->geometricBounds(); for (SPItemView *v = group->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *g = dynamic_cast(v->arenaitem); group->_clearFlow(g); g->setStyle(object->style); // pass the bbox of the flowtext object as paintbox (used for paintserver fills) - group->layout.show(g, &paintbox); + group->layout.show(g, pbox); } } static void sp_flowtext_modified(SPObject *object, guint flags) { - SPObject *ft = SP_FLOWTEXT (object); + SPObject *ft = object; SPObject *region = NULL; if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -198,13 +197,12 @@ static void sp_flowtext_modified(SPObject *object, guint flags) // FIXME: the below stanza is copied over from sp_text_modified, consider factoring it out if (flags & ( SP_OBJECT_STYLE_MODIFIED_FLAG )) { SPFlowtext *text = SP_FLOWTEXT(object); - NRRect paintbox; - text->invoke_bbox( &paintbox, Geom::identity(), TRUE); + Geom::OptRect pbox = text->geometricBounds(); for (SPItemView* v = text->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *g = dynamic_cast(v->arenaitem); text->_clearFlow(g); g->setStyle(object->style); - text->layout.show(g, &paintbox); + text->layout.show(g, pbox); } } @@ -329,53 +327,33 @@ static Inkscape::XML::Node *sp_flowtext_write(SPObject *object, Inkscape::XML::D return repr; } -static void -sp_flowtext_bbox(SPItem const *item, NRRect *bbox, Geom::Affine const &transform, unsigned const /*flags*/) +static Geom::OptRect +sp_flowtext_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) { SPFlowtext *group = SP_FLOWTEXT(item); - group->layout.getBoundingBox(bbox, transform); + Geom::OptRect bbox = group->layout.bounds(transform); // Add stroke width - SPStyle* style = item->style; - if ( !style->stroke.isNone() ) { - double const scale = transform.descrim(); - 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); - if ( fabs(bbox->x1 - bbox->x0) > -0.00001 && fabs(bbox->y1 - bbox->y0) > -0.00001 ) { - bbox->x0-=0.5*width; - bbox->x1+=0.5*width; - bbox->y0-=0.5*width; - bbox->y1+=0.5*width; - } - } + // FIXME this code is incorrect + if (type == SPItem::VISUAL_BBOX && !item->style->stroke.isNone()) { + double scale = transform.descrim(); + bbox->expandBy(0.5 * item->style->stroke_width.computed * scale); } + return bbox; } static void sp_flowtext_print(SPItem *item, SPPrintContext *ctx) { SPFlowtext *group = SP_FLOWTEXT(item); + Geom::OptRect pbox, bbox, dbox; - NRRect pbox; - item->invoke_bbox( &pbox, Geom::identity(), TRUE); - NRRect bbox; - Geom::OptRect bbox_maybe = item->getBboxDesktop(); - if (!bbox_maybe) { - return; - } - bbox.x0 = bbox_maybe->min()[Geom::X]; - bbox.y0 = bbox_maybe->min()[Geom::Y]; - bbox.x1 = bbox_maybe->max()[Geom::X]; - bbox.y1 = bbox_maybe->max()[Geom::Y]; - - NRRect dbox; - dbox.x0 = 0.0; - dbox.y0 = 0.0; - dbox.x1 = item->document->getWidth(); - dbox.y1 = item->document->getHeight(); + pbox = item->geometricBounds(); + bbox = item->desktopVisualBounds(); + dbox = Geom::Rect::from_xywh(Geom::Point(0,0), item->document->getDimensions()); Geom::Affine const ctm (item->i2dt_affine()); - group->layout.print(ctx, &pbox, &dbox, &bbox, ctm); + group->layout.print(ctx, pbox, dbox, bbox, ctm); } @@ -417,9 +395,8 @@ sp_flowtext_show(SPItem *item, Inkscape::Drawing &drawing, unsigned/* key*/, uns flowed->setStyle(group->style); // pass the bbox of the flowtext object as paintbox (used for paintserver fills) - NRRect paintbox; - item->invoke_bbox( &paintbox, Geom::identity(), TRUE); - group->layout.show(flowed, &paintbox); + Geom::OptRect bbox = group->geometricBounds(); + group->layout.show(flowed, bbox); return flowed; } -- cgit v1.2.3 From 8e867961dfc221568661c695aeddc10552f0accb Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 4 Sep 2011 23:17:50 +0200 Subject: Fix crashes with empty text objects (bzr r10617) --- src/sp-flowtext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-flowtext.cpp') diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index bd73a65c9..e7dcc559f 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -335,7 +335,7 @@ sp_flowtext_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBox // Add stroke width // FIXME this code is incorrect - if (type == SPItem::VISUAL_BBOX && !item->style->stroke.isNone()) { + if (bbox && type == SPItem::VISUAL_BBOX && !item->style->stroke.isNone()) { double scale = transform.descrim(); bbox->expandBy(0.5 * item->style->stroke_width.computed * scale); } -- cgit v1.2.3