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_vertical_offset_works(self): surface, cairo_context = self._create_real_surface( 'vertical_offset_works.svg' ) layout = pangocairocffi.create_layout(cairo_context) layout.set_markup('Hi from Παν語') line_string = LineString([[5, 40], [45, 40], [90, 80]]) for vertical_offset in [-13, 0, 13]: offset_linestring, _ = parallel_offset_with_matching_direction( line_string, vertical_offset, side=Side.LEFT ) debug.draw_line_string(cairo_context, offset_linestring) red = max(0.0, vertical_offset / 13) green = max(0.0, -vertical_offset / 13) cairo_context.set_source_rgba(red, green, 0, 0.2) cairo_context.stroke() text_path = TextPath(line_string, layout) text_path.vertical_offset = vertical_offset cairo_context.set_source_rgb(red, green, 0) text_path.draw(cairo_context) surface.finish()
def test_vertical_offset_fails_on_invalid_offset_shape(self): surface, cairo_context = self._create_void_surface() layout = pangocairocffi.create_layout(cairo_context) layout.set_markup('Hi from Παν語') line_string = LineString([[0, 0], [40, 0], [40, 40], [0, 40], [0, 0]]) text_path = TextPath(line_string, layout) text_path.vertical_offset = -10 with self.assertRaises(RuntimeError): text_path.draw(cairo_context)
def test_setters_getters(self): surface, cairo_context = self._create_void_surface() layout = pangocairocffi.create_layout(cairo_context) layout.set_markup('Hi from Παν語') line_string = LineString([[0, 0], [600, 0]]) text_path = TextPath(line_string, layout) assert isinstance(text_path.side, Side) assert isinstance(text_path.alignment, Alignment) assert isinstance(text_path.start_offset, float) assert isinstance(text_path.vertical_offset, float) text_path.side = Side.RIGHT text_path.alignment = Alignment.RIGHT text_path.start_offset = 12 text_path.vertical_offset = 34 assert isinstance(text_path.side, Side) assert isinstance(text_path.alignment, Alignment) assert isinstance(text_path.start_offset, float) assert isinstance(text_path.vertical_offset, float) text_path.layout_engine_class = Svg