summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3246206)
raw | patch | inline | side by side (parent: 3246206)
author | Diederik van Lierop <mailat-signdiedenrezidotnl> | |
Sun, 13 Dec 2009 13:00:22 +0000 (14:00 +0100) | ||
committer | Diederik van Lierop <mailat-signdiedenrezidotnl> | |
Sun, 13 Dec 2009 13:00:22 +0000 (14:00 +0100) |
src/libnrtype/Layout-TNG-OutIter.cpp | patch | blob | history | |
src/libnrtype/Layout-TNG.h | patch | blob | history | |
src/selcue.cpp | patch | blob | history | |
src/sp-text.cpp | patch | blob | history |
index 0fc061bfc38f0c33f763edd37fc3a912ae634b80..f4e8e4031f6cc84cc958e4324d474663dc136fd1 100644 (file)
}
}
+boost::optional<Geom::Point> Layout::baselineAnchorPoint() const
+{
+ iterator pos = this->begin();
+ Geom::Point left_pt = this->characterAnchorPoint(pos);
+ pos.thisEndOfLine();
+ Geom::Point right_pt = this->characterAnchorPoint(pos);
+ Geom::Point mid_pt = (left_pt + right_pt)/2;
+
+ switch (this->paragraphAlignment(pos)) {
+ case LEFT:
+ case FULL:
+ return left_pt;
+ break;
+ case CENTER:
+ return mid_pt;
+ break;
+ case RIGHT:
+ return right_pt;
+ break;
+ default:
+ return boost::optional<Geom::Point>();
+ break;
+ }
+}
+
Geom::Point Layout::chunkAnchorPoint(iterator const &it) const
{
unsigned chunk_index;
unsigned line_index = _parent_layout->_characters[_char_index].chunk(_parent_layout).in_line;
if (line_index == _parent_layout->_lines.size() - 1)
return false; // nowhere to go
- else
+ else
n = MIN (n, static_cast<int>(_parent_layout->_lines.size() - 1 - line_index));
if (_parent_layout->_lines[line_index + n].in_shape != _parent_layout->_lines[line_index].in_shape) {
// switching between shapes: adjust the stored x to compensate
line_index = _parent_layout->_characters[_char_index].chunk(_parent_layout).in_line;
if (line_index == 0)
return false; // nowhere to go
- else
+ else
n = MIN (n, static_cast<int>(line_index));
if (_parent_layout->_lines[line_index - n].in_shape != _parent_layout->_lines[line_index].in_shape) {
// switching between shapes: adjust the stored x to compensate
index 19680b140a56a0cfc2c7b3ba9fea7c2c400c6118..8cd26edefd7aa0e063e49c9ba4a484a307652348 100644 (file)
/** For latin text, the left side of the character, on the baseline */
Geom::Point characterAnchorPoint(iterator const &it) const;
+ /** For left aligned text, the leftmost end of the baseline
+ For rightmost text, the rightmost... you probably got it by now ;-)*/
+ boost::optional<Geom::Point> baselineAnchorPoint() const;
+
/** This is that value to apply to the x,y attributes of tspan role=line
elements, and hence it takes alignment into account. */
Geom::Point chunkAnchorPoint(iterator const &it) const;
diff --git a/src/selcue.cpp b/src/selcue.cpp
index 714daaa7ea980da371a87faa0c8d07d09fd5c8ae..8756524dd6b37c01078f93f0c96ae3d82414057d 100644 (file)
--- a/src/selcue.cpp
+++ b/src/selcue.cpp
if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { // visualize baseline
Inkscape::Text::Layout const *layout = te_get_layout(item);
if (layout != NULL && layout->outputExists()) {
- Geom::Point a = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(item);
- baseline_point = sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRL,
- "mode", SP_CTRL_MODE_XOR,
- "size", 4.0,
- "filled", 0,
- "stroked", 1,
- "stroke_color", 0x000000ff,
- NULL);
-
- sp_canvas_item_show(baseline_point);
- SP_CTRL(baseline_point)->moveto(a);
- sp_canvas_item_move_to_z(baseline_point, 0);
+ boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
+ if (pt) {
+ baseline_point = sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRL,
+ "mode", SP_CTRL_MODE_XOR,
+ "size", 4.0,
+ "filled", 0,
+ "stroked", 1,
+ "stroke_color", 0x000000ff,
+ NULL);
+
+ sp_canvas_item_show(baseline_point);
+ SP_CTRL(baseline_point)->moveto((*pt) * sp_item_i2d_affine(item));
+ sp_canvas_item_move_to_z(baseline_point, 0);
+ }
}
}
diff --git a/src/sp-text.cpp b/src/sp-text.cpp
index 87c67c646184e847aa74dc7a4b000d6f50a05d89..423922b80c991a11207973b3ab800b1185a18ee3 100644 (file)
--- a/src/sp-text.cpp
+++ b/src/sp-text.cpp
static void sp_text_snappoints(SPItem const *item, bool const target, SnapPointsWithType &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)
+ // of this point depending on the text alignment (left vs. right)
Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item);
- if(layout != NULL) {
- int type = target ? int(Inkscape::SNAPTARGET_TEXT_BASELINE) : int(Inkscape::SNAPSOURCE_TEXT_BASELINE);
-
- Inkscape::Text::Layout::iterator pos = layout->begin();
- Inkscape::Text::Layout::Alignment text_alignment = layout->paragraphAlignment(pos);
-
- Geom::Point left_pt = layout->characterAnchorPoint(pos) * sp_item_i2d_affine(item);
- pos.thisEndOfLine();
- Geom::Point right_pt = layout->characterAnchorPoint(pos) * sp_item_i2d_affine(item);
- Geom::Point mid_pt = (left_pt + right_pt)/2;
-
- switch (text_alignment) {
- case Inkscape::Text::Layout::LEFT:
- case Inkscape::Text::Layout::FULL:
- p.push_back(std::make_pair(left_pt, type));
- break;
- case Inkscape::Text::Layout::CENTER:
- p.push_back(std::make_pair(mid_pt, type));
- break;
- default: //RIGHT
- p.push_back(std::make_pair(right_pt, type));
- break;
+ if (layout != NULL && layout->outputExists()) {
+ boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
+ if (pt) {
+ int type = target ? int(Inkscape::SNAPTARGET_TEXT_BASELINE) : int(Inkscape::SNAPSOURCE_TEXT_BASELINE);
+ p.push_back(std::make_pair((*pt) * sp_item_i2d_affine(item), type));
}
}
}