From a681c327ed85c124846c5640e738945e5c2b4527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 6 Dec 2013 23:15:22 +0100 Subject: [PATCH] ParagraphLayout: Added GetTextBounds(). Untestet. --- .../haiku-depot/textview/ParagraphLayout.cpp | 40 +++++++++++++++++++ .../haiku-depot/textview/ParagraphLayout.h | 4 ++ 2 files changed, 44 insertions(+) diff --git a/src/apps/haiku-depot/textview/ParagraphLayout.cpp b/src/apps/haiku-depot/textview/ParagraphLayout.cpp index 62b57d1b52..1884fd7f99 100644 --- a/src/apps/haiku-depot/textview/ParagraphLayout.cpp +++ b/src/apps/haiku-depot/textview/ParagraphLayout.cpp @@ -278,6 +278,46 @@ ParagraphLayout::CountGlyphs() const } +void +ParagraphLayout::GetTextBounds(int32 textOffset, float& x1, float& y1, + float& x2, float& y2) +{ + _ValidateLayout(); + + if (fGlyphInfos.CountItems() == 0) { + x1 = 0.0f; + y1 = 0.0f; + x2 = 0.0f; + y2 = 0.0f; + + return; + } + + if (textOffset >= fGlyphInfos.CountItems()) { + const GlyphInfo& glyph = fGlyphInfos.LastItem(); + const LineInfo& line = fLineInfos.ItemAt(glyph.lineIndex); + + x1 = glyph.x + glyph.width; + x2 = x1; + y1 = line.y; + y1 = y1 + line.height; + + return; + } + + if (textOffset < 0) + textOffset = 0; + + const GlyphInfo& glyph = fGlyphInfos.ItemAtFast(textOffset); + const LineInfo& line = fLineInfos.ItemAt(glyph.lineIndex); + + x1 = glyph.x; + x2 = x1 + glyph.width; + y1 = line.y; + y1 = y1 + line.height; +} + + // #pragma mark - private diff --git a/src/apps/haiku-depot/textview/ParagraphLayout.h b/src/apps/haiku-depot/textview/ParagraphLayout.h index ff21fcf04c..a65b1eaa3e 100644 --- a/src/apps/haiku-depot/textview/ParagraphLayout.h +++ b/src/apps/haiku-depot/textview/ParagraphLayout.h @@ -191,6 +191,10 @@ public: int32 CountGlyphs() const; + void GetTextBounds(int32 textOffset, + float& x1, float& y1, + float& x2, float& y2); + private: void _Init();