From 8c1eca445dea3195aa0020a1ac2a5764d4c1560d Mon Sep 17 00:00:00 2001 From: buliabyak Date: Fri, 18 Jul 2008 03:21:52 +0000 Subject: [PATCH] add utility function for average linespacing --- src/text-editing.cpp | 13 +++++++++++++ src/text-editing.h | 2 ++ 2 files changed, 15 insertions(+) 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 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); -- 2.30.2