Esempio n. 1
0
    def test_glyph_item_iterator(self):
        text = 'Hi from Παν語'
        layout = Layout(self.pango_context)
        layout.set_text(text)
        layout_iter = layout.get_iter()

        glyph_item_iter = GlyphItemIter()
        assert isinstance(glyph_item_iter.get_pointer(), ffi.CData)

        assert glyph_item_iter.init_start(
            layout_iter.get_run(),
            text
        )

        assert isinstance(glyph_item_iter.glyph_item, GlyphItem)
        assert glyph_item_iter.text == text

        # Verify first cluster
        assert glyph_item_iter.start_glyph == 0
        assert glyph_item_iter.start_index == 0
        assert glyph_item_iter.start_char == 0
        assert glyph_item_iter.end_glyph == 1
        assert glyph_item_iter.end_index == 1
        assert glyph_item_iter.end_char == 1

        assert not glyph_item_iter.prev_cluster()
        assert glyph_item_iter.next_cluster()

        # Verify second cluster
        assert glyph_item_iter.start_glyph == 1
        assert glyph_item_iter.start_index == 1
        assert glyph_item_iter.start_char == 1
        assert glyph_item_iter.end_glyph == 2
        assert glyph_item_iter.end_index == 2
        assert glyph_item_iter.end_char == 2

        assert glyph_item_iter.init_end(
            layout_iter.get_run(),
            text
        )

        # Verify last cluster
        assert glyph_item_iter.start_glyph == 7
        assert glyph_item_iter.start_index == 7
        assert glyph_item_iter.start_char == 7
        assert glyph_item_iter.end_glyph == 8
        assert glyph_item_iter.end_index == 8
        assert glyph_item_iter.end_char == 8

        assert not glyph_item_iter.next_cluster()
        assert glyph_item_iter.prev_cluster()

        # Verify second to last cluster
        assert glyph_item_iter.start_glyph == 6
        assert glyph_item_iter.start_index == 6
        assert glyph_item_iter.start_char == 6
        assert glyph_item_iter.end_glyph == 7
        assert glyph_item_iter.end_index == 7
        assert glyph_item_iter.end_char == 7
    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 Παν語'
Esempio n. 3
0
    def test_layout_setting_text():
        context = Context()
        layout = Layout(context)

        layout.set_width(300)

        layout.set_text('Hi from Pango')
        layout.set_markup('<span font="italic 30">Hi from Παν語</span>')
    def test_glyph_item_copies(self):
        text = 'Hi from Παν語'
        layout = Layout(self.pango_context)
        layout.set_text(text)
        layout_iter = layout.get_iter()
        layout_run = layout_iter.get_run()

        assert layout_run.copy().get_pointer() != layout_run.get_pointer()
    def test_layout_run_properties(self):
        layout = Layout(self.pango_context)
        layout.set_text('Hello World')
        layout_iter = layout.get_iter()

        layout_run = layout_iter.get_run()
        layout_run_item = layout_run.item
        assert isinstance(layout_run_item, Item)
    def test_layout_run_from_pointer(self):
        layout = Layout(self.pango_context)
        layout.set_text('Hello World')
        layout_iter = layout.get_iter()

        layout_run = layout_iter.get_run()
        same_layout = LayoutRun.from_pointer(layout_run.get_pointer())

        assert isinstance(same_layout, LayoutRun)
    def test_glyph_item_get_logical_widths(self):
        text = 'Hi from Παν語'
        layout = Layout(self.pango_context)
        layout.set_text(text)
        layout_iter = layout.get_iter()
        layout_run = layout_iter.get_run()
        logical_widths = layout_run.get_logical_widths(text)

        assert len(logical_widths) == 8
        assert isinstance(logical_widths[0], int)
    def test_glyph_item_splits(self):
        text = 'Hi from Παν語'
        layout = Layout(self.pango_context)
        layout.set_text(text)
        layout_iter = layout.get_iter()
        layout_run = layout_iter.get_run()
        layout_run_hi = layout_run.split(text, 3)

        # Substring "Hi "
        assert layout_run_hi.item.num_chars == 3
        assert layout_run_hi.item.offset == 0

        # Substring "from "
        assert layout_run.item.num_chars == 5
        assert layout_run.item.offset == 3
Esempio n. 9
0
    def test_set_attributes(self):
        context = Context()
        layout = Layout(context)
        layout.set_text("Working?")
        attr = Attribute.from_size(5, 1, 4)
        attr_list = AttrList()

        attr_list.insert(attr)

        layout.set_attributes(attr_list)
        layout.get_attributes()

        # Resetting the attributes
        layout.set_attributes(None)
        layout.get_attributes()
    def test_item_properties(self):
        layout = Layout(self.pango_context)
        layout.set_text('Hi from Παν語')
        layout_iter = layout.get_iter()

        layout_run = layout_iter.get_run()
        layout_run_item = layout_run.item

        assert layout_run_item.length == 8
        assert layout_run_item.offset == 0
        assert layout_run_item.num_chars == 8
        assert isinstance(layout_run_item.get_pointer(), ffi.CData)

        assert layout_iter.next_run()
        layout_run = layout_iter.get_run()
        layout_run_item = layout_run.item

        assert layout_run_item.length == 6
        assert layout_run_item.offset == 8
        assert layout_run_item.num_chars == 3
        assert isinstance(layout_run_item.get_pointer(), ffi.CData)