TextDocumentLayout: Added TextOffsetAt()
It iterates over the ParagraphLayoutInfos and finds the one which must contain the location. Untestet.
This commit is contained in:
@@ -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
|
// #pragma mark - private
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,9 @@ public:
|
|||||||
float& x1, float& y1,
|
float& x1, float& y1,
|
||||||
float& x2, float& y2);
|
float& x2, float& y2);
|
||||||
|
|
||||||
|
int32 TextOffsetAt(float x, float y,
|
||||||
|
bool& rightOfCenter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Init();
|
void _Init();
|
||||||
void _ValidateLayout();
|
void _ValidateLayout();
|
||||||
|
|||||||
Reference in New Issue
Block a user