Pages: [1]   Go Down
Author Topic: fontcreator2 problem  (Read 976 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi guys,
im sorry if his kind of thread has been created b4. I did a lil searching but didn't found anything so i decided to create my own thread.

Now, problem is that i can't get the program running. every time i double click on start.bat, a dos window appear and dissapear. Then nothing happened. Can somebody give me a tutorial on this? i've installed java btw and i think it might have something to do with java virtual machine.
thanks in advance
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8647
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The start.bat file contains:

    @echo off
    javaw -classpath . FontCreator

If you open a DOS window, navigate to the folder containing start.bat and then run that javaw command you will probably see some more useful error messages.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Faraday Member
**
Karma: 23
Posts: 3469
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Or trash the fontcreator. You do not need it. There are other ways to create fonts. I use "The Gimp" to create fonts. Once the fonts are ready I export them as PNG. I just type all characters in one long row. Then use a little python script to extract what I need:

Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import Image

minimum_spacing = 2
invert = True

first_character_number = 32
space_width = 3              # = width for space character


def hexit(byte):
if byte > 15:
return hex(byte)
else:
return "0x0"+hex(byte)[-1]


def invert(im):
inv = im.copy()
(width, height) = im.size[-2:]

for row in xrange(0, height):
for col in range(0, width):
inv.putpixel((col, row), 255-inv.getpixel((col, row)))
return inv


def bounding_box(im):
(width, height) = im.size[-2:]

(xmax, ymax, xmin, ymin) = (0, 0, width, height)
for row in xrange(0, height):
for col in range(0, width):
if im.getpixel((col, row)) <> 0:
xmax = max(xmax, col)
xmin = min(xmin, col)
ymax = max(ymax, row)
ymin = min(ymin, row)

return (xmin, ymin, xmax+1 , ymax+1 )


def is_empty(im, x, y0, y1):
for row in range(y0, y1):
if  im.getpixel((x, row)) <> 0:
return False
return True


def is_spacer(im, x, y0, y1):
for delta in range(0, minimum_spacing):
if not is_empty(im, x+delta, y0, y1):
return False
return True


def compute_col(im, x, y0, y1):
col = [im.getpixel((x, row))/255 for row in range(y0, y1)]
return col


for infile in sys.argv[1:]:
print
# read image
im = Image.open(infile)

# display some information about the image
print "processing: "
print infile
print "Properties", im.format, im.mode, im.size

# convert to black and white
bw_image = im.convert("1")
print "Color statistics", im.getcolors()

if invert:
inv = invert(bw_image)
print "Color statistics inverse", inv.getcolors()
im = inv

# determine bounding box
bbox = bounding_box(im)
print "Bounding box", bbox

# determine common data
(x0, y0, x1, y1) = bbox
height = y1-y0
bytes_per_colum = (height+7)/8
print "Bytes per colum", bytes_per_colum

# initialize for parsing
spacer_behind = False

charwdithlist = []
charlist = []
current_char = []
current_width = 0

if space_width > 0:
# fill space character
current_width = space_width
current_char = [0 for i in xrange(0, space_width * bytes_per_colum)]
spacer_behind = True

chars = 0

# main parse loop
for col in xrange(x0, x1):
if (spacer_behind and is_empty(im, col, y0, y1)) or is_spacer(im, col, y0, y1):
# skip spacer colums
spacer_behind = True

else:
if spacer_behind:
# flush character
charwdithlist += [current_width]

transformed_char = []
#print "bbc", bytes_per_colum
#print "cc", current_char
for bcol in xrange(0, bytes_per_colum):
#print "slice", current_char[bcol::bytes_per_colum]
transformed_char += current_char[bcol::bytes_per_colum]

charlist += [transformed_char]
#print "tc", transformed_char
#print "cl", charlist

# begin new character
current_char = []
current_width = 0
spacer_behind = False

# for verbose output
print "character", chars, col
chars += 1

# parsing current char
col = compute_col(im, col, y0, y1)
print ''.join([['.', '#'][pixel] for pixel in col])+"  "+str(col)
# compute bytes for current colum
bit = 0
byte = 0
for pixel in col:
if bit == 0:
bit = 1
byte += (bit * pixel)
bit += bit
bit %= 256
if bit == 0:
current_char += [byte]
#print bin(byte) + "  " + hex(byte)
byte = 0
if bit > 0:
current_char += [byte]
#print bin(byte) + "  " + hex(byte)
#print current_char
current_width += 1

# deal with very last char
charwdithlist += [current_width]
transformed_char = []
#print "bbc", bytes_per_colum
#print "cc", current_char
for bcol in xrange(0, bytes_per_colum):
#print "slice", current_char[bcol::bytes_per_colum]
transformed_char += current_char[bcol::bytes_per_colum]
charlist += [transformed_char]


chars            = len(charwdithlist)
bytes            = 6 + chars
for charbytes in charlist:
bytes += len(charbytes)
fontname         = infile.split('.')[0]
output_filename  = fontname+".h"
h_name           = fontname.upper()

print "//"
print "//", fontname
print "//"
print "// created with FontExtractor.py"
print "// written by Udo Klein"
print "//"
print "//"
print "// File name         :", output_filename
print "// Font height       :", height
print "// Font size in bytes:", bytes
print "// Font first char   :", first_character_number
print "// Font last char    :", first_character_number + chars - 1
print "// Font used chars   :", chars
print "//"
print "// The font data is defined as"
print "//"
print "// struct _FONT_ {"
print "//     uint16_t   font_Size_in_Bytes_over_all_included_Size_itself;"
print "//     uint8:t    font_height;"
print "//     unit8_t    font_First_Char;"
print "//     uint8_t    font_Char_Count;"
print "//"
print "//     uint8_t    font_Char_Widths[font_Char_Count];"
print "//                  // for each character the separate width in pixels,"
print "//"
print "//     uint8_t    font_data[];"
print "//                  // bit field of all characters"
print "//"
print "// nth  row: n bytes with lowest signigificant bit = uppermost pixel"
print "// last row: similar but padding of the lowest significant bits"
print
print "#include <inttypes.h>"
print "#include <avr/pgmspace.h>"
print
print "#ifndef ", h_name+"_H"
print "#define ", h_name+"_H"
print
print "#define ", h_name+"_HEIGHT", 0
print
print "static uint8_t "+fontname+"[] PROGMEM = {"
print "    "+hexit(bytes/255)+", "+hexit(bytes%255)+", // size"
print "    "+hexit(0)+",       // width"
print "    "+hexit(height)+",       // height"
print "    "+hexit(first_character_number)+",       // first char"
print "    "+hexit(chars)+",       // char count"
print
print "    // char widths (in pixels)"
for line in xrange(0, (chars+7) / 8):
print "    " + \
      ", ".join([hexit(x) for x in charwdithlist[line*8:line*8+8]]) + \
      ",  // " + \
      ", ".join([hexit(first_character_number+x) for x in xrange(line*8, line*8+len(charwdithlist[line*8:line*8+8]))])
print
print "   // font data"
for c in xrange(0, len(charlist)):
char = charlist[c]
print "    " + \
      ", ".join([hexit(x) for x in char]) + \
      [",", ""][(c+1)/len(charlist)] + \
      "  // " + \
      hex(c+first_character_number) + \
      "  " + \
      [chr(c+first_character_number), "'\\'"][int(chr(c+first_character_number) == "\\")]
print "};"
print "#endif"

Maybe not the most elegant. But it did the job. Attention: I use my own LCD libraries hence the font encoding may differ for your libraries. So if this program does not work for you you may have to rewrite parts of it.

Udo
Logged

Check out my experiments http://blog.blinkenlight.net

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The start.bat file contains:

    @echo off
    javaw -classpath . FontCreator

If you open a DOS window, navigate to the folder containing start.bat and then run that javaw command you will probably see some more useful error messages.

it says javaw is not recognised.. what should i do?

to Udo: im afraid your method is too advanced for a newbie for me smiley-cry
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

problem solved  smiley-grin

actually i didn't have the java 64bit version. the fontcreator couldn't start because im on a 64bits windows.
after i installed the 64bits version, it works
thanks for the help anyway
Logged

Pages: [1]   Go Up
Jump to: