Exporting¶
mcfonts is able to export Minecraft fonts into other formats. This is called exporting. It is not possible to import a non-Minecraft format into mcfonts yet.
Exporting takes 3 parameters:
A callable of signature [dict[str,
mcfonts.glyphs.Glyph
],mcfonts.export_formats.ExportSettings
] -> bytesA dictionary conforming to
mcfonts.export_formats.ExportSettings
, or NoneAn instance of
mcfonts.filters.Filter
, or None
No keys of the ExportSettings are required; all are optional, but they are all recommended.
Formats¶
mcfonts can export into a variety of formats, and is built to allow more export formats to be added on. By default, it supports 3 formats:
It is easy to export into any of these formats.
OpenType¶
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. Maximum amount of glyphs exportable is 65,535; any excess will be truncated.
import mcfonts
...
# If needed
settings = {...: ...}
filter_inst = mcfonts.filters.Filter(...)
# End if needed
font.export(mcfonts.export_formats.opentype, settings, filter_inst)
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:
Open the font
Press Control-A
Go to
Go to
Wait for the operation to finish.
YAFF¶
This font will have naïve scaling for characters.
import mcfonts
...
# If needed
settings = {...: ...}
filter_inst = mcfonts.filters.Filter(...)
# End if needed
font.export(mcfonts.export_formats.yaff, settings, filter_inst)
Unihex¶
import mcfonts
...
# If needed
settings = {...: ...}
filter_inst = mcfonts.filters.Filter(...)
# End if needed
font.export(mcfonts.export_formats.unihex, settings, filter_inst)
Filter¶
A 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.
Examples¶
Filter providers¶
This will export glyphs that belong to a selection of provider types. In this scenario, this will exclude Bitmap and Space.
mcfonts.filters.Filter(
filtered_providers = {mcfonts.providers.bitmap.BitmapProvider, mcfonts.providers.space.SpaceProvider}
# Default provider policy is EXCLUDE
)
It is also possible to accomplish the same using an inverse:
mcfonts.filters.Filter(
filtered_providers = {...} # Providers that are not Bitmap, Space
provider_policy=mcfonts.filters.Policy.INCLUDE
)
Filter characters¶
This will export glyphs that do not belong to a set of characters.
mcfonts.filters.Filter(
filtered_characters = {"a", "b", "c"}
)
You can also do the inverse - include only glyphs belonging to a set of characters.
mcfonts.filters.Filter(
filtered_characters = {"a", "b", "c"},
character_policy = mcfonts.filters.Policy.INCLUDE
)
Filter both¶
You can combine the two to filter out both providers and characters. The provider predicate takes precedence over a character predicate.
mcfonts.filters.Filter(
filtered_providers = {mcfonts.providers.bitmap.BitmapProvider, mcfonts.providers.space.SpaceProvider},
filtered_characters = {"a", "b", "c"},
provider_policy = mcfonts.filters.Policy.EXCLUDE,
character_policy = mcfonts.filters.Policy.INCLUDE
)