pax_global_header 0000666 0000000 0000000 00000000064 14463407374 0014526 g ustar 00root root 0000000 0000000 52 comment=0abf992fb701a26c544be9589f06892535834289
CairoSVG-2.7.1/ 0000775 0000000 0000000 00000000000 14463407374 0013152 5 ustar 00root root 0000000 0000000 CairoSVG-2.7.1/.github/ 0000775 0000000 0000000 00000000000 14463407374 0014512 5 ustar 00root root 0000000 0000000 CairoSVG-2.7.1/.github/FUNDING.yml 0000664 0000000 0000000 00000000116 14463407374 0016325 0 ustar 00root root 0000000 0000000 # These are supported funding model platforms
open_collective: courtbouillon
CairoSVG-2.7.1/.github/workflows/ 0000775 0000000 0000000 00000000000 14463407374 0016547 5 ustar 00root root 0000000 0000000 CairoSVG-2.7.1/.github/workflows/tests.yml 0000664 0000000 0000000 00000001720 14463407374 0020434 0 ustar 00root root 0000000 0000000 name: CairoSVG's tests
on: [push, pull_request]
jobs:
tests:
name: ${{ matrix.os }} - ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.7', '3.11']
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/setup-python@v4
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: Install tests’ requirements
run: python -m pip install .[test] pytest-xdist
- name: Launch tests
run: python -m pytest -n auto
- name: Check coding style
run: python -m flake8
- name: Check imports order
run: python -m isort . --check --diff
CairoSVG-2.7.1/.gitignore 0000664 0000000 0000000 00000000153 14463407374 0015141 0 ustar 00root root 0000000 0000000 __pycache__
*.egg-info
/test_non_regression/output
/build
/dist
.coverage
.cache
.eggs
.idea
.pytest_cache
CairoSVG-2.7.1/.gitmodules 0000664 0000000 0000000 00000000137 14463407374 0015330 0 ustar 00root root 0000000 0000000 [submodule "test/cairosvg_reference"]
path = test_non_regression/cairosvg_reference
url = ./
CairoSVG-2.7.1/LICENSE 0000664 0000000 0000000 00000016742 14463407374 0014171 0 ustar 00root root 0000000 0000000 GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library. CairoSVG-2.7.1/NEWS.rst 0000664 0000000 0000000 00000026534 14463407374 0014472 0 ustar 00root root 0000000 0000000 ======
News
======
Version 2.7.1 released on 2023-08-05
====================================
- Don’t draw clipPath when defined after reference
- Handle evenodd fill rule with gradients and patterns
- Fix ratio and clip for "image" tags with no size
- Handle data-URLs in safe mode
- Use f-strings
Version 2.7.0 released on 2023-03-20
====================================
**WARNING:** this is a security update.
When processing SVG files, CairoSVG could access other files online, possibly
leading to very long renderings or other security problems.
This feature is now disabled by default. External resources can still be
accessed using the "unsafe" or the "url_fetcher" parameter.
Version 2.6.0 released on 2023-01-12
====================================
* Drop support of Python 3.5 and 3.6, add support of Python 3.9, 3.10 and 3.11
* Support crispEdges value for text antialiasing
* Don’t crash when including CMYK images
* Only update docstrings when not optimized
* Don’t restore current point after empty paths
* Assume that 1ch equals 0.5em
* Fix various deprecation warnings
Version 2.5.2 released on 2021-03-06
====================================
* Fix marker path scale
Version 2.5.1 released on 2021-01-06
====================================
**WARNING:** this is a security update.
When processing SVG files, CairoSVG was using two regular expressions which are
vulnerable to Regular Expression Denial of Service (REDoS).
If an attacker provided a malicious SVG, it could make CairoSVG get stuck
processing the file for a very long time.
Other bug fixes:
* Fix marker positions for unclosed paths
* Follow hint when only output_width or output_height is set
* Handle opacity on raster images
* Don’t crash when use tags reference unknown tags
* Take care of the next letter when A/a is replaced by l
* Fix misalignment in node.vertices
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
====================================
* Fix race condition in tests
* Fix scale for images with no viewBox
Version 2.4.1 released on 2019-08-21
====================================
* Fix the --scale parameter
* Allow href attributes with no namespace
* Fix the tree root detection
Version 2.4.0 released on 2019-05-20
====================================
* Fix aspect and position when resizing root SVG tag
* Follow aspect and position hints when using forced output size
Version 2.3.1 released on 2019-04-18
====================================
* Fix relative paths on Windows
Version 2.3.0 released on 2019-02-08
====================================
* Drop Python 3.4 support
* Make text selectable on generated PDF files
* Don't inherit dx and dy attributes
* Fix support of alignment-baseline="hanging"
* Fix backslashes in docstrings and comments
* Fix local anchors with files with no given URL
* Close VERSION's file descriptor
* Clean packaging
* Include LICENSE in distributed packages
Version 2.2.1 released on 2018-09-27
====================================
* Fix packaging
Version 2.2.0 released on 2018-09-21
====================================
* Clean packaging
* Fix T commands used with previous relative commands in paths
* Use real functions for svg2* commands, improving IDE integration
* Fix files management on Windows
* Handle image-rendering property
* Fix crash with some text samples
* Fix position of embedded svg tags with a viewbox not at position (0, 0)
* Add output-width and output-height options
* Handle references to inner document tags defined after the anchor
* Fix offsets for texts on paths
Version 2.1.3 released on 2018-01-03
====================================
* Fix T commands following q or t in paths
Version 2.1.2 released on 2017-12-01
====================================
* Fix font-size
Version 2.1.1 released on 2017-09-30
====================================
* Use http://www.w3.org/2000/svg as default namespace
Version 2.1.0 released on 2017-09-30
====================================
* Use cssselect2 and tinycss2 instead of cssselect and tinycss
* Don't require lxml anymore
* Rely on defusedxml to detect unsafe SVG files
Version 2.0.3 released on 2017-05-02
====================================
* Add ``python_requires`` in ``setup.py``
Version 2.0.2 released on 2017-03-20
====================================
* Handle ``text-align`` in textPath tags
* Test with Python 3.6
Version 2.0.1, released on 2017-01-04
=====================================
* Don't crash on relative refs with no input URL
Version 2.0.0, released on 2016-11-24
=====================================
* Drop Python 2 support
* Drop pycairo support
* Rely on cairocffi, lxml, cssselect, pillow and tinycss
* Fix markers
* Fix URL/id handling
* Use bounding boxes for gradients
* Split deployment and development tests
* Add a scale option
* Add a parent size option
* Test with Travis
Version 1.0.22, released on 2016-06-16
======================================
* Fix crash when lxml is not installed
Version 1.0.21, released on 2016-06-14
======================================
**WARNING:** this is a security update.
CairoSVG was vulnerable to XML eXternal Entity (XXE) attacks, this release
fixes this vulnerability by not resolving the XML entities anymore.
The ``--unsafe`` option has been added to force the resolution of XML
entities. Obviously, this option is not safe and should only be used with
trusted SVG files.
Version 1.0.20, released on 2016-02-23
======================================
* Allow the user to give parent size
Version 1.0.19, released on 2015-10-30
======================================
* Drastically improve the performance of ``Node()``
Version 1.0.18, released on 2015-10-20
======================================
* Use cairo groups to apply filters
Version 1.0.17, released on 2015-10-09
======================================
* Fix scale and position of markers
Version 1.0.16, released on 2015-08-05
======================================
* Support the text-rendering property
Version 1.0.15, released on 2015-06-22
======================================
* Use xMidYMid as default preserveAspectRatio value
Version 1.0.14, released on 2015-06-02
======================================
* Support the shape-rendering property
Version 1.0.13, released on 2015-02-26
======================================
* Fix end markers
Version 1.0.12, released on 2015-02-26
======================================
* Don't crash when paths with markers end with a move_to action
Version 1.0.11, released on 2015-02-11
======================================
* Allow commas in viewboxes
Version 1.0.10, released on 2015-02-09
======================================
* Allow quotes around font names
Version 1.0.9, released on 2014-08-12
=====================================
* Don't crash when gradients are applied to paths
Version 1.0.8, released on 2014-07-14
=====================================
* Don't create an atomic layer for transparent tags with no children
Version 1.0.7, released on 2014-05-06
=====================================
* Fix scaling with negative viewBox origin
* Automatically detect size and position of circles and ellipses for gradients
Version 1.0.6, released on 2014-03-07
=====================================
* Fall back to pycairo if cairocffi is unable to find the cairo library
Version 1.0.5, released on 2014-03-06
=====================================
* Don't inherit clip* and overflow properties
* Don't transform the root svg tag according to the PreservAspectRatio attribute
* Add simple support for alignment-baseline
* Add cairocffi into setup.py deps
Version 1.0.4, released on 2014-01-21
=====================================
* Clear relative coordinates when absolute coordinates are set in tspan tags
Version 1.0.3, released on 2013-11-27
=====================================
* Fix clips and viewboxes
* Don't draw an empty image when locale is not set
Version 1.0.2, released on 2013-11-19
=====================================
* Don't crash when locale is not set
* Get the xml_tree from the root parent when creating nodes from string
Version 1.0.1, released on 2013-09-24
=====================================
* Don't crash when svg tag has no width or height
Version 1.0, released on 2013-09-06
===================================
* CairoCFFI support
* Support of more external CSS stylesheets
* Handle more filters
* Use pillow instead of pystacia
* Fix a lot of bugs with text (whitespaces, text on a path, etc.)
* Inherit attributes in ``use`` tags
* Cache trees for ``use`` tags
* Handle conditional structures
Version 0.5, released on 2012-12-13
===================================
* Simple support of the ``image`` tag thanks to pystacia
* Better tests with pystacia instead of pypng (~35% faster)
* Handle s after C/S and S after c/s in paths
* Handle rounded corners with 2 different radii for rectangles
* Fix python 2.6 support
* Fix markers with empty paths and z/Z points
* Fix initial m in paths with no current point
* Fix transformations order
Version 0.4.4, released on 2012-07-05
=====================================
* Use a default font size of 12pt
* Fix a bug about non-invertible matrices
* Fix the installation for python 3 with LANG=C
Version 0.4.3, released on 2012-05-04
=====================================
* Fix the version detection without cairo
Version 0.4.2, released on 2012-05-04
=====================================
* Don't rely on cairo import to find the version
Version 0.4.1, released on 2012-04-25
=====================================
* Use cssselect
Version 0.4, released on 2012-04-19
===================================
* Reliable testing suite
* Use tinycss instead of cssutils to parse CSS
Version 0.3.1, released on 2012-02-20
=====================================
* Percentages, em and ex units
* Real opacity
Version 0.3, released on 2012-01-27
===================================
* Simple inline CSS support
* Support for transformations in patterns and gradients
* Real by-surface DPI management (default value set to 96)
* Handle exponents
Version 0.2, released on 2012-01-04
===================================
* **Change the Python API again** to be compatible with 0.1.1 and before:
``svg2pdf(source_as_bytes) -> bytes`` but still support filenames or
file objects with keyword-only parameters. See the docstrings.
* Add support for ``display``, ``visibility``, ``stop-opacity`` and
``stroke-miterlimit``
* Internal refactoring
Version 0.1.2, released on 2011-12-14
=====================================
**Backward incompatible change** in the Python API: previously the input
could be either a filename or SVG content as a string. Now a string is always
interpreted as a filename, but file-like objects are also accepted.
Use a StringIO object if you have SVG content in a string.
Version 0.1.1, released on 2011-12-13
=====================================
Fix Python 2.6 compatibility.
Version 0.1, released on 2011-12-13
===================================
* First release
* PDF, PS and PNG export
* Easy installer
CairoSVG-2.7.1/README.rst 0000664 0000000 0000000 00000002040 14463407374 0014635 0 ustar 00root root 0000000 0000000 CairoSVG is an SVG converter based on Cairo. It can export SVG files to PDF,
EPS, PS, and PNG files.
* Free software: LGPL license
* For Python 3.7+, 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
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.
CairoSVG-2.7.1/cairosvg/ 0000775 0000000 0000000 00000000000 14463407374 0014767 5 ustar 00root root 0000000 0000000 CairoSVG-2.7.1/cairosvg/VERSION 0000664 0000000 0000000 00000000005 14463407374 0016032 0 ustar 00root root 0000000 0000000 2.7.1 CairoSVG-2.7.1/cairosvg/__init__.py 0000664 0000000 0000000 00000011277 14463407374 0017110 0 ustar 00root root 0000000 0000000 """
CairoSVG - A simple SVG converter based on Cairo.
"""
import os
import sys
from pathlib import Path
if hasattr(sys, 'frozen'):
if hasattr(sys, '_MEIPASS'):
# Frozen with PyInstaller
# See https://github.com/Kozea/WeasyPrint/pull/540
ROOT = Path(sys._MEIPASS) / 'cairosvg'
else:
# Frozen with something else (py2exe, etc.)
# See https://github.com/Kozea/WeasyPrint/pull/269
ROOT = Path(os.path.dirname(sys.executable))
else:
ROOT = Path(os.path.dirname(__file__))
VERSION = __version__ = (ROOT / 'VERSION').read_text().strip()
# VERSION is used in the "url" module imported by "surface"
from . import surface # noqa isort:skip
SURFACES = {
'PDF': surface.PDFSurface,
'PNG': surface.PNGSurface,
'PS': surface.PSSurface,
'EPS': surface.EPSSurface,
'SVG': surface.SVGSurface,
}
def svg2svg(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.SVGSurface.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)
def svg2png(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.PNGSurface.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)
def svg2pdf(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.PDFSurface.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)
def svg2ps(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.PSSurface.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)
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)
if __debug__:
svg2svg.__doc__ = surface.Surface.convert.__doc__.replace(
'the format for this class', 'SVG')
svg2png.__doc__ = surface.Surface.convert.__doc__.replace(
'the format for this class', 'PNG')
svg2pdf.__doc__ = surface.Surface.convert.__doc__.replace(
'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')
CairoSVG-2.7.1/cairosvg/__main__.py 0000664 0000000 0000000 00000005745 14463407374 0017074 0 ustar 00root root 0000000 0000000 """
Command-line interface to CairoSVG.
"""
import argparse
import os
import sys
from . import SURFACES, VERSION
def main(argv=None, stdout=None, stdin=None):
"""Entry-point of the executable."""
# Get command-line options
parser = argparse.ArgumentParser(
description='Convert SVG files to other formats')
parser.add_argument('input', default='-', help='input filename or URL')
parser.add_argument(
'-v', '--version', action='version', version=VERSION)
parser.add_argument(
'-f', '--format', help='output format',
choices=sorted([surface.lower() for surface in SURFACES]))
parser.add_argument(
'-d', '--dpi', default=96, type=float,
help='ratio between 1 inch and 1 pixel')
parser.add_argument(
'-W', '--width', default=None, type=float,
help='width of the parent container in pixels')
parser.add_argument(
'-H', '--height', default=None, type=float,
help='height of the parent container in pixels')
parser.add_argument(
'-s', '--scale', default=1, type=float, help='output scaling factor')
parser.add_argument(
'-b', '--background', metavar='COLOR', help='output background color')
parser.add_argument(
'-n', '--negate-colors', action='store_true',
help='replace every vector color with its complement')
parser.add_argument(
'-i', '--invert-images', action='store_true',
help='replace every raster pixel with its complementary color')
parser.add_argument(
'-u', '--unsafe', action='store_true',
help='fetch external files, resolve XML entities and allow very large '
'files (WARNING: vulnerable to XXE attacks and various DoS)')
parser.add_argument(
'--output-width', default=None, type=float,
help='desired output width in pixels')
parser.add_argument(
'--output-height', default=None, type=float,
help='desired output height in pixels')
parser.add_argument('-o', '--output', default='-', help='output filename')
options = parser.parse_args(argv)
kwargs = {
'parent_width': options.width, 'parent_height': options.height,
'dpi': options.dpi, 'scale': options.scale, 'unsafe': options.unsafe,
'background_color': options.background,
'negate_colors': options.negate_colors,
'invert_images': options.invert_images,
'output_width': options.output_width,
'output_height': options.output_height}
stdin = stdin or sys.stdin
stdout = stdout or sys.stdout
kwargs['write_to'] = (
stdout.buffer if options.output == '-' else options.output)
if options.input == '-':
kwargs['file_obj'] = stdin.buffer
else:
kwargs['url'] = options.input
output_format = (
options.format or
os.path.splitext(options.output)[1].lstrip('.') or
'pdf').upper()
SURFACES[output_format.upper()].convert(**kwargs)
if __name__ == '__main__': # pragma: no cover
main()
CairoSVG-2.7.1/cairosvg/bounding_box.py 0000664 0000000 0000000 00000033234 14463407374 0020023 0 ustar 00root root 0000000 0000000 """
Calculate bounding box for SVG shapes and paths.
A bounding box is a (minx, miny, width, height) tuple.
"""
from math import acos, atan, cos, fmod, isinf, pi, radians, sin, sqrt, tan
from .features import match_features
from .helpers import PATH_LETTERS, normalize, point, size
from .parser import Tree
from .url import parse_url
EMPTY_BOUNDING_BOX = float('inf'), float('inf'), 0, 0
def calculate_bounding_box(surface, node):
"""Calculate ``node``'s bounding box.
See https://www.w3.org/TR/SVG/coords.html#ObjectBoundingBox
"""
if 'bounding_box' not in node and node.tag in BOUNDING_BOX_METHODS:
bounding_box = BOUNDING_BOX_METHODS[node.tag](surface, node)
if is_non_empty_bounding_box(bounding_box):
node['bounding_box'] = bounding_box
return node.get('bounding_box')
def bounding_box_rect(surface, node):
"""Get the bounding box of a ``rect`` node."""
x, y = size(surface, node.get('x'), 'x'), size(surface, node.get('y'), 'y')
width = size(surface, node.get('width'), 'x')
height = size(surface, node.get('height'), 'y')
return x, y, width, height
def bounding_box_circle(surface, node):
"""Get the bounding box of a ``circle`` node."""
cx = size(surface, node.get('cx'), 'x')
cy = size(surface, node.get('cy'), 'y')
r = size(surface, node.get('r'))
return cx - r, cy - r, 2 * r, 2 * r
def bounding_box_ellipse(surface, node):
"""Get the bounding box of an ``ellipse`` node."""
rx = size(surface, node.get('rx'), 'x')
ry = size(surface, node.get('ry'), 'y')
cx = size(surface, node.get('cx'), 'x')
cy = size(surface, node.get('cy'), 'y')
return cx - rx, cy - ry, 2 * rx, 2 * ry
def bounding_box_line(surface, node):
"""Get the bounding box of a ``line`` node."""
x1, y1, x2, y2 = tuple(
size(surface, node.get(position), position[0])
for position in ('x1', 'y1', 'x2', 'y2'))
x, y = min(x1, x2), min(y1, y2)
width, height = max(x1, x2) - x, max(y1, y2) - y
return x, y, width, height
def bounding_box_polyline(surface, node):
"""Get the bounding box of a ``polyline`` or ``polygon`` node."""
bounding_box = EMPTY_BOUNDING_BOX
points = []
normalized_points = normalize(node.get('points', ''))
while normalized_points:
x, y, normalized_points = point(surface, normalized_points)
points.append((x, y))
return extend_bounding_box(bounding_box, points)
def bounding_box_path(surface, node):
"""Get the bounding box of a ``path`` node."""
path_data = node.get('d', '')
# Normalize path data for correct parsing
for letter in PATH_LETTERS:
path_data = path_data.replace(letter, f' {letter} ')
path_data = normalize(path_data)
bounding_box = EMPTY_BOUNDING_BOX
previous_x = 0
previous_y = 0
letter = 'M' # Move as default
while path_data:
path_data = path_data.strip()
if path_data.split(' ', 1)[0] in PATH_LETTERS:
letter, path_data = (path_data + ' ').split(' ', 1)
if letter in 'aA':
# Elliptical arc curve
rx, ry, path_data = point(None, path_data)
rotation, path_data = path_data.split(' ', 1)
rotation = radians(float(rotation))
# The large and sweep values are not always separated from the
# following values, here is the crazy parser
large, path_data = path_data[0], path_data[1:].strip()
while not large[-1].isdigit():
large, path_data = large + path_data[0], path_data[1:].strip()
sweep, path_data = path_data[0], path_data[1:].strip()
while not sweep[-1].isdigit():
sweep, path_data = sweep + path_data[0], path_data[1:].strip()
large, sweep = bool(int(large)), bool(int(sweep))
x, y, path_data = point(None, path_data)
# Relative coordinate, convert to absolute
if letter == 'a':
x += previous_x
y += previous_y
# Extend bounding box with start and end coordinates
arc_bounding_box = bounding_box_elliptical_arc(
previous_x, previous_y, rx, ry, rotation, large, sweep, x, y)
x1, y1, width, height = arc_bounding_box
x2 = x1 + width
y2 = y1 + height
points = (x1, y1), (x2, y2)
bounding_box = extend_bounding_box(bounding_box, points)
previous_x = x
previous_y = y
elif letter in 'cC':
# Curve
x1, y1, path_data = point(None, path_data)
x2, y2, path_data = point(None, path_data)
x, y, path_data = point(None, path_data)
# Relative coordinates, convert to absolute
if letter == 'c':
x1 += previous_x
y1 += previous_y
x2 += previous_x
y2 += previous_y
x += previous_x
y += previous_y
# Extend bounding box with all coordinates
bounding_box = extend_bounding_box(
bounding_box, ((x1, y1), (x2, y2), (x, y)))
previous_x = x
previous_y = y
elif letter in 'hH':
# Horizontal line
x, path_data = (path_data + ' ').split(' ', 1)
x = size(surface, x, 'x')
# Relative coordinate, convert to absolute
if letter == 'h':
x += previous_x
# Extend bounding box with coordinate
bounding_box = extend_bounding_box(
bounding_box, ((x, previous_y),))
previous_x = x
elif letter in 'lLmMtT':
# Line/Move/Smooth quadratic curve
x, y, path_data = point(None, path_data)
# Relative coordinate, convert to absolute
if letter in 'lmt':
x += previous_x
y += previous_y
# Extend bounding box with coordinate
bounding_box = extend_bounding_box(bounding_box, ((x, y),))
previous_x = x
previous_y = y
elif letter in 'qQsS':
# Quadratic curve/Smooth curve
x1, y1, path_data = point(None, path_data)
x, y, path_data = point(None, path_data)
# Relative coordinates, convert to absolute
if letter in 'qs':
x1 += previous_x
y1 += previous_y
x += previous_x
y += previous_y
# Extend bounding box with coordinates
bounding_box = extend_bounding_box(
bounding_box, ((x1, y1), (x, y)))
previous_x = x
previous_y = y
elif letter in 'vV':
# Vertical line
y, path_data = (path_data + ' ').split(' ', 1)
y = size(surface, y, 'y')
# Relative coordinate, convert to absolute
if letter == 'v':
y += previous_y
# Extend bounding box with coordinate
bounding_box = extend_bounding_box(
bounding_box, ((previous_x, y),))
previous_y = y
path_data = path_data.strip()
return bounding_box
def bounding_box_text(surface, node):
"""Get the bounding box of a ``text`` node."""
return node.get('text_bounding_box')
def angle(bx, by):
"""Get the angle between vector (1,0) and vector (bx,by)."""
return fmod(
2 * pi + (1 if by > 0 else -1) * acos(bx / sqrt(bx * bx + by * by)),
2 * pi)
def bounding_box_elliptical_arc(x1, y1, rx, ry, phi, large, sweep, x, y):
"""Get the bounding box of an elliptical arc described by the parameters.
See following website for original code:
http://fridrich.blogspot.nl/2011/06/bounding-box-of-svg-elliptical-arc.html
"""
rx, ry = abs(rx), abs(ry)
if rx == 0 or ry == 0:
return min(x, x1), min(y, y1), abs(x - x1), abs(y - y1)
x1prime = cos(phi) * (x1 - x) / 2 + sin(phi) * (y1 - y) / 2
y1prime = -sin(phi) * (x1 - x) / 2 + cos(phi) * (y1 - y) / 2
radicant = (
rx ** 2 * ry ** 2 - rx ** 2 * y1prime ** 2 - ry ** 2 * x1prime ** 2)
radicant /= rx ** 2 * y1prime ** 2 + ry ** 2 * x1prime ** 2
cxprime = cyprime = 0
if radicant < 0:
ratio = rx / ry
radicant = y1prime ** 2 + x1prime ** 2 / ratio ** 2
if radicant < 0:
return min(x, x1), min(y, y1), abs(x - x1), abs(y - y1)
ry = sqrt(radicant)
rx = ratio * ry
else:
factor = (-1 if large == sweep else 1) * sqrt(radicant)
cxprime = factor * rx * y1prime / ry
cyprime = -factor * ry * x1prime / rx
cx = cxprime * cos(phi) - cyprime * sin(phi) + (x1 + x) / 2
cy = cxprime * sin(phi) + cyprime * cos(phi) + (y1 + y) / 2
if phi == 0 or phi == pi:
minx = cx - rx
tminx = angle(-rx, 0)
maxx = cx + rx
tmaxx = angle(rx, 0)
miny = cy - ry
tminy = angle(0, -ry)
maxy = cy + ry
tmaxy = angle(0, ry)
elif phi == pi / 2 or phi == 3 * pi / 2:
minx = cx - ry
tminx = angle(-ry, 0)
maxx = cx + ry
tmaxx = angle(ry, 0)
miny = cy - rx
tminy = angle(0, -rx)
maxy = cy + rx
tmaxy = angle(0, rx)
else:
tminx = -atan(ry * tan(phi) / rx)
tmaxx = pi - atan(ry * tan(phi) / rx)
minx = cx + rx * cos(tminx) * cos(phi) - ry * sin(tminx) * sin(phi)
maxx = cx + rx * cos(tmaxx) * cos(phi) - ry * sin(tmaxx) * sin(phi)
if minx > maxx:
minx, maxx = maxx, minx
tminx, tmaxx = tmaxx, tminx
tmp_y = cy + rx * cos(tminx) * sin(phi) + ry * sin(tminx) * cos(phi)
tminx = angle(minx - cx, tmp_y - cy)
tmp_y = cy + rx * cos(tmaxx) * sin(phi) + ry * sin(tmaxx) * cos(phi)
tmaxx = angle(maxx - cx, tmp_y - cy)
tminy = atan(ry / (tan(phi) * rx))
tmaxy = atan(ry / (tan(phi) * rx)) + pi
miny = cy + rx * cos(tminy) * sin(phi) + ry * sin(tminy) * cos(phi)
maxy = cy + rx * cos(tmaxy) * sin(phi) + ry * sin(tmaxy) * cos(phi)
if miny > maxy:
miny, maxy = maxy, miny
tminy, tmaxy = tmaxy, tminy
tmp_x = cx + rx * cos(tminy) * cos(phi) - ry * sin(tminy) * sin(phi)
tminy = angle(tmp_x - cx, miny - cy)
tmp_x = cx + rx * cos(tmaxy) * cos(phi) - ry * sin(tmaxy) * sin(phi)
tmaxy = angle(tmp_x - cx, maxy - cy)
angle1 = angle(x1 - cx, y1 - cy)
angle2 = angle(x - cx, y - cy)
if not sweep:
angle1, angle2 = angle2, angle1
other_arc = False
if angle1 > angle2:
angle1, angle2 = angle2, angle1
other_arc = True
if ((not other_arc and (angle1 > tminx or angle2 < tminx)) or
(other_arc and not (angle1 > tminx or angle2 < tminx))):
minx = min(x, x1)
if ((not other_arc and (angle1 > tmaxx or angle2 < tmaxx)) or
(other_arc and not (angle1 > tmaxx or angle2 < tmaxx))):
maxx = max(x, x1)
if ((not other_arc and (angle1 > tminy or angle2 < tminy)) or
(other_arc and not (angle1 > tminy or angle2 < tminy))):
miny = min(y, y1)
if ((not other_arc and (angle1 > tmaxy or angle2 < tmaxy)) or
(other_arc and not (angle1 > tmaxy or angle2 < tmaxy))):
maxy = max(y, y1)
return minx, miny, maxx - minx, maxy - miny
def bounding_box_group(surface, node):
"""Get the bounding box of a ``g`` node."""
bounding_box = EMPTY_BOUNDING_BOX
for child in node.children:
bounding_box = combine_bounding_box(
bounding_box, calculate_bounding_box(surface, child))
return bounding_box
def bounding_box_use(surface, node):
"""Get the bounding box of a ``use`` node."""
href = parse_url(node.get_href()).geturl()
tree = Tree(
url=href, url_fetcher=node.url_fetcher, parent=node,
unsafe=node.unsafe)
if not match_features(tree.xml_tree):
return None
return calculate_bounding_box(surface, tree)
def extend_bounding_box(bounding_box, points):
"""Extend the ``bounding_box`` by the points."""
minx, miny, width, height = bounding_box
maxx, maxy = (
float('-inf') if isinf(minx) else minx + width,
float('-inf') if isinf(miny) else miny + height)
x_list, y_list = zip(*points)
minx, miny, maxx, maxy = (
min(minx, *x_list), min(miny, *y_list),
max(maxx, *x_list), max(maxy, *y_list))
return minx, miny, maxx - minx, maxy - miny
def combine_bounding_box(bounding_box, another_bounding_box):
"""Combine the ``bounding_box`` with ``another_bounding_box``."""
if is_valid_bounding_box(another_bounding_box):
minx, miny, width, height = another_bounding_box
maxx, maxy = minx + width, miny + height
bounding_box = extend_bounding_box(
bounding_box, ((minx, miny), (maxx, maxy)))
return bounding_box
def is_valid_bounding_box(bounding_box):
"""Know whether bounding box has been initialized."""
# If 'minx' or 'miny' is set, 'maxx' and 'maxy' will also be set (resulting
# in a valid bounding box)
return bounding_box and not isinf(bounding_box[0] + bounding_box[1])
def is_non_empty_bounding_box(bounding_box):
"""Know whether bounding box is valid and has a size."""
return is_valid_bounding_box(bounding_box) and 0 not in bounding_box[2:]
BOUNDING_BOX_METHODS = {
'rect': bounding_box_rect,
'circle': bounding_box_circle,
'ellipse': bounding_box_ellipse,
'line': bounding_box_line,
'polyline': bounding_box_polyline,
'polygon': bounding_box_polyline,
'path': bounding_box_path,
'text': bounding_box_text,
'tspan': bounding_box_text,
'textPath': bounding_box_text,
'g': bounding_box_group,
'use': bounding_box_use,
'marker': bounding_box_group,
}
CairoSVG-2.7.1/cairosvg/colors.py 0000664 0000000 0000000 00000024660 14463407374 0016652 0 ustar 00root root 0000000 0000000 """
SVG colors.
"""
import re
COLORS = {
'aliceblue': (240 / 255, 248 / 255, 255 / 255, 1),
'antiquewhite': (250 / 255, 235 / 255, 215 / 255, 1),
'aqua': (0 / 255, 255 / 255, 255 / 255, 1),
'aquamarine': (127 / 255, 255 / 255, 212 / 255, 1),
'azure': (240 / 255, 255 / 255, 255 / 255, 1),
'beige': (245 / 255, 245 / 255, 220 / 255, 1),
'bisque': (255 / 255, 228 / 255, 196 / 255, 1),
'black': (0 / 255, 0 / 255, 0 / 255, 1),
'blanchedalmond': (255 / 255, 235 / 255, 205 / 255, 1),
'blue': (0 / 255, 0 / 255, 255 / 255, 1),
'blueviolet': (138 / 255, 43 / 255, 226 / 255, 1),
'brown': (165 / 255, 42 / 255, 42 / 255, 1),
'burlywood': (222 / 255, 184 / 255, 135 / 255, 1),
'cadetblue': (95 / 255, 158 / 255, 160 / 255, 1),
'chartreuse': (127 / 255, 255 / 255, 0 / 255, 1),
'chocolate': (210 / 255, 105 / 255, 30 / 255, 1),
'coral': (255 / 255, 127 / 255, 80 / 255, 1),
'cornflowerblue': (100 / 255, 149 / 255, 237 / 255, 1),
'cornsilk': (255 / 255, 248 / 255, 220 / 255, 1),
'crimson': (220 / 255, 20 / 255, 60 / 255, 1),
'cyan': (0 / 255, 255 / 255, 255 / 255, 1),
'darkblue': (0 / 255, 0 / 255, 139 / 255, 1),
'darkcyan': (0 / 255, 139 / 255, 139 / 255, 1),
'darkgoldenrod': (184 / 255, 134 / 255, 11 / 255, 1),
'darkgray': (169 / 255, 169 / 255, 169 / 255, 1),
'darkgreen': (0 / 255, 100 / 255, 0 / 255, 1),
'darkgrey': (169 / 255, 169 / 255, 169 / 255, 1),
'darkkhaki': (189 / 255, 183 / 255, 107 / 255, 1),
'darkmagenta': (139 / 255, 0 / 255, 139 / 255, 1),
'darkolivegreen': (85 / 255, 107 / 255, 47 / 255, 1),
'darkorange': (255 / 255, 140 / 255, 0 / 255, 1),
'darkorchid': (153 / 255, 50 / 255, 204 / 255, 1),
'darkred': (139 / 255, 0 / 255, 0 / 255, 1),
'darksalmon': (233 / 255, 150 / 255, 122 / 255, 1),
'darkseagreen': (143 / 255, 188 / 255, 143 / 255, 1),
'darkslateblue': (72 / 255, 61 / 255, 139 / 255, 1),
'darkslategray': (47 / 255, 79 / 255, 79 / 255, 1),
'darkslategrey': (47 / 255, 79 / 255, 79 / 255, 1),
'darkturquoise': (0 / 255, 206 / 255, 209 / 255, 1),
'darkviolet': (148 / 255, 0 / 255, 211 / 255, 1),
'deeppink': (255 / 255, 20 / 255, 147 / 255, 1),
'deepskyblue': (0 / 255, 191 / 255, 255 / 255, 1),
'dimgray': (105 / 255, 105 / 255, 105 / 255, 1),
'dimgrey': (105 / 255, 105 / 255, 105 / 255, 1),
'dodgerblue': (30 / 255, 144 / 255, 255 / 255, 1),
'firebrick': (178 / 255, 34 / 255, 34 / 255, 1),
'floralwhite': (255 / 255, 250 / 255, 240 / 255, 1),
'forestgreen': (34 / 255, 139 / 255, 34 / 255, 1),
'fuchsia': (255 / 255, 0 / 255, 255 / 255, 1),
'gainsboro': (220 / 255, 220 / 255, 220 / 255, 1),
'ghostwhite': (248 / 255, 248 / 255, 255 / 255, 1),
'gold': (255 / 255, 215 / 255, 0 / 255, 1),
'goldenrod': (218 / 255, 165 / 255, 32 / 255, 1),
'gray': (128 / 255, 128 / 255, 128 / 255, 1),
'grey': (128 / 255, 128 / 255, 128 / 255, 1),
'green': (0 / 255, 128 / 255, 0 / 255, 1),
'greenyellow': (173 / 255, 255 / 255, 47 / 255, 1),
'honeydew': (240 / 255, 255 / 255, 240 / 255, 1),
'hotpink': (255 / 255, 105 / 255, 180 / 255, 1),
'indianred': (205 / 255, 92 / 255, 92 / 255, 1),
'indigo': (75 / 255, 0 / 255, 130 / 255, 1),
'ivory': (255 / 255, 255 / 255, 240 / 255, 1),
'khaki': (240 / 255, 230 / 255, 140 / 255, 1),
'lavender': (230 / 255, 230 / 255, 250 / 255, 1),
'lavenderblush': (255 / 255, 240 / 255, 245 / 255, 1),
'lawngreen': (124 / 255, 252 / 255, 0 / 255, 1),
'lemonchiffon': (255 / 255, 250 / 255, 205 / 255, 1),
'lightblue': (173 / 255, 216 / 255, 230 / 255, 1),
'lightcoral': (240 / 255, 128 / 255, 128 / 255, 1),
'lightcyan': (224 / 255, 255 / 255, 255 / 255, 1),
'lightgoldenrodyellow': (250 / 255, 250 / 255, 210 / 255, 1),
'lightgray': (211 / 255, 211 / 255, 211 / 255, 1),
'lightgreen': (144 / 255, 238 / 255, 144 / 255, 1),
'lightgrey': (211 / 255, 211 / 255, 211 / 255, 1),
'lightpink': (255 / 255, 182 / 255, 193 / 255, 1),
'lightsalmon': (255 / 255, 160 / 255, 122 / 255, 1),
'lightseagreen': (32 / 255, 178 / 255, 170 / 255, 1),
'lightskyblue': (135 / 255, 206 / 255, 250 / 255, 1),
'lightslategray': (119 / 255, 136 / 255, 153 / 255, 1),
'lightslategrey': (119 / 255, 136 / 255, 153 / 255, 1),
'lightsteelblue': (176 / 255, 196 / 255, 222 / 255, 1),
'lightyellow': (255 / 255, 255 / 255, 224 / 255, 1),
'lime': (0 / 255, 255 / 255, 0 / 255, 1),
'limegreen': (50 / 255, 205 / 255, 50 / 255, 1),
'linen': (250 / 255, 240 / 255, 230 / 255, 1),
'magenta': (255 / 255, 0 / 255, 255 / 255, 1),
'maroon': (128 / 255, 0 / 255, 0 / 255, 1),
'mediumaquamarine': (102 / 255, 205 / 255, 170 / 255, 1),
'mediumblue': (0 / 255, 0 / 255, 205 / 255, 1),
'mediumorchid': (186 / 255, 85 / 255, 211 / 255, 1),
'mediumpurple': (147 / 255, 112 / 255, 219 / 255, 1),
'mediumseagreen': (60 / 255, 179 / 255, 113 / 255, 1),
'mediumslateblue': (123 / 255, 104 / 255, 238 / 255, 1),
'mediumspringgreen': (0 / 255, 250 / 255, 154 / 255, 1),
'mediumturquoise': (72 / 255, 209 / 255, 204 / 255, 1),
'mediumvioletred': (199 / 255, 21 / 255, 133 / 255, 1),
'midnightblue': (25 / 255, 25 / 255, 112 / 255, 1),
'mintcream': (245 / 255, 255 / 255, 250 / 255, 1),
'mistyrose': (255 / 255, 228 / 255, 225 / 255, 1),
'moccasin': (255 / 255, 228 / 255, 181 / 255, 1),
'navajowhite': (255 / 255, 222 / 255, 173 / 255, 1),
'navy': (0 / 255, 0 / 255, 128 / 255, 1),
'oldlace': (253 / 255, 245 / 255, 230 / 255, 1),
'olive': (128 / 255, 128 / 255, 0 / 255, 1),
'olivedrab': (107 / 255, 142 / 255, 35 / 255, 1),
'orange': (255 / 255, 165 / 255, 0 / 255, 1),
'orangered': (255 / 255, 69 / 255, 0 / 255, 1),
'orchid': (218 / 255, 112 / 255, 214 / 255, 1),
'palegoldenrod': (238 / 255, 232 / 255, 170 / 255, 1),
'palegreen': (152 / 255, 251 / 255, 152 / 255, 1),
'paleturquoise': (175 / 255, 238 / 255, 238 / 255, 1),
'palevioletred': (219 / 255, 112 / 255, 147 / 255, 1),
'papayawhip': (255 / 255, 239 / 255, 213 / 255, 1),
'peachpuff': (255 / 255, 218 / 255, 185 / 255, 1),
'peru': (205 / 255, 133 / 255, 63 / 255, 1),
'pink': (255 / 255, 192 / 255, 203 / 255, 1),
'plum': (221 / 255, 160 / 255, 221 / 255, 1),
'powderblue': (176 / 255, 224 / 255, 230 / 255, 1),
'purple': (128 / 255, 0 / 255, 128 / 255, 1),
'red': (255 / 255, 0 / 255, 0 / 255, 1),
'rosybrown': (188 / 255, 143 / 255, 143 / 255, 1),
'royalblue': (65 / 255, 105 / 255, 225 / 255, 1),
'saddlebrown': (139 / 255, 69 / 255, 19 / 255, 1),
'salmon': (250 / 255, 128 / 255, 114 / 255, 1),
'sandybrown': (244 / 255, 164 / 255, 96 / 255, 1),
'seagreen': (46 / 255, 139 / 255, 87 / 255, 1),
'seashell': (255 / 255, 245 / 255, 238 / 255, 1),
'sienna': (160 / 255, 82 / 255, 45 / 255, 1),
'silver': (192 / 255, 192 / 255, 192 / 255, 1),
'skyblue': (135 / 255, 206 / 255, 235 / 255, 1),
'slateblue': (106 / 255, 90 / 255, 205 / 255, 1),
'slategray': (112 / 255, 128 / 255, 144 / 255, 1),
'slategrey': (112 / 255, 128 / 255, 144 / 255, 1),
'snow': (255 / 255, 250 / 255, 250 / 255, 1),
'springgreen': (0 / 255, 255 / 255, 127 / 255, 1),
'steelblue': (70 / 255, 130 / 255, 180 / 255, 1),
'tan': (210 / 255, 180 / 255, 140 / 255, 1),
'teal': (0 / 255, 128 / 255, 128 / 255, 1),
'thistle': (216 / 255, 191 / 255, 216 / 255, 1),
'tomato': (255 / 255, 99 / 255, 71 / 255, 1),
'turquoise': (64 / 255, 224 / 255, 208 / 255, 1),
'violet': (238 / 255, 130 / 255, 238 / 255, 1),
'wheat': (245 / 255, 222 / 255, 179 / 255, 1),
'white': (255 / 255, 255 / 255, 255 / 255, 1),
'whitesmoke': (245 / 255, 245 / 255, 245 / 255, 1),
'yellow': (255 / 255, 255 / 255, 0 / 255, 1),
'yellowgreen': (154 / 255, 205 / 255, 50 / 255, 1),
'activeborder': (0, 0, 1, 1),
'activecaption': (0, 0, 1, 1),
'appworkspace': (1, 1, 1, 1),
'background': (1, 1, 1, 1),
'buttonface': (0, 0, 0, 1),
'buttonhighlight': (0.8, 0.8, 0.8, 1),
'buttonshadow': (0.2, 0.2, 0.2, 1),
'buttontext': (0, 0, 0, 1),
'captiontext': (0, 0, 0, 1),
'graytext': (0.2, 0.2, 0.2, 1),
'highlight': (0, 0, 1, 1),
'highlighttext': (0.8, 0.8, 0.8, 1),
'inactiveborder': (0.2, 0.2, 0.2, 1),
'inactivecaption': (0.8, 0.8, 0.8, 1),
'inactivecaptiontext': (0.2, 0.2, 0.2, 1),
'infobackground': (0.8, 0.8, 0.8, 1),
'infotext': (0, 0, 0, 1),
'menu': (0.8, 0.8, 0.8, 1),
'menutext': (0.2, 0.2, 0.2, 1),
'scrollbar': (0.8, 0.8, 0.8, 1),
'threeddarkshadow': (0.2, 0.2, 0.2, 1),
'threedface': (0.8, 0.8, 0.8, 1),
'threedhighlight': (1, 1, 1, 1),
'threedlightshadow': (0.2, 0.2, 0.2, 1),
'threedshadow': (0.2, 0.2, 0.2, 1),
'window': (0.8, 0.8, 0.8, 1),
'windowframe': (0.8, 0.8, 0.8, 1),
'windowtext': (0, 0, 0, 1),
'none': (0, 0, 0, 0),
'transparent': (0, 0, 0, 0),
}
RGBA = re.compile(r'rgba\((.+?)\)')
RGB = re.compile(r'rgb\((.+?)\)')
HEX_RRGGBB = re.compile('#[0-9a-f]{6}')
HEX_RGB = re.compile('#[0-9a-f]{3}')
def color(string, opacity=1):
"""Replace ``string`` representing a color by a RGBA tuple.
See http://www.w3.org/TR/SVG/types.html#DataTypeColor
"""
if not string:
return (0, 0, 0, 0)
string = string.strip().lower()
if string in COLORS:
r, g, b, a = COLORS[string]
return (r, g, b, a * opacity)
match = RGBA.search(string)
if match:
r, g, b, a = tuple(
float(i.strip(' %')) / 100 if '%' in i else float(i) / 255
for i in match.group(1).strip().split(','))
return (r, g, b, a * 255 * opacity)
match = RGB.search(string)
if match:
r, g, b = tuple(
float(i.strip(' %')) / 100 if '%' in i else float(i) / 255
for i in match.group(1).strip().split(','))
return (r, g, b, opacity)
match = HEX_RRGGBB.search(string)
if match:
plain_color = tuple(
int(value, 16) / 255 for value in (
string[1:3], string[3:5], string[5:7]))
return plain_color + (opacity,)
match = HEX_RGB.search(string)
if match:
plain_color = tuple(
int(value, 16) / 15 for value in (
string[1], string[2], string[3]))
return plain_color + (opacity,)
return (0, 0, 0, 1)
def negate_color(rgba_tuple):
"""Replace ``rgba_tuple`` with its complementary color."""
r, g, b, a = rgba_tuple
return (1 - r, 1 - g, 1 - b, a)
CairoSVG-2.7.1/cairosvg/css.py 0000664 0000000 0000000 00000007675 14463407374 0016150 0 ustar 00root root 0000000 0000000 """
Handle CSS stylesheets.
"""
import cssselect2
import tinycss2
from .url import parse_url
def find_stylesheets(tree):
"""Find the stylesheets included in ``tree``."""
# TODO: support contentStyleType on
CairoSVG-2.7.1/test_non_regression/fail/draft/paths-data-20-f.png 0000664 0000000 0000000 00000015312 14463407374 0024456 0 ustar 00root root 0000000 0000000 PNG
IHDR h 7( cHRM z&