Example #1
0
    def test_context_properties(self):
        context = Context()

        desc = FontDescription()
        desc.set_family('sans-serif')
        context.set_font_description(desc)
        assert context.get_font_description().get_family() == 'sans-serif'

        context.set_base_gravity(Gravity.EAST)
        assert context.get_base_gravity() == Gravity.EAST
        assert context.get_gravity() == Gravity.EAST

        context.set_gravity_hint(GravityHint.STRONG)
        assert context.get_gravity_hint() == GravityHint.STRONG
Example #2
0
 def test_from_font_desc(self):
     font_desc = FontDescription()
     a = Attribute.from_font_desc(font_desc, 1, 10)
     b = Attribute.from_font_desc(font_desc, 1, 10)
     assert a.start_index == 1
     assert a.end_index == 10
     assert a == b
Example #3
0
def get_text_height(pctx: pangocffi.Context, style: TextStyle,
                    resolution_scale: float):
    font = FontDescription()
    font.set_family(style.font)
    font.set_absolute_size(to_pango_units(style.size))
    ret = pangocffi.pango.pango_context_get_metrics(pctx.get_pointer(),
                                                    font.get_pointer(),
                                                    pangocffi.ffi.NULL)

    descent = from_pango_units(
        pangocffi.pango.pango_font_metrics_get_descent(ret))
    ascent = from_pango_units(
        pangocffi.pango.pango_font_metrics_get_ascent(ret))
    return (ascent + descent) * resolution_scale
Example #4
0
    def test_layout_setting_font_description():
        context = Context()
        layout = Layout(context)

        # Assert that the font description is not set
        assert layout.get_font_description() is None

        # Creating the font description
        desc = FontDescription()
        desc.set_family('sans-serif')
        layout.set_font_description(desc)

        # Verifying the font description was set
        same_desc = layout.get_font_description()
        assert same_desc.get_family() == desc.get_family()

        # Changing the font description
        desc.set_family('serif')
        assert same_desc.get_family() != desc.get_family()

        # Resetting the font description
        layout.set_font_description(None)
        assert layout.get_font_description() is None
Example #5
0
 def test_font_description_init_identical(self):
     desc = FontDescription()
     identical_desc = desc.from_pointer(desc.get_pointer())
     assert identical_desc == desc
Example #6
0
    def test_setting_properties(self):
        desc = FontDescription()

        assert desc.get_family() is None
        desc.set_family('sans-serif')
        assert desc.get_family() == 'sans-serif'

        desc.set_style(Style.NORMAL)
        assert desc.get_style() == Style.NORMAL

        desc.set_variant(Variant.NORMAL)
        assert desc.get_variant() == Variant.NORMAL

        desc.set_weight(700)
        assert desc.get_weight() == 700
        desc.set_weight(Weight.BOOK)
        assert desc.get_weight() == Weight.BOOK.value

        desc.set_stretch(Stretch.NORMAL)
        assert desc.get_stretch() == Stretch.NORMAL

        desc.set_size(123)
        assert desc.get_size() == 123
        assert not desc.get_size_is_absolute()

        desc.set_absolute_size(1.23)
        assert desc.get_size() != 123
        assert desc.get_size_is_absolute()

        desc.set_gravity(Gravity.EAST)
        assert desc.get_gravity() == Gravity.EAST
Example #7
0
 def test_font_description_returns_null_from_null_pointer(self):
     with self.assertRaises(ValueError):
         FontDescription.from_pointer(ffi.NULL)
Example #8
0
 def test_font_description_not_implemented_equality(self):
     desc = FontDescription()
     assert ('not an object' != desc)