* Enum definitions for text alignment 4.x-dev

Tue, 20 Jul 2021 09:36:01 +0300

author
cemkalyoncu
date
Tue, 20 Jul 2021 09:36:01 +0300
branch
4.x-dev
changeset 1724
f5aa57571f69
parent 1723
0e1b70c82324
child 1725
ebbf2e5bfb34

* Enum definitions for text alignment
* AdvancedPrinter fixes

Source/Gorgon/Graphics.h file | annotate | diff | comparison | revisions
Source/Gorgon/Graphics/AdvancedPrinterImpl.h file | annotate | diff | comparison | revisions
Source/Gorgon/Graphics/FreeType.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/Graphics/FreeType.h file | annotate | diff | comparison | revisions
--- a/Source/Gorgon/Graphics.h	Sun Jul 18 13:52:02 2021 +0300
+++ b/Source/Gorgon/Graphics.h	Tue Jul 20 09:36:01 2021 +0300
@@ -75,6 +75,12 @@
 			Right		= 16,
 		};
 
+        DefineEnumStrings(TextAlignment, {
+            {TextAlignment::Left,   "Left"},
+            {TextAlignment::Center, "Center"},
+            {TextAlignment::Right, "Right"},
+        });
+
 		/// Defines how an object is placed in a 2D axis system
 		enum class Placement {
 			/// Placed at top left
--- a/Source/Gorgon/Graphics/AdvancedPrinterImpl.h	Sun Jul 18 13:52:02 2021 +0300
+++ b/Source/Gorgon/Graphics/AdvancedPrinterImpl.h	Tue Jul 20 09:36:01 2021 +0300
@@ -151,7 +151,7 @@
         int maxb = 0; //maximum baseline of a line
         long curindex = 0;
 
-        auto changeprinter = [&](auto p) {
+        auto changeprinter = [&](auto p, bool temp = false) {
             printer = p;
             renderer = &printer->GetGlyphRenderer();
 
@@ -161,15 +161,17 @@
             height = renderer->GetLineGap();
             baseline = renderer->GetBaseLine();
             em = renderer->GetEMSize();
-            lineth = std::min(1, (int)std::round(renderer->GetLineThickness()));
+            lineth = std::max(1, (int)std::round(renderer->GetLineThickness()));
 
-            if(underlineon) {
-                underlines.back().finishat = (long)acc.size();
-                underlineon = false;
-            }
-            if(strikeon) {
-                strikes.back().finishat = (long)acc.size();
-                strikeon = false;
+            if(!temp) {
+                if(underlineon) {
+                    underlines.back().finishat = (long)acc.size();
+                    underlineon = false;
+                }
+                if(strikeon) {
+                    strikes.back().finishat = (long)acc.size();
+                    strikeon = false;
+                }
             }
         };
         
@@ -737,23 +739,21 @@
                 }
             }
 
-            if(wrapwidth > 0) {
-                switch(align(printer->GetDefaultAlign())) {
-                case TextAlignment::Right:
-                    xoff = wrapwidth - totalw;
-                    lineend = wrapwidth + location.X;
+            switch(align(printer->GetDefaultAlign())) {
+            case TextAlignment::Right:
+                xoff = wrapwidth - totalw;
+                lineend = wrapwidth + location.X;
 
-                    break;
-                case TextAlignment::Center:
-                    xoff = (wrapwidth - totalw) / 2;
-                    lineend = wrapwidth - xoff + location.X;
+                break;
+            case TextAlignment::Center:
+                xoff = (wrapwidth - totalw) / 2;
+                lineend = wrapwidth - xoff + location.X;
 
-                    break;
-                default:
-                    lineend = totalw + location.X;
+                break;
+            default:
+                lineend = totalw + location.X;
 
-                    break;
-                }
+                break;
             }
 
             int lineh = linespacing(maxh, printer->GetLineSpacing() * (maxh + extralineoffset + extralineheight));
@@ -876,7 +876,7 @@
             //line X locations determined here
             for(auto &u : underlines) {
                 if(u.startat >= 0 && u.startat < end) {
-                    u.start = acc[u.startat].location.X;
+                    u.start = acc[u.startat].location.X + acc[u.startat].renderer->GetOffset(acc[u.startat].g).X;
                     u.y = acc[u.startat].location.Y;
                 }
                 else if(u.startat == -1 && end != 0) {
@@ -884,7 +884,7 @@
                 }
 
                 if(u.finishat >= 0 && u.finishat < end) {
-                    u.end = acc[u.finishat].location.X;
+                    u.end = acc[u.finishat].location.X + acc[u.startat].renderer->GetOffset(acc[u.startat].g).X;
                 }
             }
 
@@ -933,8 +933,11 @@
             newline = ind == 0;
 
             int regionendy = cur.Y + lineh;
-            if(nl != -1)
+            if(nl != -1) {
                 cur.Y += lineh;
+                curunderlineoff += lineh;
+                curstrikeoff    += lineh;
+            }
 
             int nextlinexstart = location.X + indent + hangingindent * beginparag;
 
@@ -1074,6 +1077,8 @@
                     [](auto u) { return u.finishat == -2; }
                 ), strikes.end()
             );
