Browse Source

Add support for botchar to load_ttf() #5

James Bowman 6 years ago
parent
commit
c6ada425d1
4 changed files with 22 additions and 16 deletions
  1. 9 9
      default_assets.h
  2. 11 5
      gameduino2/prep.py
  3. 1 1
      scripts/gd2asset
  4. 1 1
      scripts/gd3asset

+ 9 - 9
default_assets.h

@@ -1,33 +1,33 @@
 // This file was generated with the command-line:
-//    /usr/local/bin/gd3asset -f xxx testdata/felix.png,format=L2 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 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 10
-#define HOBBY_OF_NIGHT_HEIGHT 16
+#define HOBBY_OF_NIGHT_WIDTH 11
+#define HOBBY_OF_NIGHT_HEIGHT 14
 #define HOBBY_OF_NIGHT_CELLS 96
-#define 0 23832UL
+#define 0 72216UL
 #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 43092UL
+#define ASSETS_END 91476UL
 #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, 10, 16, 0};
+static const shape_t HOBBY_OF_NIGHT_SHAPE = {1, 11, 14, 0};
 static const shape_t AUREK_BESH_SHAPE = {2, 21, 15, 0};
 struct {
   Bitmap felix;
   Bitmap hobby_of_night;
   Bitmap aurek_besh;
 } bitmaps = {
- /*            felix */  {{320, 200}, {160, 100},      0x0UL, 17,  0},
- /*   hobby_of_night */  {{ 10,  16}, {  5,   8},   0x3e80UL,  2,  1},
- /*       aurek_besh */  {{ 21,  15}, { 10,   7},   0x69e0UL,  2,  2}
+ /*            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}
 };

+ 11 - 5
gameduino2/prep.py

@@ -49,7 +49,13 @@ def join(tiles):
     return o
 
 def setwidth(im, w):
-    e = Image.new(im.mode, (w, im.size[1]))
+    e = im.resize((w, im.size[1]))
+    nch = len(e.mode)
+    if nch == 1:
+        black = 0
+    else:
+        black = (0,) * nch
+    e.paste(black, (0, 0, e.size[0], e.size[1]))
     e.paste(im, (0, 0))
     return e
 
@@ -332,9 +338,9 @@ class AssetBin(gameduino2.base.GD2):
         self.alldata += dblock
         self.cmd_setfont(h, p1)
 
-    def load_ttf(self, name, ttfname, size, format, topchar = 127):
+    def load_ttf(self, name, ttfname, size, format, botchar = 32, topchar = 127):
         font = ImageFont.truetype(ttfname, size)
-        rr = range(32, topchar + 1)
+        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()])
@@ -347,7 +353,7 @@ class AssetBin(gameduino2.base.GD2):
         alle = gd2.prep.extents(im)
 
         # render and crop the characters to the extents
-        ims = [None] * 32
+        ims = [None] * botchar
         for i in rr:
             im = Image.new("L", (fw+16, fh+16))
             dr = ImageDraw.Draw(im)
@@ -456,7 +462,7 @@ class AssetBin(gameduino2.base.GD2):
             fmt = gd2.ARGB4
             for child in root.iter('SubTexture'):
                 a = child.attrib
-                print a
+                # print a
                 (x, y, width, height) = [int(a[n]) for n in ["x", "y", "width", "height"]]
                 sub = im.crop((x, y, x + width, y + height))
                 if scale is not None:

+ 1 - 1
scripts/gd2asset

@@ -57,7 +57,7 @@ class GD2Assets(gd2.prep.AssetBin):
 
     def ttf(self, suffix, f, size = '12', format = 'L4', topchar = '127'):
         name = cname(os.path.basename(f[0])[:-1 - len(suffix)])
-        self.load_ttf(name, f[0], int(size), self.parse_format(format), int(topchar, 0))
+        self.load_ttf(name, f[0], int(size), self.parse_format(format), topchar = int(topchar, 0))
 
     def sample(self, suffix, f):
         name = os.path.basename(f[0])[:-1 - len(suffix)].upper()

+ 1 - 1
scripts/gd3asset

@@ -57,7 +57,7 @@ class GD2Assets(gd2.prep.AssetBin):
 
     def ttf(self, suffix, f, size = '12', format = 'L4', topchar = '127'):
         name = cname(os.path.basename(f[0])[:-1 - len(suffix)])
-        self.load_ttf(name, f[0], int(size), self.parse_format(format), int(topchar, 0))
+        self.load_ttf(name, f[0], int(size), self.parse_format(format), topchar = int(topchar, 0))
 
     def sample(self, suffix, f):
         name = os.path.basename(f[0])[:-1 - len(suffix)].upper()