diff options
Diffstat (limited to 'indra/llrender')
-rw-r--r-- | indra/llrender/llfontgl.cpp | 56 | ||||
-rw-r--r-- | indra/llrender/llfontgl.h | 4 |
2 files changed, 23 insertions, 37 deletions
diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp index 82e8227ffe..6e6d02177d 100644 --- a/indra/llrender/llfontgl.cpp +++ b/indra/llrender/llfontgl.cpp @@ -115,23 +115,23 @@ static LLFastTimer::DeclareTimer FTM_RENDER_FONTS("Fonts"); S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, const LLRect& rect, const LLColor4 &color, HAlign halign, VAlign valign, U8 style, ShadowType shadow, S32 max_chars, F32* right_x, BOOL use_ellipses) const { - F32 x = rect.mLeft; + F32 x = (F32)rect.mLeft; F32 y = 0.f; switch(valign) { case TOP: - y = rect.mTop; + y = (F32)rect.mTop; break; case VCENTER: - y = rect.getCenterY(); + y = (F32)rect.getCenterY(); break; case BASELINE: case BOTTOM: - y = rect.mBottom; + y = (F32)rect.mBottom; break; default: - y = rect.mBottom; + y = (F32)rect.mBottom; break; } return render(wstr, begin_offset, x, y, color, halign, valign, style, shadow, max_chars, rect.getWidth(), right_x, use_ellipses); @@ -185,9 +185,6 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons //gGL.translateUI(-pixel_offset_x, -pixel_offset_y, 0.f); LLVector2 origin(floorf(sCurOrigin.mX*sScaleX), floorf(sCurOrigin.mY*sScaleY)); - // snap the text origin to a pixel grid to start with - origin.mV[VX] -= llround((F32)sCurOrigin.mX) - (sCurOrigin.mX); - origin.mV[VY] -= llround((F32)sCurOrigin.mY) - (sCurOrigin.mY); // Depth translation, so that floating text appears 'inworld' // and is correclty occluded. @@ -215,16 +212,17 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons cur_y = ((F32)y * sScaleY) + origin.mV[VY]; // Offset y by vertical alignment. + // use unscaled font metrics here switch (valign) { case TOP: - cur_y -= mFontFreetype->getAscenderHeight(); + cur_y -= llceil(mFontFreetype->getAscenderHeight()); break; case BOTTOM: - cur_y += mFontFreetype->getDescenderHeight(); + cur_y += llceil(mFontFreetype->getDescenderHeight()); break; case VCENTER: - cur_y -= (mFontFreetype->getAscenderHeight() - mFontFreetype->getDescenderHeight()) / 2.f; + cur_y -= llceil((llceil(mFontFreetype->getAscenderHeight()) - llceil(mFontFreetype->getDescenderHeight())) / 2.f); break; case BASELINE: // Baseline, do nothing. @@ -250,7 +248,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 = llround(cur_x); + F32 start_x = (F32)llround(cur_x); const LLFontBitmapCache* font_bitmap_cache = mFontFreetype->getFontBitmapCache(); @@ -334,10 +332,10 @@ 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(llround(cur_render_x + (F32)fgi->mXBearing), - llround(cur_render_y + (F32)fgi->mYBearing), - llround(cur_render_x + (F32)fgi->mXBearing) + (F32)fgi->mWidth, - llround(cur_render_y + (F32)fgi->mYBearing) - (F32)fgi->mHeight); + LLRectf screen_rect((F32)llround(cur_render_x + (F32)fgi->mXBearing), + (F32)llround(cur_render_y + (F32)fgi->mYBearing), + (F32)llround(cur_render_x + (F32)fgi->mXBearing) + (F32)fgi->mWidth, + (F32)llround(cur_render_y + (F32)fgi->mYBearing) - (F32)fgi->mHeight); if (glyph_count >= GLYPH_BATCH_SIZE) { @@ -390,12 +388,12 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons //FIXME: add underline as glyph? if (style_to_add & UNDERLINE) { - F32 descender = mFontFreetype->getDescenderHeight(); + F32 descender = (F32)llfloor(mFontFreetype->getDescenderHeight()); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); gGL.begin(LLRender::LINES); - gGL.vertex2f(start_x, cur_y - (descender)); - gGL.vertex2f(cur_x, cur_y - (descender)); + gGL.vertex2f(start_x, cur_y - descender); + gGL.vertex2f(cur_x, cur_y - descender); gGL.end(); } @@ -444,19 +442,9 @@ S32 LLFontGL::renderUTF8(const std::string &text, S32 begin_offset, S32 x, S32 y } // font metrics - override for LLFontFreetype that returns units of virtual pixels -F32 LLFontGL::getLineHeight() const +S32 LLFontGL::getLineHeight() const { - return (F32)llround(mFontFreetype->getLineHeight() / sScaleY); -} - -F32 LLFontGL::getAscenderHeight() const -{ - return (F32)llround(mFontFreetype->getAscenderHeight() / sScaleY); -} - -F32 LLFontGL::getDescenderHeight() const -{ - return (F32)llround(mFontFreetype->getDescenderHeight() / sScaleY); + return llceil(mFontFreetype->getAscenderHeight() / sScaleY) + llceil(mFontFreetype->getDescenderHeight() / sScaleY); } S32 LLFontGL::getWidth(const std::string& utf8text) const @@ -645,7 +633,7 @@ S32 LLFontGL::maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_ch } // Round after kerning. - cur_x = llround(cur_x); + cur_x = (F32)llround(cur_x); drawn_x = cur_x; } @@ -716,7 +704,7 @@ S32 LLFontGL::firstDrawableChar(const llwchar* wchars, F32 max_pixels, S32 text_ } // Round after kerning. - total_width = llround(total_width); + total_width = (F32)llround(total_width); } if (drawable_chars == 0) @@ -799,7 +787,7 @@ S32 LLFontGL::charFromPixelOffset(const llwchar* wchars, S32 begin_offset, F32 t // Round after kerning. - cur_x = llround(cur_x); + cur_x = (F32)llround(cur_x); } return llmin(max_chars, pos - begin_offset); diff --git a/indra/llrender/llfontgl.h b/indra/llrender/llfontgl.h index dc8d848ed2..9d7e2891e3 100644 --- a/indra/llrender/llfontgl.h +++ b/indra/llrender/llfontgl.h @@ -115,9 +115,7 @@ public: S32 renderUTF8(const std::string &text, S32 begin_offset, S32 x, S32 y, const LLColor4 &color, HAlign halign, VAlign valign, U8 style = NORMAL, ShadowType shadow = NO_SHADOW) const; // font metrics - override for LLFontFreetype that returns units of virtual pixels - F32 getLineHeight() const; - F32 getAscenderHeight() const; - F32 getDescenderHeight() const; + S32 getLineHeight() const; S32 getWidth(const std::string& utf8text) const; S32 getWidth(const llwchar* wchars) const; |