Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3

Author Topic: df2ttf - Automatic TTF generator  (Read 13093 times)

keenerd

  • Bay Watcher
    • View Profile
df2ttf - Automatic TTF generator
« on: June 23, 2010, 12:10:49 pm »

Yesterday I asked Talryth to make a TTF of his most excellent 15x15 tileset.  After a brief conversation, I tried to do it myself.  It actually ended up working.  Releasing this because (all?) the current TTFs are made by with a closed source and slow (on the order of 30 minutes per font) AutoHotKey script for an $80 windows-only app.  If the last sentence made you cringe a few times, this is the app for you.  (No offense, Elvang.)

Works with BMPs or PNGs, square or rectangle.  Has a handful of settings to help with making one-bit fonts (which fbterm desperately needs).  Usually takes less than 30 seconds.

Requires Python, Python Imaging Library and Fontforge* so it should be cross platform.
* Fontforge on Windows requires Cygwin.

Source is GPL and contains some goodies like the unicode mapping for a DF font and a homebrew bitmap-to-svg converter (optimized for pixel art).  Though I think the vectorizer  could be a lot better, it works fine at the single native resolution.

download: http://kmkeen.com/df2ttf/df2ttf.py.txt

--help docs:
Code: [Select]
Usage: df2ttf.py [options] tileset.png/bmp

Convert a Dwarf Fortress PNG/BMP tileset to a TrueType Font.  See
http://kmkeen.com/df2ttf/ for more.

Options:
  -h, --help        show this help message and exit
  -g, --gamma       Enable gamma correction.
  -d, --dither      Enable dithering, implies -b.
  -b, --blackwhite  Create 1 bit font.
Logged

Star Weaver

  • Bay Watcher
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #1 on: July 06, 2010, 09:37:06 am »

Hey, I tried this on the ironhand tiles and the result was really messy and slow to render (plus fontforge said 4 of the tiles were too much for it...).

I didn't try any of the optional options (yet), but I'm not sure how much help they would be :\.
Logged

keenerd

  • Bay Watcher
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #2 on: July 17, 2010, 12:55:25 pm »

Ouch.  My previous bunker buster was to test with Aesomatica, and Ironhand is three times worse.

I can't reproduce your error though.  Converts fine here (774KB ttf).  In general sprite based tilesets will not convert to fonts very well.

The -b option will speed things up a lot, while making it much more ugly.

Also, fixed a bug with indexed pngs.

Logged

Ruirize

  • Escaped Lunatic
    • View Profile
    • 2DCraft - A free 2D clone of Minecraft!
Re: df2ttf - Automatic TTF generator
« Reply #3 on: June 11, 2011, 06:17:32 pm »

Necrobump incoming.

I'm interested in using this tool to create a TTF of the awesome Phoebus tileset.

I have completely failed. I cannot for the life of me get fontforge to compile, and to be honest, I'm getting bored of trying (You know, it takes almost an hour to compile on my computer).
I don't suppose someone could convert it for me? This is for dfterm, by the way.

Thanks,
Ruirize
Logged
░▒▓█▌2DCraft▐█▓▒░ - The free 2D Minecraft clone!

keenerd

  • Bay Watcher
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #4 on: September 24, 2011, 08:38:25 am »

Sure.  Be warned that this is only the tiles, not the full graphics pack.  And it is huge.

Here is the heavy grayscale version (518KB): http://kmkeen.com/tmp/Phoebus_16x16-gray.ttf

And a lighter black and white version (41KB): http://kmkeen.com/tmp/Phoebus_16x16-bw.ttf
Logged

thistleknot

  • Bay Watcher
  • Escaped Normalized Spreadsheet Berserker
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #5 on: February 23, 2012, 01:09:21 am »

I couldn't get it to work

df2ttf.py tileset.png
  File "V:\downloads\Games\dwarf fortress\34.02\df2ttf.py", line 195
    print 'Missing required PNG argument.'
                                         ^
SyntaxError: invalid syntax
« Last Edit: February 24, 2012, 09:06:35 am by thistleknot »
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #6 on: February 23, 2012, 03:18:18 am »

I think its because the script is a Python 2.X script, and from the look of it, you have Python 3.X ( print is now a function )
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

keenerd

  • Bay Watcher
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #7 on: February 23, 2012, 05:06:08 am »

Sadly it will have to remain a python2 script for now.  When the Python Image Library works a bit better in python 3 I'll make the code run under both.
Logged

thistleknot

  • Bay Watcher
  • Escaped Normalized Spreadsheet Berserker
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #8 on: February 23, 2012, 10:30:40 am »

V:\downloads\Games\dwarf fortress\34.02>df2ttf.py tileset.png
Traceback (most recent call last):
  File "V:\downloads\Games\dwarf fortress\34.02\df2ttf.py", line 7, in <module>
    import Image, ImageChops
ImportError: No module named Image

keenerd

  • Bay Watcher
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #9 on: February 23, 2012, 11:33:26 am »

