Beispiel #1
0
def text(x,
         y,
         text,
         font,
         fontsize=None,
         align=1,
         left=None,
         sub_minus=False,
         upper=False,
         grid=False):
    if fontsize is None:
        fontsize = font['fontsize']
    xo = x
    line = []
    tracking = font['tracking']

    if grid:
        if sub_minus:
            iter_l = ('–' if c == '-' else c for c in text)
        else:
            iter_l = text

        for character in iter_l:
            try:
                line.append(
                    (font['__gridfont__'].character_index(character), x, y))
                x += (font['__gridfont__'].advance_pixel_width(character) *
                      fontsize + tracking)
            except TypeError:
                line.append((-1, x, y))
    else:
        if upper:
            text = text.upper()
        if sub_minus:
            text = text.replace('-', '–')

        HBB = hb.buffer_create()
        cp = list(map(ord, text))
        hb.buffer_add_codepoints(HBB, cp, 0, len(cp))
        hb.buffer_guess_segment_properties(HBB)
        hb.shape(font['__hb_font__'], HBB, [])
        factor = font['__factor__']
        for N, P in zip(hb.buffer_get_glyph_infos(HBB),
                        hb.buffer_get_glyph_positions(HBB)):
            line.append((N.codepoint, x + P.x_offset * factor, y))
            x += P.x_advance * factor + tracking
    if align == 0:
        dx = (xo - x) / 2
        line = [(g[0], g[1] + dx, g[2]) for g in line]
    elif align == -1:
        dx = xo - x
        if left is not None:
            dx = max(dx, left - xo)
        line = [(g[0], g[1] + dx, g[2]) for g in line]

    return font['font'], fontsize, line, x - xo - tracking
Beispiel #2
0
def text(x, y, text, font, fontsize=None, align=1, left=None, sub_minus=False, upper=False, grid=False):
    if fontsize is None:
        fontsize = font["fontsize"]
    xo = x
    line = []
    tracking = font["tracking"]

    if grid:
        if sub_minus:
            iter_l = ("–" if c == "-" else c for c in text)
        else:
            iter_l = text

        for character in iter_l:
            try:
                line.append((font["__gridfont__"].character_index(character), x, y))
                x += font["__gridfont__"].advance_pixel_width(character) * fontsize + tracking
            except TypeError:
                line.append((-1, x, y))
    else:
        if upper:
            text = text.upper()
        if sub_minus:
            text = text.replace("-", "–")

        HBB = hb.buffer_create()
        cp = list(map(ord, text))
        hb.buffer_add_codepoints(HBB, cp, 0, len(cp))
        hb.buffer_guess_segment_properties(HBB)
        hb.shape(font["__hb_font__"], HBB, [])
        factor = font["__factor__"]
        for N, P in zip(hb.buffer_get_glyph_infos(HBB), hb.buffer_get_glyph_positions(HBB)):
            line.append((N.codepoint, x + P.x_offset * factor, y))
            x += P.x_advance * factor + tracking
    if align == 0:
        dx = (xo - x) / 2
        line = [(g[0], g[1] + dx, g[2]) for g in line]
    elif align == -1:
        dx = xo - x
        if left is not None:
            dx = max(dx, left - xo)
        line = [(g[0], g[1] + dx, g[2]) for g in line]

    return font["font"], fontsize, line, x - xo - tracking
Beispiel #3
0
def _unpack_hb_buffer(HBB):
    return ((N.cluster, N.codepoint, P.x_advance, P.x_offset) for N, P in zip(
        hb.buffer_get_glyph_infos(HBB), hb.buffer_get_glyph_positions(HBB)))
Beispiel #4
0
def _unpack_hb_buffer(HBB):
    return ((N.cluster, N.codepoint, P.x_advance, P.x_offset) for N, P in zip(hb.buffer_get_glyph_infos(HBB), hb.buffer_get_glyph_positions(HBB)))