+            if(strikes.empty())
+                strikeon = false;
             //END
 
             //if requested do paragraph
@@ -1090,7 +1095,7 @@
             baselineoffsetatlastspace = 0;
 
             auto backup = printer;
-            changeprinter(findfont(fontid));
+            changeprinter(findfont(fontid), true);
 
             //if still doing scripts, readjust exta line height and offset
             if(baselineoffset < 0) {
@@ -1098,7 +1103,7 @@
                 if(height > extralineheight)
                     extralineheight = height;
 
-                changeprinter(backup);
+                changeprinter(backup, true);
             }
             else if(baselineoffset > 0) {
                 auto offset = renderer->GetBaseLine() * baselineoffset;
@@ -1106,7 +1111,7 @@
                 if(offset > extralineoffset)
                     extralineoffset = offset;
 
-                changeprinter(backup);
+                changeprinter(backup, true);
             }
             //END
 
@@ -1234,10 +1239,12 @@
             bool dounderline = underline(printer->GetUnderline());
 
             if(dounderline) {
+                auto underlineoffset = underlinesettings.offset(height, renderer->GetUnderlineOffset());
+
                 if(g == '\t' && !underlinesettings.tabs) {
                     dounderline = false;
                 }
-                else if(!underlinesettings.descenders && renderer->GetOffset(g).Y+renderer->GetSize(g).Height > 0) {
+                else if(!underlinesettings.descenders && renderer->GetOffset(g).Y+renderer->GetSize(g).Height > underlineoffset - baseline) {
                     dounderline = false;
                 }
                 else if(!underlinesettings.spaces && internal::isspace(g)) {
@@ -1398,12 +1405,14 @@
 
         }
 
-        location = cur;
         if(!acc.empty()) {
             if(!doline(-1)) {
                 done = true;
             }
         }
+
+
+        location = cur;
         
         if(!done)
             glyphr(*renderer, 0xffff, location, 0.f, std::numeric_limits<long>::max());
--- a/Source/Gorgon/Graphics/FreeType.cpp	Sun Jul 18 13:52:02 2021 +0300
+++ b/Source/Gorgon/Graphics/FreeType.cpp	Tue Jul 20 09:36:01 2021 +0300
@@ -583,9 +583,6 @@
         
         FT_Vector p;
         FT_Get_Kerning(lib->face, glyphmap.at(chr1).ftindex, glyphmap.at(chr2).ftindex, FT_KERNING_DEFAULT, &p);
-        
-        if(p.x != 0)
-            p.x = p.x;
 
         return {std::round(p.x / 64.f), std::round(p.y / 64.f)};
     }
--- a/Source/Gorgon/Graphics/FreeType.h	Sun Jul 18 13:52:02 2021 +0300
+++ b/Source/Gorgon/Graphics/FreeType.h	Tue Jul 20 09:36:01 2021 +0300
@@ -305,7 +305,7 @@
 
 		/// Width of a digit, if digits do not have the same width, maximum should be returned. For
 		/// practical reasons, this function is expected to consider arabic numerals.
-		virtual int GetDigitWidth() const override { return GetSize("0").Width; }
+		virtual int GetDigitWidth() const override { return GetSize((Glyph)'0').Width; }
         
         /// Baseline point of glyphs from the top.
         virtual float GetBaseLine() const override { return baseline; }

mercurial