summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrichard <none@none>2009-12-11 13:50:40 -0800
committerrichard <none@none>2009-12-11 13:50:40 -0800
commitb8fdf825102cdc260a54565f9ee5e67ab160c207 (patch)
treed0fca955799a24ffdf98a3acb8887258e465c997
parent2feb3f538e000a9562c0bea8a0ed19ea04525c6b (diff)
fix for ellipses not appearing in single line text widgets
fix for ellipses sometimes appearing at end of wrapped line of text reviewed by James
-rw-r--r--indra/llrender/llfontfreetype.h3
-rw-r--r--indra/llrender/llfontgl.cpp16
-rw-r--r--indra/llui/lldraghandle.cpp1
-rw-r--r--indra/llui/lltextbase.cpp55
-rw-r--r--indra/newview/llexpandabletextbox.cpp23
5 files changed, 66 insertions, 32 deletions
diff --git a/indra/llrender/llfontfreetype.h b/indra/llrender/llfontfreetype.h
index 1325b4995b..7a5d029038 100644
--- a/indra/llrender/llfontfreetype.h
+++ b/indra/llrender/llfontfreetype.h
@@ -58,9 +58,8 @@ private:
~LLFontManager();
};
-class LLFontGlyphInfo
+struct LLFontGlyphInfo
{
-public:
LLFontGlyphInfo(U32 index);
U32 mGlyphIndex;
diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp
index 19afa997fa..db1f019a81 100644
--- a/indra/llrender/llfontgl.cpp
+++ b/indra/llrender/llfontgl.cpp
@@ -235,7 +235,8 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons
if (use_ellipses)
{
// check for too long of a string
- if (getWidthF32(wstr.c_str(), begin_offset, max_chars) * sScaleX > scaled_max_pixels)
+ S32 string_width = llround(getWidthF32(wstr.c_str(), begin_offset, max_chars) * sScaleX);
+ if (string_width > scaled_max_pixels)
{
// use four dots for ellipsis width to generate padding
const LLWString dots(utf8str_to_wstring(std::string("....")));
@@ -490,6 +491,7 @@ S32 LLFontGL::maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_ch
// avoid S32 overflow when max_pixels == S32_MAX by staying in floating point
F32 scaled_max_pixels = ceil(max_pixels * sScaleX);
+ F32 width_padding = 0.f;
S32 i;
for (i=0; (i < max_chars); i++)
@@ -533,9 +535,17 @@ S32 LLFontGL::maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_ch
}
}
- cur_x += mFontFreetype->getXAdvance(wch);
+ LLFontGlyphInfo* fgi = mFontFreetype->getGlyphInfo(wch);
+
+ // account for glyphs that run beyond the starting point for the next glyphs
+ width_padding = llmax( 0.f, // always use positive padding amount
+ width_padding - fgi->mXAdvance, // previous padding left over after advance of current character
+ (F32)(fgi->mWidth + fgi->mXBearing) - fgi->mXAdvance); // difference between width of this character and advance to next character
+
+ cur_x += fgi->mXAdvance;
- if (scaled_max_pixels < cur_x)
+ // clip if current character runs past scaled_max_pixels (using width_padding)
+ if (scaled_max_pixels < cur_x + width_padding)
{
clip = TRUE;
break;
diff --git a/indra/llui/lldraghandle.cpp b/indra/llui/lldraghandle.cpp
index d9b98b1c28..a93c666648 100644
--- a/indra/llui/lldraghandle.cpp
+++ b/indra/llui/lldraghandle.cpp
@@ -112,6 +112,7 @@ void LLDragHandleTop::setTitle(const std::string& title)
params.font(font);
params.follows.flags(FOLLOWS_TOP | FOLLOWS_LEFT | FOLLOWS_RIGHT);
params.font_shadow(LLFontGL::DROP_SHADOW_SOFT);
+ params.use_ellipses = true;
mTitleBox = LLUICtrlFactory::create<LLTextBox> (params);
addChild( mTitleBox );
}
diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp
index e0503a0844..d50abaa83a 100644
--- a/indra/llui/lltextbase.cpp
+++ b/indra/llui/lltextbase.cpp
@@ -561,14 +561,14 @@ void LLTextBase::drawText()
S32 clipped_end = llmin( line_end, cur_segment->getEnd() ) - cur_segment->getStart();
- if (mUseEllipses
- && clipped_end == line_end
- && next_line == last_line
- && last_line < (S32)mLineInfoList.size())
+ if (mUseEllipses // using ellipses
+ && clipped_end == line_end // last segment on line
+ && next_line == last_line // this is the last visible line
+ && last_line < (S32)mLineInfoList.size()) // and there is more text to display
{
- // more text to go, but we can't fit it
- // so attempt to draw one extra character to force ellipses
- clipped_end++;
+ // more lines of text to go, but we can't fit them
+ // so shrink text rect to force ellipses
+ text_rect.mRight -= 2;
}
text_rect.mLeft = (S32)(cur_segment->draw(seg_start - cur_segment->getStart(), clipped_end, selection_left, selection_right, text_rect));
@@ -1071,7 +1071,7 @@ void LLTextBase::reflow(S32 start_index)
while(mReflowNeeded)
{
- mReflowNeeded = FALSE;
+ mReflowNeeded = false;
// shrink document to minimum size (visible portion of text widget)
// to force inlined widgets with follows set to shrink
@@ -1101,8 +1101,8 @@ void LLTextBase::reflow(S32 start_index)
segment_set_t::iterator seg_iter = mSegments.begin();
S32 seg_offset = 0;
S32 line_start_index = 0;
- const S32 text_width = mTextRect.getWidth() - mHPad; // reserve room for margin
- S32 remaining_pixels = text_width;
+ const S32 text_available_width = mTextRect.getWidth() - mHPad; // reserve room for margin
+ S32 remaining_pixels = text_available_width;
LLWString text(getWText());
S32 line_count = 0;
@@ -1142,10 +1142,11 @@ void LLTextBase::reflow(S32 start_index)
S32 last_segment_char_on_line = segment->getStart() + seg_offset;
- S32 text_left = getLeftOffset(text_width - remaining_pixels);
+ S32 text_actual_width = text_available_width - remaining_pixels;
+ S32 text_left = getLeftOffset(text_actual_width);
LLRect line_rect(text_left,
cur_top,
- text_left + (text_width - remaining_pixels),
+ text_left + text_actual_width,
cur_top - line_height);
// if we didn't finish the current segment...
@@ -1160,7 +1161,7 @@ void LLTextBase::reflow(S32 start_index)
line_start_index = segment->getStart() + seg_offset;
cur_top -= llround((F32)line_height * mLineSpacingMult) + mLineSpacingPixels;
- remaining_pixels = text_width;
+ remaining_pixels = text_available_width;
line_height = 0;
}
// ...just consumed last segment..
@@ -1188,7 +1189,7 @@ void LLTextBase::reflow(S32 start_index)
line_start_index = segment->getStart() + seg_offset;
cur_top -= llround((F32)line_height * mLineSpacingMult) + mLineSpacingPixels;
line_height = 0;
- remaining_pixels = text_width;
+ remaining_pixels = text_available_width;
}
++seg_iter;
seg_offset = 0;
@@ -2096,7 +2097,13 @@ void LLTextBase::updateRects()
LLRect doc_rect = mContentsRect;
// use old mTextRect constraint document to width of viewable region
doc_rect.mLeft = 0;
- doc_rect.mRight = llmax(mTextRect.getWidth(), mContentsRect.mRight);
+
+ // allow horizontal scrolling?
+ // if so, use entire width of text contents (sans scrollbars)
+ // otherwise, stop at width of mTextRect
+ doc_rect.mRight = mScroller
+ ? llmax(mScroller->getRect().mRight - mScroller->getBorderWidth(), mContentsRect.mRight)
+ : mTextRect.getWidth();
mDocumentView->setShape(doc_rect);
@@ -2115,8 +2122,10 @@ void LLTextBase::updateRects()
needsReflow();
}
- // update document container again, using new mTextRect
- doc_rect.mRight = llmax(mTextRect.getWidth(), mContentsRect.mRight);
+ // update document container again, using new mTextRect (that has scrollbars enabled as needed)
+ doc_rect.mRight = mScroller
+ ? llmax(mTextRect.getWidth(), mContentsRect.mRight)
+ : mTextRect.getWidth();
mDocumentView->setShape(doc_rect);
}
@@ -2413,10 +2422,18 @@ bool LLNormalTextSegment::getDimensions(S32 first_char, S32 num_chars, S32& widt
if (num_chars > 0)
{
LLWString text = mEditor.getWText();
- width = mStyle->getFont()->getWidth(text.c_str(), mStart + first_char, num_chars);
// if last character is a newline, then return true, forcing line break
llwchar last_char = text[mStart + first_char + num_chars - 1];
- force_newline = (last_char == '\n');
+ if (last_char == '\n')
+ {
+ force_newline = true;
+ // don't count newline in font width
+ width = mStyle->getFont()->getWidth(text.c_str(), mStart + first_char, num_chars - 1);
+ }
+ else
+ {
+ width = mStyle->getFont()->getWidth(text.c_str(), mStart + first_char, num_chars);
+ }
}
else
{
diff --git a/indra/newview/llexpandabletextbox.cpp b/indra/newview/llexpandabletextbox.cpp
index bd6936f05c..9c37c953fe 100644
--- a/indra/newview/llexpandabletextbox.cpp
+++ b/indra/newview/llexpandabletextbox.cpp
@@ -51,8 +51,16 @@ public:
/*virtual*/ bool getDimensions(S32 first_char, S32 num_chars, S32& width, S32& height) const
{
// more label always spans width of text box
- width = mEditor.getTextRect().getWidth() - mEditor.getHPad();
- height = llceil(mStyle->getFont()->getLineHeight());
+ if (num_chars == 0)
+ {
+ width = 0;
+ height = 0;
+ }
+ else
+ {
+ width = mEditor.getDocumentView()->getRect().getWidth() - mEditor.getHPad();
+ height = llceil(mStyle->getFont()->getLineHeight());
+ }
return true;
}
/*virtual*/ S32 getOffset(S32 segment_local_x_coord, S32 start_offset, S32 num_chars, bool round) const
@@ -104,7 +112,8 @@ private:
LLExpandableTextBox::LLTextBoxEx::Params::Params()
: more_label("more_label")
-{}
+{
+}
LLExpandableTextBox::LLTextBoxEx::LLTextBoxEx(const Params& p)
: LLTextBox(p),
@@ -117,16 +126,13 @@ LLExpandableTextBox::LLTextBoxEx::LLTextBoxEx(const Params& p)
void LLExpandableTextBox::LLTextBoxEx::reshape(S32 width, S32 height, BOOL called_from_parent)
{
+ hideExpandText();
LLTextBox::reshape(width, height, called_from_parent);
if (getTextPixelHeight() > getRect().getHeight())
{
showExpandText();
}
- else
- {
- hideExpandText();
- }
}
void LLExpandableTextBox::LLTextBoxEx::setText(const LLStringExplicit& text,const LLStyle::Params& input_params)
@@ -317,7 +323,8 @@ void LLExpandableTextBox::expandTextBox()
mTextBox->hideExpandText();
S32 text_delta = mTextBox->getVerticalTextDelta();
- text_delta += mTextBox->getVPad() * 2 + mScroll->getBorderWidth() * 2;
+ text_delta += mTextBox->getVPad() * 2;
+ text_delta += mScroll->getBorderWidth() * 2;
// no need to expand
if(text_delta <= 0)
{