示例#1
0
def get_glyphs(ctx, layout_data, text, width, text_style, markup):
    glyphs = []
    i = -1
    for item in text:
        i += 1

        if item in NONPRINTING_CHARS:
            res = False
            if markup and not item == '\n':
                for mrk in markup:
                    if 'u' in mrk[0] or 's' in mrk[0]:
                        if i >= mrk[1][0] and i < mrk[1][1]:
                            res = True
                            break
            if not res:
                glyphs.append(None)
                continue

        ctx.new_path()
        ctx.move_to(0, 0)
        layout = core.create_layout(ctx)
        text_range = [i, i + len(item)]
        vpos = core.set_glyph_layout(item, width, text_style, markup,
                                     text_range, True, layout)
        if vpos:
            for index in range(*text_range):
                x, y, w, h, base_line, byte_index = layout_data[index]
                dh = (y - base_line) * vpos
                layout_data[index] = (x, y + dh, w, h, base_line + dh,
                                      byte_index)
        core.layout_path(ctx, layout)
        cpath = ctx.copy_path()
        m00 = 1.0
        m11 = -1.0
        if os.name == 'nt':
            m00 *= 0.1
            m11 *= 0.1
        matrix = cairo.Matrix(m00, 0.0, 0.0, m11, layout_data[i][0],
                              layout_data[i][1])
        libcairo.apply_cmatrix(cpath, matrix)
        glyphs.append(cpath)
    return glyphs
示例#2
0
def get_rtl_glyphs(ctx, layout_data, log_layout_data, byte_dict, rtl_regs,
                   text, width, text_style, markup):
    glyphs = []
    for item in layout_data:
        try:
            index = byte_dict[item[5]]
            txt = text[index]
            if is_item_in_rtl(index, rtl_regs):
                text_range = [index - len(txt) + 1, index + 1]
            else:
                text_range = [index, index + len(txt)]

        except:
            continue

        if txt in NONPRINTING_CHARS:
            glyphs.append(None)
            continue

        ctx.new_path()
        ctx.move_to(0, 0)
        layout = core.create_layout(ctx)
        vpos = core.set_glyph_layout(txt, width, text_style, markup,
                                     text_range, True, layout)
        if vpos:
            for index in range(*text_range):
                x, y, w, h, base_line, byte_index = log_layout_data[index]
                dh = (y - base_line) * vpos
                log_layout_data[index] = (x, y + dh, w, h, base_line + dh,
                                          byte_index)
        core.layout_path(ctx, layout)
        cpath = ctx.copy_path()
        m00 = 1.0
        m11 = -1.0
        if os.name == 'nt':
            m00 *= 0.1
            m11 *= 0.1
        matrix = cairo.Matrix(m00, 0.0, 0.0, m11, item[0], item[1])
        libcairo.apply_cmatrix(cpath, matrix)
        glyphs.append(cpath)
    return glyphs
示例#3
0
文件: __init__.py 项目: Scrik/sk1-wx
def get_rtl_glyphs(ctx, layout_data, byte_dict, text, width, text_style, attributes):
	glyphs = []
	for item in layout_data:
		try:
			txt = text[byte_dict[item[5]]]
		except:continue

		if txt in NONPRINTING_CHARS:
			glyphs.append(None)
			continue

		ctx.new_path()
		ctx.move_to(0, 0)
		layout = _libpango.create_layout(ctx)
		_set_layout(layout, txt, width, text_style, attributes)
		_libpango.layout_path(ctx, layout)
		cpath = ctx.copy_path()
		matrix = cairo.Matrix(1.0, 0.0, 0.0, -1.0, item[0], item[1])
		libcairo.apply_cmatrix(cpath, matrix)
		glyphs.append(cpath)
	return glyphs
示例#4
0
文件: __init__.py 项目: Scrik/sk1-wx
def get_glyphs(ctx, layout_data, text, width, text_style, attributes):
	glyphs = []
	i = -1
	for item in text:
		i += 1

		if item in NONPRINTING_CHARS:
			glyphs.append(None)
			continue

		ctx.new_path()
		ctx.move_to(0, 0)
		layout = _libpango.create_layout(ctx)
		_set_layout(layout, item, width, text_style, attributes)
		_libpango.layout_path(ctx, layout)
		cpath = ctx.copy_path()
		matrix = cairo.Matrix(1.0, 0.0, 0.0, -1.0,
							layout_data[i][0], layout_data[i][1])
		libcairo.apply_cmatrix(cpath, matrix)
		glyphs.append(cpath)
	return glyphs