Ver código fonte

experimental, when render FT font apply global scale and rebuild with pixel perfect font

dmuratshin 9 anos atrás
pai
commit
b6b58708db

+ 4 - 2
oxygine/src/STDMaterial.cpp

@@ -160,7 +160,10 @@ namespace oxygine
 
     void STDMaterial::doRender(TextField* tf, const RenderState& rs)
     {
-        text::Node* root = tf->getRootNode();
+
+        float scale = sqrtf(rs.transform.a * rs.transform.a + rs.transform.c * rs.transform.c);
+
+        text::Node* root = tf->getRootNode(scale);
         if (!root)
             return;
 
@@ -180,7 +183,6 @@ namespace oxygine
         int sdfSize;
         if (tf->getFont()->isSDF(sdfSize))
         {
-            float scale = sqrtf(rs.transform.a * rs.transform.a + rs.transform.c * rs.transform.c);
 
             if (tf->getFontSize())
                 scale = scale * tf->getFontSize() / sdfSize;

+ 7 - 5
oxygine/src/TextField.cpp

@@ -22,6 +22,7 @@ namespace oxygine
     {
         _flags |= flag_rebuild;
         _style.font = NULL;
+        _rtscale = 0;
 
         if (DebugActor::resSystem)
         {
@@ -252,12 +253,12 @@ namespace oxygine
 
     text::Symbol* TextField::getSymbolAt(int pos) const
     {
-        return const_cast<TextField*>(this)->getRootNode()->getSymbol(pos);
+        return const_cast<TextField*>(this)->getRootNode(1)->getSymbol(pos);
     }
 
     const Rect& TextField::getTextRect() const
     {
-        const_cast<TextField*>(this)->getRootNode();
+        const_cast<TextField*>(this)->getRootNode(1);
         return _textRect;
     }
 
@@ -268,9 +269,9 @@ namespace oxygine
     }
 
 
-    text::Node* TextField::getRootNode()
+    text::Node* TextField::getRootNode(float scale)
     {
-        if ((_flags & flag_rebuild) && _style.font)
+        if ((_flags & flag_rebuild || _rtscale != scale) && _style.font)
         {
             delete _root;
 
@@ -286,7 +287,8 @@ namespace oxygine
                 _root = new text::TextNode(_text.c_str());
             }
 
-            text::Aligner rd(_style);
+            _rtscale = scale;
+            text::Aligner rd(_style, scale);
 
             rd.width = (int)getWidth();
             rd.height = (int)getHeight();

+ 2 - 1
oxygine/src/TextField.h

@@ -102,7 +102,7 @@ namespace oxygine
         std::string dump(const dumpOptions& options) const;
         void doRender(RenderState const& parentRenderState);
 
-        text::Node* getRootNode();
+        text::Node* getRootNode(float scale);
     protected:
         enum
         {
@@ -114,6 +114,7 @@ namespace oxygine
 
         text::Node* _root;
         Rect _textRect;
+        float _rtscale;
 
 
         void needRebuild();

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

@@ -6,9 +6,13 @@ namespace oxygine
 {
     namespace text
     {
+#define GSCALE 1
 
-        Aligner::Aligner(const TextStyle& Style): width(0), height(0), _x(0), _y(0), _lineWidth(0), bounds(0, 0, 0, 0), style(Style)
+        Aligner::Aligner(const TextStyle& Style, float gscale): width(0), height(0), _x(0), _y(0), _lineWidth(0), bounds(0, 0, 0, 0), style(Style), _globalScale(gscale)
         {
+#ifdef GSCALE
+            style.fontSize = style.fontSize  * _globalScale;
+#endif
             _font = style.font->getFont(0, style.fontSize);
             _line.reserve(50);
         }
@@ -69,6 +73,9 @@ namespace oxygine
             _scale = _font->getScale();
             if (st.fontSize)
                 _scale = _font->getSize() / float(st.fontSize);
+#ifdef GSCALE
+            _scale =  _globalScale;
+#endif
 
             width = int(width * _scale);
             height = int(height * _scale);

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

@@ -27,7 +27,7 @@ namespace oxygine
         class Aligner
         {
         public:
-            Aligner(const TextStyle& style);
+            Aligner(const TextStyle& style, float gscale);
             ~Aligner();
 
 
@@ -60,6 +60,7 @@ namespace oxygine
             void _nextLine(line& ln);
 
             float _scale;
+            float _globalScale;
             int _x, _y;
             line _line;
             int _lineWidth;