ParagraphLayout: Refactored _GetEmptyLayoutBounds().
Even for an empty Paragraph, some meaningful bounds can be computed when it contains an empty TextSpan. However, this is not yet achieved, since no LineInfo is generated for such an empty Paragraph.
This commit is contained in:
parent
b3299ecd73
commit
41889b59f3
|
@ -342,11 +342,7 @@ ParagraphLayout::GetLineBounds(int32 lineIndex, float& x1, float& y1,
|
|||
_ValidateLayout();
|
||||
|
||||
if (fGlyphInfos.CountItems() == 0) {
|
||||
x1 = 0.0f;
|
||||
y1 = 0.0f;
|
||||
x2 = 0.0f;
|
||||
y2 = 0.0f;
|
||||
|
||||
_GetEmptyLayoutBounds(x1, y1, x2, y2);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -381,11 +377,7 @@ ParagraphLayout::GetTextBounds(int32 textOffset, float& x1, float& y1,
|
|||
_ValidateLayout();
|
||||
|
||||
if (fGlyphInfos.CountItems() == 0) {
|
||||
x1 = 0.0f;
|
||||
y1 = 0.0f;
|
||||
x2 = 0.0f;
|
||||
y2 = 0.0f;
|
||||
|
||||
_GetEmptyLayoutBounds(x1, y1, x2, y2);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -948,3 +940,28 @@ ParagraphLayout::_DrawSpan(BView* view, BPoint offset,
|
|||
|
||||
view->DrawString(span.Text(), offset, &delta);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ParagraphLayout::_GetEmptyLayoutBounds(float& x1, float& y1, float& x2,
|
||||
float& y2) const
|
||||
{
|
||||
if (fLineInfos.CountItems() == 0) {
|
||||
x1 = 0.0f;
|
||||
y1 = 0.0f;
|
||||
x2 = 0.0f;
|
||||
y2 = 0.0f;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If the paragraph had at least a single empty TextSpan, the layout
|
||||
// can compute some meaningful bounds.
|
||||
const Bullet& bullet = fParagraphStyle.Bullet();
|
||||
x1 = fParagraphStyle.LineInset() + fParagraphStyle.FirstLineInset()
|
||||
+ bullet.Spacing();
|
||||
x2 = x1;
|
||||
const LineInfo& lineInfo = fLineInfos.ItemAt(0);
|
||||
y1 = lineInfo.y;
|
||||
y2 = lineInfo.y + lineInfo.height;
|
||||
}
|
||||
|
|
|
@ -231,6 +231,9 @@ private:
|
|||
const TextSpan& span,
|
||||
int32 textOffset) const;
|
||||
|
||||
void _GetEmptyLayoutBounds(float& x1, float& y1,
|
||||
float& x2, float& y2) const;
|
||||
|
||||
private:
|
||||
TextSpanList fTextSpans;
|
||||
ParagraphStyle fParagraphStyle;
|
||||
|
|
Loading…
Reference in New Issue