def get_text_paths(orig_text, width, text_style, attributes): if not orig_text: orig_text = NONPRINTING_CHARS[0] _set_layout(PANGO_LAYOUT, orig_text, width, text_style, attributes) w, h = _libpango.get_layout_pixel_size(PANGO_LAYOUT) surf = cairo.ImageSurface(cairo.FORMAT_RGB24, 100, 100) ctx = cairo.Context(surf) ctx.set_matrix(libcairo.DIRECT_MATRIX) line_points = [] for item in get_line_positions(): line_points.append([0.0, item]) text = '' + orig_text clusters = [] rtl_regs = [] rtl_flag = False #Ligature support if text_style[5]: data = get_cluster_positions() layout_data, clusters, clusters_index, bidi_flag, rtl_flag = data if not rtl_flag and not bidi_flag: if clusters: text = cluster_text(text, clusters) if check_manyamar(orig_text): word_group(text) log_layout_data = layout_data glyphs = get_glyphs(ctx, layout_data, text, width, text_style, attributes) else: byte_dict = utf8_to_ucs4_dict(text) clusters = fix_rlt_clusters(clusters_index, byte_dict) text = cluster_text(text, clusters) byte_dict = utf8_to_ucs4_dict(text) rtl_regs = find_rtl_regs(layout_data) log_rtl_regs = fix_rlt_regs(rtl_regs, layout_data, byte_dict) for item in log_rtl_regs: if check_arabic(text[item[0]:item[1]]): rtl_word_group_in_reg(text, item) glyphs = get_rtl_glyphs(ctx, layout_data, byte_dict, text, width, text_style, attributes) log_layout_data = get_log_layout_data(layout_data, byte_dict, rtl_regs) #Simple char-by-char rendering else: layout_data = get_char_positions() log_layout_data = layout_data glyphs = get_glyphs(ctx, layout_data, text, width, text_style, attributes) layout_bbox = [0.0, layout_data[0][1], float(w), layout_data[0][1] - float(h)] return glyphs, line_points, log_layout_data, layout_bbox, clusters
def get_sample_size(text, family, fontsize): _set_sample_layout(PANGO_LAYOUT, text, family, fontsize) return _libpango.get_layout_pixel_size(PANGO_LAYOUT)
def get_layout_size(layout=PANGO_LAYOUT): return _libpango.get_layout_pixel_size(layout)
def get_layout_bbox(): w, h = _libpango.get_layout_pixel_size(PANGO_LAYOUT) return [0.0, 0.0, float(w), float(-h)]