ParagraphLayout: Added GetTextBounds(). Untestet.

This commit is contained in:
Stephan Aßmus 2013-12-06 23:15:22 +01:00
parent cd50559dde
commit a681c327ed
2 changed files with 44 additions and 0 deletions

View File

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

View File

@ -191,6 +191,10 @@ public:
int32 CountGlyphs() const;
void GetTextBounds(int32 textOffset,
float& x1, float& y1,
float& x2, float& y2);
private:
void _Init();