From 41889b59f3cae37272cd395697994e9e9fe873bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 22 Jan 2014 00:12:11 +0100 Subject: [PATCH] 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. --- .../haiku-depot/textview/ParagraphLayout.cpp | 37 ++++++++++++++----- .../haiku-depot/textview/ParagraphLayout.h | 3 ++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/apps/haiku-depot/textview/ParagraphLayout.cpp b/src/apps/haiku-depot/textview/ParagraphLayout.cpp index 1b0992abf6..4d49ba6432 100644 --- a/src/apps/haiku-depot/textview/ParagraphLayout.cpp +++ b/src/apps/haiku-depot/textview/ParagraphLayout.cpp @@ -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; +} diff --git a/src/apps/haiku-depot/textview/ParagraphLayout.h b/src/apps/haiku-depot/textview/ParagraphLayout.h index 99bf5b76c6..4cc46df80c 100644 --- a/src/apps/haiku-depot/textview/ParagraphLayout.h +++ b/src/apps/haiku-depot/textview/ParagraphLayout.h @@ -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;