Browse Source

Add firstchar and charset arguments

[#5]
James Bowman 1 year ago
parent
commit
d38ba58108
4 changed files with 32 additions and 19 deletions
  1. 9 9
      default_assets.h
  2. 9 2
      gameduino2/prep.py
  3. 7 4
      scripts/gd2asset
  4. 7 4
      scripts/gd3asset

+ 9 - 9
default_assets.h

@@ -1,26 +1,26 @@
 // This file was generated with the command-line:
-//    /usr/local/bin/gd2asset -f xxx testdata/felix.png,format=RGB332 testdata/Hobby-of-night.ttf testdata/0.wav Aurek-Besh.ttf
+//    /usr/local/bin/gd2asset -f xxx testdata/felix.png,format=RGB332 testdata/Hobby-of-night.ttf,topchar=0x39 testdata/0.wav Aurek-Besh.ttf
 
 #define FELIX_HANDLE 0
 #define FELIX_WIDTH 320
 #define FELIX_HEIGHT 200
 #define FELIX_CELLS 1
 #define HOBBY_OF_NIGHT_HANDLE 1
-#define HOBBY_OF_NIGHT_WIDTH 11
-#define HOBBY_OF_NIGHT_HEIGHT 14
-#define HOBBY_OF_NIGHT_CELLS 96
-#define 0 72216UL
+#define HOBBY_OF_NIGHT_WIDTH 9
+#define HOBBY_OF_NIGHT_HEIGHT 13
+#define HOBBY_OF_NIGHT_CELLS 26
+#define 0 65840UL
 #define 0_LENGTH 3272
 #define 0_FREQ 8000
 #define AUREK_BESH_HANDLE 2
 #define AUREK_BESH_WIDTH 21
 #define AUREK_BESH_HEIGHT 15
 #define AUREK_BESH_CELLS 96
-#define ASSETS_END 91476UL
+#define ASSETS_END 85100UL
 #define LOAD_ASSETS()  (GD.safeload("xxx"), GD.loadptr = ASSETS_END)
 
 static const shape_t FELIX_SHAPE = {0, 320, 200, 0};
-static const shape_t HOBBY_OF_NIGHT_SHAPE = {1, 11, 14, 0};
+static const shape_t HOBBY_OF_NIGHT_SHAPE = {1, 9, 13, 0};
 static const shape_t AUREK_BESH_SHAPE = {2, 21, 15, 0};
 struct {
   Bitmap felix;
@@ -28,6 +28,6 @@ struct {
   Bitmap aurek_besh;
 } bitmaps = {
  /*            felix */  {{320, 200}, {160, 100},      0x0UL,  4,  0},
- /*   hobby_of_night */  {{ 11,  14}, {  5,   7},   0xfa00UL,  2,  1},
- /*       aurek_besh */  {{ 21,  15}, { 10,   7},  0x126e0UL,  2,  2}
+ /*   hobby_of_night */  {{  9,  13}, {  4,   6},   0xfa00UL,  2,  1},
+ /*       aurek_besh */  {{ 21,  15}, { 10,   7},  0x10df8UL,  2,  2}
 };

+ 9 - 2
gameduino2/prep.py

@@ -343,9 +343,13 @@ class AssetBin(gameduino2.base.GD2):
         self.alldata += dblock
         self.cmd_setfont(h, p1)
 
-    def load_ttf(self, name, ttfname, size, format, botchar = 32, topchar = 127):
+    def load_ttf(self, name, ttfname, size, format, botchar = 32, topchar = 127, charset = None):
         font = ImageFont.truetype(ttfname, size)
-        rr = range(botchar, topchar + 1)
+        if charset is not None:
+            topchar = botchar + len(charset)
+            rr = [ord(c) for c in charset]
+        else:
+            rr = range(botchar, topchar + 1)
         sizes = {c:font.getsize(chr(c)) for c in rr}
         fw = max([w for (w, _) in sizes.values()])
         fh = max([h for (_, h) in sizes.values()])
@@ -365,6 +369,9 @@ class AssetBin(gameduino2.base.GD2):
             dr.text((8, 8), chr(i), font=font, fill=255)
             ims.append(im.crop(alle))
         widths = [sizes.get(c, (0,0))[0] for c in range(128)]
+        if charset is not None:
+            for i,c in enumerate(charset):
+                widths[botchar + i] = sizes.get(ord(c), (0,0))[0]
         self.load_font(name, ims, widths, format)
 
     def load_tiles(self, name, file_name, scale = None, preview = False):

+ 7 - 4
scripts/gd2asset

@@ -35,8 +35,8 @@ class GD2Assets(gd2.prep.AssetBin):
             'jpg' : (self.image, "JPEG image file (options: format)"),
             'bmp' : (self.image, "BMP image file (options: format)"),
             'gif' : (self.image, "GIF image file (options: format)"),
-            'ttf' : (self.ttf, "TrueType font file (options: format, size, topchar)"),
-            'otf' : (self.ttf, "OpenType font file (options: format, size, topchar)"),
+            'ttf' : (self.ttf, "TrueType font file (options: format, size, botchar, charset, topchar)"),
+            'otf' : (self.ttf, "OpenType font file (options: format, size, botchar, charset, topchar)"),
             'wav' : (self.sample, "Audio sample, mono 16-bit (no options)"),
         }
 
@@ -55,9 +55,12 @@ class GD2Assets(gd2.prep.AssetBin):
                          self.parse_format(format),
                          dither = '-d' in self.opts)
 
