summaryrefslogtreecommitdiffstats
path: root/src/sp-text.cpp
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-04-05 17:42:32 +0000
committerMarkus Engel <markus.engel@tum.de>2013-04-05 17:42:32 +0000
commit19d00efa85cfc42ccae9bd17ef575602f0d22c50 (patch)
treecab58b197a09a98c23b0a22ba9492207e7c14071 /src/sp-text.cpp
parentMerged Group and subclasses. (diff)
downloadinkscape-19d00efa85cfc42ccae9bd17ef575602f0d22c50.tar.gz
inkscape-19d00efa85cfc42ccae9bd17ef575602f0d22c50.zip
Merged more classes.
(bzr r11608.1.78)
Diffstat (limited to 'src/sp-text.cpp')
-rw-r--r--src/sp-text.cpp280
1 files changed, 121 insertions, 159 deletions
diff --git a/src/sp-text.cpp b/src/sp-text.cpp
index f35b9bb3b..386b49d26 100644
--- a/src/sp-text.cpp
+++ b/src/sp-text.cpp
@@ -71,84 +71,55 @@ namespace {
/*#####################################################
# SPTEXT
#####################################################*/
-G_DEFINE_TYPE(SPText, sp_text, G_TYPE_OBJECT);
+SPText::SPText() : SPItem(), CItem(this) {
+ delete this->citem;
+ this->citem = this;
+ this->cobject = this;
-static void
-sp_text_class_init (SPTextClass *classname)
-{
-}
-
-CText::CText(SPText* text) : CItem(text) {
- this->sptext = text;
+ new (&this->layout) Inkscape::Text::Layout;
+ new (&this->attributes) TextTagAttributes;
}
-CText::~CText() {
+SPText::~SPText() {
}
-SPText::SPText() : SPItem() {
- SPText* text = this;
-
- text->ctext = new CText(text);
- text->typeHierarchy.insert(typeid(SPText));
+void SPText::build(SPDocument *doc, Inkscape::XML::Node *repr) {
+ this->readAttr( "x" );
+ this->readAttr( "y" );
+ this->readAttr( "dx" );
+ this->readAttr( "dy" );
+ this->readAttr( "rotate" );
- delete text->citem;
- text->citem = text->ctext;
- text->cobject = text->ctext;
-
- new (&text->layout) Inkscape::Text::Layout;
- new (&text->attributes) TextTagAttributes;
-}
+ CItem::build(doc, repr);
-static void
-sp_text_init (SPText *text)
-{
- new (text) SPText();
+ this->readAttr( "sodipodi:linespacing" ); // has to happen after the styles are read
}
-void CText::release() {
- SPText* object = this->sptext;
-
- SPText *text = SP_TEXT(object);
- text->attributes.~TextTagAttributes();
- text->layout.~Layout();
+void SPText::release() {
+ this->attributes.~TextTagAttributes();
+ this->layout.~Layout();
CItem::release();
}
-void CText::build(SPDocument *doc, Inkscape::XML::Node *repr) {
- SPText* object = this->sptext;
-
- object->readAttr( "x" );
- object->readAttr( "y" );
- object->readAttr( "dx" );
- object->readAttr( "dy" );
- object->readAttr( "rotate" );
-
- CItem::build(doc, repr);
-
- object->readAttr( "sodipodi:linespacing" ); // has to happen after the styles are read
-}
-
-void CText::set(unsigned int key, const gchar* value) {
- SPText* object = this->sptext;
-
- SPText *text = SP_TEXT (object);
-
- if (text->attributes.readSingleAttribute(key, value)) {
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+void SPText::set(unsigned int key, const gchar* value) {
+ if (this->attributes.readSingleAttribute(key, value)) {
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
} else {
switch (key) {
case SP_ATTR_SODIPODI_LINESPACING:
// convert deprecated tag to css
if (value) {
- text->style->line_height.set = TRUE;
- text->style->line_height.inherit = FALSE;
- text->style->line_height.normal = FALSE;
- text->style->line_height.unit = SP_CSS_UNIT_PERCENT;
- text->style->line_height.value = text->style->line_height.computed = sp_svg_read_percentage (value, 1.0);
+ this->style->line_height.set = TRUE;
+ this->style->line_height.inherit = FALSE;
+ this->style->line_height.normal = FALSE;
+ this->style->line_height.unit = SP_CSS_UNIT_PERCENT;
+ this->style->line_height.value = this->style->line_height.computed = sp_svg_read_percentage (value, 1.0);
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
break;
+
default:
CItem::set(key, value);
break;
@@ -156,54 +127,50 @@ void CText::set(unsigned int key, const gchar* value) {
}
}
-void CText::child_added(Inkscape::XML::Node *rch, Inkscape::XML::Node *ref) {
- SPText* object = this->sptext;
-
- SPText *text = SP_TEXT (object);
-
+void SPText::child_added(Inkscape::XML::Node *rch, Inkscape::XML::Node *ref) {
CItem::child_added(rch, ref);
- text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_CONTENT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_CONTENT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
}
-void CText::remove_child(Inkscape::XML::Node *rch) {
- SPText* object = this->sptext;
-
- SPText *text = SP_TEXT (object);
-
+void SPText::remove_child(Inkscape::XML::Node *rch) {
CItem::remove_child(rch);
- text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_CONTENT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_CONTENT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
}
-void CText::update(SPCtx *ctx, guint flags) {
- SPText* object = this->sptext;
-
- SPText *text = SP_TEXT (object);
-
+void SPText::update(SPCtx *ctx, guint flags) {
CItem::update(ctx, flags);
guint cflags = (flags & SP_OBJECT_MODIFIED_CASCADE);
- if (flags & SP_OBJECT_MODIFIED_FLAG) cflags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
+ if (flags & SP_OBJECT_MODIFIED_FLAG) {
+ cflags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
+ }
// Create temporary list of children
GSList *l = NULL;
- for (SPObject *child = object->firstChild() ; child ; child = child->getNext() ) {
- sp_object_ref(child, object);
+
+ for (SPObject *child = this->firstChild() ; child ; child = child->getNext() ) {
+ sp_object_ref(child, this);
l = g_slist_prepend (l, child);
}
+
l = g_slist_reverse (l);
+
while (l) {
SPObject *child = reinterpret_cast<SPObject*>(l->data); // We just built this list, so cast is safe.
l = g_slist_remove (l, child);
+
if (cflags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
/* fixme: Do we need transform? */
child->updateDisplay(ctx, cflags);
}
- sp_object_unref(child, object);
+
+ sp_object_unref(child, this);
}
+
if (flags & ( SP_OBJECT_STYLE_MODIFIED_FLAG |
SP_OBJECT_CHILD_MODIFIED_FLAG |
SP_TEXT_LAYOUT_MODIFIED_FLAG ) )
@@ -211,95 +178,103 @@ void CText::update(SPCtx *ctx, guint flags) {
/* fixme: It is not nice to have it here, but otherwise children content changes does not work */
/* fixme: Even now it may not work, as we are delayed */
/* fixme: So check modification flag everywhere immediate state is used */
- text->rebuildLayout();
+ this->rebuildLayout();
+
+ Geom::OptRect paintbox = this->geometricBounds();
- Geom::OptRect paintbox = text->geometricBounds();
- for (SPItemView* v = text->display; v != NULL; v = v->next) {
+ for (SPItemView* v = this->display; v != NULL; v = v->next) {
Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem);
- text->_clearFlow(g);
- g->setStyle(object->style);
- // pass the bbox of the text object as paintbox (used for paintserver fills)
- text->layout.show(g, paintbox);
+ this->_clearFlow(g);
+ g->setStyle(this->style);
+ // pass the bbox of the this this as paintbox (used for paintserver fills)
+ this->layout.show(g, paintbox);
}
}
}
-void CText::modified(guint flags) {
- SPText* object = this->sptext;
-
+void SPText::modified(guint flags) {
// CItem::onModified(flags);
guint cflags = (flags & SP_OBJECT_MODIFIED_CASCADE);
+
if (flags & SP_OBJECT_MODIFIED_FLAG) {
cflags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
}
// FIXME: all that we need to do here is to call setStyle, to set the changed
// style, but there's no easy way to access the drawing glyphs or texts corresponding to a
- // text object. Therefore we do here the same as in _update, that is, destroy all items
+ // text this. Therefore we do here the same as in _update, that is, destroy all items
// and create new ones. This is probably quite wasteful.
if (flags & ( SP_OBJECT_STYLE_MODIFIED_FLAG )) {
- SPText *text = SP_TEXT (object);
- Geom::OptRect paintbox = text->geometricBounds();
- for (SPItemView* v = text->display; v != NULL; v = v->next) {
+ Geom::OptRect paintbox = this->geometricBounds();
+
+ for (SPItemView* v = this->display; v != NULL; v = v->next) {
Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem);
- text->_clearFlow(g);
- g->setStyle(object->style);
- text->layout.show(g, paintbox);
+ this->_clearFlow(g);
+ g->setStyle(this->style);
+ this->layout.show(g, paintbox);
}
}
// Create temporary list of children
GSList *l = NULL;
- for (SPObject *child = object->firstChild() ; child ; child = child->getNext() ) {
- sp_object_ref(child, object);
+
+ for (SPObject *child = this->firstChild() ; child ; child = child->getNext() ) {
+ sp_object_ref(child, this);
l = g_slist_prepend (l, child);
}
+
l = g_slist_reverse (l);
+
while (l) {
SPObject *child = reinterpret_cast<SPObject*>(l->data); // We just built this list, so cast is safe.
l = g_slist_remove (l, child);
+
if (cflags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
child->emitModified(cflags);
}
- sp_object_unref(child, object);
+
+ sp_object_unref(child, this);
}
}
-Inkscape::XML::Node *CText::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPText* object = this->sptext;
-
- SPText *text = SP_TEXT (object);
-
+Inkscape::XML::Node *SPText::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if (flags & SP_OBJECT_WRITE_BUILD) {
if (!repr) {
- repr = xml_doc->createElement("svg:text");
+ repr = xml_doc->createElement("svg:this");
}
+
GSList *l = NULL;
- for (SPObject *child = object->firstChild() ; child ; child = child->getNext() ) {
+
+ for (SPObject *child = this->firstChild() ; child ; child = child->getNext() ) {
if (SP_IS_TITLE(child) || SP_IS_DESC(child)) {
continue;
}
+
Inkscape::XML::Node *crepr = NULL;
+
if (SP_IS_STRING(child)) {
crepr = xml_doc->createTextNode(SP_STRING(child)->string.c_str());
} else {
crepr = child->updateRepr(xml_doc, NULL, flags);
}
+
if (crepr) {
l = g_slist_prepend (l, crepr);
}
}
+
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 = object->firstChild() ; child ; child = child->getNext() ) {
+ for (SPObject *child = this->firstChild() ; child ; child = child->getNext() ) {
if (SP_IS_TITLE(child) || SP_IS_DESC(child)) {
continue;
}
+
if (SP_IS_STRING(child)) {
child->getRepr()->setContent(SP_STRING(child)->string.c_str());
} else {
@@ -308,15 +283,15 @@ Inkscape::XML::Node *CText::write(Inkscape::XML::Document *xml_doc, Inkscape::XM
}
}
- text->attributes.writeTo(repr);
+ this->attributes.writeTo(repr);
// deprecated attribute, but keep it around for backwards compatibility
- if (text->style->line_height.set && !text->style->line_height.inherit && !text->style->line_height.normal && text->style->line_height.unit == SP_CSS_UNIT_PERCENT) {
+ if (this->style->line_height.set && !this->style->line_height.inherit && !this->style->line_height.normal && this->style->line_height.unit == SP_CSS_UNIT_PERCENT) {
Inkscape::SVGOStringStream os;
- os << (text->style->line_height.value * 100.0) << "%";
- text->getRepr()->setAttribute("sodipodi:linespacing", os.str().c_str());
+ os << (this->style->line_height.value * 100.0) << "%";
+ this->getRepr()->setAttribute("sodipodi:linespacing", os.str().c_str());
} else {
- text->getRepr()->setAttribute("sodipodi:linespacing", NULL);
+ this->getRepr()->setAttribute("sodipodi:linespacing", NULL);
}
CItem::write(xml_doc, repr, flags);
@@ -324,50 +299,43 @@ Inkscape::XML::Node *CText::write(Inkscape::XML::Document *xml_doc, Inkscape::XM
return repr;
}
-Geom::OptRect CText::bbox(Geom::Affine const &transform, SPItem::BBoxType type) {
- SPText* item = this->sptext;
-
- Geom::OptRect bbox = SP_TEXT(item)->layout.bounds(transform);
+Geom::OptRect SPText::bbox(Geom::Affine const &transform, SPItem::BBoxType type) {
+ Geom::OptRect bbox = SP_TEXT(this)->layout.bounds(transform);
// FIXME this code is incorrect
- if (bbox && type == SPItem::VISUAL_BBOX && !item->style->stroke.isNone()) {
+ if (bbox && type == SPItem::VISUAL_BBOX && !this->style->stroke.isNone()) {
double scale = transform.descrim();
- bbox->expandBy(0.5 * item->style->stroke_width.computed * scale);
+ bbox->expandBy(0.5 * this->style->stroke_width.computed * scale);
}
+
return bbox;
}
-Inkscape::DrawingItem* CText::show(Inkscape::Drawing &drawing, unsigned key, unsigned flags) {
- SPText* item = this->sptext;
-
- SPText *group = (SPText *) item;
-
+Inkscape::DrawingItem* SPText::show(Inkscape::Drawing &drawing, unsigned key, unsigned flags) {
Inkscape::DrawingGroup *flowed = new Inkscape::DrawingGroup(drawing);
flowed->setPickChildren(false);
- flowed->setStyle(group->style);
+ flowed->setStyle(this->style);
// pass the bbox of the text object as paintbox (used for paintserver fills)
- group->layout.show(flowed, group->geometricBounds());
+ this->layout.show(flowed, this->geometricBounds());
return flowed;
}
-void CText::hide(unsigned int key) {
+void SPText::hide(unsigned int key) {
// CItem::onHide(key);
}
-gchar* CText::description() {
- SPText* item = this->sptext;
-
- SPText *text = reinterpret_cast<SPText *>(item);
- SPStyle *style = text->style;
+gchar* SPText::description() {
+ SPStyle *style = this->style;
font_instance *tf = font_factory::Default()->FaceFromStyle(style);
char name_buf[256];
char *n;
+
if (tf) {
tf->Family(name_buf, sizeof(name_buf));
n = xml_quote_strdup(name_buf);
@@ -380,41 +348,38 @@ gchar* CText::description() {
GString *xs = SP_PX_TO_METRIC_STRING(style->font_size.computed, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->getDefaultMetric());
char const *trunc = "";
- Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item);
+ Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) this);
+
if (layout && layout->inputTruncated()) {
trunc = _(" [truncated]");
}
- char *ret = ( SP_IS_TEXT_TEXTPATH(item)
+ char *ret = ( SP_IS_TEXT_TEXTPATH(this)
? g_strdup_printf(_("<b>Text on path</b>%s (%s, %s)"), trunc, n, xs->str)
: g_strdup_printf(_("<b>Text</b>%s (%s, %s)"), trunc, n, xs->str) );
g_free(n);
return ret;
}
-void CText::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
- SPText* item = this->sptext;
-
+void SPText::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
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);
+ Inkscape::Text::Layout const *layout = te_get_layout(this);
+
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));
+ p.push_back(Inkscape::SnapCandidatePoint((*pt) * this->i2dt_affine(), Inkscape::SNAPSOURCE_TEXT_ANCHOR, Inkscape::SNAPTARGET_TEXT_ANCHOR));
}
}
}
}
-Geom::Affine CText::set_transform(Geom::Affine const &xform) {
- SPText* item = this->sptext;
-
- SPText *text = SP_TEXT(item);
-
+Geom::Affine SPText::set_transform(Geom::Affine const &xform) {
// we cannot optimize textpath because changing its fontsize will break its match to the path
- if (SP_IS_TEXT_TEXTPATH (text))
+ if (SP_IS_TEXT_TEXTPATH (this))
return xform;
/* This function takes care of scaling & translation only, we return whatever parts we can't
@@ -438,37 +403,34 @@ Geom::Affine CText::set_transform(Geom::Affine const &xform) {
ret[3] /= ex;
// Adjust x/y, dx/dy
- text->_adjustCoordsRecursive (item, xform * ret.inverse(), ex);
+ this->_adjustCoordsRecursive (this, xform * ret.inverse(), ex);
// Adjust font size
- text->_adjustFontsizeRecursive (item, ex);
+ this->_adjustFontsizeRecursive (this, ex);
// Adjust stroke width
- item->adjust_stroke_width_recursive (ex);
+ this->adjust_stroke_width_recursive (ex);
// Adjust pattern fill
- item->adjust_pattern(xform * ret.inverse());
+ this->adjust_pattern(xform * ret.inverse());
// Adjust gradient fill
- item->adjust_gradient(xform * ret.inverse());
+ this->adjust_gradient(xform * ret.inverse());
- item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
return ret;
}
-void CText::print(SPPrintContext *ctx) {
- SPText* item = this->sptext;
-
- SPText *group = SP_TEXT (item);
+void SPText::print(SPPrintContext *ctx) {
Geom::OptRect pbox, bbox, dbox;
+ pbox = this->geometricBounds();
+ bbox = this->desktopVisualBounds();
+ dbox = Geom::Rect::from_xywh(Geom::Point(0,0), this->document->getDimensions());
- 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());
+ Geom::Affine const ctm (this->i2dt_affine());
- group->layout.print(ctx,pbox,dbox,bbox,ctm);
+ this->layout.print(ctx,pbox,dbox,bbox,ctm);
}
/*