summaryrefslogtreecommitdiff
path: root/indra/llrender/llfontgl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llrender/llfontgl.cpp')
-rw-r--r--indra/llrender/llfontgl.cpp51
1 files changed, 38 insertions, 13 deletions
diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp
index 16eec1fdd2..89da15ed43 100644
--- a/indra/llrender/llfontgl.cpp
+++ b/indra/llrender/llfontgl.cpp
@@ -90,14 +90,14 @@ void LLFontGL::destroyGL()
mFontFreetype->destroyGL();
}
-bool LLFontGL::loadFace(const std::string& filename, F32 point_size, const F32 vert_dpi, const F32 horz_dpi, bool is_fallback, S32 face_n)
+bool LLFontGL::loadFace(const std::string& filename, F32 point_size, const F32 vert_dpi, const F32 horz_dpi, S32 weight, bool is_fallback, S32 face_n, EFontHinting hinting, S32 flags)
{
if(mFontFreetype == reinterpret_cast<LLFontFreetype*>(NULL))
{
mFontFreetype = new LLFontFreetype;
}
- return mFontFreetype->loadFace(filename, point_size, vert_dpi, horz_dpi, is_fallback, face_n);
+ return mFontFreetype->loadFace(filename, point_size, vert_dpi, horz_dpi, weight, is_fallback, face_n, hinting, flags);
}
S32 LLFontGL::getNumFaces(const std::string& filename)
@@ -345,6 +345,15 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons
break;
}
+ // Calculate horizontal offset for tabular numbers (center narrow digits)
+ F32 x_offset = 0.0f;
+ if (mFontFreetype->getFontWeight() > 0 && fgi->mChar >= '0' && fgi->mChar <= '9' && mFontFreetype->getMaxDigitWidth() > 0.0f)
+ {
+ // getXAdvance will return max digit width.
+ // use mXAdvanceRaw directly here, since we don't want to get max width instead.
+ x_offset = (mFontFreetype->getMaxDigitWidth() - fgi->mXAdvanceRaw) * 0.5f;
+ }
+
// Draw the text at the appropriate location
//Specify vertices and texture coordinates
LLRectf uv_rect((fgi->mXBitmapOffset) * inv_width,
@@ -352,9 +361,9 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons
(fgi->mXBitmapOffset + fgi->mWidth) * inv_width,
(fgi->mYBitmapOffset - PAD_UVY) * inv_height);
// snap glyph origin to whole screen pixel
- LLRectf screen_rect((F32)ll_round(cur_render_x + (F32)fgi->mXBearing),
+ LLRectf screen_rect((F32)ll_round(cur_render_x + (F32)fgi->mXBearing + x_offset),
(F32)ll_round(cur_render_y + (F32)fgi->mYBearing),
- (F32)ll_round(cur_render_x + (F32)fgi->mXBearing) + (F32)fgi->mWidth,
+ (F32)ll_round(cur_render_x + (F32)fgi->mXBearing + x_offset) + (F32)fgi->mWidth,
(F32)ll_round(cur_render_y + (F32)fgi->mYBearing) - (F32)fgi->mHeight);
if (glyph_count >= GLYPH_BATCH_SIZE)
@@ -375,7 +384,7 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons
col, style_to_add, shadow, drop_shadow_strength);
chars_drawn++;
- cur_x += fgi->mXAdvance;
+ cur_x += mFontFreetype->getXAdvance(fgi);
cur_y += fgi->mYAdvance;
llwchar next_char = wstr[i+1];
@@ -605,10 +614,15 @@ S32 LLFontGL::maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_ch
S32 start_of_last_word = 0;
bool in_word = false;
- // avoid S32 overflow when max_pixels == S32_MAX by staying in floating point
F32 scaled_max_pixels = max_pixels * sScaleX;
+ if (scaled_max_pixels >= (F32)S32_MAX)
+ {
+ scaled_max_pixels = (F32)S32_MAX;
+ }
+
F32 width_padding = 0.f;
+ const S32 LAST_CHARACTER = LLFontFreetype::LAST_CHAR_FULL;
LLFontGlyphInfo* next_glyph = NULL;
S32 i;
@@ -665,21 +679,25 @@ S32 LLFontGL::maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_ch
}
}
+ F32 advance = mFontFreetype->getXAdvance(fgi);
+
// 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
+ width_padding - advance, // previous padding left over after advance of current character
+ (F32)(fgi->mWidth + fgi->mXBearing) - advance); // difference between width of this character and advance to next character
- cur_x += fgi->mXAdvance;
+ cur_x += advance;
- // clip if current character runs past scaled_max_pixels (using width_padding)
+ // Clip if current character runs past scaled_max_pixels (using width_padding)
if (scaled_max_pixels < cur_x + width_padding)
{
clip = true;
break;
}
- if (((i+1) < max_chars) && wchars[i+1])
+ if (((i+1) < max_chars)
+ && wchars[i+1]
+ && (wchars[i + 1] < LAST_CHARACTER))
{
// Kern this puppy.
next_glyph = mFontFreetype->getGlyphInfo(wchars[i+1], EFontGlyphType::Unspecified);
@@ -735,7 +753,7 @@ S32 LLFontGL::firstDrawableChar(const llwchar* wchars, F32 max_pixels, S32 text_
// other characters just use advance
F32 width = (i == start)
? (F32)(fgi->mWidth + fgi->mXBearing) // use actual width for last character
- : fgi->mXAdvance; // use advance for all other characters
+ : mFontFreetype->getXAdvance(fgi); // use advance for all other characters
if( scaled_max_pixels < (total_width + width) )
{
@@ -1115,7 +1133,14 @@ LLFontGL* LLFontGL::getFontSansSerifSmallItalic()
//static
LLFontGL* LLFontGL::getFontSansSerif()
{
- static LLFontGL* fontp = getFont(LLFontDescriptor("SansSerif","Medium",0));
+ static LLFontGL* fontp = getFont(LLFontDescriptor("SansSerif","Small",0));
+ return fontp;
+}
+
+// static
+LLFontGL* LLFontGL::getFontSansSerifMedium()
+{
+ static LLFontGL* fontp = getFont(LLFontDescriptor("SansSerif", "Medium", 0));
return fontp;
}