Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pangocffi v0.11.0 + Use property() for setting resolution #29

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pangocairocffi/create_update_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def update_context(
cairo_t_pointer = _get_cairo_t_from_cairo_ctx(cairo_context)
pangocairo.pango_cairo_update_context(
cairo_t_pointer,
pango_context.get_pointer()
pango_context.pointer
)


Expand Down Expand Up @@ -86,4 +86,4 @@ def update_layout(
a Pango layout
"""
cairo_t_pointer = _get_cairo_t_from_cairo_ctx(cairo_context)
pangocairo.pango_cairo_update_layout(cairo_t_pointer, layout.get_pointer())
pangocairo.pango_cairo_update_layout(cairo_t_pointer, layout.pointer)
8 changes: 4 additions & 4 deletions pangocairocffi/font_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def set_resolution(context: Context, dpi: float) -> None:
involved; the terminology is conventional.) A 0 or negative value
means to use the resolution from the font map.
"""
pangocairo.pango_cairo_context_set_resolution(context.get_pointer(), dpi)
pangocairo.pango_cairo_context_set_resolution(context.pointer, dpi)


def get_resolution(context: Context) -> float:
Expand All @@ -45,7 +45,7 @@ def get_resolution(context: Context) -> float:
the resolution in "dots per inch". A negative value will be returned
if no resolution has previously been set.
"""
return pangocairo.pango_cairo_context_get_resolution(context.get_pointer())
return pangocairo.pango_cairo_context_get_resolution(context.pointer)


def set_font_options(
Expand All @@ -65,7 +65,7 @@ def set_font_options(
"""
if options is None:
options = ffi.NULL
context_pointer = context.get_pointer()
context_pointer = context.pointer
pangocairo.pango_cairo_context_set_font_options(context_pointer, options)


Expand All @@ -82,7 +82,7 @@ def get_font_options(context: Context) -> Optional[ffi.CData]:
a cairo_font_options_t pointer previously set on the context,
otherwise ``None``.
"""
context_pointer = context.get_pointer()
context_pointer = context.pointer
font_option_pointer = pangocairo.pango_cairo_context_get_font_options(
context_pointer
)
Expand Down
44 changes: 19 additions & 25 deletions pangocairocffi/font_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def _init_pointer(self, pointer: ffi.CData):
pointer = ffi.cast('PangoCairoFontMap *', pointer)
self._pointer = pointer

def get_pointer(self) -> ffi.CData:
@property
def pointer(self) -> ffi.CData:
"""
Returns the pointer to the font map

Expand Down Expand Up @@ -122,7 +123,7 @@ def set_default(
"""
fontmap_pointer = ffi.NULL
if fontmap is not None:
fontmap_pointer = fontmap.get_pointer()
fontmap_pointer = fontmap.pointer
pangocairo.pango_cairo_font_map_set_default(fontmap_pointer)

@classmethod
Expand All @@ -143,7 +144,7 @@ def from_cairo_font_type(

def __eq__(self, other):
if isinstance(other, PangoCairoFontMap):
return self.get_pointer() == other.get_pointer()
return self.pointer == other.pointer
return NotImplemented

def get_cairo_font_type_pointer(self) -> ffi.CData:
Expand All @@ -155,33 +156,26 @@ def get_cairo_font_type_pointer(self) -> ffi.CData:
the pointer to the ``cairo_font_type_t``.
"""
return pangocairo.pango_cairo_font_map_get_font_type(
self.get_pointer()
self.pointer
)

def set_resolution(self, dpi: float) -> None:
"""
Sets the resolution for the ``fontmap``. This is a scale factor between
points specified in a Pango FontDescription and Cairo units. The
default value is 96, meaning that a 10 point font will be 13
units high. (10 * 96. / 72. = 13.3).

:param dpi:
the resolution in "dots per inch". (Physical inches aren't
actually involved; the terminology is conventional.)
"""
pangocairo.pango_cairo_font_map_set_resolution(self.get_pointer(), dpi)

def get_resolution(self) -> float:
"""
Returns the resolution for the ``fontmap``.
def _set_resolution(self, dpi: float) -> None:
pangocairo.pango_cairo_font_map_set_resolution(self.pointer, dpi)

:return:
the resolution in "dots per inch"
"""
def _get_resolution(self) -> float:
return pangocairo.pango_cairo_font_map_get_resolution(
self.get_pointer()
self.pointer
)

resolution: float = property(_get_resolution, _set_resolution)
"""
The resolution for the ``fontmap`` in "dots per inch". This is a scale
factor between points specified in a Pango FontDescription and Cairo units.
The default value is 96, meaning that a 10 point font will be 13 units
high. (10 * 96. / 72. = 13.3). (Physical inches aren't actually involved;
the terminology is conventional.)
"""

def create_context(self) -> Context:
"""
Creates a Pango ``Context`` connected to ``fontmap``. This is
Expand All @@ -192,6 +186,6 @@ def create_context(self) -> Context:
the newly allocated Pango ``Context``.
"""
context_pointer = pango.pango_font_map_create_context(
self.get_pointer()
self.pointer
)
return Context.from_pointer(context_pointer, gc=True)
6 changes: 3 additions & 3 deletions pangocairocffi/render_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def show_glyph_item(
pangocairo.pango_cairo_show_glyph_item(
cairo_context_pointer,
text_pointer,
glyph_item.get_pointer()
glyph_item.pointer
)


Expand Down Expand Up @@ -102,7 +102,7 @@ def show_layout(
cairo_context_pointer = _get_cairo_t_from_cairo_ctx(cairo_context)
pangocairo.pango_cairo_show_layout(
cairo_context_pointer,
layout.get_pointer()
layout.pointer
)


Expand Down Expand Up @@ -206,7 +206,7 @@ def layout_path(
cairo_context_pointer = _get_cairo_t_from_cairo_ctx(cairo_context)
pangocairo.pango_cairo_layout_path(
cairo_context_pointer,
layout.get_pointer()
layout.pointer
)


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cffi >= 1.1.0
cairocffi >= 1.0.2
pangocffi >= 0.8.0
pangocffi >= 0.11.0
flake8
coverage
pytest
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ setup_requires =
install_requires =
cffi >= 1.1.0
cairocffi >= 1.0.2
pangocffi >= 0.10.0
pangocffi >= 0.11.0
python_requires = >= 3.6

[options.package_data]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def test_pdf():
context.rotate(-0.1)

layout = pangocairocffi.create_layout(context)
layout.set_width(pangocffi.units_from_double(width))
layout.set_alignment(pangocffi.Alignment.CENTER)
layout.set_markup('<span font="italic 30">Hi from Παν語</span>')
layout.width = pangocffi.units_from_double(width)
layout.alignment = pangocffi.Alignment.CENTER
layout.apply_markup('<span font="italic 30">Hi from Παν語</span>')

pangocairocffi.show_layout(context, layout)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_error_underline.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def test_pdf():
ctx = cairocffi.Context(surface)

layout = pangocairocffi.create_layout(ctx)
layout.set_width(pangocffi.units_from_double(width))
layout.set_alignment(pangocffi.Alignment.CENTER)
layout.set_markup('Hi from Παν語')
layout.width = pangocffi.units_from_double(width)
layout.alignment = pangocffi.Alignment.CENTER
layout.apply_markup('Hi from Παν語')

layout_logical_extent = layout.get_extents()[1]
layout_baseline = pangocffi.units_to_double(layout.get_baseline())
Expand Down
16 changes: 8 additions & 8 deletions tests/test_extents.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ def _show_label(
):
context.translate(position[0], position[1])
label = pangocairocffi.create_layout(context)
label.set_width(pangocffi.units_from_double(width))
label.set_alignment(pangocffi.Alignment.LEFT)
label.set_markup('<span font-family="sans-serif">%s</span>' % text)
label.width = pangocffi.units_from_double(width)
label.alignment = pangocffi.Alignment.LEFT
label.apply_markup('<span font-family="sans-serif">%s</span>' % text)
pangocairocffi.show_layout(context, label)
context.translate(-position[0], -position[1])

Expand All @@ -359,11 +359,11 @@ def test_pdf():
ctx.translate(width / 2, 10)

layout = pangocairocffi.create_layout(ctx)
layout.set_width(pangocffi.units_from_double(width / 2))
layout.set_alignment(pangocffi.Alignment.CENTER)
layout.set_markup('<span font="italic 30">Hi from Παν語</span>\n'
'The text layout engine library for displaying '
'<span font-weight="bold">multi-language</span> text!')
layout.width = pangocffi.units_from_double(width / 2)
layout.alignment = pangocffi.Alignment.CENTER
layout.apply_markup('<span font="italic 30">Hi from Παν語</span>\n'
'The text layout engine library for displaying '
'<span font-weight="bold">multi-language</span> text!')

translate_y = 110
label_pos = (-width / 2 + 30, 30)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_font_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ def test_font_map():
font_map_new = PangoCairoFontMap()
assert font_map_new != font_map_default

resolution = font_map_new.get_resolution()
resolution = font_map_new.resolution
assert resolution == 96
font_map_new.set_resolution(123)
assert font_map_new.get_resolution() == 123
font_map_new.resolution = 123
assert font_map_new.resolution == 123

PangoCairoFontMap.set_default(font_map_new)
assert font_map_new == PangoCairoFontMap.get_default()
Expand Down
10 changes: 5 additions & 5 deletions tests/test_glyph_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def render_run_glyph_items(
a Pango layout
"""
layout_iter = layout.get_iter()
layout_text = layout.get_text()
layout_text = layout.text

alternate = False
while True:
Expand Down Expand Up @@ -119,7 +119,7 @@ def render_cluster_glyph_items(
"""
layout_run_iter = layout.get_iter()
layout_cluster_iter = layout.get_iter()
layout_text = layout.get_text()
layout_text = layout.text

alternate = False
while True:
Expand Down Expand Up @@ -164,9 +164,9 @@ def test_pdf():
ctx.translate(width / 4, 100)

layout = pangocairocffi.create_layout(ctx)
layout.set_width(pangocffi.units_from_double(width / 2))
layout.set_alignment(pangocffi.Alignment.CENTER)
layout.set_markup(
layout.width = pangocffi.units_from_double(width / 2)
layout.alignment = pangocffi.Alignment.CENTER
layout.apply_markup(
'<span font="italic 30">Hi from Παν語</span>\n'
'<span font="sans-serif">The text layout engine library for '
'displaying <span font-weight="bold">multi-language</span> text!\n'
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py36, py37, py38, py39
envlist = py36, py37, py38, py39, py310

[gh-actions]
python =
Expand Down