Skip to content

Commit

Permalink
Merge pull request #71 from leifgehrmann/upgrade-pangocffi
Browse files Browse the repository at this point in the history
Upgrade pangocffi
  • Loading branch information
leifgehrmann authored Jul 1, 2024
2 parents 050a922 + 68b198d commit 9316037
Show file tree
Hide file tree
Showing 17 changed files with 688 additions and 378 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.9]
python-version: [3.11]
poetry-version: [1.4.2]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -33,6 +33,11 @@ jobs:
brew install cairo
brew install pango
brew install gdal
# https://github.com/Kozea/CairoSVG/issues/354#issuecomment-1160552256
sudo ln -s /opt/homebrew/lib/libcairo* .
sudo ln -s /opt/homebrew/lib/libpango* .
sudo ln -s /opt/homebrew/lib/libgobject* .
sudo ln -s /opt/homebrew/lib/libglib* .
- name: Install System Dependencies (ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ on:
pull_request:

jobs:
build:
pytest:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: [3.11]
poetry-version: [1.4.2]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -39,7 +39,7 @@ jobs:
run: |
poetry run pytest --cov --cov-report xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
8 changes: 8 additions & 0 deletions map_engraver/canvas/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ def __init__(
width,
height
)
# In version 1.5 the document units are no longer easy to read via
# regular expressions. 1.4 uses the old format that has 'MediaBox'
# in the PDF output.
surface.restrict_to_version(cairo.PDF_VERSION_1_4)
elif surface_type == 'svg':
surface = cairo.SVGSurface(
self.path_as_posix,
width,
height
)
# In cairo-1.17.8 the default document unit was changed to
# cairo.SVG_UNIT_USER, which can be ambiguous. Here we reset it
# back to cairo.SVG_UNIT_PT like older versions of cairo.
surface.set_document_unit(cairo.SVG_UNIT_PT)
elif surface_type == 'png':
surface = cairo.ImageSurface(
cairo.FORMAT_ARGB32,
Expand Down
431 changes: 226 additions & 205 deletions poetry.lock

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@ license = "LGPL-3.0-only"

[tool.poetry.dependencies]
python = "^3.9"
cairocffi = "^1.4.0"
tqdm = "^4.64.0"
cairocffi = "^1.7.1"
Shapely = "^2.0.1"
CairoSVG = "^2.7.0"
pyproj = "^3.4.0"
Pillow = "^10.0.1"
pangocffi = "^0.11.0"
pyproj = "^3.6.1"
Pillow = "^10.3.0"
pangocffi = "^0.13.0"
pangocairocffi = "^0.7.0"

[tool.poetry.group.gdal]
optional = true

[tool.poetry.group.gdal.dependencies]
# We need to lock ourselves to 3.4.3 as that is the version that is supported
# by GitHub Action Ubuntu environments. See .github/workflows/build.yml
GDAL = "3.4.3"
[tool.poetry.group.gdal.dependencies]
gdal = "3.8.4"

[tool.poetry.dev-dependencies]
flake8 = "^6.1.0"
pytest = "^7.4.2"
coverage = "^7.3.1"
pytest-cov = "^4.1.0"
[tool.poetry.group.dev.dependencies]
flake8 = "^7.1.0"
pytest = "^8.2.2"
coverage = "^7.5.4"
pytest-cov = "^5.0.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
23 changes: 15 additions & 8 deletions tests/data/geotiff/test_canvas_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from map_engraver.drawable.geometry.polygon_drawer import PolygonDrawer
from map_engraver.drawable.images.bitmap import Bitmap
from tests.utils import svg_has_style_attr


class TestCanvasTransform(unittest.TestCase):
Expand Down Expand Up @@ -56,7 +57,7 @@ def test_transform_geotiff_to_crs_within_canvas_invalid(self):

with self.assertRaisesRegex(
RuntimeError,
'not recognized as a supported file format.'
'not recognized as( being in)? a supported file format.'
):
transform_geotiff_to_crs_within_canvas(
input_file, canvas_mask, builder, output_file
Expand Down Expand Up @@ -204,15 +205,21 @@ def test_build_geotiff_crs_within_canvas_matrix(self):

with open(canvas_file, 'r') as file:
data = file.read()
assert data.find(

assert svg_has_style_attr(
data, 'path', 'd',
'M -0.000432709 -0.000179234 '
'L 26.999834 0.000401775 '
'L 26.999823 31.499943 '
'L 0.0000793665 31.500624 Z '
'M -0.000432709 -0.000179234'
) != -1
assert data.find(
'matrix('
'1.094261,-2.64178,2.64178,1.094261,18.938447,82.311553'
')'
) != -1
)

assert svg_has_style_attr(
data, 'path', 'transform',
'matrix\\('
'1.094261, ?-2.64178, ?2.64178, ?'
'1.094261, ?18.938447, ?82.311553'
'\\)',
escape=False
)
30 changes: 21 additions & 9 deletions tests/drawable/geometry/test_line_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from map_engraver.canvas import CanvasBuilder
from map_engraver.canvas.canvas_unit import CanvasUnit as Cu
from map_engraver.drawable.geometry.line_drawer import LineDrawer
from tests.utils import svg_has_style_attr


class TestLineDrawer(unittest.TestCase):
Expand Down Expand Up @@ -50,10 +51,15 @@ def test_line_string(self):

with open(path, 'r') as file:
data = file.read()
assert data.find('M 30 30 L 70 30 L 70 70 L 30 70') != -1
assert data.find('fill:none') != -1
assert data.find('stroke-width:1.5') != -1
assert data.find('stroke:rgb(0%,100%,0%);') != -1
assert svg_has_style_attr(
data, 'path', 'd', 'M 30 30 L 70 30 L 70 70 L 30 70'
)
assert svg_has_style_attr(data, 'path', 'fill', 'none')
assert svg_has_style_attr(data, 'path', 'fill', 'none')
assert svg_has_style_attr(data, 'path', 'stroke-width', '1.5')
assert svg_has_style_attr(
data, 'path', 'stroke', 'rgb\\(0%, ?100%, ?0%\\)', escape=False
)

def test_multi_line_string(self):
path = Path(__file__).parent.joinpath(
Expand Down Expand Up @@ -90,8 +96,14 @@ def test_multi_line_string(self):

with open(path, 'r') as file:
data = file.read()
assert data.find('M 30 30 L 70 30 L 70 70 L 30 70') != -1
assert data.find('M 40 40 L 40 60 L 60 60 L 60 40') != -1
assert data.find('fill:none') != -1
assert data.find('stroke-width:1.5') != -1
assert data.find('stroke:rgb(100%,0%,0%);') != -1
assert svg_has_style_attr(
data, 'path', 'd', 'M 30 30 L 70 30 L 70 70 L 30 70'
)
assert svg_has_style_attr(
data, 'path', 'd', 'M 40 40 L 40 60 L 60 60 L 60 40'
)
assert svg_has_style_attr(data, 'path', 'fill', 'none')
assert svg_has_style_attr(data, 'path', 'stroke-width', '1.5')
assert svg_has_style_attr(
data, 'path', 'stroke', 'rgb\\(100%, ?0%, ?0%\\)', escape=False
)
55 changes: 38 additions & 17 deletions tests/drawable/geometry/test_polygon_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from map_engraver.canvas import CanvasBuilder
from map_engraver.canvas.canvas_unit import CanvasUnit as Cu
from map_engraver.drawable.geometry.polygon_drawer import PolygonDrawer
from tests.utils import svg_has_style_attr


class TestPolygonDrawer(unittest.TestCase):
Expand Down Expand Up @@ -43,10 +44,14 @@ def test_only_fill(self):

with open(path, 'r') as file:
data = file.read()
assert data.find('M 30 30 L 70 30 L 70 70 L 30 70 Z M 30 30') != -1
assert data.find('fill:rgb(0%,100%,0%)') != -1
assert data.find('stroke:none') != -1
assert data.find('stroke-width:') == -1
assert svg_has_style_attr(
data, 'path', 'd', 'M 30 30 L 70 30 L 70 70 L 30 70 Z M 30 30'
)
assert svg_has_style_attr(
data, 'path', 'fill', 'rgb\\(0%, ?100%, ?0%\\)', escape=False
)
assert not svg_has_style_attr(data, 'path', 'stroke')
assert not svg_has_style_attr(data, 'path', 'stroke-width')

def test_only_stroke(self):
path = Path(__file__).parent.joinpath(
Expand Down Expand Up @@ -79,10 +84,14 @@ def test_only_stroke(self):

with open(path, 'r') as file:
data = file.read()
assert data.find('M 30 30 L 70 30 L 70 70 L 30 70 Z M 30 30') != -1
assert data.find('fill:none') != -1
assert data.find('stroke-width:1.5') != -1
assert data.find('stroke:rgb(0%,100%,0%);') != -1
assert svg_has_style_attr(
data, 'path', 'd', 'M 30 30 L 70 30 L 70 70 L 30 70 Z M 30 30'
)
assert svg_has_style_attr(data, 'path', 'fill', 'none')
assert svg_has_style_attr(data, 'path', 'stroke-width', '1.5')
assert svg_has_style_attr(
data, 'path', 'stroke', 'rgb\\(0%, ?100%, ?0%\\)', escape=False
)

def test_fill_preserve(self):
path = Path(__file__).parent.joinpath(
Expand Down Expand Up @@ -116,10 +125,16 @@ def test_fill_preserve(self):

with open(path, 'r') as file:
data = file.read()
assert data.find('M 30 30 L 70 30 L 70 70 L 30 70 Z M 30 30') != -1
assert data.find('fill:rgb(100%,0%,0%)') != -1
assert data.find('stroke-width:2') != -1
assert data.find('stroke:rgb(0%,100%,0%);') != -1
assert svg_has_style_attr(
data, 'path', 'd', 'M 30 30 L 70 30 L 70 70 L 30 70 Z M 30 30'
)
assert svg_has_style_attr(
data, 'path', 'fill', 'rgb\\(100%, ?0%, ?0%\\)', escape=False
)
assert svg_has_style_attr(data, 'path', 'stroke-width', '2')
assert svg_has_style_attr(
data, 'path', 'stroke', 'rgb\\(0%, ?100%, ?0%\\)', escape=False
)

def test_multipolygons(self):
path = Path(__file__).parent.joinpath(
Expand Down Expand Up @@ -161,8 +176,14 @@ def test_multipolygons(self):

with open(path, 'r') as file:
data = file.read()
assert data.find('M 30 30 L 40 30 L 40 70 L 30 70 Z M 30 30') != -1
assert data.find('M 60 30 L 70 30 L 70 70 L 60 70 Z M 60 30') != -1
assert data.find('fill:none') != -1
assert data.find('stroke-width:1.5') != -1
assert data.find('stroke:rgb(0%,100%,0%);') != -1
assert svg_has_style_attr(
data, 'path', 'd', 'M 30 30 L 40 30 L 40 70 L 30 70 Z M 30 30'
)
assert svg_has_style_attr(
data, 'path', 'd', 'M 30 30 L 40 30 L 40 70 L 30 70 Z M 30 30'
)
assert svg_has_style_attr(data, 'path', 'fill', 'none')
assert svg_has_style_attr(data, 'path', 'stroke-width', '1.5')
assert svg_has_style_attr(
data, 'path', 'stroke', 'rgb\\(0%, ?100%, ?0%\\)', escape=False
)
69 changes: 48 additions & 21 deletions tests/drawable/geometry/test_stripe_filled_polygon_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from map_engraver.canvas.canvas_unit import CanvasUnit as Cu
from map_engraver.drawable.geometry.stripe_filled_polygon_drawer import \
StripeFilledPolygonDrawer
from tests.utils import svg_has_style_attr


class TestStripeFilledPolygonDrawer(unittest.TestCase):
Expand Down Expand Up @@ -88,11 +89,17 @@ def test_single_stripe(self):

with open(path, 'r') as file:
data = file.read()
assert data.find('M 30 30 L 70 30 L 70 70 L 30 70 Z M 30 30') != -1
assert data.find('M 40 40 L 60 40 L 60 60 L 40 60 Z M 40 40') == -1
assert data.find('fill:rgb(0%,100%,0%)') != -1
assert data.find('stroke:none') != -1
assert data.find('stroke-width:') == -1
assert svg_has_style_attr(
data, 'path', 'd', 'M 30 30 L 70 30 L 70 70 L 30 70 Z M 30 30'
)
assert not svg_has_style_attr(
data, 'path', 'd', 'M 40 40 L 60 40 L 60 60 L 40 60 Z M 40 40'
)
assert svg_has_style_attr(
data, 'path', 'fill', 'rgb\\(0%, ?100%, ?0%\\)', escape=False
)
assert not svg_has_style_attr(data, 'path', 'stroke')
assert not svg_has_style_attr(data, 'path', 'stroke-width')

def test_two_vertical_stripes(self):
path = Path(__file__).parent.joinpath(
Expand Down Expand Up @@ -127,12 +134,20 @@ def test_two_vertical_stripes(self):

with open(path, 'r') as file:
data = file.read()
assert data.find('M 30 30 L 30 70 L 50 70 L 50 30 Z M 30 30') != -1
assert data.find('M 50 30 L 50 70 L 70 70 L 70 30 Z M 50 30') != -1
assert data.find('fill:rgb(0%,100%,0%)') != -1
assert data.find('fill:rgb(0%,0%,100%)') != -1
assert data.find('stroke:none') != -1
assert data.find('stroke-width:') == -1
assert svg_has_style_attr(
data, 'path', 'd', 'M 30 30 L 30 70 L 50 70 L 50 30 Z M 30 30'
)
assert svg_has_style_attr(
data, 'path', 'd', 'M 50 30 L 50 70 L 70 70 L 70 30 Z M 50 30'
)
assert svg_has_style_attr(
data, 'path', 'fill', 'rgb\\(0%, ?100%, ?0%\\)', escape=False
)
assert svg_has_style_attr(
data, 'path', 'fill', 'rgb\\(0%, ?0%, ?100%\\)', escape=False
)
assert not svg_has_style_attr(data, 'path', 'stroke')
assert not svg_has_style_attr(data, 'path', 'stroke-width')

def test_large_stripes(self):
path = Path(__file__).parent.joinpath(
Expand Down Expand Up @@ -167,11 +182,17 @@ def test_large_stripes(self):

with open(path, 'r') as file:
data = file.read()
assert data.find('M 30 30 L 30 70 L 70 70 L 70 30 Z M 30 30') != -1
assert data.find('fill:rgb(0%,100%,0%)') != -1
assert data.find('fill:rgb(0%,0%,100%)') == -1
assert data.find('stroke:none') != -1
assert data.find('stroke-width:') == -1
assert svg_has_style_attr(
data, 'path', 'd', 'M 30 30 L 30 70 L 70 70 L 70 30 Z M 30 30'
)
assert svg_has_style_attr(
data, 'path', 'fill', 'rgb\\(0%, ?100%, ?0%\\)', escape=False
)
assert not svg_has_style_attr(
data, 'path', 'fill', 'rgb\\(0%, ?0%, ?100%\\)', escape=False
)
assert not svg_has_style_attr(data, 'path', 'stroke')
assert not svg_has_style_attr(data, 'path', 'stroke-width')

def test_multi_polygons(self):
path = Path(__file__).parent.joinpath(
Expand Down Expand Up @@ -223,8 +244,14 @@ def test_multi_polygons(self):

with open(path, 'r') as file:
data = file.read()
assert data.find('fill:rgb(100%,100%,0%)') != -1
assert data.find('fill:rgb(0%,0%,0%)') != -1
assert data.find('fill:rgb(70%,0%,70%)') != -1
assert data.find('stroke:none') != -1
assert data.find('stroke-width:') == -1
assert svg_has_style_attr(
data, 'path', 'fill', 'rgb\\(100%, ?100%, ?0%\\)', escape=False
)
assert svg_has_style_attr(
data, 'path', 'fill', 'rgb\\(0%, ?0%, ?0%\\)', escape=False
)
assert svg_has_style_attr(
data, 'path', 'fill', 'rgb\\(70%, ?0%, ?70%\\)', escape=False
)
assert not svg_has_style_attr(data, 'path', 'stroke')
assert not svg_has_style_attr(data, 'path', 'stroke-width')
Loading

0 comments on commit 9316037

Please sign in to comment.