TextDocumentLayout: First/LastOffsetOnLine() forgot to convert...
... back from paragraph local offsets to document global offsets.
This commit is contained in:
@@ -169,10 +169,11 @@ TextDocumentLayout::LineIndexForOffset(int32 textOffset)
|
|||||||
int32
|
int32
|
||||||
TextDocumentLayout::FirstOffsetOnLine(int32 lineIndex)
|
TextDocumentLayout::FirstOffsetOnLine(int32 lineIndex)
|
||||||
{
|
{
|
||||||
int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex);
|
int32 paragraphOffset;
|
||||||
|
int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex, paragraphOffset);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(index);
|
const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(index);
|
||||||
return info.layout->FirstOffsetOnLine(lineIndex);
|
return info.layout->FirstOffsetOnLine(lineIndex) + paragraphOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -182,10 +183,11 @@ TextDocumentLayout::FirstOffsetOnLine(int32 lineIndex)
|
|||||||
int32
|
int32
|
||||||
TextDocumentLayout::LastOffsetOnLine(int32 lineIndex)
|
TextDocumentLayout::LastOffsetOnLine(int32 lineIndex)
|
||||||
{
|
{
|
||||||
int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex);
|
int32 paragraphOffset;
|
||||||
|
int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex, paragraphOffset);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(index);
|
const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(index);
|
||||||
return info.layout->LastOffsetOnLine(lineIndex);
|
return info.layout->LastOffsetOnLine(lineIndex) + paragraphOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -213,7 +215,8 @@ void
|
|||||||
TextDocumentLayout::GetLineBounds(int32 lineIndex, float& x1, float& y1,
|
TextDocumentLayout::GetLineBounds(int32 lineIndex, float& x1, float& y1,
|
||||||
float& x2, float& y2)
|
float& x2, float& y2)
|
||||||
{
|
{
|
||||||
int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex);
|
int32 paragraphOffset;
|
||||||
|
int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex, paragraphOffset);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(index);
|
const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(index);
|
||||||
info.layout->GetLineBounds(lineIndex, x1, y1, x2, y2);
|
info.layout->GetLineBounds(lineIndex, x1, y1, x2, y2);
|
||||||
@@ -349,10 +352,12 @@ TextDocumentLayout::_ParagraphLayoutIndexForOffset(int32& textOffset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32
|
int32
|
||||||
TextDocumentLayout::_ParagraphLayoutIndexForLineIndex(int32& lineIndex)
|
TextDocumentLayout::_ParagraphLayoutIndexForLineIndex(int32& lineIndex,
|
||||||
|
int32& paragraphOffset)
|
||||||
{
|
{
|
||||||
_ValidateLayout();
|
_ValidateLayout();
|
||||||
|
|
||||||
|
paragraphOffset = 0;
|
||||||
int32 paragraphs = fParagraphLayouts.CountItems();
|
int32 paragraphs = fParagraphLayouts.CountItems();
|
||||||
for (int32 i = 0; i < paragraphs; i++) {
|
for (int32 i = 0; i < paragraphs; i++) {
|
||||||
const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(i);
|
const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(i);
|
||||||
@@ -360,6 +365,7 @@ TextDocumentLayout::_ParagraphLayoutIndexForLineIndex(int32& lineIndex)
|
|||||||
int32 lineCount = info.layout->CountLines();
|
int32 lineCount = info.layout->CountLines();
|
||||||
if (lineIndex >= lineCount) {
|
if (lineIndex >= lineCount) {
|
||||||
lineIndex -= lineCount;
|
lineIndex -= lineCount;
|
||||||
|
paragraphOffset += info.layout->CountGlyphs();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,8 @@ private:
|
|||||||
int32 _ParagraphLayoutIndexForOffset(
|
int32 _ParagraphLayoutIndexForOffset(
|
||||||
int32& textOffset);
|
int32& textOffset);
|
||||||
int32 _ParagraphLayoutIndexForLineIndex(
|
int32 _ParagraphLayoutIndexForLineIndex(
|
||||||
int32& lineIndex);
|
int32& lineIndex,
|
||||||
|
int32& paragraphOffset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float fWidth;
|
float fWidth;
|
||||||
|
|||||||
Reference in New Issue
Block a user