Commit aaef5c162cc13961cfd9bd32e633907bf606e73b

sammy 2010-05-23T14:20:37

Enforce GL_POLYGON_BIT in FTPolygonFont, so that the caller's context does not interfere with our rendering. Addresses SF bug #2021485.

diff --git a/src/FTFont/FTPolygonFont.cpp b/src/FTFont/FTPolygonFont.cpp
index 594e91f..2948e0c 100644
--- a/src/FTFont/FTPolygonFont.cpp
+++ b/src/FTFont/FTPolygonFont.cpp
@@ -2,7 +2,7 @@
  * FTGL - OpenGL font library
  *
  * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
- * Copyright (c) 2008 Sam Hocevar <sam@hocevar.net>
+ * Copyright (c) 2008-2010 Sam Hocevar <sam@hocevar.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -87,3 +87,40 @@ FTPolygonFontImpl::FTPolygonFontImpl(FTFont *ftFont,
     load_flags = FT_LOAD_NO_HINTING;
 }
 
+
+template <typename T>
+inline FTPoint FTPolygonFontImpl::RenderI(const T* string, const int len,
+                                          FTPoint position, FTPoint spacing,
+                                          int renderMode)
+{
+    // Protect GL_POLYGON
+    glPushAttrib(GL_POLYGON_BIT);
+
+    // Activate front and back face filling. If the caller wants only
+    // front face, it can set proper culling.
+    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+
+    FTPoint tmp = FTFontImpl::Render(string, len,
+                                     position, spacing, renderMode);
+
+    glPopAttrib();
+
+    return tmp;
+}
+
+
+FTPoint FTPolygonFontImpl::Render(const char * string, const int len,
+                                  FTPoint position, FTPoint spacing,
+                                  int renderMode)
+{
+    return RenderI(string, len, position, spacing, renderMode);
+}
+
+
+FTPoint FTPolygonFontImpl::Render(const wchar_t * string, const int len,
+                                  FTPoint position, FTPoint spacing,
+                                  int renderMode)
+{
+    return RenderI(string, len, position, spacing, renderMode);
+}
+
diff --git a/src/FTFont/FTPolygonFontImpl.h b/src/FTFont/FTPolygonFontImpl.h
index ddf46ed..3f4f1e2 100644
--- a/src/FTFont/FTPolygonFontImpl.h
+++ b/src/FTFont/FTPolygonFontImpl.h
@@ -2,7 +2,7 @@
  * FTGL - OpenGL font library
  *
  * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
- * Copyright (c) 2008 Sam Hocevar <sam@hocevar.net>
+ * Copyright (c) 2008-2010 Sam Hocevar <sam@hocevar.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -45,16 +45,29 @@ class FTPolygonFontImpl : public FTFontImpl
          * Set the outset distance for the font. Only implemented by
          * FTOutlineFont, FTPolygonFont and FTExtrudeFont
          *
-         * @param depth  The outset distance.
+         * @param outset  The outset distance.
          */
         virtual void Outset(float o) { outset = o; }
 
+        virtual FTPoint Render(const char *s, const int len,
+                               FTPoint position, FTPoint spacing,
+                               int renderMode);
+
+        virtual FTPoint Render(const wchar_t *s, const int len,
+                               FTPoint position, FTPoint spacing,
+                               int renderMode);
+
     private:
         /**
-         * The outset distance (front and back) for the font.
+         * The outset distance for the font.
          */
         float outset;
+
+        /* Internal generic Render() implementation */
+        template <typename T>
+        inline FTPoint RenderI(const T *s, const int len,
+                               FTPoint position, FTPoint spacing, int mode);
 };
 
-#endif  //  __FTPolygonFontImpl__
+#endif // __FTPolygonFontImpl__