Example #1
0
def _HB_cast_glyphs(cp, a, b, font, factor, runinfo, FSTYLE):
    HBB = hb.buffer_create()
    hb.buffer_add_codepoints(HBB, cp, a, b - a)
    hb.buffer_set_direction(HBB, runinfo[1])
    hb.buffer_set_script(HBB, runinfo[2])
    hb.shape(font, HBB, FSTYLE['__ot_features__'])
    return _compose_glyphs(_unpack_hb_buffer(HBB), factor, FSTYLE['shift'], FSTYLE['tracking'])
Example #2
0
def _HB_cast_glyphs(cp, a, b, font, factor, runinfo, FSTYLE):
    HBB = hb.buffer_create()
    hb.buffer_add_codepoints(HBB, cp, a, b - a)
    hb.buffer_set_direction(HBB, runinfo[1])
    hb.buffer_set_script(HBB, runinfo[2])
    hb.shape(font, HBB, FSTYLE['__ot_features__'])
    return _compose_glyphs(_unpack_hb_buffer(HBB), factor, FSTYLE['shift'],
                           FSTYLE['tracking'])
Example #3
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
Example #4
0
 def __init__(self, cp, a, b, runinfo, fontinfo):
     self._cp       = cp
     self._font     = font = fontinfo[1]
     self._compose  = fontinfo[2], fontinfo[0]['shift'], fontinfo[0]['tracking']
     self._features = fontinfo[0]['__ot_features__']
     self._HBB      = hb.buffer_create()
     self._runinfo  = runinfo
     self._d        = runinfo[0]
     self._glyphs   = list(self._reshape(cp, a, b))
     if self._d:
         self._logical_glyphs = list(reversed(self._glyphs))
     else:
         self._logical_glyphs = self._glyphs
     self._present = [G[0] for G in self._logical_glyphs]
     self._present.append(b)
     
     self._RIGHT_CACHE = {a: (self._logical_glyphs, 0, 0)}
Example #5
0
    def __init__(self, cp, a, b, runinfo, fontinfo):
        self._cp = cp
        self._font = font = fontinfo[1]
        self._compose = fontinfo[2], fontinfo[0]['shift'], fontinfo[0][
            'tracking']
        self._features = fontinfo[0]['__ot_features__']
        self._HBB = hb.buffer_create()
        self._runinfo = runinfo
        self._d = runinfo[0]
        self._glyphs = list(self._reshape(cp, a, b))
        if self._d:
            self._logical_glyphs = list(reversed(self._glyphs))
        else:
            self._logical_glyphs = self._glyphs
        self._present = [G[0] for G in self._logical_glyphs]
        self._present.append(b)

        self._RIGHT_CACHE = {a: (self._logical_glyphs, 0, 0)}
Example #6
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