def render_sample(ctx, text, family, fontsize): ctx.new_path() ctx.move_to(0, 0) layout = _libpango.create_layout(ctx) _set_sample_layout(layout, text, family, fontsize) _libpango.layout_path(ctx, layout) #---Font sampling end
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
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
def create_layout(ctx=CTX): return _libpango.create_layout(ctx)
import os import cairo from copy import deepcopy from markup import apply_markup, apply_glyph_markup import _libpango PANGO_UNITS = 1024 SURFACE = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1) CTX = cairo.Context(SURFACE) DIRECT_MATRIX = cairo.Matrix() PANGO_MATRIX = cairo.Matrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0) PANGO_LAYOUT = _libpango.create_layout(CTX) NONPRINTING_CHARS = ' \n\t '.decode('utf-8') def get_version(): return _libpango.get_version() # --- Glyph caching GLYPH_CACHE = {} def get_glyph_cache(font_name, char): ret = None char = str(char)
def render_sample(ctx, text, family, fontsize): ctx.new_path() ctx.move_to(0, 0) layout = _libpango.create_layout(ctx) _set_sample_layout(layout, text, family, fontsize) _libpango.layout_path(ctx, layout)