summaryrefslogtreecommitdiff
path: root/indra/llrender
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llrender')
-rw-r--r--indra/llrender/llfontfreetype.h3
-rw-r--r--indra/llrender/llfontgl.cpp30
2 files changed, 21 insertions, 12 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 a28ffbfdc0..db1f019a81 100644
--- a/indra/llrender/llfontgl.cpp
+++ b/indra/llrender/llfontgl.cpp
@@ -195,7 +195,7 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons
cur_y += mFontFreetype->getDescenderHeight();
break;
case VCENTER:
- cur_y -= ((mFontFreetype->getAscenderHeight() - mFontFreetype->getDescenderHeight())/2.f);
+ cur_y -= (mFontFreetype->getAscenderHeight() - mFontFreetype->getDescenderHeight()) / 2.f;
break;
case BASELINE:
// Baseline, do nothing.
@@ -221,7 +221,7 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons
cur_render_y = cur_y;
cur_render_x = cur_x;
- F32 start_x = cur_x;
+ F32 start_x = llround(cur_x);
const LLFontBitmapCache* font_bitmap_cache = mFontFreetype->getFontBitmapCache();
@@ -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("....")));
@@ -301,8 +302,8 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons
// Must do this to cur_x, not just to cur_render_x, otherwise you
// will squish sub-pixel kerned characters too close together.
// For example, "CCCCC" looks bad.
- cur_x = (F32)llfloor(cur_x + 0.5f);
- //cur_y = (F32)llfloor(cur_y + 0.5f);
+ cur_x = (F32)llround(cur_x);
+ //cur_y = (F32)llround(cur_y);
cur_render_x = cur_x;
cur_render_y = cur_y;
@@ -461,7 +462,7 @@ F32 LLFontGL::getWidthF32(const llwchar* wchars, S32 begin_offset, S32 max_chars
cur_x += mFontFreetype->getXKerning(wch, next_char);
}
// Round after kerning.
- cur_x = (F32)llfloor(cur_x + 0.5f);
+ cur_x = (F32)llround(cur_x);
}
// add in extra pixels for last character's width past its xadvance
@@ -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;
@@ -548,7 +558,7 @@ S32 LLFontGL::maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_ch
}
// Round after kerning.
- cur_x = (F32)llfloor(cur_x + 0.5f);
+ cur_x = llround(cur_x);
drawn_x = cur_x;
}
@@ -660,7 +670,7 @@ S32 LLFontGL::charFromPixelOffset(const llwchar* wchars, S32 begin_offset, F32 t
}
// Round after kerning.
- cur_x = (F32)llfloor(cur_x + 0.5f);
+ cur_x = llround(cur_x);
}
return llmin(max_chars, pos - begin_offset);