Commit 9f52ec90ec0bfd656cffcef1c9d988e11583cad4

sammy 2008-04-25T10:01:07

* Align FTPixmapGlyph and FTTextureGlyph objects at round pixel coordinates to reduce bleeding. Patch by Ton Roosendaal, from Blender commit r4411.

diff --git a/src/FTPixmapGlyph.cpp b/src/FTPixmapGlyph.cpp
index dd56097..00d7dcf 100644
--- a/src/FTPixmapGlyph.cpp
+++ b/src/FTPixmapGlyph.cpp
@@ -34,6 +34,8 @@
 
 #include "config.h"
 
+#include <math.h>
+
 #include "FTPixmapGlyph.h"
 
 FTPixmapGlyph::FTPixmapGlyph( FT_GlyphSlot glyph)
@@ -97,8 +99,8 @@ const FTPoint& FTPixmapGlyph::Render(const FTPoint& pen, int renderMode)
     {
         float dx, dy;
 
-        dx = pen.X() + pos.X();
-        dy = pen.Y() - pos.Y();
+        dx = floor(pen.X() + pos.X());
+        dy = floor(pen.Y() - pos.Y());
 
         glBitmap(0, 0, 0.0f, 0.0f, dx, dy, (const GLubyte*)0);
         glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
diff --git a/src/FTTextureGlyph.cpp b/src/FTTextureGlyph.cpp
index b478f5b..fca61ac 100644
--- a/src/FTTextureGlyph.cpp
+++ b/src/FTTextureGlyph.cpp
@@ -34,6 +34,8 @@
 
 #include "config.h"
 
+#include <math.h>
+
 #include "FTTextureGlyph.h"
 
 GLint FTTextureGlyph::activeTextureID = 0;
@@ -93,30 +95,31 @@ FTTextureGlyph::~FTTextureGlyph()
 
 const FTPoint& FTTextureGlyph::Render(const FTPoint& pen, int renderMode)
 {
+    float dx, dy;
+
     if(activeTextureID != glTextureID)
     {
         glBindTexture(GL_TEXTURE_2D, (GLuint)glTextureID);
         activeTextureID = glTextureID;
     }
 
-    glTranslatef(pen.X(),  pen.Y(), 0.0f);
+    dx = floor(pen.X() + pos.X());
+    dy = floor(pen.Y() + pos.Y());
 
     glBegin(GL_QUADS);
         glTexCoord2f(uv[0].X(), uv[0].Y());
-        glVertex2f(pos.X(), pos.Y());
+        glVertex2f(dx, dy);
 
         glTexCoord2f(uv[0].X(), uv[1].Y());
-        glVertex2f(pos.X(), pos.Y() - destHeight);
+        glVertex2f(dx, dy - destHeight);
 
         glTexCoord2f(uv[1].X(), uv[1].Y());
-        glVertex2f(destWidth + pos.X(), pos.Y() - destHeight);
+        glVertex2f(dx + destWidth, dy - destHeight);
 
         glTexCoord2f(uv[1].X(), uv[0].Y());
-        glVertex2f(destWidth + pos.X(), pos.Y());
+        glVertex2f(dx + destWidth, dy);
     glEnd();
 
-    glTranslatef(-pen.X(), -pen.Y(), 0.0f);
-
     return advance;
 }