diff options
| author | jvoisin | 2022-03-16 20:23:49 +0100 |
|---|---|---|
| committer | jvoisin | 2022-03-16 20:23:49 +0100 |
| commit | 12582ba2f5017906e3e3382197f6eaf732d1d10e (patch) | |
| tree | 47b1ce8c9e9e315483b0716d7fa865fd46a9ffd1 /libmat2/images.py | |
| parent | 35092562e6773c7bc20ddef43bb4a2f94d8d9415 (diff) | |
Try to use modern rsvg functions when we can
Diffstat (limited to '')
| -rw-r--r-- | libmat2/images.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/libmat2/images.py b/libmat2/images.py index c584c1c..3da2673 100644 --- a/libmat2/images.py +++ b/libmat2/images.py | |||
| @@ -30,12 +30,23 @@ class SVGParser(exiftool.ExiftoolParser): | |||
| 30 | svg = Rsvg.Handle.new_from_file(self.filename) | 30 | svg = Rsvg.Handle.new_from_file(self.filename) |
| 31 | except GLib.GError: | 31 | except GLib.GError: |
| 32 | raise ValueError | 32 | raise ValueError |
| 33 | dimensions = svg.get_dimensions() | 33 | |
| 34 | surface = cairo.SVGSurface(self.output_filename, | 34 | try: |
| 35 | dimensions.height, | 35 | _, _, _, _, has_viewbox, viewbox = svg.get_intrinsic_dimensions() |
| 36 | dimensions.width) | 36 | if has_viewbox is False: |
| 37 | raise ValueError | ||
| 38 | _, width, height = svg.get_intrinsic_size_in_pixels() | ||
| 39 | except AttributeError: | ||
| 40 | dimensions = svg.get_dimensions() | ||
| 41 | height, width = dimensions.height, dimensions.width | ||
| 42 | |||
| 43 | surface = cairo.SVGSurface(self.output_filename, height, width) | ||
| 37 | context = cairo.Context(surface) | 44 | context = cairo.Context(surface) |
| 38 | svg.render_cairo(context) | 45 | try: |
| 46 | svg.render_document(context, viewbox) | ||
| 47 | except AttributeError: | ||
| 48 | svg.render_cairo(context) | ||
| 49 | |||
| 39 | surface.finish() | 50 | surface.finish() |
| 40 | return True | 51 | return True |
| 41 | 52 | ||
