def test_layout_setting_text(self): layout = Layout(self.pango_context) layout.set_text('Hi from Παν語') assert layout.get_text() == 'Hi from Παν語' layout.set_markup('<span font="italic 30">Hello from Παν語</span>') assert layout.get_text() == 'Hello from Παν語'
def render_cluster_glyph_items( ctx: cairocffi.Context, layout: pangocffi.Layout ): """ Renders each cluster within a layout with a unique rotation and color. Warning: Does not support bidirectional text. :param ctx: a Cairo context :param layout: a Pango layout """ layout_run_iter = layout.get_iter() layout_cluster_iter = layout.get_iter() layout_text = layout.get_text() alternate = False while True: layout_run = layout_run_iter.get_run() layout_line_baseline = layout_run_iter.get_baseline() if layout_run is None: if not layout_run_iter.next_run(): break continue clusters = get_clusters_from_glyph_item(layout_run, layout_text) for cluster in clusters: cluster_extents = layout_cluster_iter.get_cluster_extents()[1] layout_cluster_iter.next_cluster() alternate = not alternate ctx.set_source_rgba(0.5, 0, 1 if alternate else 0.5, 0.9) ctx.save() ctx.translate( pangocffi.units_to_double(cluster_extents.x), pangocffi.units_to_double(layout_line_baseline) ) ctx.rotate(-0.05 if alternate else 0.05) pangocairocffi.show_glyph_item( ctx, layout_text, cluster ) ctx.restore() if not layout_run_iter.next_run(): break
def __init__(self, line_string: LineString, layout: Layout): if layout.get_line_count() > 1: raise ValueError('layout cannot be more than one line.') self._layout = layout self._input_line_string = line_string self._layout_text = layout.get_text() self._alignment = Alignment.LEFT self._start_offset = 0 self._vertical_offset = 0 self._side = Side.LEFT self._layout_clusters = LayoutClusters(self._layout) self._layout_engine_class = SvgLayoutEngine self._layout_engine = None
def render_run_glyph_items( ctx: cairocffi.Context, layout: pangocffi.Layout ) -> None: """ Renders each layout run within a layout with a unique rotation and color. :param ctx: a Cairo context :param layout: a Pango layout """ layout_iter = layout.get_iter() layout_text = layout.get_text() alternate = False while True: layout_run = layout_iter.get_run() layout_run_extents = layout_iter.get_run_extents()[1] layout_line_baseline = layout_iter.get_baseline() if layout_run is None: if not layout_iter.next_run(): break continue alternate = not alternate ctx.set_source_rgba(0, 0.5, 1 if alternate else 0.5, 0.9) ctx.save() ctx.translate( pangocffi.units_to_double(layout_run_extents.x), pangocffi.units_to_double(layout_line_baseline) ) ctx.rotate(0.05 if alternate else -0.05) pangocairocffi.show_glyph_item(ctx, layout_text, layout_run) ctx.restore() if not layout_iter.next_run(): break