From 075b1a35c940e9099f5d77181c325ffd7cf6e309 Mon Sep 17 00:00:00 2001
From: Daniele Cattaneo <daniele.cattaneo@polimi.it>
Date: Sat, 27 May 2023 23:31:39 +0200
Subject: [PATCH] Mark the Font constructors as constexpr to allow the compiler
 to put fonts in rodata.

Signed-off-by: Federico Terraneo <fede.tft@miosix.org>
---
 font.cpp | 12 ------------
 font.h   | 12 ++++++++----
 2 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/font.cpp b/font.cpp
index 09d1cc0..6f15466 100644
--- a/font.cpp
+++ b/font.cpp
@@ -37,18 +37,6 @@ namespace mxgui {
 // Class Font
 //
 
-Font::Font(unsigned char startChar, unsigned char endChar, unsigned char height,
-        unsigned char width, unsigned char dataSize, bool antialiased,
-        const void *data): startChar(startChar), endChar(endChar),
-        height(height), width(width), dataSize(dataSize),
-        antialiased(antialiased), widths(0), offset(0), data(data) {}
-
-Font::Font(unsigned char startChar, unsigned char endChar, unsigned char height,
-        unsigned char dataSize, bool antialiased, const unsigned char *widths,
-        const unsigned short *offset, const void *data): startChar(startChar),
-        endChar(endChar), height(height), width(0), dataSize(dataSize),
-        antialiased(antialiased), widths(widths), offset(offset), data(data) {}
-
 short int Font::calculateLength(const char *s) const
 {
     if(isFixedWidth())
diff --git a/font.h b/font.h
index 1f03a37..33578de 100644
--- a/font.h
+++ b/font.h
@@ -56,9 +56,11 @@ public:
      * \param data pinter to the font data. This must point to a static array
      * so that no memeory leak problems occur
      */
-    Font(unsigned char startChar, unsigned char endChar, unsigned char height,
+    constexpr Font(unsigned char startChar, unsigned char endChar, unsigned char height,
         unsigned char width, unsigned char dataSize, bool antialiased,
-        const void *data);
+        const void *data): startChar(startChar), endChar(endChar),
+        height(height), width(width), dataSize(dataSize),
+        antialiased(antialiased), widths(0), offset(0), data(data) {}
     /**
      * Creates a variable width font.
      * \param startChar the first character available, example ' ' (ASCII space)
@@ -74,9 +76,11 @@ public:
      * \param data pinter to the font data. This must point to a static array
      * so that no memeory leak problems occur
      */
-    Font(unsigned char startChar, unsigned char endChar, unsigned char height,
+    constexpr Font(unsigned char startChar, unsigned char endChar, unsigned char height,
         unsigned char dataSize, bool antialiased, const unsigned char *widths,
-        const unsigned short *offset, const void *data);
+        const unsigned short *offset, const void *data): startChar(startChar),
+        endChar(endChar), height(height), width(0), dataSize(dataSize),
+        antialiased(antialiased), widths(widths), offset(offset), data(data) {}
 
     /**
      * Draw a string on a surface.
-- 
GitLab