當前位置: 首頁>>代碼示例>>Python>>正文


Python freetype.FT_LOAD_TARGET_MONO屬性代碼示例

本文整理匯總了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) 
開發者ID:peterhinch,項目名稱:micropython-font-to-py,代碼行數:9,代碼來源:font_to_py.py

示例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) 
開發者ID:jeffmer,項目名稱:micropython-ili9341,代碼行數:8,代碼來源:font_to_py.py

示例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 
開發者ID:googlefonts,項目名稱:nototools,代碼行數:13,代碼來源:font_tests.py

示例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 
開發者ID:bk1285,項目名稱:rpi_wordclock,代碼行數:41,代碼來源:fontdemo.py

示例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) 
開發者ID:bk1285,項目名稱:rpi_wordclock,代碼行數:7,代碼來源:fontdemo.py

示例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) 
開發者ID:peterhinch,項目名稱:micropython-font-to-py,代碼行數:53,代碼來源:font_to_py.py


注:本文中的freetype.FT_LOAD_TARGET_MONO屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。