Bitmap Font Rendering Script
Version 1.0
By Paradox, with an immense amount of debugging help from Trickster.
The Purpose of This Script:
This script was created to enhance your displays. You can easily make your own, amazing fonts using this.
The bonus of this script, is that you can easily create amazing, per-pixel full-colour fonts!
But, how can I use it?:
This is more or less a development tool for scripters. It allows for nicer windows, and such.
Setup:
All you need is at least one font, and one is included with the script. It is Verdana, put into an image. Of course, you can make much fancier ones, but I'm no artist.
Making a font is easy, too: you just create an image, with enough equal spaces for 26 characters (wide) and 3 rows. The example font shows you, as each character has a bounding box of 15x21.
Script:
[spoiler=Verdana BitFont]
http://img402.imageshack.us/img402/2540/verdanaxh4.png[/img]
Extract all fonts you use to the Pictures folder. (Note: RENAME THIS ONE TO Verdana.png!)
[/spoiler]
Frequently Asked Questions:
How do I change the default font?
You can change it by finding this line in the script:
and changing 'Verdana' to your font's filename.
Future features:
Possibly, more characters and whatnot?
Credit goes to Paradox
And possibly, Trickster as a small mention, if he wills it.
Version 1.0
By Paradox, with an immense amount of debugging help from Trickster.
Quick Glimpse at the Default Font in-action
Spoiler
http://img295.imageshack.us/img295/191/bitmapfontscreenooofo9.jpg[/img]
The Purpose of This Script:
This script was created to enhance your displays. You can easily make your own, amazing fonts using this.
The bonus of this script, is that you can easily create amazing, per-pixel full-colour fonts!
But, how can I use it?:
This is more or less a development tool for scripters. It allows for nicer windows, and such.
Adds this method:
Bitmap#bitmap_font(x, y, text, [ font])
Bitmap#bitmap_font(x, y, text, [ font])
Expand to see the code.
Setup:
All you need is at least one font, and one is included with the script. It is Verdana, put into an image. Of course, you can make much fancier ones, but I'm no artist.
Making a font is easy, too: you just create an image, with enough equal spaces for 26 characters (wide) and 3 rows. The example font shows you, as each character has a bounding box of 15x21.
Script:
Version 1.0
Spoiler
#==============================================================================
# Image Fonts
#------------------------------------------------------------------------------
# Author : Paradox (& Trickster)
# Revision : 1
# Date : January 2, 2007
#==============================================================================
# ** Bitmap
#------------------------------------------------------------------------------
# This class is a type pertaining to images.
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
# * Bitmap Font
# x : the x of the starting letter
# y : the y of the starting letter
# text : the text to display
# font : the font to render (optional)
#--------------------------------------------------------------------------
def bitmap_font(x, y, text, font = 'Verdana')
# Create the font
font_image = RPG::Cache.picture(font)
# Determine sizing.
char_width = font_image.width / 26
char_height = font_image.height / 3
# Loop through each letter.
text.length.times do |index|
# Get the Byte.
byte = text[index]
# Get Letter
letter = byte.chr
# If it is a letter
if letter =~ /[A-Z]/
iX = (byte - 65) * char_width
iY = char_height
elsif letter =~ /[a-z]/
iX =(byte - 97) * char_width
iY = 0
# If it is a number
elsif letter =~ /[0-9]/
iX = letter.to_i * char_width
iY = 2 * char_height
# Otherwise it's a symbol
else
unless letter == ' ' or letter == ''
# Define the order
order = ['.', ',', '$', '!', '(', ')', '-', '/', '\\', '?', ';', ':', '#', '&', '"', "'"]
iX = (order.index(letter) + 10) * char_width
iY = 2 * char_height
end
end
# If it's not a space, draw it
if letter != ' ' and letter != ""
rect = Rect.new(iX, iY, char_width, char_height)
# Blit it to the screen
self.blt((index * char_width) + x, y, font_image, rect)
end
end
end
end
# Image Fonts
#------------------------------------------------------------------------------
# Author : Paradox (& Trickster)
# Revision : 1
# Date : January 2, 2007
#==============================================================================
# ** Bitmap
#------------------------------------------------------------------------------
# This class is a type pertaining to images.
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
# * Bitmap Font
# x : the x of the starting letter
# y : the y of the starting letter
# text : the text to display
# font : the font to render (optional)
#--------------------------------------------------------------------------
def bitmap_font(x, y, text, font = 'Verdana')
# Create the font
font_image = RPG::Cache.picture(font)
# Determine sizing.
char_width = font_image.width / 26
char_height = font_image.height / 3
# Loop through each letter.
text.length.times do |index|
# Get the Byte.
byte = text[index]
# Get Letter
letter = byte.chr
# If it is a letter
if letter =~ /[A-Z]/
iX = (byte - 65) * char_width
iY = char_height
elsif letter =~ /[a-z]/
iX =(byte - 97) * char_width
iY = 0
# If it is a number
elsif letter =~ /[0-9]/
iX = letter.to_i * char_width
iY = 2 * char_height
# Otherwise it's a symbol
else
unless letter == ' ' or letter == ''
# Define the order
order = ['.', ',', '$', '!', '(', ')', '-', '/', '\\', '?', ';', ':', '#', '&', '"', "'"]
iX = (order.index(letter) + 10) * char_width
iY = 2 * char_height
end
end
# If it's not a space, draw it
if letter != ' ' and letter != ""
rect = Rect.new(iX, iY, char_width, char_height)
# Blit it to the screen
self.blt((index * char_width) + x, y, font_image, rect)
end
end
end
end
Expand to see the code.
[spoiler=Verdana BitFont]
http://img402.imageshack.us/img402/2540/verdanaxh4.png[/img]
Extract all fonts you use to the Pictures folder. (Note: RENAME THIS ONE TO Verdana.png!)
[/spoiler]
Frequently Asked Questions:
How do I change the default font?
You can change it by finding this line in the script:
def bitmap_font(x, y, text, font = 'Verdana')
Expand to see the code.
and changing 'Verdana' to your font's filename.
Future features:
Possibly, more characters and whatnot?
Credit goes to Paradox
And possibly, Trickster as a small mention, if he wills it.