TextDocumentLayout: Added TextOffsetAt()

It iterates over the ParagraphLayoutInfos and finds
the one which must contain the location. Untestet.
This commit is contained in:
Stephan Aßmus 2013-12-07 12:15:13 +01:00
parent e174294891
commit 26fd5e9804
2 changed files with 26 additions and 0 deletions

View File

@ -144,6 +144,29 @@ TextDocumentLayout::GetTextBounds(int32 textOffset, float& x1, float& y1,
}
int32
TextDocumentLayout::TextOffsetAt(float x, float y, bool& rightOfCenter)
{
_ValidateLayout();
int32 textOffset = 0;
rightOfCenter = false;
int32 paragraphs = fParagraphLayouts.CountItems();
for (int32 i = 0; i < paragraphs; i++) {
const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(i);
if (y > info.y + info.layout->Height()) {
textOffset += info.layout->CountGlyphs();
continue;
}
textOffset += info.layout->TextOffsetAt(x, y - info.y, rightOfCenter);
break;
}
return textOffset;
}
// #pragma mark - private

View File

@ -92,6 +92,9 @@ public:
float& x1, float& y1,
float& x2, float& y2);
int32 TextOffsetAt(float x, float y,
bool& rightOfCenter);
private:
void _Init();
void _ValidateLayout();