Post Reply 

Bitmap font generator script

Feb 4, 2012, 14:50
Post: #1
Bitmap font generator script
I have searched this forum but cannot find something related to my problem.

I found some Python script plugin witch generates "Bitmap font texture".
Here is a script.

The problem is when i generate it adds some offset on Y axis and its not starting from X=0, Y=0:
Plugin options:
[Image: pluginoptions.jpg]
Texture generated:
[Image: fontgenerated.jpg]

Text is cut off. By browsing this script i didn't find nothing that could add this offset except Gimp it self.
I need precise placement of each char/glyph. Any solutions?
Find all posts by this user
Quote this message in a reply
Feb 4, 2012, 17:19
Post: #2
RE: Bitmap font generator script
Nothing adds an "offset". What happens is that Gimp draws each character in a "box" that is high enough to accommodate the highest character in the font (Capital I with some diacritic mark, for instance, or a box-drawing character). So the space between the average character and the top of the image is expected. If you use the text tool to draw the same characters the layer will have the same space at the top (and at the bottom, for that matter).

The script you have sizes the image first before generating the characters. It is mistaken in the way it computes this size, both horizontally and vertically.

You should be able to fix this by using
Code:
pdb.gimp_image_resize_to_layers(image)
just before the image is flattened.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Feb 4, 2012, 17:54
Post: #3
RE: Bitmap font generator script
Thanks for answering.

Can you clear something to me please:
When i choose 16 as font "size", is that value in pixel units?
Is it precisely 16 when asked or it depends on font and chooses by it self the nearest size it have to 16?
If largest height of glyph is 16 pixels there should not be cutoff like in my image above 1520 x 16?
Can you tell me how can i obtain width of some glyph? Does "font" variable has some attrribute for "widest" glyph width?
I want each cell/box for a glyph to be:
Code:
char_begin = 32
char_end = 127
...
cell.w = widest_glyph.width
cell.h = largest_glyph.height
...
image_w = (char_end - char_begin) * cell.w
image_h = cell.h

Thanks for your time.
Find all posts by this user
Quote this message in a reply
Feb 4, 2012, 18:53
Post: #4
RE: Bitmap font generator script
When i choose 16 as font "size", is that value in pixel units?
Yes

Is it precisely 16 when asked or it depends on font and chooses by it self the nearest size it have to 16?
Your question should be "Precisely 16 pixels where?". And the answer is: between the baseline of two consecutive lines of text, according to the font designer. But AFAIK there is no direct relationship to anything you could measure on the glyphs (like the height above baseline of capitals).

If largest height of glyph is 16 pixels there should not be cutoff like in my image above 1520 x 16?
Why not? Where is it defined that Gimp should produce the smallest box that holds the character? As the function name implies (gimp_text_fontname()) for Gimp we are talking about text, not individual characters. So Gimp also takes in account the needed interline spacing, and doesn't even use the minimal one (which woul dbe unredable in many cases).

Can you tell me how can i obtain width of some glyph? Does "font" variable has some attribute for "widest" glyph width?
The font variable is just a font name. To get the glyph widths, the best way is to obtain the dimension of the layer produced for each glyph (which what happens in the script above).

I want each cell/box for a glyph to be:
Code:
char_begin = 32
char_end = 127
...
cell.w = widest_glyph.width
cell.h = largest_glyph.height
...
image_w = (char_end - char_begin) * cell.w
image_h = cell.h

This requires to create a layer for each glyph, measure them, deduce the biggest size, resize them (btw, how? centered? left? right?), and rearrange them, and finally adjust the image canvas.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Feb 7, 2012, 15:39
Post: #5
RE: Bitmap font generator script
This is one and only which I was looking for, Same problem I were facing. So its my pleasure to have this thread. Thanks for sharing...
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How to modify this script-fu? Zakary81 1 18 Yesterday 12:48
Last Post: paynekj
  Need help in running a gui script-fu via command line eyalzek 2 226 Oct 4, 2014 14:05
Last Post: eyalzek
  Color menuitems in script or plugin Barbie 4 387 Sep 29, 2014 09:51
Last Post: paynekj
  script-fu ok in gimp, not in commad line dominique 1 265 Sep 28, 2014 03:18
Last Post: dominique
  Script fu and Color to alpha john 4 399 Sep 20, 2014 08:46
Last Post: rich2005

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS