dmuratshin 9 年之前
父節點
當前提交
d6943b1c23

+ 4 - 7
oxygine/src/TextField.cpp

@@ -294,16 +294,13 @@ namespace oxygine
         if (!_style.font)
             return _root;
 
-
-        int fontSize = _style.fontSize;
-        float scale = globalScale;
-
-        _style.font->alignSize(globalScale, _style.fontSize, scale, fontSize);
+        float scale = 1.0f;
+        const Font* font = _style.font->getClosestFont(globalScale, _style.fontSize, scale);
 
         if ((_flags & flag_rebuild || _rtscale != scale) && _style.font)
         {
             _rtscale = scale;
-            _realFontSize = fontSize;
+            //_realFontSize = fontSize;
             delete _root;
 
             _flags &= ~flag_rebuild;
@@ -318,7 +315,7 @@ namespace oxygine
                 _root = new text::TextNode(_text.c_str());
             }
 
-            text::Aligner rd(_style, fontSize, scale, getSize());
+            text::Aligner rd(_style, font, scale, getSize());
             rd.begin();
             _root->resize(rd);
             rd.end();

+ 6 - 0
oxygine/src/res/ResFont.cpp

@@ -17,4 +17,10 @@ namespace oxygine
         }*/
     }
 
+    const oxygine::Font* ResFont::getClosestFont(float worldScale, int styleFontSize, float& resScale) const
+    {
+        resScale = 1.0f;
+        return getFont(0, styleFontSize);
+    }
+
 }

+ 1 - 1
oxygine/src/res/ResFont.h

@@ -16,7 +16,7 @@ namespace oxygine
         int getSize() const { return _size; }
 
         virtual void alignSize(float worldScale, int styleFontSize, float& resScale, int& resFontSize) const;
-
+        virtual const Font* getClosestFont(float worldScale, int styleFontSize, float& resScale) const;
     protected:
         int _size;
     };

+ 9 - 0
oxygine/src/res/ResFontBM.cpp

@@ -86,6 +86,15 @@ namespace oxygine
         }
     }
 
+    const oxygine::Font* ResFontBM::getClosestFont(float worldScale, int styleFontSize, float& resScale) const
+    {
+        if (!styleFontSize)
+            styleFontSize = _size;
+        resScale = _size / float(styleFontSize);
+
+        return _font;
+    }
+
     void ResFontBM::init(const char* path, bool premultipliedAlpha)
     {
         _premultipliedAlpha = premultipliedAlpha;

+ 1 - 0
oxygine/src/res/ResFontBM.h

@@ -27,6 +27,7 @@ namespace oxygine
         bool isSDF(int& size) const OVERRIDE;
 
         void alignSize(float scale, int fontSize, float& resScale, int& resFontSize) const OVERRIDE;
+        const Font* getClosestFont(float worldScale, int styleFontSize, float& resScale) const OVERRIDE;
 
     private:
         struct page

+ 1 - 3
oxygine/src/text_utils/Aligner.cpp

@@ -8,11 +8,9 @@ namespace oxygine
     {
 #define GSCALE 1
 
-        Aligner::Aligner(const TextStyle& Style, int fs, float gscale, const Vector2& size): width((int)size.x), height((int)size.y), _x(0), _y(0), _lineWidth(0), bounds(0, 0, 0, 0), style(Style), _scale(gscale), _fontSize(fs)
+        Aligner::Aligner(const TextStyle& Style, const Font* font, float gscale, const Vector2& size): width((int)size.x), height((int)size.y), _x(0), _y(0), _lineWidth(0), bounds(0, 0, 0, 0), style(Style), _scale(gscale), _font(font)
         {
             //log::messageln("gscale %f, adjScale %f globscale %f, %d %f", gscale, _globalScale, _fontSize, fs);
-
-            _font = style.font->getFont(0, _fontSize);
             _line.reserve(50);
             _lineSkip = (int)(_font->getBaselineDistance() * style.baselineScale) + style.linesOffset;
         }

+ 1 - 2
oxygine/src/text_utils/Aligner.h

@@ -27,7 +27,7 @@ namespace oxygine
         class Aligner
         {
         public:
-            Aligner(const TextStyle& style, int fs, float gscale, const Vector2& size);
+            Aligner(const TextStyle& style, const Font* font, float gscale, const Vector2& size);
             ~Aligner();
 
 
@@ -65,7 +65,6 @@ namespace oxygine
             int _x, _y;
             line _line;
             int _lineWidth;
-            int _fontSize;
             int _lineSkip;
         };
     }