]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Merge branch 'sev/xolonium4-badges' into 'master'
authorAnt Zucaro <azucaro@gmail.com>
Sun, 6 Nov 2016 00:58:59 +0000 (00:58 +0000)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 6 Nov 2016 00:58:59 +0000 (00:58 +0000)
Render badges with Xolonium 4.0

I have recently finished Xolonium 4.0, available [here](https://fontlibrary.org/en/font/xolonium).
Most notably, it now also includes a hinted ttf version. As a result, it should be possible to render the badges with sharper text.

Now, there is no point in just telling you this, so I pushed this branch as a potential update for the badge scripts. It adds the necessary hinting options and slightly adjusts some of the font sizes and positions, to optimize the result. Of course, it is necessary to install the new ttf version first.

Old/New:
![badges-x4](/uploads/d7334628b9d396332c41bb832f409c8e/badges-x4.png)

I also have noticed that the rendered badge images are quite heavy. It would be fairly easy to cut their size by reducing the colors to 8bit, without a noticable effect on quality. I have added an exemplary script (optimize.sh), which could reduce file sizes by almost half.

See merge request !3

xonstat/batch/badges/gen_badges.py
xonstat/batch/badges/optimize.sh [new file with mode: 0755]
xonstat/batch/badges/skin.py

index 908aba06623e730578a33df4017ddac4f647c450..f9d97d6e8a5bd76e64171cd46bebb227bc677225 100644 (file)
@@ -34,18 +34,18 @@ skin_archer = Skin( "archer",
         #bg              = "background_archer-v2_full",
         bg              = "background_archer-v3",
         overlay         = "",
-        nick_maxwidth  = 260,
-        gametype_pos    = (91,33),
-        nostats_pos            = (91,59),
-        elo_pos        = (91,47),
-        rank_pos    = (91,58),
-        winp_pos       = (509,20),
-        wins_pos       = (508,35),
-        loss_pos       = (508,45),
-        kdr_pos                = (392,20),
-        kills_pos      = (392,35),
-        deaths_pos     = (392,45),
-        ptime_color    = (0.05, 0.05, 0.1),
+        nick_maxwidth   = 260,
+        gametype_pos    = (95,33),
+        nostats_pos     = (95,59),
+        elo_pos         = (95,47),
+        rank_pos        = (95,58),
+        winp_pos        = (509,19),
+        wins_pos        = (508,34),
+        loss_pos        = (508,45),
+        kdr_pos         = (392,19),
+        kills_pos       = (392,34),
+        deaths_pos      = (392,45),
+        ptime_color     = (0.05, 0.05, 0.1),
     )
 
 # minimal skin - writes PNGs into "output/minimal/###.png"
@@ -56,7 +56,7 @@ skin_minimal = Skin( "minimal",
         width           = 560,
         height          = 40,
         nick_fontsize   = 16,
-        nick_pos        = (36,16),
+        nick_pos        = (36,17),
         num_gametypes   = 3,
         nick_maxwidth   = 280,
         gametype_pos    = (70,30),
@@ -78,14 +78,14 @@ skin_minimal = Skin( "minimal",
         #nostats_text    = "no stats yet!",
         #nostats_color   = (0.7, 0.4, 0.4),
         kdr_pos         = (392,15),
-        kdr_fontsize    = 10,
+        kdr_fontsize    = 11,
         kdr_colortop    = (0.6, 0.8, 0.6),
         kdr_colormid    = (0.6, 0.6, 0.6),
         kdr_colorbot    = (0.8, 0.6, 0.6),
         kills_pos       = None,
         deaths_pos      = None,
-        winp_pos        = (508,15),
-        winp_fontsize   = 10,
+        winp_pos        = (509,15),
+        winp_fontsize   = 11,
         winp_colortop   = (0.6, 0.8, 0.8),
         winp_colormid   = (0.6, 0.6, 0.6),
         winp_colorbot   = (0.8, 0.8, 0.6),
diff --git a/xonstat/batch/badges/optimize.sh b/xonstat/batch/badges/optimize.sh
new file mode 100755 (executable)
index 0000000..7d268b9
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/sh -e
+# Optimize png files in output directory
+
+find output -name "*.png" | while read png; do
+       # Reduce colors to 8bit
+       # <http://pngquant.org>
+       pngquant --skip-if-larger --force --output "$png" 256 "$png"
+
+       # Adjust bit depth, remove clutter
+       # <http://optipng.sourceforge.net>
+       optipng -o 1 -strip all "$png"
+
+       # Compress with zopfli
+       # <http://www.advancemame.it>
+       #advpng -z -4 "$png"
+done
index 6cd310dffdb89967083e9a8bbfecc48331563cdb..421c0f9b3c055074921fadcb76bf3559ad004852 100644 (file)
@@ -66,8 +66,8 @@ class Skin:
             'font':             "Xolonium",
             'width':            560,
             'height':           70,
-            'nick_fontsize':    20,
-            'nick_pos':         (52,18),
+            'nick_fontsize':    22,
+            'nick_pos':         (53,20),
             'nick_maxwidth':    270,
             'gametype_fontsize':10,
             'gametype_pos':     (101,33),
@@ -99,18 +99,18 @@ class Skin:
             'wintext_color':    (0.8, 0.8, 0.8),
             'wintext_text':     "Win Percentage",
             'wintext_align':    0,
-            'winp_fontsize':    12,
-            'winp_pos':         (508,19),
+            'winp_fontsize':    15,
+            'winp_pos':         (509,18),
             'winp_colortop':    (0.2, 1.0, 1.0),
             'winp_colormid':    (0.4, 0.8, 0.4),
             'winp_colorbot':    (1.0, 1.0, 0.2),
             'winp_align':       0,
-            'wins_fontsize':    8,
+            'wins_fontsize':    9,
             'wins_pos':         (508,33),
             'wins_color':       (0.6, 0.8, 0.8),
             'wins_align':       0,
-            'loss_fontsize':    8,
-            'loss_pos':         (508,43),
+            'loss_fontsize':    9,
+            'loss_pos':         (508,44),
             'loss_color':       (0.8, 0.8, 0.6),
             'loss_align':       0,
             'kdtext_fontsize':  10,
@@ -120,22 +120,22 @@ class Skin:
             'kdtext_bg':        (0.8, 0.8, 0.8, 0.1),
             'kdtext_text':      "Kill Ratio",
             'kdtext_align':     0,
-            'kdr_fontsize':     12,
-            'kdr_pos':          (392,19),
+            'kdr_fontsize':     15,
+            'kdr_pos':          (392,18),
             'kdr_colortop':     (0.2, 1.0, 0.2),
             'kdr_colormid':     (0.8, 0.8, 0.4),
             'kdr_colorbot':     (1.0, 0.2, 0.2),
             'kdr_align':        0,
-            'kills_fontsize':   8,
+            'kills_fontsize':   9,
             'kills_pos':        (392,33),
             'kills_color':      (0.6, 0.8, 0.6),
             'kills_align':      0,
-            'deaths_fontsize':  8,
-            'deaths_pos':       (392,43),
+            'deaths_fontsize':  9,
+            'deaths_pos':       (392,44),
             'deaths_color':     (0.8, 0.6, 0.6),
             'deaths_align':     0,
             'ptime_fontsize':   10,
-            'ptime_pos':        (451,60),
+            'ptime_pos':        (451,59),
             'ptime_color':      (0.1, 0.1, 0.1),
             'ptime_text':       "Playing Time: %s",
             'ptime_align':      0,
@@ -223,6 +223,13 @@ class Skin:
         self.ctx = ctx
         ctx.set_antialias(C.ANTIALIAS_GRAY)
 
+        # set font hinting options
+        fo = C.FontOptions()
+        fo.set_antialias(C.ANTIALIAS_GRAY)
+        fo.set_hint_style(C.HINT_STYLE_FULL)
+        fo.set_hint_metrics(C.HINT_METRICS_ON)
+        ctx.set_font_options(fo)
+
         # draw background
         if self.bg == None:
             if self.bgcolor != None: