D-side / ftl_font

Font dissection tools for FTL Faster Than Light version 1.6
MIT License
10 stars 0 forks source link

Possible to export as TTF/OTF/etc? #1

Open IamCarbonMan opened 6 years ago

IamCarbonMan commented 6 years ago

I'm trying to use the fonts within FTL in another project. Disassembling them helps, but it would be extremely nice to be able to convert them into a bitmap font.

D-side commented 6 years ago

I haven't found any tools that make working with TTF or OTF programmatically easy enough. I would've went for one of those as an intermediate output format otherwise, because there are a few mature graphical editors out there for modders to use. But, alas, I didn't find anything.

I found that most of the time people need bitmap fonts out of "regular" fonts, and not the other way around as we would want. The only thing I've found during my brief search is that FontForge may be able to import the glyphs provided they are properly named. Which is not hard to arrange.

You can modify the code that does the disassembly to adjust the way it exports PNGs. This is the line that defines the filename of individual disassembled glyphs:

https://github.com/D-side/ftl_font/blob/8bf0c1fbbc929ff39a87e4669873f27b26ef5b5a/lib/ftl_font/binary_wrapper.rb#L42

#{c.character} is Ruby syntax for replacing this part of the string with the textual value of c.character, which in this case is a decimal equivalent of UTF-8's 4-byte code point. It's not the same as Unicode code point though, so this is what I think would satisfy FontForge:

    filename = "uni#{c.utf8_character.codepoints.first}.png"

Not sure about the leading zeros though, I can see them in the docs, but I'm not sure if there is any significance behind them.

Also, glyphs don't store baselines and spacing. Not sure if anything can be done about them other than typing in manually following the exported index JSON, which for hundreds of characters would most certainly be a major pain.

Also you might want to ask the nice people at Subset Games about whether they would allow the use of their FTL assets for something other than FTL mods 🙂

gradientogames commented 2 years ago

I have a similar issue, for another project I would like to extract all the fonts for a project, I can make ttf files but a json file and a png with all characters of the .font file in one sheet.

I know I might be being stupid but this project doesnt have a detailed enough tutorial or documentation, but is there a way to do this?

D-side commented 2 years ago

@gradientogames because of how rare uses of this tool are, I did not bother with more generic documentation, yes. It was originally built to support localization and related modding efforts around FTL, all that targeted the game itself, so there are no facilities for the processes that in the generate something other than FTL font files.

So if you have something else in mind for the font data, then it calls for a new Ruby script alongside dismantle/reassemble that'll do what you need. I'll be happy to help, it shouldn't be a lot of work, but I'll need to know the intended shape of the data in more specific terms 🙂

If you'd rather avoid learning Ruby and want to do this yourself, the key bit of information in this project is the binary structure of the file expressed reasonably declaratively in these files: file section (header with a list of characters) and tex section.

gradientogames commented 2 years ago

@D-side if you can, that would be great! Im allready learning c# for unity, python, javascript and I don't want another language on top of that so if you can, amazing! But if not, I could just manually rip the font from the game (I allready did with the title font, why not the others).