Code

add utility function for average linespacing
authorbuliabyak <buliabyak@users.sourceforge.net>
Fri, 18 Jul 2008 03:21:52 +0000 (03:21 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Fri, 18 Jul 2008 03:21:52 +0000 (03:21 +0000)
src/text-editing.cpp
src/text-editing.h

index b103a01087560a4d44ae90a3815986342142da63..b92d85b15f03c8428464a3da065489f696335eb4 100644 (file)
@@ -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)
 {
index d0bbc3051e3f09b28fc300973bf98ff9b697eb37..2f3e5363c8fd8fe6459cb168a4ab022cc50151e3 100644 (file)
@@ -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);