ParagraphLayout: Added line info methods

* CountLines()
 * LineIndexForOffset()
 * Bug fixes in GetTextBounds()
This commit is contained in:
Stephan Aßmus 2013-12-07 00:13:41 +01:00
parent ab86f2c321
commit e3dc81cc9b
2 changed files with 34 additions and 2 deletions

View File

@ -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;
}

View File

@ -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,