Tuesday, 6 December 2011

Using bitmap font

If you use DRAW dialect to create drawings with text like this:

view layout [
box black 100x100 effect [
draw [
pen red
line 30x30 50x20 70x70 40x50
pen blue
box 20x20 80x80
fill-pen 0.100.0
box 20x60 40x80
pen white
text 8x25 "Example"
fill-pen gold
flood 2x2 ]]]

You should obtain this result:
Sometime it happens that under Linux and MacOS you don't see the text Example.

Under Linux it's easy to avoid font problems just declares the font to use (Example FreeSans.ttf):
my-font: make face/font [
name: "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
with your path to font you want to use
size: 12]

and then

view layout [ box black 100x100 effect [
draw [
font my-font
line 30x30 50x20 70x70 40x50
text 8x25 "Now it works!"]]]

If you want your script cross-platform, you can set the lines just if the OS is Linux:

;check OS
switch system/version/4 [
4 [ ; it's Linux ]
3 [ ;it's Windows ]
2 [;it's MacOS X ]

Another solution works for every OS: using the bitmap font. If you load your preferred bitmap font, your texts will be transformed in transparent images that you can use in VID, DRAW or wherever you like.
You can download the script from here:
If you run the script as is, the example will pop-up:
Comment the last line to avoid this behavior.
You may convert font from OpenType to BDF by  otf2bdf.
How to use:

  1. Load the font you want to use, in BDF format
  2. Create the transparent image(s) with you font and text
  3. Put them wherever you like
Example, with tektite font:

>> a: read %tektite.bdf
>> my-font: make bdf-font [ parse-font a ]
>> my-text: my-font/render "Hello world!"
>> view layout [image my-text ]

You can use the image both in VID and in DRAW!!!

No comments:

Post a Comment