forked from nobuyukinyuu/BitmapFontCutter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
124 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
 | ||
 | ||
## 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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |