summaryrefslogtreecommitdiffstats
path: root/src/sp-flowtext.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-10-02 22:44:54 +0000
committerjabiertxof <info@marker.es>2016-10-02 22:44:54 +0000
commit90e142963afd950b2868434075890054aef090b3 (patch)
treeedcaf3d0d85b614e5f327fb58c909ffee5207e26 /src/sp-flowtext.cpp
parentAdded some widgets from caligraphic tool (diff)
parentAdjust dock size to minimum width during canvas table size allocation signal. (diff)
downloadinkscape-90e142963afd950b2868434075890054aef090b3.tar.gz
inkscape-90e142963afd950b2868434075890054aef090b3.zip
Update to trunk and some fixes
(bzr r14865.1.14)
Diffstat (limited to 'src/sp-flowtext.cpp')
-rw-r--r--src/sp-flowtext.cpp87
1 files changed, 52 insertions, 35 deletions
diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp
index b87507e18..264558014 100644
--- a/src/sp-flowtext.cpp
+++ b/src/sp-flowtext.cpp
@@ -2,7 +2,7 @@
*/
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include <config.h>
#endif
#include <glibmm/i18n.h>
#include <cstring>
@@ -13,23 +13,20 @@
#include "style.h"
#include "inkscape.h"
#include "document.h"
-#include "selection.h"
#include "desktop.h"
-#include "xml/repr.h"
-
#include "sp-flowdiv.h"
#include "sp-flowregion.h"
#include "sp-flowtext.h"
#include "sp-string.h"
-#include "sp-use.h"
#include "sp-rect.h"
#include "text-tag-attributes.h"
-#include "text-chemistry.h"
#include "text-editing.h"
#include "sp-text.h"
+#include "libnrtype/font-instance.h"
+
#include "livarot/Shape.h"
#include "display/drawing-text.h"
@@ -70,9 +67,9 @@ void SPFlowtext::update(SPCtx* ctx, unsigned int flags) {
GSList *l = NULL;
- for (SPObject *child = this->firstChild() ; child ; child = child->getNext() ) {
- sp_object_ref(child);
- l = g_slist_prepend(l, child);
+ for (auto& child: children) {
+ sp_object_ref(&child);
+ l = g_slist_prepend(l, &child);
}
l = g_slist_reverse(l);
@@ -133,9 +130,9 @@ void SPFlowtext::modified(unsigned int flags) {
}
}
- for ( SPObject *o = this->firstChild() ; o ; o = o->getNext() ) {
- if (dynamic_cast<SPFlowregion *>(o)) {
- region = o;
+ for (auto& o: children) {
+ if (dynamic_cast<SPFlowregion *>(&o)) {
+ region = &o;
break;
}
}
@@ -221,11 +218,11 @@ Inkscape::XML::Node* SPFlowtext::write(Inkscape::XML::Document* doc, Inkscape::X
GSList *l = NULL;
- for (SPObject *child = this->firstChild() ; child ; child = child->getNext() ) {
+ for (auto& child: children) {
Inkscape::XML::Node *c_repr = NULL;
- if ( dynamic_cast<SPFlowdiv *>(child) || dynamic_cast<SPFlowpara *>(child) || dynamic_cast<SPFlowregion *>(child) || dynamic_cast<SPFlowregionExclude *>(child)) {
- c_repr = child->updateRepr(doc, NULL, flags);
+ if ( dynamic_cast<SPFlowdiv *>(&child) || dynamic_cast<SPFlowpara *>(&child) || dynamic_cast<SPFlowregion *>(&child) || dynamic_cast<SPFlowregionExclude *>(&child)) {
+ c_repr = child.updateRepr(doc, NULL, flags);
}
if ( c_repr ) {
@@ -239,9 +236,9 @@ Inkscape::XML::Node* SPFlowtext::write(Inkscape::XML::Document* doc, Inkscape::X
l = g_slist_remove(l, l->data);
}
} else {
- for (SPObject *child = this->firstChild() ; child ; child = child->getNext() ) {
- if ( dynamic_cast<SPFlowdiv *>(child) || dynamic_cast<SPFlowpara *>(child) || dynamic_cast<SPFlowregion *>(child) || dynamic_cast<SPFlowregionExclude *>(child)) {
- child->updateRepr(flags);
+ for (auto& child: children) {
+ if ( dynamic_cast<SPFlowdiv *>(&child) || dynamic_cast<SPFlowpara *>(&child) || dynamic_cast<SPFlowregion *>(&child) || dynamic_cast<SPFlowregionExclude *>(&child)) {
+ child.updateRepr(flags);
}
}
}
@@ -339,6 +336,26 @@ void SPFlowtext::_buildLayoutInput(SPObject *root, Shape const *exclusion_shape,
bool with_indent = false;
if (dynamic_cast<SPFlowpara *>(root)) {
+
+ layout.strut.reset();
+ if (style) {
+ font_instance *font = font_factory::Default()->FaceFromStyle( style );
+ if (font) {
+ font->FontMetrics(layout.strut.ascent, layout.strut.descent, layout.strut.xheight);
+ font->Unref();
+ }
+ layout.strut *= style->font_size.computed;
+ if (style->line_height.normal ) {
+ layout.strut.computeEffective( Inkscape::Text::Layout::LINE_HEIGHT_NORMAL );
+ } else if (style->line_height.unit == SP_CSS_UNIT_NONE) {
+ layout.strut.computeEffective( style->line_height.computed );
+ } else {
+ if( style->font_size.computed > 0.0 ) {
+ layout.strut.computeEffective( style->line_height.computed/style->font_size.computed );
+ }
+ }
+ }
+
// emulate par-indent with the first char's kern
SPObject *t = root;
SPFlowtext *ft = NULL;
@@ -368,8 +385,8 @@ void SPFlowtext::_buildLayoutInput(SPObject *root, Shape const *exclusion_shape,
*pending_line_break_object = NULL;
}
- for (SPObject *child = root->firstChild() ; child ; child = child->getNext() ) {
- SPString *str = dynamic_cast<SPString *>(child);
+ for (auto& child: root->children) {
+ SPString *str = dynamic_cast<SPString *>(&child);
if (str) {
if (*pending_line_break_object) {
if (dynamic_cast<SPFlowregionbreak *>(*pending_line_break_object))
@@ -380,12 +397,12 @@ void SPFlowtext::_buildLayoutInput(SPObject *root, Shape const *exclusion_shape,
*pending_line_break_object = NULL;
}
if (with_indent) {
- layout.appendText(str->string, root->style, child, &pi);
+ layout.appendText(str->string, root->style, &child, &pi);
} else {
- layout.appendText(str->string, root->style, child);
+ layout.appendText(str->string, root->style, &child);
}
} else {
- SPFlowregion *region = dynamic_cast<SPFlowregion *>(child);
+ SPFlowregion *region = dynamic_cast<SPFlowregion *>(&child);
if (region) {
std::vector<Shape*> const &computed = region->computed;
for (std::vector<Shape*>::const_iterator it = computed.begin() ; it != computed.end() ; ++it) {
@@ -399,8 +416,8 @@ void SPFlowtext::_buildLayoutInput(SPObject *root, Shape const *exclusion_shape,
}
}
//Xml Tree is being directly used while it shouldn't be.
- else if (!dynamic_cast<SPFlowregionExclude *>(child) && !sp_repr_is_meta_element(child->getRepr())) {
- _buildLayoutInput(child, exclusion_shape, shapes, pending_line_break_object);
+ else if (!dynamic_cast<SPFlowregionExclude *>(&child) && !sp_repr_is_meta_element(child.getRepr())) {
+ _buildLayoutInput(&child, exclusion_shape, shapes, pending_line_break_object);
}
}
}
@@ -418,9 +435,9 @@ Shape* SPFlowtext::_buildExclusionShape() const
Shape *shape = new Shape();
Shape *shape_temp = new Shape();
- for (SPObject *child = children ; child ; child = child->getNext() ) {
+ for (auto& child: children) {
// RH: is it right that this shouldn't be recursive?
- SPFlowregionExclude *c_child = dynamic_cast<SPFlowregionExclude *>(child);
+ SPFlowregionExclude *c_child = dynamic_cast<SPFlowregionExclude *>(const_cast<SPObject*>(&child));
if ( c_child && c_child->computed && c_child->computed->hasEdges() ) {
if (shape->hasEdges()) {
shape_temp->Booleen(shape, c_child->computed, bool_op_union);
@@ -571,9 +588,9 @@ SPItem *SPFlowtext::get_frame(SPItem const *after)
SPItem *frame = 0;
SPObject *region = 0;
- for (SPObject *o = firstChild() ; o ; o = o->getNext() ) {
- if (dynamic_cast<SPFlowregion *>(o)) {
- region = o;
+ for (auto& o: children) {
+ if (dynamic_cast<SPFlowregion *>(&o)) {
+ region = &o;
break;
}
}
@@ -581,8 +598,8 @@ SPItem *SPFlowtext::get_frame(SPItem const *after)
if (region) {
bool past = false;
- for (SPObject *o = region->firstChild() ; o ; o = o->getNext() ) {
- SPItem *item = dynamic_cast<SPItem *>(o);
+ for (auto& o: region->children) {
+ SPItem *item = dynamic_cast<SPItem *>(&o);
if (item) {
if ( (after == NULL) || past ) {
frame = item;
@@ -685,9 +702,9 @@ Geom::Affine SPFlowtext::set_transform (Geom::Affine const &xform)
}
SPObject *region = NULL;
- for ( SPObject *o = this->firstChild() ; o ; o = o->getNext() ) {
- if (dynamic_cast<SPFlowregion *>(o)) {
- region = o;
+ for (auto& o: children) {
+ if (dynamic_cast<SPFlowregion *>(&o)) {
+ region = &o;
break;
}
}