def _compute_best_text_path(self): text_path_a = TextPath(self._input_line_string, self._layout) text_path_a.side = self._side text_path_a.alignment = self._alignment text_path_a.start_offset = self._start_offset text_path_a.vertical_offset = self._vertical_offset text_path_a.layout_engine_class = self._layout_engine_class text_path_b = TextPath(self._input_line_string, self._layout) text_path_b.side = self._side.flipped text_path_b.alignment = self._alignment text_path_b.start_offset = self._start_offset text_path_b.vertical_offset = self._vertical_offset text_path_b.layout_engine_class = self._layout_engine_class baseline_a = text_path_a.compute_baseline() baseline_b = text_path_b.compute_baseline() ltr_length_a = line_string_helper.left_to_right_length(baseline_a) ltr_length_b = line_string_helper.left_to_right_length(baseline_b) if ltr_length_a > ltr_length_b: self._text_path = text_path_a else: self._text_path = text_path_b
def test_compute_baseline(self): surface, cairo_context = self._create_real_surface( 'compute_baseline.svg' ) layout = pangocairocffi.create_layout(cairo_context) layout.set_markup('<span font="8">Hi from Παν語</span>') line_string = LineString([[0, 10], [50, 20], [100, 10]]) text_path = TextPath(line_string, layout) text_path.alignment = Alignment.CENTER text_path.draw(cairo_context) baseline = text_path.compute_baseline() debug.draw_line_string(cairo_context, baseline) cairo_context.stroke() assert isinstance(baseline, LineString) assert baseline.length > 0 assert baseline.length < line_string.length surface.finish()