summaryrefslogtreecommitdiff
path: root/indra/llrender/llfontgl.cpp
diff options
context:
space:
mode:
authorRichard Nelson <richard@lindenlab.com>2009-10-14 20:16:18 +0000
committerRichard Nelson <richard@lindenlab.com>2009-10-14 20:16:18 +0000
commitfd312d1929de708e5765cf1b3815cb61752fc355 (patch)
treecc4dbf334b89970f1499acfaee3571b7cd529374 /indra/llrender/llfontgl.cpp
parent7197e1aa962be6174a219027ced4dec72b5553a2 (diff)
improved metrics for llfontgl::getWidth (use greater of character width/xadvance)
llfontgl::Addchar now called consistently when requesting font metrics no longer possible to have font glyph info without rendered font EXT-1294 - LLExpandableTextBox: wrong ellipses reviewed by James and Mani
Diffstat (limited to 'indra/llrender/llfontgl.cpp')
-rw-r--r--indra/llrender/llfontgl.cpp50
1 files changed, 16 insertions, 34 deletions
diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp
index 2d7b9760e8..c9163d2890 100644
--- a/indra/llrender/llfontgl.cpp
+++ b/indra/llrender/llfontgl.cpp
@@ -252,11 +252,6 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons
{
llwchar wch = wstr[i];
- if (!mFontFreetype->hasGlyph(wch))
- {
- addChar(wch);
- }
-
const LLFontGlyphInfo* fgi= mFontFreetype->getGlyphInfo(wch);
if (!fgi)
{
@@ -299,10 +294,6 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons
if (next_char && (next_char < LAST_CHARACTER))
{
// Kern this puppy.
- if (!mFontFreetype->hasGlyph(next_char))
- {
- addChar(next_char);
- }
cur_x += mFontFreetype->getXKerning(wch, next_char);
}
@@ -442,15 +433,22 @@ F32 LLFontGL::getWidthF32(const llwchar* wchars, S32 begin_offset, S32 max_chars
F32 cur_x = 0;
const S32 max_index = begin_offset + max_chars;
- for (S32 i = begin_offset; i < max_index; i++)
+
+ F32 width_padding = 0.f;
+ for (S32 i = begin_offset; i < max_index && wchars[i] != 0; i++)
{
llwchar wch = wchars[i];
- if (wch == 0)
- {
- break; // done
- }
- cur_x += mFontFreetype->getXAdvance(wch);
+ const LLFontGlyphInfo* fgi= mFontFreetype->getGlyphInfo(wch);
+
+ F32 advance = mFontFreetype->getXAdvance(wch);
+
+ // for the last character we want to measure the greater of its width and xadvance values
+ // so keep track of the difference between these values for the each character we measure
+ // so we can fix things up at the end
+ width_padding = llmax(0.f, (F32)fgi->mWidth - advance);
+
+ cur_x += advance;
llwchar next_char = wchars[i+1];
if (((i + 1) < begin_offset + max_chars)
@@ -464,6 +462,9 @@ F32 LLFontGL::getWidthF32(const llwchar* wchars, S32 begin_offset, S32 max_chars
cur_x = (F32)llfloor(cur_x + 0.5f);
}
+ // add in extra pixels for last character's width past its xadvance
+ cur_x += width_padding;
+
return cur_x / sScaleX;
}
@@ -663,25 +664,6 @@ S32 LLFontGL::charFromPixelOffset(const llwchar* wchars, S32 begin_offset, F32 t
return llmin(max_chars, pos - begin_offset);
}
-BOOL LLFontGL::addChar(llwchar wch) const
-{
- if (!mFontFreetype->addChar(wch))
- {
- return FALSE;
- }
-
- stop_glerror();
-
- LLFontGlyphInfo *glyph_info = mFontFreetype->getGlyphInfo(wch);
- U32 bitmap_num = glyph_info->mBitmapNum;
-
- const LLFontBitmapCache* font_bitmap_cache = mFontFreetype->getFontBitmapCache();
- LLImageGL *image_gl = font_bitmap_cache->getImageGL(bitmap_num);
- LLImageRaw *image_raw = font_bitmap_cache->getImageRaw(bitmap_num);
- image_gl->setSubImage(image_raw, 0, 0, image_gl->getWidth(), image_gl->getHeight());
- return TRUE;
-}
-
const LLFontDescriptor& LLFontGL::getFontDesc() const
{
return mFontDescriptor;