Permalink
Browse files

Reworked spacing calculation

  • Loading branch information...
TorD committed May 29, 2015
1 parent e1a00a6 commit 10c048b8f2ff3085b46c5d6421b799991514b46d
Binary file not shown.
@@ -9,8 +9,9 @@ def parse(font_image)
set_vars(bitmap)
parse_line_starts(bitmap)
parse_bitmap(bitmap)
#@@char_data.each{|cd| puts "Character #{cd.id.chr}: x:#{cd.x}, y:#{cd.y}, width:#{cd.width}, height: #{cd.height}, space: #{cd.x_advance}"}
return info(font_image), parse_char_data, kerning, File.basename(font_image)
parse_char_data
@@char_data.each{|cd| puts "Character #{cd.id.chr}: x:#{cd.x}, y:#{cd.y}, width:#{cd.width}, height: #{cd.height}, space: #{cd.x_advance}"}
return info(font_image), @@char_data, kerning, File.basename(font_image)
end
def parse_line_starts(bitmap)
@@ -55,8 +56,6 @@ def parse_char_data
cd.x_offset = 0
cd.y_offset = get_y_offset(cd)
end
@@char_data
end
def get_y_offset(char_data)
@@ -91,14 +90,20 @@ def store_dimension_data(ox, oy, bitmap)
# Local vars store
x = y = 0
# Get width
x += 1 while is_valid_char_outline?(ox + x, oy, bitmap)
data.width = x - 2 # We ignore the first and last pixel as that's the outline
data.x_advance = data.width + get_x_advance_for(ox + x, oy, bitmap)
# Get height
y += 1 while is_valid_char_outline?(ox, oy + y, bitmap)
data.height = y - 2 # Like width
data.height = 0
data.height += 1 while is_valid_char_outline?(ox, oy + data.height, bitmap)
data.height -= 2 # Like width
# Get width
data.width = 0
data.width += 1 while is_valid_char_outline?(ox + data.width, oy, bitmap)
data.width -= 2 # We ignore the first and last pixel as that's the outline
data.x_advance = 0
data.x_advance += 1 while is_valid_char_spacing?(ox + 1 + data.x_advance, oy + data.height + 1, bitmap)
data.x_advance = data.width if data.x_advance <= 1
puts "data.x_advance: #{data.x_advance} | #{oy} / #{oy + data.height + 1}"
store = (@@stored_control_data << StoredDim.new).last
store.xr = ox..(ox + data.width + 1)
@@ -1,18 +1,21 @@
#==============================================================================
#
# TDD Ace Bitmap Font - 0.0.8
# TDD Ace Bitmap Font - 0.1.0
# _____________________________________________________________________________
#
# + Author: Galenmereth / Tor Damian Design
# + E-mail: post@tordamian.com
# -----------------------------------------------------------------------------
# + Last updated: 05/28/2015
# + Last updated: 05/29/2015
# + Level: Easy, Normal
# + Requires: n/a
# _____________________________________________________________________________
#
# ▼ Changelog
# -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
# 0.1.0 Fixed spacing bug for single characters, reorganized parser system to
# support the new optional Image Font Parser.
#
# 0.0.8 Added ADJUST_HORIZONTAL_DRAW_POSITION setting.
#
# 0.0.7 Added ADJUST_VERTICAL_DRAW_POSITION setting.
@@ -120,7 +123,7 @@ module SETTINGS
#
# DEFAULT: false (OFF)
#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
DEFAULT_FONT = "POPit"
DEFAULT_FONT = "bmf_example"
#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
# - Center Vertical -
View
@@ -1,19 +1,22 @@
# encoding: UTF-8
#==============================================================================
#
# TDD Ace Bitmap Font - 0.0.8
# TDD Ace Bitmap Font - 0.1.0
# _____________________________________________________________________________
#
# + Author: Galenmereth / Tor Damian Design
# + E-mail: post@tordamian.com
# -----------------------------------------------------------------------------
# + Last updated: 05/28/2015
# + Last updated: 05/29/2015
# + Level: Easy, Normal
# + Requires: n/a
# _____________________________________________________________________________
#
# ▼ Changelog
# -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
# 0.1.0 Fixed spacing bug for single characters, reorganized parser system to
# support the new optional Image Font Parser.
#
# 0.0.8 Added ADJUST_HORIZONTAL_DRAW_POSITION setting.
#
# 0.0.7 Added ADJUST_VERTICAL_DRAW_POSITION setting.
@@ -121,7 +124,7 @@ module SETTINGS
#
# DEFAULT: false (OFF)
#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
DEFAULT_FONT = "POPit"
DEFAULT_FONT = "bmf_example"
#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
# - Center Vertical -
@@ -834,8 +837,9 @@ def parse(font_image)
set_vars(bitmap)
parse_line_starts(bitmap)
parse_bitmap(bitmap)
#@@char_data.each{|cd| puts "Character #{cd.id.chr}: x:#{cd.x}, y:#{cd.y}, width:#{cd.width}, height: #{cd.height}, space: #{cd.x_advance}"}
return info(font_image), parse_char_data, kerning, File.basename(font_image)
parse_char_data
@@char_data.each{|cd| puts "Character #{cd.id.chr}: x:#{cd.x}, y:#{cd.y}, width:#{cd.width}, height: #{cd.height}, space: #{cd.x_advance}"}
return info(font_image), @@char_data, kerning, File.basename(font_image)
end
def parse_line_starts(bitmap)
@@ -880,8 +884,6 @@ def parse_char_data
cd.x_offset = 0
cd.y_offset = get_y_offset(cd)
end
@@char_data
end
def get_y_offset(char_data)
@@ -916,14 +918,20 @@ def store_dimension_data(ox, oy, bitmap)
# Local vars store
x = y = 0
# Get width
x += 1 while is_valid_char_outline?(ox + x, oy, bitmap)
data.width = x - 2 # We ignore the first and last pixel as that's the outline
data.x_advance = data.width + get_x_advance_for(ox + x, oy, bitmap)
# Get height
y += 1 while is_valid_char_outline?(ox, oy + y, bitmap)
data.height = y - 2 # Like width
data.height = 0
data.height += 1 while is_valid_char_outline?(ox, oy + data.height, bitmap)
data.height -= 2 # Like width
# Get width
data.width = 0
data.width += 1 while is_valid_char_outline?(ox + data.width, oy, bitmap)
data.width -= 2 # We ignore the first and last pixel as that's the outline
data.x_advance = 0
data.x_advance += 1 while is_valid_char_spacing?(ox + 1 + data.x_advance, oy + data.height + 1, bitmap)
data.x_advance = data.width if data.x_advance <= 1
puts "data.x_advance: #{data.x_advance} | #{oy} / #{oy + data.height + 1}"
store = (@@stored_control_data << StoredDim.new).last
store.xr = ox..(ox + data.width + 1)
View
@@ -1,12 +1,10 @@
Cache:106:in `initialize': No such file or directory - BitmapFonts/BitmapFonts/bmf_example.bft.PNG, Errno::ENOENT
from Cache:106:in `new'
from Cache:106:in `normal_bitmap'
from Cache:91:in `load_bitmap'
from (eval):644:in `bitmap_font'
from (eval):590:in `block in draw_bitmap_text'
from (eval):577:in `each_char'
from (eval):577:in `draw_bitmap_text'
from (eval):541:in `draw_text'
(eval):466:in `+': nil can't be coerced into Fixnum, TypeError
from (eval):466:in `block in calculate_text_width'
from (eval):463:in `each_char'
from (eval):463:in `calculate_text_width'
from (eval):638:in `bitmap_text_width'
from (eval):564:in `draw_bitmap_text'
from (eval):543:in `draw_text'
from Scene_Title:61:in `draw_game_title'
from Scene_Title:53:in `create_foreground'
from Scene_Title:16:in `start'

0 comments on commit 10c048b

Please sign in to comment.