def test_layout_setting_properties(): context = Context() layout = Layout(context) layout.set_width(300) assert layout.get_width() == 300 layout.set_height(400) assert layout.get_height() == 400 assert layout.get_spacing() == 0 layout.set_spacing(30) assert layout.get_spacing() == 30 layout.set_alignment(Alignment.CENTER) assert layout.get_alignment() is Alignment.CENTER layout.set_ellipsize(EllipsizeMode.MIDDLE) assert layout.get_ellipsize() is EllipsizeMode.MIDDLE ink_rect, logical_rect = layout.get_extents() assert logical_rect.width == 0 assert logical_rect.height == 0 width, height = layout.get_size() assert width == 0 assert height == 0 baseline = layout.get_baseline() assert baseline == 0 line_count = layout.get_line_count() assert line_count == 1
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 test_layout_setting_properties(self): layout = Layout(self.pango_context) layout.set_width(300) assert layout.get_width() == 300 layout.set_height(400) assert layout.get_height() == 400 assert layout.get_spacing() == 0 layout.set_spacing(30) assert layout.get_spacing() == 30 layout.set_alignment(Alignment.CENTER) assert layout.get_alignment() is Alignment.CENTER layout.set_ellipsize(EllipsizeMode.MIDDLE) assert layout.get_ellipsize() is EllipsizeMode.MIDDLE layout.set_wrap(WrapMode.WORD_CHAR) assert layout.get_wrap() is WrapMode.WORD_CHAR ink_rect, logical_rect = layout.get_extents() assert logical_rect.width == 0 # The height of the layout will be the height of the font, despite no # text being set against the layout. assert logical_rect.height > 0 width, height = layout.get_size() assert width == 0 # The height of the layout will be the height of the font, despite no # text being set against the layout. assert height > 0 baseline = layout.get_baseline() # The baseline of the layout will correspond to the selected font, # despite no text being set against the layout. assert baseline > 0 line_count = layout.get_line_count() assert line_count == 1
def compute_subtext_extents(layout: Layout, parsed_text, id_index: int) -> Tuple[float, float]: """ Returns the x coordinate and width of a subtext of a single line. """ assert layout.get_line_count() == 1 (start, end) = get_byte_range(parsed_text, id_index) iter = layout.get_iter() x = None width = 0 while True: byte_offset = iter.get_index() if start <= byte_offset < end: extents = from_pango_rect(iter.get_char_extents()) if x is None: assert start == byte_offset x = extents.x width += extents.width if byte_offset >= end or not iter.next_char(): break assert x is not None return (x, width)