summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2008-07-18 03:21:52 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2008-07-18 03:21:52 +0000
commit5a2f34e66aca5955e548211a7cb694b91ceaeacb (patch)
tree154c207458fec35df63cb64c99bc5baa0aefb957 /src
parentfix artefacts left by text cursor and disappearing cursor on empty canvas (diff)
downloadinkscape-5a2f34e66aca5955e548211a7cb694b91ceaeacb.tar.gz
inkscape-5a2f34e66aca5955e548211a7cb694b91ceaeacb.zip
add utility function for average linespacing
(bzr r6343)
Diffstat (limited to 'src')
-rw-r--r--src/text-editing.cpp13
-rw-r--r--src/text-editing.h2
2 files changed, 15 insertions, 0 deletions
diff --git a/src/text-editing.cpp b/src/text-editing.cpp
index b103a0108..b92d85b15 100644
--- a/src/text-editing.cpp
+++ b/src/text-editing.cpp
@@ -1086,6 +1086,19 @@ sp_te_adjust_tspan_letterspacing_screen(SPItem *text, Inkscape::Text::Layout::it
text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
}
+double
+sp_te_get_average_linespacing (SPItem *text)
+{
+ Inkscape::Text::Layout const *layout = te_get_layout(text);
+ if (!layout)
+ return 0;
+
+ unsigned line_count = layout->lineIndex(layout->end());
+ double all_lines_height = layout->characterAnchorPoint(layout->end())[NR::Y] - layout->characterAnchorPoint(layout->begin())[NR::Y];
+ double average_line_height = all_lines_height / (line_count == 0 ? 1 : line_count);
+ return average_line_height;
+}
+
void
sp_te_adjust_linespacing_screen (SPItem *text, Inkscape::Text::Layout::iterator const &/*start*/, Inkscape::Text::Layout::iterator const &/*end*/, SPDesktop *desktop, gdouble by)
{
diff --git a/src/text-editing.h b/src/text-editing.h
index d0bbc3051..2f3e5363c 100644
--- a/src/text-editing.h
+++ b/src/text-editing.h
@@ -36,6 +36,8 @@ std::vector<NR::Point> sp_te_create_selection_quads(SPItem const *item, Inkscape
Inkscape::Text::Layout::iterator sp_te_get_position_by_coords (SPItem const *item, NR::Point &i_p);
void sp_te_get_cursor_coords (SPItem const *item, Inkscape::Text::Layout::iterator const &position, NR::Point &p0, NR::Point &p1);
+double sp_te_get_average_linespacing (SPItem *text);
+
SPStyle const * sp_te_style_at_position(SPItem const *text, Inkscape::Text::Layout::iterator const &position);