Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe authored Nov 23, 2020
2 parents 279fff1 + 83c0b83 commit 1d61bfd
Show file tree
Hide file tree
Showing 30 changed files with 217 additions and 397 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

open_collective: courtbouillon
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CairoSVG's tests
on: [push]

jobs:
tests:
name: ${{ matrix.os }} - ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.6, 3.7, 3.8]
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install CairoSVG
run: pip install --upgrade -e.[test]
- name: Setup fonts
run: |
mkdir ~/.fonts
cp ./test_non_regression/resources/*.*tf ~/.fonts
fc-cache -f -v
- name: Launch tests
run: python setup.py test
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

15 changes: 15 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
======


Version 2.5.0 released on 2020-10-29
====================================

* Drop support of Python 3.5, add support of Python 3.9.
* Add EPS export
* Add background-color, negate-colors, and invert-images options
* Improve support for font weights
* Fix opacity of patterns and gradients
* Support auto-start-reverse value for orient
* Draw images contained in defs
* Add Exif transposition support
* Handle dominant-baseline
* Support transform-origin


Version 2.4.2 released on 2019-09-10
====================================

Expand Down
26 changes: 19 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
==========
CairoSVG
==========
CairoSVG is an SVG converter based on Cairo. It can export SVG files to PDF,
EPS, PS, and PNG files.

CairoSVG is a SVG converter based on Cairo. It can export SVG files to PDF,
PostScript and PNG files.
* Free software: LGPL license
* For Python 3.6+, tested on CPython and PyPy
* Documentation: https://cairosvg.org/documentation/
* Changelog: https://github.com/Kozea/CairoSVG/releases
* Code, issues, tests: https://github.com/Kozea/CairoSVG
* Code of conduct: https://www.courtbouillon.org/code-of-conduct
* Professional support: https://www.courtbouillon.org
* Donation: https://opencollective.com/courtbouillon

For further information, please visit the `CairoSVG Website
<http://www.cairosvg.org/>`_.
CairoSVG has been created and developed by Kozea (https://kozea.fr).
Professional support, maintenance and community management is provided by
CourtBouillon (https://www.courtbouillon.org).

Copyrights are retained by their contributors, no copyright assignment is
required to contribute to CairoSVG. Unless explicitly stated otherwise, any
contribution intentionally submitted for inclusion is licensed under the LGPL
license, without any additional terms or conditions. For full
authorship information, see the version control history.
2 changes: 1 addition & 1 deletion cairosvg/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.2
2.5.0
33 changes: 16 additions & 17 deletions cairosvg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
# This file is part of CairoSVG
# Copyright © 2010-2018 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with CairoSVG. If not, see <http://www.gnu.org/licenses/>.

"""
CairoSVG - A simple SVG converter based on Cairo.
Expand All @@ -27,7 +11,7 @@
if hasattr(sys, '_MEIPASS'):
# Frozen with PyInstaller
# See https://github.com/Kozea/WeasyPrint/pull/540
ROOT = Path(sys._MEIPASS)
ROOT = Path(sys._MEIPASS) / 'cairosvg'
else:
# Frozen with something else (py2exe, etc.)
# See https://github.com/Kozea/WeasyPrint/pull/269
Expand All @@ -46,6 +30,7 @@
'PDF': surface.PDFSurface,
'PNG': surface.PNGSurface,
'PS': surface.PSSurface,
'EPS': surface.EPSSurface,
'SVG': surface.SVGSurface,
}

Expand Down Expand Up @@ -99,6 +84,18 @@ def svg2ps(bytestring=None, *, file_obj=None, url=None, dpi=96,
output_width=output_width, output_height=output_height)


def svg2eps(bytestring=None, *, file_obj=None, url=None, dpi=96,
parent_width=None, parent_height=None, scale=1, unsafe=False,
background_color=None, negate_colors=False, invert_images=False,
write_to=None, output_width=None, output_height=None):
return surface.EPSSurface.convert(
bytestring=bytestring, file_obj=file_obj, url=url, dpi=dpi,
parent_width=parent_width, parent_height=parent_height, scale=scale,
background_color=background_color, negate_colors=negate_colors,
invert_images=invert_images, unsafe=unsafe, write_to=write_to,
output_width=output_width, output_height=output_height)


svg2svg.__doc__ = surface.Surface.convert.__doc__.replace(
'the format for this class', 'SVG')
svg2png.__doc__ = surface.Surface.convert.__doc__.replace(
Expand All @@ -107,3 +104,5 @@ def svg2ps(bytestring=None, *, file_obj=None, url=None, dpi=96,
'the format for this class', 'PDF')
svg2ps.__doc__ = surface.Surface.convert.__doc__.replace(
'the format for this class', 'PS')
svg2eps.__doc__ = surface.Surface.convert.__doc__.replace(
'the format for this class', 'EPS')
16 changes: 0 additions & 16 deletions cairosvg/__main__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
# This file is part of CairoSVG
# Copyright © 2010-2018 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with CairoSVG. If not, see <http://www.gnu.org/licenses/>.

"""
Command-line interface to CairoSVG.
Expand Down
16 changes: 0 additions & 16 deletions cairosvg/bounding_box.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
# This file is part of CairoSVG
# Copyright © 2010-2018 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with CairoSVG. If not, see <http://www.gnu.org/licenses/>.

"""
Calculate bounding box for SVG shapes and paths.
Expand Down
16 changes: 0 additions & 16 deletions cairosvg/colors.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
# This file is part of CairoSVG
# Copyright © 2010-2018 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with CairoSVG. If not, see <http://www.gnu.org/licenses/>.

"""
SVG colors.
Expand Down
16 changes: 0 additions & 16 deletions cairosvg/css.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
# This file is part of CairoSVG
# Copyright © 2010-2018 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with CairoSVG. If not, see <http://www.gnu.org/licenses/>.

"""
Handle CSS stylesheets.
Expand Down
38 changes: 13 additions & 25 deletions cairosvg/defs.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
# This file is part of CairoSVG
# Copyright © 2010-2018 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with CairoSVG. If not, see <http://www.gnu.org/licenses/>.

"""
Externally defined elements managers.
Expand Down Expand Up @@ -77,19 +61,20 @@ def parse_all_defs(surface, node):
def parse_def(surface, node):
"""Parse the SVG definitions."""
for def_type in (
'marker', 'gradient', 'pattern', 'path', 'mask', 'filter'):
'marker', 'gradient', 'pattern', 'path', 'mask', 'filter',
'image'):
if def_type in node.tag.lower() and 'id' in node:
getattr(surface, '{}s'.format(def_type))[node['id']] = node


def gradient_or_pattern(surface, node, name):
def gradient_or_pattern(surface, node, name, opacity):
"""Gradient or pattern color."""
if name in surface.gradients:
update_def_href(surface, name, surface.gradients)
return draw_gradient(surface, node, name)
return draw_gradient(surface, node, name, opacity)
elif name in surface.patterns:
update_def_href(surface, name, surface.patterns)
return draw_pattern(surface, node, name)
return draw_pattern(surface, node, name, opacity)


def marker(surface, node):
Expand Down Expand Up @@ -169,7 +154,7 @@ def paint_mask(surface, node, name, opacity):
surface.context.restore()


def draw_gradient(surface, node, name):
def draw_gradient(surface, node, name, opacity):
"""Gradients colors."""
gradient_node = surface.gradients[name]

Expand Down Expand Up @@ -201,6 +186,9 @@ def draw_gradient(surface, node, name):
fy = size(surface, gradient_node.get('fy', str(cy)), height_ref)
gradient_pattern = cairo.RadialGradient(fx, fy, 0, cx, cy, r)

else:
return False

# Apply matrix to set coordinate system for gradient
if gradient_node.get('gradientUnits') != 'userSpaceOnUse':
gradient_pattern.set_matrix(cairo.Matrix(
Expand All @@ -216,7 +204,7 @@ def draw_gradient(surface, node, name):
offset = max(offset, size(surface, child.get('offset'), 1))
stop_color = surface.map_color(
child.get('stop-color', 'black'),
float(child.get('stop-opacity', 1)))
float(child.get('stop-opacity', 1)) * opacity)
gradient_pattern.add_color_stop_rgba(offset, *stop_color)

# Set spread method for gradient outside target bounds
Expand All @@ -227,9 +215,10 @@ def draw_gradient(surface, node, name):
return True


def draw_pattern(surface, node, name):
def draw_pattern(surface, node, name, opacity):
"""Draw a pattern image."""
pattern_node = surface.patterns[name]
pattern_node['opacity'] = float(pattern_node.get('opacity', 1)) * opacity
pattern_node.tag = 'g'
transform(surface, pattern_node.get('patternTransform'))

Expand All @@ -248,8 +237,7 @@ def draw_pattern(surface, node, name):
pattern_width = size(surface, pattern_node.get('width', 0), 1)
pattern_height = size(surface, pattern_node.get('height', 0), 1)
else:
width = size(surface, node.get('width'), 'x')
height = size(surface, node.get('height'), 'y')
_, _, width, height = calculate_bounding_box(surface, node)
x = size(surface, pattern_node.get('x'), 1) * width
y = size(surface, pattern_node.get('y'), 1) * height
pattern_width = (
Expand Down
16 changes: 0 additions & 16 deletions cairosvg/features.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
# This file is part of CairoSVG
# Copyright © 2010-2018 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with CairoSVG. If not, see <http://www.gnu.org/licenses/>.

"""
Helpers related to SVG conditional processing.
Expand Down
Loading

0 comments on commit 1d61bfd

Please sign in to comment.