Converting¶
You can convert both glyphs and providers to another via their respective converters.
For
Glyph:mcfonts.convert.glyphs.
Both glyph and provider converters operate on the same structure.
For example, to convert a UnihexGlyph to a BitmapGlyph:
from mcfonts.glyph.bitmap import BitmapGlyph
from mcfonts.glyph.unihex import UnihexGlyph
from mcfonts.convert.glyphs import GLYPH_CONVERTERS
unihex_glyph = UnihexGlyph(...)
bitmap_glyph = GLYPH_CONVERTERS[(UnihexGlyph, BitmapGlyph)](unihex_glyph)
assert isinstance(bitmap_glyph, BitmapGlyph)
The above example can be easily adapted to convert providers as well:
from mcfonts.provider.bitmap import BitmapProvider
from mcfonts.provider.unihex import UnihexProvider
from mcfonts.convert.providers import PROVIDER_CONVERTERS
unihex_provider = UnihexProvider(...)
bitmap_provider = PROVIDER_CONVERTERS[(UnihexProvider, BitmapProvider)](unihex_provider)
assert isinstance(bitmap_provider, BitmapProvider)
Warning
Not all converters will work universally.
For example, converting a BitmapGlyph to a SpaceGlyph will only work if the bitmap's image is entirely transparent.
For example, converting a BitmapProvider to a SpaceProvider will only work if every glyph in the provider is entirely transparent.
If a conversion fails, ValueError is raised.
Standard converters¶
This is a list of glyph converters available by default:
Bitmap --> Unihex
Bitmap --> Space
Unihex --> Bitmap
Unihex --> Space
Space --> Bitmap
This is a list of provider converters available by default:
Bitmap --> Unihex
Bitmap --> Legacy unicode
Unihex --> Bitmap
Unihex --> Legacy unicode
Legacy unicode --> Bitmap
Legacy unicode --> Unihex