* Prevented crash when printer tab width is 0 4.x-dev

Thu, 13 May 2021 11:30:10 +0300

author
cemkalyoncu
date
Thu, 13 May 2021 11:30:10 +0300
branch
4.x-dev
changeset 1665
17e509887b6b
parent 1664
49482fe2a227
child 1666
470774d50052

* Prevented crash when printer tab width is 0
* When ther requested font family is not found, default one is now used properly

Source/Gorgon/Graphics/AdvancedPrinterImpl.h file | annotate | diff | comparison | revisions
Source/Gorgon/Graphics/Font.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/Widgets/Generator.cpp file | annotate | diff | comparison | revisions
Testing/Source/Manual/GraphicsHelper.h file | annotate | diff | comparison | revisions
--- a/Source/Gorgon/Graphics/AdvancedPrinterImpl.h	Thu May 13 11:19:07 2021 +0300
+++ b/Source/Gorgon/Graphics/AdvancedPrinterImpl.h	Thu May 13 11:30:10 2021 +0300
@@ -1141,10 +1141,13 @@
 
             if(g == '\t') {
                 auto off = cur.X + hspace - location.X;
+                int tw = tabwidth(printer->GetTabWidth());
+                if(tw <= 0)
+                    tw = 1;
                 hspace = 0;
-                off += tabwidth(printer->GetTabWidth());
-                off /= tabwidth(printer->GetTabWidth());
-                off *= tabwidth(printer->GetTabWidth());
+                off += tw;
+                off /= tw;
+                off *= tw;
 
                 gw = off - cur.X + location.X;
 
--- a/Source/Gorgon/Graphics/Font.cpp	Thu May 13 11:19:07 2021 +0300
+++ b/Source/Gorgon/Graphics/Font.cpp	Thu May 13 11:30:10 2021 +0300
@@ -44,6 +44,9 @@
         }
         template<class T_>
         void dodefaulttab(T_ s, T_ &x, T_ w) {
+            if(w <= 0)
+                w = 1;
+            
             x -= s;
             x += w;
             x /= w;
--- a/Source/Gorgon/Widgets/Generator.cpp	Thu May 13 11:19:07 2021 +0300
+++ b/Source/Gorgon/Widgets/Generator.cpp	Thu May 13 11:30:10 2021 +0300
@@ -119,7 +119,7 @@
         return "";
     }
     
-    std::string FindFontFile(std::string family, bool bold, bool italic, const std::vector<Gorgon::OS::FontFamily> &list) {
+    std::string FindFontFile(std::string family, bool bold, bool italic, const std::vector<Gorgon::OS::FontFamily> &list, bool mono) {
         family = String::ToLower(family);
     retry:
         for(auto &f : list) {
@@ -142,7 +142,7 @@
         }
         
         //switch to default font
-        auto fam = FindDefaultFontFamily(false, list);
+        auto fam = String::ToLower(FindDefaultFontFamily(mono, list));
         
         if(fam != family) {
             family = fam;
@@ -228,10 +228,10 @@
         
         InitFonts(
             size, 
-            FindFontFile(family, false, false, fontlist),
-            FindFontFile(family, true, false, fontlist),
-            FindFontFile(family, false, true, fontlist),
-            FindFontFile(family, true, true, fontlist),
+            FindFontFile(family, false, false, fontlist, false),
+            FindFontFile(family, true, false, fontlist, false),
+            FindFontFile(family, false, true, fontlist, false),
+            FindFontFile(family, true, true, fontlist, false),
             mono
         );
         
@@ -254,10 +254,10 @@
         InitFonts(
             size, 
             regular, bold, italic, bolditalic,
-            FindFontFile(mono, false, false, fontlist),
-            FindFontFile(mono, true, false, fontlist),
-            FindFontFile(mono, false, true, fontlist),
-            FindFontFile(mono, true, true, fontlist)
+            FindFontFile(mono, false, false, fontlist, true),
+            FindFontFile(mono, true, false, fontlist, true),
+            FindFontFile(mono, false, true, fontlist, true),
+            FindFontFile(mono, true, true, fontlist, true)
         );
         
         if(init) fontlist = {};
--- a/Testing/Source/Manual/GraphicsHelper.h	Thu May 13 11:19:07 2021 +0300
+++ b/Testing/Source/Manual/GraphicsHelper.h	Thu May 13 11:30:10 2021 +0300
@@ -46,7 +46,7 @@
 
         Graphics::Initialize();
         auto &gen = *new Gorgon::Widgets::SimpleGenerator;
-        gen.Init("", "", 7.5);
+        gen.Init("xyz", "", 7.5);
         UI::Initialize(gen);
         //UI::Initialize();
 

mercurial