Selaa lähdekoodia

Merge branch 'apply-font-global-scale' of github.com:oxygine/oxygine-framework into apply-font-global-scale

dmuratshin 9 vuotta sitten
vanhempi
sitoutus
c9f6972daa

+ 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();

+ 3 - 14
oxygine/src/res/ResFont.cpp

@@ -1,20 +1,9 @@
 #include "ResFont.h"
 namespace oxygine
 {
-
-    void ResFont::alignSize(float worldScale, int styleFontSize, float& resScale, int& resFontSize) const
+    const oxygine::Font* ResFont::getClosestFont(float worldScale, int styleFontSize, float& resScale) const
     {
-        resFontSize = styleFontSize;
-        resScale = worldScale;
-
-        /*
-        if (fontSize)
-            resScale = _font->getSize() / float(fontSize);
-        else
-        {
-            resFontSize = _font->getScale();
-            resScale = _font->getScale();
-        }*/
+        resScale = 1.0f;
+        return getFont(0, styleFontSize);
     }
-
 }

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

@@ -15,8 +15,7 @@ namespace oxygine
         virtual bool isSDF(int& size) const { size = 0; return false; }
         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;
     };

+ 4 - 8
oxygine/src/res/ResFontBM.cpp

@@ -72,18 +72,14 @@ namespace oxygine
         return _sdf;
     }
 
-    void ResFontBM::alignSize(float worldScale, int styleFontSize, float& resScale, int& resFontSize) const
+    const oxygine::Font* ResFontBM::getClosestFont(float worldScale, int styleFontSize, float& resScale) const
     {
-        resFontSize = styleFontSize;
-        resScale = worldScale;
-
         if (styleFontSize)
-            resScale = _font->getSize() / float(styleFontSize);
+            resScale = _size / float(styleFontSize);
         else
-        {
-            resFontSize = _font->getScale();
             resScale = _font->getScale();
-        }
+
+        return _font;
     }
 
     void ResFontBM::init(const char* path, bool premultipliedAlpha)

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

@@ -26,7 +26,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;
         };
     }