本文整理汇总了Python中freetype.FT_LOAD_TARGET_MONO属性的典型用法代码示例。如果您正苦于以下问题:Python freetype.FT_LOAD_TARGET_MONO属性的具体用法?Python freetype.FT_LOAD_TARGET_MONO怎么用?Python freetype.FT_LOAD_TARGET_MONO使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类freetype
的用法示例。
在下文中一共展示了freetype.FT_LOAD_TARGET_MONO属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _glyph_for_character
# 需要导入模块: import freetype [as 别名]
# 或者: from freetype import FT_LOAD_TARGET_MONO [as 别名]
def _glyph_for_character(self, char):
# Let FreeType load the glyph for the given character and tell it to
# render a monochromatic bitmap representation.
assert char != ''
self._face.load_char(char, freetype.FT_LOAD_RENDER |
freetype.FT_LOAD_TARGET_MONO)
return Glyph.from_glyphslot(self._face.glyph)
示例2: _glyph_for_character
# 需要导入模块: import freetype [as 别名]
# 或者: from freetype import FT_LOAD_TARGET_MONO [as 别名]
def _glyph_for_character(self, char):
# Let FreeType load the glyph for the given character and tell it to
# render a monochromatic bitmap representation.
self._face.load_char(char, freetype.FT_LOAD_RENDER |
freetype.FT_LOAD_TARGET_MONO)
return Glyph.from_glyphslot(self._face.glyph)
示例3: get_rendered_char_height
# 需要导入模块: import freetype [as 别名]
# 或者: from freetype import FT_LOAD_TARGET_MONO [as 别名]
def get_rendered_char_height(font_filename, font_size, char, target="mono"):
if target == "mono":
render_params = freetype.FT_LOAD_TARGET_MONO
elif target == "lcd":
render_params = freetype.FT_LOAD_TARGET_LCD
render_params |= freetype.FT_LOAD_RENDER
face = freetype.Face(font_filename)
face.set_char_size(font_size * 64)
face.load_char(char, render_params)
return face.glyph.bitmap.rows
示例4: unpack_mono_bitmap
# 需要导入模块: import freetype [as 别名]
# 或者: from freetype import FT_LOAD_TARGET_MONO [as 别名]
def unpack_mono_bitmap(bitmap):
"""
Unpack a freetype FT_LOAD_TARGET_MONO glyph bitmap into a bytearray where each
pixel is represented by a single byte.
"""
# Allocate a bytearray of sufficient size to hold the glyph bitmap.
data = bytearray(bitmap.rows * bitmap.width)
# Iterate over every byte in the glyph bitmap. Note that we're not
# iterating over every pixel in the resulting unpacked bitmap --
# we're iterating over the packed bytes in the input bitmap.
for y in range(bitmap.rows):
for byte_index in range(bitmap.pitch):
# Read the byte that contains the packed pixel data.
byte_value = bitmap.buffer[y * bitmap.pitch + byte_index]
# We've processed this many bits (=pixels) so far. This determines
# where we'll read the next batch of pixels from.
num_bits_done = byte_index * 8
# Pre-compute where to write the pixels that we're going
# to unpack from the current byte in the glyph bitmap.
rowstart = y * bitmap.width + byte_index * 8
# Iterate over every bit (=pixel) that's still a part of the
# output bitmap. Sometimes we're only unpacking a fraction of a byte
# because glyphs may not always fit on a byte boundary. So we make sure
# to stop if we unpack past the current row of pixels.
for bit_index in range(min(8, bitmap.width - num_bits_done)):
# Unpack the next pixel from the current glyph byte.
bit = byte_value & (1 << (7 - bit_index))
# Write the pixel to the output bytearray. We ensure that `off`
# pixels have a value of 0 and `on` pixels have a value of 1.
data[rowstart + bit_index] = 1 if bit else 0
return data
示例5: glyph_for_character
# 需要导入模块: import freetype [as 别名]
# 或者: from freetype import FT_LOAD_TARGET_MONO [as 别名]
def glyph_for_character(self, char):
# Let FreeType load the glyph for the given character and tell it to render
# a monochromatic bitmap representation.
self.face.load_char(char, freetype.FT_LOAD_RENDER | freetype.FT_LOAD_TARGET_MONO)
return Glyph.from_glyphslot(self.face.glyph)
示例6: unpack_mono_bitmap
# 需要导入模块: import freetype [as 别名]
# 或者: from freetype import FT_LOAD_TARGET_MONO [as 别名]
def unpack_mono_bitmap(bitmap):
"""
Unpack a freetype FT_LOAD_TARGET_MONO glyph bitmap into a bytearray
where each pixel is represented by a single byte.
"""
# Allocate a bytearray of sufficient size to hold the glyph bitmap.
data = bytearray(bitmap.rows * bitmap.width)
# Iterate over every byte in the glyph bitmap. Note that we're not
# iterating over every pixel in the resulting unpacked bitmap --
# we're iterating over the packed bytes in the input bitmap.
for row in range(bitmap.rows):
for byte_index in range(bitmap.pitch):
# Read the byte that contains the packed pixel data.
byte_value = bitmap.buffer[row * bitmap.pitch + byte_index]
# We've processed this many bits (=pixels) so far. This
# determines where we'll read the next batch of pixels from.
num_bits_done = byte_index * 8
# Pre-compute where to write the pixels that we're going
# to unpack from the current byte in the glyph bitmap.
rowstart = row * bitmap.width + byte_index * 8
# Iterate over every bit (=pixel) that's still a part of the
# output bitmap. Sometimes we're only unpacking a fraction of
# a byte because glyphs may not always fit on a byte boundary.
# So we make sure to stop if we unpack past the current row
# of pixels.
for bit_index in range(min(8, bitmap.width - num_bits_done)):
# Unpack the next pixel from the current glyph byte.
bit = byte_value & (1 << (7 - bit_index))
# Write the pixel to the output bytearray. We ensure that
# `off` pixels have a value of 0 and `on` pixels have a
# value of 1.
data[rowstart + bit_index] = 1 if bit else 0
return data
# A Font object is a dictionary of ASCII chars indexed by a character e.g.
# myfont['a']
# Each entry comprises a list
# [0] A Bitmap instance containing the character
# [1] The width of the character data including advance (actual data stored)
# Public attributes:
# height (in pixels) of all characters
# width (in pixels) for monospaced output (advance width of widest char)