summaryrefslogtreecommitdiffstats
path: root/src/sp-flowtext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp-flowtext.cpp')
-rw-r--r--src/sp-flowtext.cpp130
1 files changed, 52 insertions, 78 deletions
diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp
index d7bc0053f..e7dcc559f 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);
@@ -46,11 +46,11 @@ 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<Inkscape::SnapCandidatePoint> &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, Inkscape::Drawing &drawing, unsigned key, unsigned flags);
static void sp_flowtext_hide(SPItem *item, unsigned key);
static SPItemClass *parent_class;
@@ -176,19 +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) {
- group->_clearFlow(NR_ARENA_GROUP(v->arenaitem));
- nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), object->style);
+ Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(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, 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;
@@ -197,12 +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) {
- 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<Inkscape::DrawingGroup *>(v->arenaitem);
+ text->_clearFlow(g);
+ g->setStyle(object->style);
+ text->layout.show(g, pbox);
}
}
@@ -327,50 +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 (bbox && 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 = NRRect(from_2geom(*bbox_maybe));
-
- NRRect dbox;
- dbox.x0 = 0.0;
- dbox.y0 = 0.0;
- dbox.x1 = item->document->getWidth();
- dbox.y1 = item->document->getHeight();
- Geom::Affine const ctm (item->i2d_affine());
+ 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);
}
@@ -388,32 +371,32 @@ static gchar *sp_flowtext_description(SPItem *item)
}
}
-static void sp_flowtext_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const */*snapprefs*/)
+static void sp_flowtext_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &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<Geom::Point> pt = layout->baselineAnchorPoint();
- if (pt) {
- p.push_back(Inkscape::SnapCandidatePoint((*pt) * item->i2d_affine(), Inkscape::SNAPSOURCE_TEXT_BASELINE, Inkscape::SNAPTARGET_TEXT_BASELINE));
+ 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);
+ if (layout != NULL && layout->outputExists()) {
+ boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
+ if (pt) {
+ p.push_back(Inkscape::SnapCandidatePoint((*pt) * item->i2dt_affine(), Inkscape::SNAPSOURCE_TEXT_ANCHOR, Inkscape::SNAPTARGET_TEXT_ANCHOR));
+ }
}
}
}
-static NRArenaItem *
-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*/)
{
SPFlowtext *group = (SPFlowtext *) item;
- NRArenaGroup *flowed = NRArenaGroup::create(arena);
- nr_arena_group_set_transparent(flowed, FALSE);
-
- nr_arena_group_set_style(flowed, group->style);
+ Inkscape::DrawingGroup *flowed = new Inkscape::DrawingGroup(drawing);
+ flowed->setPickChildren(false);
+ 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;
}
@@ -536,25 +519,16 @@ 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()
+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");
@@ -583,7 +557,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;