Exporting#

mcfonts can export a font into the OpenType font format.

This font will have an em size of 1000, and each character is scaled correctly. Glyphs are stored in a CFF Type 2 CharString format. There is no support for OpenType features such as ligatures, LOCL, colors, etc.

To export, simply run:

import mcfonts.importing
font = mcfonts.importing.from_java_font_file(...)
exported = font.export("My Font")
# To save to a file...
exported.save(...)

Fonts may be exported in either the OpenType (.otf) or WOFF2 (.woff2) format; WOFF2 is a container of OpenType.

Export Filter#

An Export Filter is a class in mcfonts.exporting.ExportFilter that is passed to exporting functions. It controls what characters and providers are exported, and under what conditions.

Look at the docstring for it to determine its policies and uses.

Export only providers with options#

To export only proivders that have Options Provider defined, run:

font.export("My Font", mcfonts.providers.CharacterFilter(options=font.options, options_policy="include_only"))

Export providers without options#

To export only providers that do not have Options Provider defined, run:

font.export("My Font", mcfonts.providers.CharacterFilter(options=font.options, options_policy="ignore_only"))

Export and ignore options#

To export all providers but ignore options if they are defined, run:

font.export("My Font", mcfonts.providers.CharacterFilter(options=font.options, options_policy="ignore")))

Export only providers of one type#

To export only providers of a type(s), run:

font.export(
    "My Font",
    provider_filter = mcfonts.providers.ProviderFilter(
        {mcfonts.providers.SpaceProvider},
        "include"
    )
)

Warning

Unless specified, this will re-include "legacy_unicode" providers for export.
This can massively inflate your font size, and you should re-add mcfonts.providers.LegacyUnicodeProvider.

Export only some characters#

What character's glyphs are included can be controlled with the select_chars option. By default, this is None (export all chars), but can be set to a set of characters:

font.export("My Font", mcfonts.providers.CharacterFilter(select_chars={"A", "B", "C"}))

Export without some characters#

font.export("My Font", mcfonts.providers.CharacterFilter(select_chars={"A", "B", "C"}, select_policy="exclude"))

Speed#

When exporting, every resource loaded will be iterated over and each pixel will be checked to determine how to create a program from it. If these resources were loaded with their colors, this incurs a heavy cost.

To fix this, run mcfonts.MinecraftFont.reload_to_monochrome() (permanent), or set read_colors=False when Importing.

Large file size#

This is an unfortunate side-effect of how mcfonts constructs its programs. Because of how data is recieved, the function that creates glyph programs is not context aware. It does not know of pixels surrounding it, so identical instructions and line directions may end up being included.

This can be fixed with FontForge:

  1. Open the font

  2. Press Control-A

  3. Go to Element ‣ Overlap ‣ Remove Overlap

  4. Go to Element ‣ Simplify ‣ Simplify

  5. Wait for the operation to finish.