TextDocumentLayout: Added TextOffsetAt()
It iterates over the ParagraphLayoutInfos and finds the one which must contain the location. Untestet.
This commit is contained in:
parent
e174294891
commit
26fd5e9804
@ -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
|
||||
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user