-    def ttf(self, suffix, f, size = '12', format = 'L4', topchar = '127'):
+    def ttf(self, suffix, f, size = '12', format = 'L4', botchar = '32', topchar = '127', charset = None):
         name = cname(os.path.basename(f[0])[:-1 - len(suffix)])
-        self.load_ttf(name, f[0], int(size), self.parse_format(format), topchar = int(topchar, 0))
+        self.load_ttf(name, f[0], int(size), self.parse_format(format),
+                      botchar = int(botchar, 0),
+                      topchar = int(topchar, 0),
+                      charset = charset)
 
     def sample(self, suffix, f):
         name = os.path.basename(f[0])[:-1 - len(suffix)].upper()

+ 7 - 4
scripts/gd3asset

@@ -35,8 +35,8 @@ class GD2Assets(gd2.prep.AssetBin):
             'jpg' : (self.image, "JPEG image file (options: format)"),
             'bmp' : (self.image, "BMP image file (options: format)"),
             'gif' : (self.image, "GIF image file (options: format)"),
-            'ttf' : (self.ttf, "TrueType font file (options: format, size, topchar)"),
-            'otf' : (self.ttf, "OpenType font file (options: format, size, topchar)"),
+            'ttf' : (self.ttf, "TrueType font file (options: format, size, botchar, charset, topchar)"),
+            'otf' : (self.ttf, "OpenType font file (options: format, size, botchar, charset, topchar)"),
             'wav' : (self.sample, "Audio sample, mono 16-bit (no options)"),
         }
 
@@ -55,9 +55,12 @@ class GD2Assets(gd2.prep.AssetBin):
                          self.parse_format(format),
                          dither = '-d' in self.opts)
 
-    def ttf(self, suffix, f, size = '12', format = 'L4', topchar = '127'):
+    def ttf(self, suffix, f, size = '12', format = 'L4', botchar = '32', topchar = '127', charset = None):
         name = cname(os.path.basename(f[0])[:-1 - len(suffix)])
-        self.load_ttf(name, f[0], int(size), self.parse_format(format), topchar = int(topchar, 0))
+        self.load_ttf(name, f[0], int(size), self.parse_format(format),
+                      botchar = int(botchar, 0),
+                      topchar = int(topchar, 0),
+                      charset = charset)
 
     def sample(self, suffix, f):
         name = os.path.basename(f[0])[:-1 - len(suffix)].upper()