From: Ingo Ruhnke Date: Mon, 4 Aug 2014 19:02:04 +0000 (+0200) Subject: Added 1-pixel transparent border around glyphs to avoid GL blending artifacts when... X-Git-Url: https://git.octo.it/?p=supertux.git;a=commitdiff_plain;h=8fc619c1560d238cbf22fb666847642a130516c6 Added 1-pixel transparent border around glyphs to avoid GL blending artifacts when scaling along with a script for doing so Only while.stf has been converted so far --- diff --git a/data/fonts/white.stf b/data/fonts/white.stf index 262cd0c6b..3668d824f 100644 --- a/data/fonts/white.stf +++ b/data/fonts/white.stf @@ -1,6 +1,7 @@ (supertux-font (glyph-width 16) (glyph-height 18) + (glyph-border 1) (surface (glyphs "white.png") (shadows "shadow.png") diff --git a/data/images/engine/fonts/shadow.png b/data/images/engine/fonts/shadow.png index 5ca06bbdc..ce1130e2b 100644 Binary files a/data/images/engine/fonts/shadow.png and b/data/images/engine/fonts/shadow.png differ diff --git a/data/images/engine/fonts/white.png b/data/images/engine/fonts/white.png index af453f863..577de6aaf 100644 Binary files a/data/images/engine/fonts/white.png and b/data/images/engine/fonts/white.png differ diff --git a/src/video/font.cpp b/src/video/font.cpp index 00b7ec1e1..f3ce6353d 100644 --- a/src/video/font.cpp +++ b/src/video/font.cpp @@ -62,6 +62,7 @@ Font::Font(GlyphWidth glyph_width_, shadow_surfaces(), char_height(), shadowsize(shadowsize_), + border(0), glyphs(65536) { for(unsigned int i=0; i<65536;i++) glyphs[i].surface_idx = -1; @@ -106,6 +107,8 @@ Font::loadFontFile(const std::string &filename) throw std::runtime_error(msg.str()); } + config_l->get("glyph-border", border); + lisp::ListIterator iter(config_l); while(iter.next()) { const std::string& token = iter.item(); @@ -190,8 +193,8 @@ Font::loadFontSurface( for( unsigned int i = 0; i < chars.size(); i++) { for(UTF8Iterator chr(chars[i]); !chr.done(); ++chr) { - int y = row * char_height; - int x = col * char_width; + int y = row * (char_height + 2*border) + border; + int x = col * (char_width + 2*border) + border; if( ++col == wrap ) { col=0; row++; } if( *chr == 0x0020 && glyphs[0x20].surface_idx != -1) continue; diff --git a/src/video/font.hpp b/src/video/font.hpp index 4704d76be..513e0d091 100644 --- a/src/video/font.hpp +++ b/src/video/font.hpp @@ -137,6 +137,7 @@ private: std::vector shadow_surfaces; int char_height; int shadowsize; + int border; /** 65536 of glyphs */ std::vector glyphs; diff --git a/tools/font-add-border.py b/tools/font-add-border.py new file mode 100755 index 000000000..a57e7e06e --- /dev/null +++ b/tools/font-add-border.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +# SuperTux +# Copyright (C) 2014 Ingo Ruhnke +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from PIL import Image +import sys +import argparse + +# Add a 1 pixel border around every glyph in a font + +def fix_font_file(filename, glyph_width, glyph_height): + print("Processing %s %dx%d" % (filename, glyph_width, glyph_height)) + img = Image.open(filename) + w, h = img.size + + assert w % glyph_width == 0, "image not multiple of glyph width" + assert h % glyph_height == 0, "image not multiple of glyph height" + + w_g = w // glyph_width + h_g = h // glyph_height + + print("Glyphs: %ax%a" % (w_g, h_g)) + + out = Image.new("RGBA", (w_g * (glyph_width + 2), h_g * (glyph_height + 2)), color=5) + + for y in range(0, h_g): + for x in range(0, w_g): + ix = x * glyph_width + iy = y * glyph_height + + ox = x * (glyph_width + 2) + 1 + oy = y * (glyph_height + 2) + 1 + + glyph = img.crop((ix, iy, ix + glyph_width, iy + glyph_height)) + out.paste(glyph, (ox, oy)) + + out.save("/tmp/out.png") + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='rFactor MAS packer') + parser.add_argument('FILE', action='store', type=str, + help='font image to change') + + parser.add_argument('GLYPH_WIDTH', action='store', type=int, + help='glyph width') + + parser.add_argument('GLYPH_HEIGHT', action='store', type=int, + help='glyph height') + + args = parser.parse_args() + + fix_font_file(args.FILE, args.GLYPH_WIDTH, args.GLYPH_HEIGHT) + +# EOF #