浏览代码

added "options" for generating custom images

dmuratshin 9 年之前
父节点
当前提交
167b2dc5e5
共有 3 个文件被更改,包括 34 次插入11 次删除
  1. 1 0
      .gitignore
  2. 28 11
      src/ResFontFT.cpp
  3. 5 0
      src/ResFontFT.h

+ 1 - 0
.gitignore

@@ -12,3 +12,4 @@ examples/HelloFreeType/proj.cmake/build_emsc/
 examples/HelloFreeType/proj.win32/Debug_v*
 *.sdf
 *.opensdf
+examples/HelloFreeType/proj.win32/HelloFreeType.suo

+ 28 - 11
src/ResFontFT.cpp

@@ -105,6 +105,19 @@ uint32_t decodeSymbol(int sym)
 
 namespace oxygine
 {
+    void ftGenDefault(ImageData& src, MemoryTexture& dest, int code, const glyphOptions& opt)
+    {
+        dest.init(src.w, src.h, TF_R8G8B8A8);
+        operations::blitPremultiply(src, dest.lock());
+    }
+
+    static ResFontFT::ftGenHook _ftGen = ftGenDefault;
+
+    void ResFontFT::setGenHook(ftGenHook f)
+    {
+        _ftGen = f;
+    }
+
     class FontFT : public Font
     {
     public:
@@ -120,7 +133,11 @@ namespace oxygine
     protected:
         ResFontFT* _rs;
         int _size;
+#if OXYGINE_VERSION > 4
+        bool loadGlyph(int code, glyph& g, const glyphOptions& opt) OVERRIDE
+#else
         bool loadGlyph(int code, glyph& g) OVERRIDE
+#endif
         {
             FT_Face face = _rs->_face;
             FT_Set_Pixel_Sizes(_rs->_face, 0, _size);
@@ -147,17 +164,14 @@ namespace oxygine
             static MemoryTexture mt;
             if (src.w && src.h)
             {
-                mt.init(src.w, src.h, TF_R8G8B8A8);
-
-                ImageData dest = mt.lock();
-                operations::blitPremultiply(src, dest);
-                //PixelA8
-
-                _rs->_atlas.add(dest, srcRect, t);
+#if OXYGINE_VERSION > 4
+                _ftGen(src, mt, code, opt);
+#else
+                _ftGen(src, mt, code, 0);
+#endif
 
+                _rs->_atlas.add(mt.lock(), srcRect, t);
                 OX_ASSERT(t);
-
-
                 g.src = srcRect.cast<RectF>();
                 Vector2 sz((float)t->getWidth(), (float)t->getHeight());
                 g.src.pos = g.src.pos.div(sz);
@@ -169,9 +183,12 @@ namespace oxygine
             g.advance_y = static_cast<short>(slot->advance.y >> 6);
             g.offset_x = slot->bitmap_left;
             g.offset_y = - slot->bitmap_top;
-            g.sh = src.h;
-            g.sw = src.w;
+            g.sw = mt.getWidth();
+            g.sh = mt.getHeight();
             g.ch = code;
+#if OXYGINE_VERSION > 4
+            g.opt = opt;
+#endif
 
             return true;
         }

+ 5 - 0
src/ResFontFT.h

@@ -13,6 +13,7 @@ namespace oxygine
 {
     class CreateResourceContext;
     class FontFT;
+    typedef unsigned int glyphOptions;
 
     class ResFontFT : public ResFont
     {
@@ -20,6 +21,10 @@ namespace oxygine
         static void initLibrary();
         static void freeLibrary();
 
+        typedef void(*ftGenHook)(ImageData& src, class Image& dest, int code, const glyphOptions& opt);
+
+        static void setGenHook(ftGenHook);
+
         ResFontFT();
         ~ResFontFT();