Initial BMF support

This commit is contained in:
sillysagiri 2024-10-15 20:40:07 +07:00
parent 58ae9d5185
commit f309d1df82
15 changed files with 337 additions and 0 deletions

BIN
assets/silly/bmf/nds12.fnt Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
assets/silly/bmf/nds12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
assets/silly/bmf/onds12.fnt Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
assets/silly/bmf/onds12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
raw/nds12/NDS12.ttf Normal file

Binary file not shown.

59
raw/nds12/config.bmfc Normal file
View File

@ -0,0 +1,59 @@
# AngelCode Bitmap Font Generator configuration file
fileVersion=1
# font settings
fontName=NDS12
fontFile=
charSet=0
fontSize=-10
aa=1
scaleH=100
useSmoothing=1
isBold=0
isItalic=0
useUnicode=1
disableBoxChars=1
outputInvalidCharGlyph=0
dontIncludeKerningPairs=0
useHinting=0
renderFromOutline=0
useClearType=1
autoFitNumPages=0
autoFitFontSizeMin=0
autoFitFontSizeMax=0
# character alignment
paddingDown=0
paddingUp=0
paddingRight=0
paddingLeft=0
spacingHoriz=1
spacingVert=1
useFixedHeight=0
forceZero=0
widthPaddingFactor=0.00
# output file
outWidth=128
outHeight=64
outBitDepth=32
fontDescFormat=2
fourChnlPacked=0
textureFormat=png
textureCompression=0
alphaChnl=1
redChnl=0
greenChnl=0
blueChnl=0
invA=0
invR=0
invG=0
invB=0
# outline
outlineThickness=1
# selected chars
chars=32-127
# imported icon images

8
raw/nds12/license.txt Normal file
View File

@ -0,0 +1,8 @@
License for NDS12 font
This font was created by Caveras with FontStruct and is licensed
under a Creative Commons Attribution Non-commercial Share Alike
license.
http://fontstruct.com/fontstructors/caveras
http://creativecommons.org/licenses/by-nc-sa/3.0/

BIN
raw/nds12/nds12.fnt Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
raw/nds12/nds12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
raw/nds12/onds12.fnt Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
raw/nds12/onds12_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

29
raw/nds12/readme.txt Normal file
View File

@ -0,0 +1,29 @@
NDS12 by Caveras - based on the original system font of the Nintendo DS.
The font file in this archive was created by Caveras using FontStruct -
the free, online font-building tool. This font has a homepage where this
archive and other versions may be found:
http://fontstruct.com/fontstructors/caveras
It is also distributed over Caveras' website: http://www.caveras.net
Try FontStruct at http://fontstruct.com - Its easy and its fun.
NOTE FOR FLASH USERS: FontStruct fonts (FontStructions) are optimized for
Flash. The font in this archive is a pixel font and best displayed at a
font-size of 16 and multiples of this number.
FontStruct is sponsored by FontShop. Visit them at http://fontshop.com.
FontShop is the original independent font retailer. Weve been around since
the dawn of digital type. Whether you need the right font or need to create
the right font from scratch, let our 23 years of experience work for you.
FontStruct is copyright © 2016 Rob Meek
LEGAL NOTICE:
In using this font you must comply with the licensing terms described in the
file “license.txt” included with this archive. If you redistribute the font
file in this archive, it must be accompanied by all the other files from this
archive, including this one.
Copyright © 2016 Caveras / Cliff Modes.

133
src/sillysagiri/BMF.java Normal file
View File