Quote
Requires Python, Python Image Library and Fontforge

It looks like you are using windows.  And you seem capable enough to configure a second hard drive.  But I really don't want to walk you through installing PIL, Fontforge and Cygwin.

You look like you want the 16x16 Phoebus tileset.  Why don't you just use the version I posted in September?

Logged

thistleknot

  • Bay Watcher
  • Escaped Normalized Spreadsheet Berserker
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #10 on: February 23, 2012, 11:44:18 am »

wasn't sure if it would work with a recent copy of df (I think I saw it somewhere, do you know where I can find that?), but I was hoping to get it working anyways.

Why would I need all those tools to get it to work in windows?  I understand it's python, but df is primarily a windows game with ports to linux second.  I could put this on a linux box, I have a flash drive with ubuntu.  Is that what I need to do?

Oh, damn requirements...  Okay.  I'll do that.  I am familiar with cygwin.
« Last Edit: February 23, 2012, 03:58:20 pm by thistleknot »
Logged

keenerd

  • Bay Watcher
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #11 on: February 23, 2012, 04:13:12 pm »

You seem to be very confused about what is going on.  And you are over using pronouns, so I barely understand what you are trying to express.

Quote from: thistleknot
wasn't sure if it would work with a recent copy of df

I presume by "it" you mean the previously posted phoebus.ttf.  Phoebus.ttf is a font.  Based on a simple tileset.  The (simple) tilesets don't break between versions.  The font literally can't break because DF has absolutely nothing to do with your choice of fonts in a terminal.  (Unless Toady randomly changes the font mapping or the simple tileset mapping, which would be silly, because every single tileset ever made would break.)

Quote from: thistleknot
(I think I saw it somewhere, do you know where I can find that?), but I was hoping to get it working anyways.

I presume by "it" you are still talking about phoebus.ttf.  Have you tried scrolling up?

Quote from: thistleknot
Why would I need all those tools to get it to work in windows?

I presume by "it" you are now talking about df2ttf.  You need those tools because they are the prerequisites to operating the df2ttf program.

Quote from: thistleknot
I understand it's python, but df is primarily a windows game with ports to linux second.

Pretty sure "it" refers to df2ttf here.  Df2ttf is primarily a linux program with support for Windows second.  Windows does not have PRINT_MODE:TEXT, the primary use for df2ttf.

Quote from: thistleknot
I could put this on a linux box, I have a flash drive with ubuntu.  Is that what I need to do?

I am not even sure what you want to do, so I can not say what you need to do.

Fontforge is a bit of a pain to install on Windows.  If you already have a linux install kicking around, that would probably be simpler for you.

If you only want phoebus don't bother with any of that and just scroll up.

If you only want one or two fonts and don't feel comfortable installing Python/PIL/Fontforge, ask me and I'll crank them out.
Logged

thistleknot

  • Bay Watcher
  • Escaped Normalized Spreadsheet Berserker
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #12 on: February 23, 2012, 06:17:18 pm »

thank you for your responses.  I can see the confusion with my use of it.

BTW, I did another search, and found the phoebus font in this thread.  Geez... /smacks forehead

thanks for your help, sorry for being such a pain with all these questions.  I honestly thought all I needed was python.  I see I failed to see the requirements, as I didn't even bother to read it (the thread).  Anyways.  Yeah, if you offer to make tilesets, that's great.  I do like to try and figure this stuff out myself, but I'll use your current one of phoebus.  Thanks a million!

I don't suppose you have ironhand's do you?  Or does it look like absolute horrid crap when converted?  I think 16x16 is pushing the limits with dfterm tho, but mayday's looked good, just couldn't fit too much on the screen.
« Last Edit: February 23, 2012, 06:21:58 pm by thistleknot »
Logged

keenerd

  • Bay Watcher
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #13 on: February 23, 2012, 06:39:21 pm »

Ironhand looks fine, it is just a rather large font file.  Here you go:

http://kmkeen.com/tmp/ironhand.ttf

The simpler line based tilesets work better as fonts.  Ironhand is almost entirely shades of gray.  It still works, just a little heavy on the memory.

Anyway, all will be forgiven if you clean up that massive wall of redundant error messages and edit it down to a single example  :-)
Logged

thistleknot

  • Bay Watcher
  • Escaped Normalized Spreadsheet Berserker
    • View Profile
Re: df2ttf - Automatic TTF generator
« Reply #14 on: February 23, 2012, 08:16:46 pm »

so why is it (between versions) that the graphical tilesets need to be updated, but the ascii one's (terminal ones, ttf) don't necessarily?  Is it because they custom fit images to people?  I don't get it, because the ttf's are based on the graphical ones.

update:

I guess it has something to do with your mentioning of the ttf's being "simple" tilesets.  I.e. basic ascii?

Nevermind.  I get it.  Basic doesn't use all the extensions that the graphical ones do.
« Last Edit: February 27, 2012, 06:26:11 pm by thistleknot »
Logged
Pages: [1] 2 3