From e3dc81cc9b0ef0190a5276c3d1b3e14c1fc83077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 7 Dec 2013 00:13:41 +0100 Subject: [PATCH] ParagraphLayout: Added line info methods * CountLines() * LineIndexForOffset() * Bug fixes in GetTextBounds() --- .../haiku-depot/textview/ParagraphLayout.cpp | 33 +++++++++++++++++-- .../haiku-depot/textview/ParagraphLayout.h | 3 ++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/apps/haiku-depot/textview/ParagraphLayout.cpp b/src/apps/haiku-depot/textview/ParagraphLayout.cpp index 1884fd7f99..f1980de8a1 100644 --- a/src/apps/haiku-depot/textview/ParagraphLayout.cpp +++ b/src/apps/haiku-depot/textview/ParagraphLayout.cpp @@ -278,6 +278,35 @@ ParagraphLayout::CountGlyphs() const } +int32 +ParagraphLayout::CountLines() +{ + _ValidateLayout(); + return fLineInfos.CountItems(); +} + + +int32 +ParagraphLayout::LineIndexForOffset(int32 textOffset) +{ + _ValidateLayout(); + + if (fGlyphInfos.CountItems() == 0) + return 0; + + if (textOffset >= fGlyphInfos.CountItems()) { + const GlyphInfo& glyph = fGlyphInfos.LastItem(); + return glyph.lineIndex; + } + + if (textOffset < 0) + textOffset = 0; + + const GlyphInfo& glyph = fGlyphInfos.ItemAtFast(textOffset); + return glyph.lineIndex; +} + + void ParagraphLayout::GetTextBounds(int32 textOffset, float& x1, float& y1, float& x2, float& y2) @@ -300,7 +329,7 @@ ParagraphLayout::GetTextBounds(int32 textOffset, float& x1, float& y1, x1 = glyph.x + glyph.width; x2 = x1; y1 = line.y; - y1 = y1 + line.height; + y2 = y1 + line.height; return; } @@ -314,7 +343,7 @@ ParagraphLayout::GetTextBounds(int32 textOffset, float& x1, float& y1, x1 = glyph.x; x2 = x1 + glyph.width; y1 = line.y; - y1 = y1 + line.height; + y2 = y1 + line.height; } diff --git a/src/apps/haiku-depot/textview/ParagraphLayout.h b/src/apps/haiku-depot/textview/ParagraphLayout.h index a65b1eaa3e..45ce12e8be 100644 --- a/src/apps/haiku-depot/textview/ParagraphLayout.h +++ b/src/apps/haiku-depot/textview/ParagraphLayout.h @@ -190,6 +190,9 @@ public: void Draw(BView* view, const BPoint& offset); int32 CountGlyphs() const; + int32 CountLines(); + + int32 LineIndexForOffset(int32 textOffset); void GetTextBounds(int32 textOffset, float& x1, float& y1,