@ -0,0 +1,133 @@
package sillysagiri;
import java.io.InputStream;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class BMF {
public static final byte ID = 0;
public static final byte X = 1;
public static final byte Y = 2;
public static final byte WIDTH = 3;
public static final byte HEIGHT = 4;
public static final byte XOFF = 5;
public static final byte YOFF = 6;
public static final byte XADV = 7;
public Image img;
public short fontSize;
public short lineHeight;
public short base;
public short[][] chars;
public BMF(String path_img, String path_fnt) throws Exception
{
img = Image.createImage(path_img);
InputStream in = this.getClass().getResourceAsStream(path_fnt);
byte[] header = new byte[4];
int size_read = in.read(header, 0, 4);
if (!(size_read == 4) &&
!(header[0] != 'B') &&
!(header[1] != 'M') &&
!(header[2] != 'F') &&
!(header[3] != 3))
{
throw new Exception("File is not bmf " + path_fnt);
}
header = null;
byte[] buffer = new byte[20];
while(size_read != -1)
{
int length;
int type;
// read type & length
size_read = in.read(buffer, 0, 5);
if (size_read == -1) break;
// get type from buffer
type = buffer[0];
// convert byte into int;
length = ((buffer[4] & 0xFF) << 24) |
((buffer[3] & 0xFF) << 16) |
((buffer[2] & 0xFF) << 8) |
(buffer[1] & 0xFF);
switch (type) {
case 1: // info block
{
// font size is signed
size_read = in.read(buffer, 0, 2);
fontSize = (short)( ((buffer[1]) << 8) |
(buffer[0]) );
// skip the rest
in.skip(length - 2);
}
break;
case 2: // common block
{
size_read = in.read(buffer, 0, 4);
lineHeight = (short)( ((buffer[1] & 0xFF) << 8) |
(buffer[0]) & 0xFF);
base = (short)( ((buffer[3] & 0xFF) << 8) |
(buffer[2]) & 0xFF);
// skip the rest
in.skip(length - 4);
}
break;
case 3: // pages block
{
// skip pages
in.skip(length);
}
break;
case 4: // chars block
{
chars = new short[96][8];
int count = length/20;
for (int i=0; i<count; i++)
{
size_read = in.read(buffer, 0, 20);
int id = ((buffer[3] & 0xFF) << 24) |
((buffer[2] & 0xFF) << 16) |
((buffer[1] & 0xFF) << 8) |
(buffer[0] & 0xFF);
// TODO: handle more glyph
if (id < 32 || id > 128) continue;
chars[id-32][ID] = (short)(((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF));
chars[id-32][X] = (short)(((buffer[5] & 0xFF) << 8) | (buffer[4] & 0xFF));
chars[id-32][Y] = (short)(((buffer[7] & 0xFF) << 8) | (buffer[6] & 0xFF));
chars[id-32][WIDTH] = (short)(((buffer[9] & 0xFF) << 8) | (buffer[8] & 0xFF));
chars[id-32][HEIGHT] = (short)(((buffer[11] & 0xFF) << 8) | (buffer[10] & 0xFF));
chars[id-32][XOFF] = (short)((buffer[13] << 8) | buffer[12]);
chars[id-32][YOFF] = (short)((buffer[15] << 8) | buffer[14]);
chars[id-32][XADV] = (short)((buffer[17] << 8) | buffer[16]);
}
}
break;
default:
break;
}
}
}
public void Draw(Graphics g, String str, int x, int y)
{
short[] cursor = new short[]{0, 0};
}
}

View File

@ -0,0 +1,29 @@
package sillysagiri.scene;
import javax.microedition.lcdui.Graphics;
import sillysagiri.Scene;
import sillysagiri.Utils;
public class DeathError extends Scene {
Exception e;
public DeathError(Exception e)
{
super();
this.e = e;
}
public void Preload() {
}
public void Destroy() {
}
public void Update(long dt, Graphics g) {
// TODO: improve death message
Utils.Clear_Screen(g, 255, 255, 255);
g.setColor(255, 0 , 0);
g.drawString(e.toString(), 0, 0, Graphics.LEFT|Graphics.TOP);
}
}

View File

@ -0,0 +1,79 @@
package sillysagiri.scene;
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import sillysagiri.BMF;
import sillysagiri.Scene;
import sillysagiri.Utils;
public class MainMenu extends Scene {
private long counter = 0;
private int state = 0;
private Image img_bg;
private Image img_bandai;
private Image img_ez;
public void Preload() {
try {
BMF bmf = new BMF("/silly/bmf/nds12.png", "/silly/bmf/nds12.fnt");
Image img_loop = Image.createImage("/m_2.png");
img_bandai = Image.createImage("/c_0.png");
img_ez = Image.createImage("/pEZ.png");
int loopCount = (int)Math.ceil((float)Utils.GetScreenHeight()/img_loop.getHeight());
img_bg = Image.createImage(img_loop.getWidth(), Utils.GetScreenHeight());
Utils.Clear_Image(img_bg, 255, 108, 0);
Graphics g_bg = img_bg.getGraphics();
for (int i = 0; i<loopCount; i++)
g_bg.drawImage(img_loop, 0, i*img_loop.getHeight(), Graphics.LEFT | Graphics.TOP);
}
catch(Exception e)
{
e.printStackTrace();
sagiri.Set_Scene(new DeathError(e));
}
}
public void Destroy() {
}
public void Update(long dt, Graphics g) {
counter += dt;
switch (state) {
case 0:
{
Utils.Clear_Screen(g, 255, 108, 0);
g.drawImage(img_bg, 0, 0, Graphics.TOP | Graphics.LEFT);
g.drawImage(
img_bandai,
Utils.GetScreenWidth()/2, Utils.GetScreenHeight()/2,
Graphics.VCENTER | Graphics.HCENTER);
if (counter >= 600) counter = 0;
if (counter < 400)
g.drawImage(
img_ez,
Utils.GetScreenWidth()/2, (int)(Utils.GetScreenHeight()*0.75),
Graphics.VCENTER | Graphics.HCENTER);
if (sagiri.input.IsKeyDownAny())
{
counter = 0;
state = 1;
}
}
break;
default: break;
}
}
}