No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generate_bitmap_font.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python
  2. import math
  3. from gimpfu import *
  4. def generate_bitmap_font(timg, tdrawable, font, font_size, first_char, glyph_width, glyph_height, antialias):
  5. char_begin = int(first_char)
  6. char_end = 256
  7. num_chars = char_end - char_begin
  8. width = int(glyph_width) * 16
  9. num_lines = num_chars / 16
  10. if num_chars % 16 > 0:
  11. num_lines += 1
  12. height = int(glyph_height) * num_lines
  13. image = gimp.Image(width, height, RGB)
  14. image.disable_undo()
  15. gimp.set_foreground(255, 255, 255)
  16. gimp.set_background(0, 0, 0)
  17. glyphs_layer = gimp.Layer(image, "Glyphs", width, height, RGBA_IMAGE, 100, NORMAL_MODE)
  18. image.add_layer(glyphs_layer, 0)
  19. disp = gimp.Display(image)
  20. for i in range(char_begin, char_end):
  21. if i == 127 or i == 129 or (i >= 141 and i <= 144) or i == 157:
  22. string = u"\u25A1"
  23. else:
  24. string = chr(i).decode('cp1252')
  25. offset = i - char_begin
  26. x_pos = (offset % 16) * int(glyph_width)
  27. y_pos = (offset / 16) * int(glyph_height)
  28. text_layer = pdb.gimp_text_fontname(image, None, x_pos, y_pos, string, -1, antialias, font_size, PIXELS, font)
  29. gimp.progress_update(float(offset) / float(num_chars))
  30. image.merge_visible_layers(CLIP_TO_IMAGE)
  31. image.enable_undo()
  32. register(
  33. "generate_bitmap_font",
  34. "Generate bitmap font",
  35. "Generate bitmap font",
  36. "Eduardo Bart",
  37. "Eduardo Bart",
  38. "2011",
  39. "<Image>/File/Create/_Generate Bitmap Font",
  40. "",
  41. [
  42. (PF_FONT, "Font", "Font", "Sans"),
  43. (PF_SPINNER, "Font_Size", "Font Size", 10, (1, 128, 1)),
  44. (PF_SPINNER, "First_Char", "First Char", 32, (0, 256, 1)),
  45. (PF_SPINNER, "Glyph_Width", "Glyph Width", 16, (2, 64, 2)),
  46. (PF_SPINNER, "Glyph_Height", "Glyph Height", 16, (2, 64, 2)),
  47. (PF_BOOL, "Antialias", "Antialias", True)
  48. ],
  49. [],
  50. generate_bitmap_font)
  51. main()