can't load_char() for FT_LOAD_TARGET_MONO
Hi all,
I found this library for monochrome font glyphs. If it is a standard, Gray 8 is set, which can be obtained. However monochrome seems impossible.
import freetype
face = freetype.Face("mplus-1p-black.ttf")
face.set_char_size( 1500 )
face.load_char('S', freetype.FT_LOAD_TARGETS['FT_LOAD_TARGET_MONO'])
bitmap = face.glyph.bitmap
print(bitmap.buffer) # error!
Comments?
What is the error you get? Did you check the example with TARGET_MONO?
@rougier What is the error you get? Did you check the example with TARGET_MONO? bitmap.buffer is None.
I noticed that the program should be modified in this way.
import freetype
face = freetype.Face("mplus-1p-black.ttf")
face.set_char_size( 1500 )
flags = freetype.FT_LOAD_FLAGS['FT_LOAD_RENDER'] | freetype.FT_LOAD_FLAGS['FT_LOAD_MONOCHROME'] | freetype.FT_LOAD_TARGETS['FT_LOAD_TARGET_MONO']
face.load_char('S', flags)
bitmap = face.glyph.bitmap
print(bitmap.buffer) # OK
It certainly works if I fix this way, but since this fact can not be understood by reading freetype-py document, please introduce it in 'samples'. (The above source code will be donated to this project)
The Freetype documentation has this paragraph:
"If FT_LOAD_RENDER is also set, the glyph is rendered in the corresponding mode (i.e., the mode that matches the used algorithm best). An exception is FT_LOAD_TARGET_MONO since it implies FT_LOAD_MONOCHROME."
It implies the converse also: if you don't have FT_LOAD_RENDER, bitmap is not generated and you need to call FT_Render_Glyph manually to generate a bitmap.
This is at the bottom of FT_LOAD_TARGET_* 's description.
@HinTak I am discussing freetype-py, where freetype has nothing to do with it.
freetype-py allows you to interact with freetype... it is based on ctypes and basically uses freetype's C API . freetype-py provides a FT_Render_Glyph which uses freetype's FT_Render_Glyph too. Anyway, you need to use freetype-py's FT_Render_Glyph, if you want to skip FT_LOAD_RENDER in FT_Load_Glyph. There are usage where loading without rendering is useful.