Giter VIP home page Giter VIP logo

ftl_font's Introduction

FTL 1.6 Font manipulation tools

This is a toolset for adding and replacing characters in fonts from FTL: Faster Than Light version 1.6.

The initial intended goal for this project is to add cyrillic symbols to these fonts, but if you find other uses for these tools, go ahead!

Also, source code doubles as documentation for the format, since it uses bit-struct that allows for pretty readable descriptions of binary structures. See lib/ftl_font/binary/*.rb for details and lib/ftl_font/binary_wrapper.rb to see how they come together. Or file an issue for me to document the format in a more human-digestible way.

Usage

This toolset is intended for use primarily on Windows machines, thus the step-by-step guides will assume Windows.

It will work on Linux and OS X as well with no changes, but the guides might not reflect the exact steps you might need to do there. If there's any demand for instructions for Linux, I'll be happy to add them in! OS X is too much of a hassle for me to test on, sorry, but steps should be almost the same.

Setting up the toolset

  1. Install Ruby 2.4. Use RubyInstaller Archives (search for Ruby 2.4.10-1 (x64), it's the one you probably want, DevKit is not necessary for this tool)
  2. Download & unpack or git clone this repository
  • See Code > Download ZIP above if you're not sure what this means; then unpack the resulting file somewhere
  1. Use Slipstream Mod Manager to unpack FTL's resource file, ftl.dat, located inside the game folder. You'll see a folder called fonts in there: copy it into the downloaded repository, you should be prompted if folders should be merged, click "yes"
  2. Install the version of Bundler used during creation (gem install bundler -v 1.1.6.1) and use it to install dependencies (bundle install).
  • setup-ruby.bat for Windows does just that in a double-click, run it, wait until it finishes and you're set!

Using the toolset

Patching

Just so you know what's what, the build process goes like this:

  • It scans font_templates folder for any *.json files; for each <name>.json file found:
    • It opens the font specified in the source option
    • It merges in every set of additions in the additions option (an "addition" is a folder of characters to add or replace)
    • It saves the resulting font into the assembled folder under the name of <name>.font (after the *.json file from font_templates)

So to alter a font you'll need to create:

  • A set of additions in additions folder: there are a few examples there, but in general every set comprises of:
    • PNG files of individual characters.
      • White on black.
      • Grays allowed as well, they'll be translucent.
    • index.json with a JSON array of parameters; one set for every character to add or replace.
  • A FontNameHere.json file in font_templates with the instructions.
    • There already is an example, you can copy it, rename appropriately, change the source font (just the file name inside the fonts folder) and adjust the list of additions (folder names inside the additions folder).
    • Note: additions specified further take precedence, you can define an addition that replaces a character in the source font or another addition, as long as that addition goes before the one you need.

If you've done that, or you want to build an example font, execute the reassemble.rb script. Once it finishes, you should have the corresponding patched *.font files in the assembled folder.

Note: in case such a font already exists there, it silently overwrites it! This is just to make adjustments quicker.

Dismantling

Useful if you want original characters from a font with the intent to edit them or just change their parameters.

The process is easy: run dismantle.rb and wait until it completes. You should then have a bunch of *.original folders inside the additions folder, ready to modify as you see fit. Yes, they are ready-to-use additions too.

Limitations

  • Some characters, namely (space) have zero width in the original fonts and thus cannot be exported as PNGs (ChunkyPNG, that I'm using, can do it, but it will choke when trying to open the result). Such characters are not currently supported in additions. Zero width can be emulated by using a 1-pixel wide black "character" with one of the spacings (before or after) set 1 pixel smaller (negatives are valid in spacings too!). You can also let me know you need proper support for these by filing an issue.
  • Characters do not support colors. Internally every pixel is represented in the font as a single byte, specifying a value of opaqueness, e. g. 0x00 for fully transparent and 0xFF for fully opaque. It makes sense to only use white, black and grays. Others won't cause crashes, but will be converted to grays anyway with an algorithm I don't know (or want to know, really).
  • Removing existing characters from fonts is not supported at this time. It's not hard to add, but there has been no demand for this.

Contributing

I'm estimating the number of potential contributors to this project as 1 (one), that's including myself. So I may have skipped some steps that could facilitate contributions for others.

I do appreciate any help with this though! If you wish to contribute, but something about this repository is stopping you from doing so, file an issue, we'll figure it out.

Why not a gem?

Packaging it up as a gem with a few executables that perform transformations of fonts looks highly appealing! But requires some work I just haven't done yet.

ftl_font's People

Contributors

d-side avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ftl_font's Issues

Some info on the font file format

image

Just in case it's still helpful

Also it looks like you're off by 8 bits in the character itself, "spacing before" is 8 bits later and there's "pad" there.
image

Texture section appears to have 2 versions supported by FTL.
Texture header is:
MAGIC always 4 characters TEX\n I think (0xa584554)... appears big-endian maybe?

Tex V2's format is:

char[4] magic
uint8_t version
uint8_t format
uint8_t mipmaps
unit8_t opaque_bitmap
int16_t width
int16_t height
int32_t field_7 // I think this is some sort of scale or font size field
int32_t pixels_offset
int32_t pixels_size
int32_t bitmap_offset
int32_t bitmap_size

Tex V1's format is:

char[4] magic
uint8_t version
uint8_t[3] // 3 bytes unused, probably padding in the original struct
int16_t width
int16_t height
uint8_t field_7  // I think this is some sort of scale or font size field
uint8_t format
uint8_t mipmaps
uint8_t opaque_bitmap
int32_t pixels_offset
int32_t pixels_size
int32_t bitmap_offset
int32_t bitmap_size

There's some weird flipping of values in the assembly code so it looks like any 2 or 4 bytes value is actually stored big-endian (this is true for both the TEX & FONT headers).

This appears to be the different texture format values supported, again v1 does something weird with remapping some of these but I think these values are valid for v2
image

This all came from decompiling FTL in Ghidra.

Possible to export as TTF/OTF/etc?

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.

Usage instructions are out of date

I apologize to you, but I am bad at understanding and it is difficult to understand. Can you help me step by step?
1: i download and install ruby installer-2.4.1-1-x64
then ?

Rewrite the manual in simpler English

The manual is using more advanced English than it needs to, which gets in the way of users that don't know English very well โ€” which, considering that the tool's original purpose was to facilitate translation of FTL into Russian, might hurt other fan translation teams too.

The target language level would be the level used in FTL, since the translators would have to handle that much in order to translate the game itself.

I'm putting this here as a backlog item, I have no scheduled plans to do it; to one person that asked so far I confirmed a few details personally, but if there are more of you out there, a clearer manual would help all of us.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.