Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
c82da85e
Commit
c82da85e
authored
Apr 24, 2013
by
Gary Hodgson
Committed by
Guillaume Seguin
May 30, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
formatting of code
parent
a5281465
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
20 additions
and
20 deletions
+20
-20
__init__.py
printrun/cairosvg/__init__.py
+5
-5
parser.py
printrun/cairosvg/parser.py
+3
-3
__init__.py
printrun/cairosvg/surface/__init__.py
+2
-2
colors.py
printrun/cairosvg/surface/colors.py
+1
-1
defs.py
printrun/cairosvg/surface/defs.py
+3
-3
helpers.py
printrun/cairosvg/surface/helpers.py
+2
-2
image.py
printrun/cairosvg/surface/image.py
+2
-2
shapes.py
printrun/cairosvg/surface/shapes.py
+1
-1
units.py
printrun/cairosvg/surface/units.py
+1
-1
No files found.
printrun/cairosvg/__init__.py
View file @
c82da85e
...
@@ -29,7 +29,7 @@ from . import surface
...
@@ -29,7 +29,7 @@ from . import surface
VERSION
=
'0.4.4'
VERSION
=
'0.4.4'
SURFACES
=
{
SURFACES
=
{
'SVG'
:
surface
.
SVGSurface
,
# Tell us if you actually use this one!
'SVG'
:
surface
.
SVGSurface
,
# Tell us if you actually use this one!
'PNG'
:
surface
.
PNGSurface
,
'PNG'
:
surface
.
PNGSurface
,
'PDF'
:
surface
.
PDFSurface
,
'PDF'
:
surface
.
PDFSurface
,
'PS'
:
surface
.
PSSurface
}
'PS'
:
surface
.
PSSurface
}
...
@@ -52,14 +52,14 @@ def main():
...
@@ -52,14 +52,14 @@ def main():
"""Entry-point of the executable."""
"""Entry-point of the executable."""
# Get command-line options
# Get command-line options
option_parser
=
optparse
.
OptionParser
(
option_parser
=
optparse
.
OptionParser
(
usage
=
"usage:
%
prog filename [options]"
,
version
=
VERSION
)
usage
=
"usage:
%
prog filename [options]"
,
version
=
VERSION
)
option_parser
.
add_option
(
option_parser
.
add_option
(
"-f"
,
"--format"
,
help
=
"output format"
)
"-f"
,
"--format"
,
help
=
"output format"
)
option_parser
.
add_option
(
option_parser
.
add_option
(
"-d"
,
"--dpi"
,
help
=
"svg resolution"
,
default
=
96
)
"-d"
,
"--dpi"
,
help
=
"svg resolution"
,
default
=
96
)
option_parser
.
add_option
(
option_parser
.
add_option
(
"-o"
,
"--output"
,
"-o"
,
"--output"
,
default
=
""
,
help
=
"output filename"
)
default
=
""
,
help
=
"output filename"
)
options
,
args
=
option_parser
.
parse_args
()
options
,
args
=
option_parser
.
parse_args
()
# Print help if no argument is given
# Print help if no argument is given
...
...
printrun/cairosvg/parser.py
View file @
c82da85e
...
@@ -79,7 +79,7 @@ def remove_svg_namespace(tree):
...
@@ -79,7 +79,7 @@ def remove_svg_namespace(tree):
class
Node
(
dict
):
class
Node
(
dict
):
"""SVG node with dict-like properties and children."""
"""SVG node with dict-like properties and children."""
def
__init__
(
self
,
node
,
parent
=
None
):
def
__init__
(
self
,
node
,
parent
=
None
):
"""Create the Node from ElementTree ``node``, with ``parent`` Node."""
"""Create the Node from ElementTree ``node``, with ``parent`` Node."""
super
(
Node
,
self
)
.
__init__
()
super
(
Node
,
self
)
.
__init__
()
self
.
children
=
()
self
.
children
=
()
...
@@ -145,11 +145,11 @@ class Node(dict):
...
@@ -145,11 +145,11 @@ class Node(dict):
children
=
[]
children
=
[]
for
child
in
node
:
for
child
in
node
:
children
.
append
(
Node
(
child
,
parent
=
self
))
children
.
append
(
Node
(
child
,
parent
=
self
))
if
child
.
tail
:
if
child
.
tail
:
anonymous
=
ElementTree
.
Element
(
'tspan'
)
anonymous
=
ElementTree
.
Element
(
'tspan'
)
anonymous
.
text
=
child
.
tail
anonymous
.
text
=
child
.
tail
children
.
append
(
Node
(
anonymous
,
parent
=
self
))
children
.
append
(
Node
(
anonymous
,
parent
=
self
))
return
list
(
children
)
return
list
(
children
)
...
...
printrun/cairosvg/surface/__init__.py
View file @
c82da85e
...
@@ -50,7 +50,7 @@ class Surface(object):
...
@@ -50,7 +50,7 @@ class Surface(object):
surface_class
=
None
surface_class
=
None
@
classmethod
@
classmethod
def
convert
(
cls
,
bytestring
=
None
,
**
kwargs
):
def
convert
(
cls
,
bytestring
=
None
,
**
kwargs
):
"""Convert a SVG document to the format for this class.
"""Convert a SVG document to the format for this class.
Specify the input by passing one of these:
Specify the input by passing one of these:
...
@@ -172,7 +172,7 @@ class Surface(object):
...
@@ -172,7 +172,7 @@ class Surface(object):
"""Draw the root ``node``."""
"""Draw the root ``node``."""
self
.
draw
(
node
)
self
.
draw
(
node
)
def
draw
(
self
,
node
,
stroke_and_fill
=
True
):
def
draw
(
self
,
node
,
stroke_and_fill
=
True
):
"""Draw ``node`` and its children."""
"""Draw ``node`` and its children."""
old_font_size
=
self
.
font_size
old_font_size
=
self
.
font_size
self
.
font_size
=
size
(
self
,
node
.
get
(
"font-size"
,
"12pt"
))
self
.
font_size
=
size
(
self
,
node
.
get
(
"font-size"
,
"12pt"
))
...
...
printrun/cairosvg/surface/colors.py
View file @
c82da85e
...
@@ -200,7 +200,7 @@ COLORS = {
...
@@ -200,7 +200,7 @@ COLORS = {
"windowtext"
:
"#000000"
}
"windowtext"
:
"#000000"
}
def
color
(
string
=
None
,
opacity
=
1
):
def
color
(
string
=
None
,
opacity
=
1
):
"""Replace ``string`` representing a color by a RGBA tuple."""
"""Replace ``string`` representing a color by a RGBA tuple."""
if
not
string
or
string
in
(
"none"
,
"transparent"
):
if
not
string
or
string
in
(
"none"
,
"transparent"
):
return
(
0
,
0
,
0
,
0
)
return
(
0
,
0
,
0
,
0
)
...
...
printrun/cairosvg/surface/defs.py
View file @
c82da85e
...
@@ -107,7 +107,7 @@ def draw_gradient(surface, node, name):
...
@@ -107,7 +107,7 @@ def draw_gradient(surface, node, name):
if
gradient_node
.
get
(
"gradientUnits"
)
!=
"userSpaceOnUse"
:
if
gradient_node
.
get
(
"gradientUnits"
)
!=
"userSpaceOnUse"
:
gradient_pattern
.
set_matrix
(
cairo
.
Matrix
(
gradient_pattern
.
set_matrix
(
cairo
.
Matrix
(
1
/
width
,
0
,
0
,
1
/
height
,
-
x
/
width
,
-
y
/
height
))
1
/
width
,
0
,
0
,
1
/
height
,
-
x
/
width
,
-
y
/
height
))
gradient_pattern
.
set_extend
(
getattr
(
gradient_pattern
.
set_extend
(
getattr
(
cairo
,
"EXTEND_
%
s"
%
node
.
get
(
"spreadMethod"
,
"pad"
)
.
upper
()))
cairo
,
"EXTEND_
%
s"
%
node
.
get
(
"spreadMethod"
,
"pad"
)
.
upper
()))
...
@@ -141,7 +141,7 @@ def draw_pattern(surface, name):
...
@@ -141,7 +141,7 @@ def draw_pattern(surface, name):
surface
.
context
.
set_source
(
pattern_pattern
)
surface
.
context
.
set_source
(
pattern_pattern
)
def
draw_marker
(
surface
,
node
,
position
=
"mid"
):
def
draw_marker
(
surface
,
node
,
position
=
"mid"
):
"""Draw a marker."""
"""Draw a marker."""
# TODO: manage markers for other tags than path
# TODO: manage markers for other tags than path
if
position
==
"start"
:
if
position
==
"start"
:
...
@@ -229,7 +229,7 @@ def use(surface, node):
...
@@ -229,7 +229,7 @@ def use(surface, node):
del
node
[
"viewBox"
]
del
node
[
"viewBox"
]
href
=
node
.
get
(
"{http://www.w3.org/1999/xlink}href"
)
href
=
node
.
get
(
"{http://www.w3.org/1999/xlink}href"
)
url
=
list
(
urls
(
href
))[
0
]
url
=
list
(
urls
(
href
))[
0
]
tree
=
Tree
(
url
=
url
,
parent
=
node
)
tree
=
Tree
(
url
=
url
,
parent
=
node
)
surface
.
set_context_size
(
*
node_format
(
surface
,
tree
))
surface
.
set_context_size
(
*
node_format
(
surface
,
tree
))
surface
.
draw
(
tree
)
surface
.
draw
(
tree
)
surface
.
context
.
restore
()
surface
.
context
.
restore
()
...
...
printrun/cairosvg/surface/helpers.py
View file @
c82da85e
...
@@ -68,7 +68,7 @@ def node_format(surface, node):
...
@@ -68,7 +68,7 @@ def node_format(surface, node):
return
width
,
height
,
viewbox
return
width
,
height
,
viewbox
def
normalize
(
string
=
None
):
def
normalize
(
string
=
None
):
"""Normalize a string corresponding to an array of various values."""
"""Normalize a string corresponding to an array of various values."""
string
=
string
.
replace
(
"-"
,
" -"
)
string
=
string
.
replace
(
"-"
,
" -"
)
string
=
string
.
replace
(
","
,
" "
)
string
=
string
.
replace
(
","
,
" "
)
...
@@ -91,7 +91,7 @@ def normalize(string=None):
...
@@ -91,7 +91,7 @@ def normalize(string=None):
return
string
.
strip
()
return
string
.
strip
()
def
point
(
surface
,
string
=
None
):
def
point
(
surface
,
string
=
None
):
"""Return ``(x, y, trailing_text)`` from ``string``."""
"""Return ``(x, y, trailing_text)`` from ``string``."""
if
not
string
:
if
not
string
:
return
(
0
,
0
,
""
)
return
(
0
,
0
,
""
)
...
...
printrun/cairosvg/surface/image.py
View file @
c82da85e
...
@@ -56,7 +56,7 @@ def open_data_url(url):
...
@@ -56,7 +56,7 @@ def open_data_url(url):
if
header
:
if
header
:
semi
=
header
.
rfind
(
";"
)
semi
=
header
.
rfind
(
";"
)
if
semi
>=
0
and
"="
not
in
header
[
semi
:]:
if
semi
>=
0
and
"="
not
in
header
[
semi
:]:
encoding
=
header
[
semi
+
1
:]
encoding
=
header
[
semi
+
1
:]
else
:
else
:
encoding
=
""
encoding
=
""
else
:
else
:
...
@@ -110,7 +110,7 @@ def image(surface, node):
...
@@ -110,7 +110,7 @@ def image(surface, node):
del
node
[
"y"
]
del
node
[
"y"
]
if
"viewBox"
in
node
:
if
"viewBox"
in
node
:
del
node
[
"viewBox"
]
del
node
[
"viewBox"
]
tree
=
Tree
(
bytestring
=
image_bytes
)
tree
=
Tree
(
bytestring
=
image_bytes
)
tree_width
,
tree_height
,
viewbox
=
node_format
(
surface
,
tree
)
tree_width
,
tree_height
,
viewbox
=
node_format
(
surface
,
tree
)
if
not
tree_width
or
not
tree_height
:
if
not
tree_width
or
not
tree_height
:
tree_width
=
tree
[
"width"
]
=
width
tree_width
=
tree
[
"width"
]
=
width
...
...
printrun/cairosvg/surface/shapes.py
View file @
c82da85e
...
@@ -49,7 +49,7 @@ def ellipse(surface, node):
...
@@ -49,7 +49,7 @@ def ellipse(surface, node):
surface
.
context
.
scale
(
1
,
ratio
)
surface
.
context
.
scale
(
1
,
ratio
)
surface
.
context
.
arc
(
surface
.
context
.
arc
(
size
(
surface
,
node
.
get
(
"x"
),
"x"
)
+
size
(
surface
,
node
.
get
(
"cx"
),
"x"
),
size
(
surface
,
node
.
get
(
"x"
),
"x"
)
+
size
(
surface
,
node
.
get
(
"cx"
),
"x"
),
(
size
(
surface
,
node
.
get
(
"y"
),
"y"
)
+
(
size
(
surface
,
node
.
get
(
"y"
),
"y"
)
+
size
(
surface
,
node
.
get
(
"cy"
),
"y"
))
/
ratio
,
size
(
surface
,
node
.
get
(
"cy"
),
"y"
))
/
ratio
,
size
(
surface
,
node
.
get
(
"rx"
),
"x"
),
0
,
2
*
pi
)
size
(
surface
,
node
.
get
(
"rx"
),
"x"
),
0
,
2
*
pi
)
surface
.
context
.
restore
()
surface
.
context
.
restore
()
...
...
printrun/cairosvg/surface/units.py
View file @
c82da85e
...
@@ -30,7 +30,7 @@ UNITS = {
...
@@ -30,7 +30,7 @@ UNITS = {
"px"
:
None
}
"px"
:
None
}
def
size
(
surface
,
string
,
reference
=
"xy"
):
def
size
(
surface
,
string
,
reference
=
"xy"
):
"""Replace a ``string`` with units by a float value.
"""Replace a ``string`` with units by a float value.
If ``reference`` is a float, it is used as reference for percentages. If it
If ``reference`` is a float, it is used as reference for percentages. If it
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment