Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryhon0 committed Oct 6, 2020
1 parent a3a6509 commit 7358786
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 113 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# BitmapFontCutter
Godot 3 resource extension for oldschool bitmap fonts.
# BitmapFontCutterPlus
Fork of [nobuyukinyuu/BitmapFontCutter](https://github.com/nobuyukinyuu/BitmapFontCutter) with some improvements.

![](https://i.imgur.com/ug6opo0.png)
![](https://i.imgur.com/gj2T3LC.png)
## Improvements
* Added an option to make non-monospaced fonts (clips characters to their bounding boxes)
* Added an option for font spacing
* Fixed incorrect incorrect number of columns

## Ussage

TODO:
* Initial texture offset
* Specify custom charset
* Better init / signal capture
* Clone the plugin repo or download it from the AssetLib
* Enable the plugin (Project > Project Settings > Plugins)
* Create a new `CutBitmapFont` resource (Right click in filesystem > New Resource > CutBitmapFont)
* Select the resource in filesystem and edit the properties in the inspector
82 changes: 0 additions & 82 deletions addons/BitmapFontCutter/cutter.gd

This file was deleted.

10 changes: 0 additions & 10 deletions addons/BitmapFontCutter/main.gd

This file was deleted.

7 changes: 0 additions & 7 deletions addons/BitmapFontCutter/plugin.cfg

This file was deleted.

89 changes: 89 additions & 0 deletions addons/BitmapFontCutterPlus/cutter.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
tool
extends BitmapFont

var index = 0
export(Vector2) var GlyphSize = Vector2(8,8) setget changeGlyphSize
export(Texture) var TextureToCut = null setget changeTexture
export(int,255) var StartChar = 32 setget changeStartChar
export(float) var Spacing = 1 setget changeSpacing
export(bool) var Monospaced = true setget changeMonospaced

func changeStartChar(value):
StartChar = value
update()

func changeGlyphSize(value):
GlyphSize = value
height = GlyphSize.y
update()

func changeTexture(value):
TextureToCut = value
index = 0
if TextureToCut:
update()

func changeSpacing(value):
Spacing = value
update()

func changeMonospaced(value):
Monospaced = value
update()

func update():
print("Cut texture to font")
if TextureToCut != null:
if GlyphSize.x > 0 and GlyphSize.y > 0:

var w = TextureToCut.get_width()
var h = TextureToCut.get_height()
var tx = w / GlyphSize.x
var ty = h / GlyphSize.y

var font = self
var i = 0 #Iterator for char index

clear()

#Begin cutting..... so edgy
font.add_texture(TextureToCut)
font.height = GlyphSize.y
for y in range(ty):
for x in range(tx+1):
var l = 0
var character_width = GlyphSize.x

if !Monospaced:
var data = TextureToCut.get_data()
data.lock()

var found = false
for xx in range(0,GlyphSize.x):
if found: break
for yy in range(0,GlyphSize.y):
var pixel = data.get_pixel(x*GlyphSize.x + xx, y*GlyphSize.y + yy)
if pixel.a != 0:
l = xx
character_width -= xx
found = true
break

found = false
for xx in range(0,GlyphSize.x):
if found: break
for yy in range(0,GlyphSize.y):
var pixel = data.get_pixel(x*GlyphSize.x + GlyphSize.x - xx -1, y*GlyphSize.y + yy)
if pixel.a != 0:
character_width -= xx
found = true
break

data.unlock()

var region = Rect2(x*GlyphSize.x + l,y*GlyphSize.y,character_width, GlyphSize.y)
font.add_char(StartChar + i, 0, region, Vector2.ZERO, character_width + Spacing)

i+=1
update_changes()
pass #if texture is null
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

importer="texture"
type="StreamTexture"
path="res://.import/icon.png-a2b10341c27fdda667abd051a3b79986.stex"
path="res://.import/icon.png-7a944b865335bcc37a4211ee6e1daf36.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/BitmapFontCutter/icon.png"
source_md5="f20f212dbac7bc998244e5dfc3111aaa"

dest_files=[ "res://.import/icon.png-a2b10341c27fdda667abd051a3b79986.stex" ]
dest_md5="bdd3a001e4bb808b264176d385f391cc"
source_file="res://addons/BitmapFontCutterPlus/icon.png"
dest_files=[ "res://.import/icon.png-7a944b865335bcc37a4211ee6e1daf36.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
Expand All @@ -26,6 +27,7 @@ flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
Expand Down
9 changes: 9 additions & 0 deletions addons/BitmapFontCutterPlus/main.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tool
extends EditorPlugin


func _enter_tree():
add_custom_type("CutBitmapFont","BitmapFont",preload("cutter.gd"),preload("icon.png"))

func _exit_tree():
remove_custom_type("CutBitmapFont")
7 changes: 7 additions & 0 deletions addons/BitmapFontCutterPlus/plugin.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[plugin]

name="BitmapFont Cutter Plus"
description="Generates BitmapFonts from a texture."
author="Ryhon, forked from Nobuyuki"
version="2.0"
script="main.gd"

0 comments on commit 7358786

Please sign in to comment.