From b1a881eb068dea7d2c840710a0aac3a5a63ba6f1 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sun, 17 Jul 2011 03:58:00 -0300 Subject: [PATCH] gimp plugin for generating font bitmaps --- .../generate_bitmap_font.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 tools/gimp-bitmap-generator/generate_bitmap_font.py diff --git a/tools/gimp-bitmap-generator/generate_bitmap_font.py b/tools/gimp-bitmap-generator/generate_bitmap_font.py new file mode 100755 index 00000000..9891a30a --- /dev/null +++ b/tools/gimp-bitmap-generator/generate_bitmap_font.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +import math +from gimpfu import * + +def generate_bitmap_font(timg, tdrawable, font, font_size, first_char, glyph_width, glyph_height, antialias): + char_begin = int(first_char) + char_end = 256 + num_chars = char_end - char_begin + width = int(glyph_width) * 16 + num_lines = num_chars / 16 + if num_chars % 16 > 0: + num_lines += 1 + height = int(glyph_height) * num_lines + + image = gimp.Image(width, height, RGB) + image.disable_undo() + + gimp.set_foreground(255, 255, 255) + gimp.set_background(0, 0, 0) + + glyphs_layer = gimp.Layer(image, "Glyphs", width, height, RGBA_IMAGE, 100, NORMAL_MODE) + image.add_layer(glyphs_layer, 0) + + disp = gimp.Display(image) + + for i in range(char_begin, char_end): + string = unichr(i) + offset = i - char_begin + + x_pos = (offset % 16) * int(glyph_width) + y_pos = (offset / 16) * int(glyph_height) + + text_layer = pdb.gimp_text_fontname(image, None, x_pos, y_pos, string, -1, antialias, font_size, PIXELS, font) + + gimp.progress_update(float(offset) / float(num_chars)) + + image.merge_visible_layers(CLIP_TO_IMAGE) + image.enable_undo() + +register( + "generate_bitmap_font", + "Generate bitmap font", + "Generate bitmap font", + "Eduardo Bart", + "Eduardo Bart", + "2011", + "/File/Create/_Generate Bitmap Font", + "", + [ + (PF_FONT, "Font", "Font", "Sans"), + (PF_SPINNER, "Font_Size", "Font Size", 10, (1, 128, 1)), + (PF_SPINNER, "First_Char", "First Char", 32, (0, 256, 1)), + (PF_SPINNER, "Glyph_Width", "Glyph Width", 16, (2, 64, 2)), + (PF_SPINNER, "Glyph_Height", "Glyph Height", 16, (2, 64, 2)), + (PF_BOOL, "Antialias", "Antialias", True) + ], + [], + generate_bitmap_font) + +main()