Open kanryu opened 5 years ago
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_LOADTARGET* '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.
I should explain this in python terms, if you do
face.load_char('S', flags)
where flags
does not include ...LOAD_RENDER
then face.glyph.bitmap
is not populated, but face.glyph.outline
is. There are usage where you want the outlines (and draw the outlines), or you want to do some manipulation before calling face.glyph.render(...)
. We have a few examples of the former for the former cases, in the /examples
directory - look at the ...outline...
ones, where NOT having ...LOAD_RENDER
is intentional.
As I already explained, this behavior is documented. If you feel this is inadequately documented, please free free to submit a pull.
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.
Comments?