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 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 getLayoutExtent(layout: pango.Layout) -> Tuple[float, float, float, float]: e = layout.get_extents() return (pango.units_to_double(e[1].x), pango.units_to_double(e[1].y), pango.units_to_double(e[1].width), pango.units_to_double(e[1].height))
def get_extents(layout: pangocffi.Layout, ink=True) -> Rect: rect_logical, rect_ink = layout.get_extents() return from_pango_rect(rect_ink if ink else rect_logical)