/
opt
/
alt
/
python27
/
lib
/
python2.7
/
site-packages
/
svgwrite
/
/opt/alt/python27/lib/python2.7/site-packages/svgwrite
mkdir
upload
Name
Size
Mode
Actions
data/
-
0755
rm
animate.py
6630
0644
edit
dl
rm
animate.pyc
7791
0644
edit
dl
rm
animate.pyo
7791
0644
edit
dl
rm
base.py
8064
0644
edit
dl
rm
base.pyc
10016
0644
edit
dl
rm
base.pyo
10016
0644
edit
dl
rm
container.py
9022
0644
edit
dl
rm
container.pyc
10945
0644
edit
dl
rm
container.pyo
10945
0644
edit
dl
rm
drawing.py
4344
0644
edit
dl
rm
drawing.pyc
4940
0644
edit
dl
rm
drawing.pyo
4940
0644
edit
dl
rm
elementfactory.py
2199
0644
edit
dl
rm
elementfactory.pyc
2964
0644
edit
dl
rm
elementfactory.pyo
2964
0644
edit
dl
rm
etree.py
1361
0644
edit
dl
rm
etree.pyc
1300
0644
edit
dl
rm
etree.pyo
1300
0644
edit
dl
rm
filters.py
7899
0644
edit
dl
rm
filters.pyc
13655
0644
edit
dl
rm
filters.pyo
13655
0644
edit
dl
rm
gradients.py
4719
0644
edit
dl
rm
gradients.pyc
6030
0644
edit
dl
rm
gradients.pyo
6030
0644
edit
dl
rm
image.py
2445
0644
edit
dl
rm
image.pyc
3021
0644
edit
dl
rm
image.pyo
3021
0644
edit
dl
rm
masking.py
1827
0644
edit
dl
rm
masking.pyc
2293
0644
edit
dl
rm
masking.pyo
2293
0644
edit
dl
rm
mixins.py
10446
0644
edit
dl
rm
mixins.pyc
13041
0644
edit
dl
rm
mixins.pyo
13041
0644
edit
dl
rm
params.py
1880
0644
edit
dl
rm
params.pyc
2791
0644
edit
dl
rm
params.pyo
2791
0644
edit
dl
rm
path.py
3591
0644
edit
dl
rm
path.pyc
3743
0644
edit
dl
rm
path.pyo
3743
0644
edit
dl
rm
pattern.py
1950
0644
edit
dl
rm
pattern.pyc
2347
0644
edit
dl
rm
pattern.pyo
2347
0644
edit
dl
rm
shapes.py
5858
0644
edit
dl
rm
shapes.pyc
6756
0644
edit
dl
rm
shapes.pyo
6756
0644
edit
dl
rm
text.py
8129
0644
edit
dl
rm
text.pyc
9729
0644
edit
dl
rm
text.pyo
9729
0644
edit
dl
rm
utils.py
6218
0644
edit
dl
rm
utils.pyc
7544
0644
edit
dl
rm
utils.pyo
7544
0644
edit
dl
rm
validator2.py
6073
0644
edit
dl
rm
validator2.pyc
7112
0644
edit
dl
rm
validator2.pyo
7112
0644
edit
dl
rm
__init__.py
2449
0644
edit
dl
rm
__init__.pyc
3226
0644
edit
dl
rm
__init__.pyo
3226
0644
edit
dl
rm
Edit:
/opt/alt/python27/lib/python2.7/site-packages/svgwrite/utils.py
(6218B)
#coding:utf-8 # Author: mozman # Purpose: svg util functions and classes # Created: 08.09.2010 # Copyright (C) 2010, Manfred Moitzi # License: MIT License """ .. autofunction:: rgb .. autofunction:: iterflatlist .. autofunction:: strlist .. autofunction:: get_unit .. autofunction:: split_coordinate .. autofunction:: split_angle .. autofunction:: rect_top_left_corner """ import sys PYTHON3 = sys.version_info[0] > 2 from functools import partial # Python 3 adaption if PYTHON3: to_unicode = str basestring = str else: def to_unicode(value): return unicode(value, encoding='utf8') if isinstance(value, str) else unicode(value) # Python 3 adaption def is_string(value): return isinstance(value, basestring) from svgwrite.data import pattern def rgb(r=0, g=0, b=0, mode='RGB'): """ Convert **r**, **g**, **b** values to a `string`. :param r: red part :param g: green part :param b: blue part :param string mode: ``'RGB | %'`` :rtype: string ========= ============================================================= mode Description ========= ============================================================= ``'RGB'`` returns a rgb-string format: ``'rgb(r, g, b)'`` ``'%'`` returns percent-values as rgb-string format: ``'rgb(r%, g%, b%)'`` ========= ============================================================= """ def percent(value): value = int(value) if value < 0: value = 0 if value > 100: value = 100 return value if mode.upper() == 'RGB': return "rgb(%d,%d,%d)" % (int(r) & 255, int(g) & 255, int(b) & 255) elif mode == "%": # see http://www.w3.org/TR/SVG11/types.html#DataTypeColor # percentage is an 'integer' value return "rgb(%d%%,%d%%,%d%%)" % (percent(r), percent(g), percent(b)) else: raise ValueError("Invalid mode '%s'" % mode) def iterflatlist(values): """ Flatten nested *values*, returns an `iterator`. """ for element in values: if hasattr(element, "__iter__") and not is_string(element): for item in iterflatlist(element): yield item else: yield element def strlist(values, seperator=","): """ Concatenate **values** with **sepertator**, `None` values will be excluded. :param values: `iterable` object :returns: `string` """ if is_string(values): return values else: return seperator.join([str(value) for value in iterflatlist(values) if value is not None]) def get_unit(coordinate): """ Get the `unit` identifier of **coordinate**, if **coordinate** has a valid `unit` identifier appended, else returns `None`. """ if isinstance(coordinate, (int, float)): return None result = pattern.coordinate.match(coordinate) if result: return result.group(3) else: raise ValueError("Invalid format: '%s'" % coordinate) def split_coordinate(coordinate): """ Split coordinate into `<number>` and 'unit` identifier. :returns: <2-tuple> (number, unit-identifier) or (number, None) if no unit-identifier is present or coordinate is an int or float. """ if isinstance(coordinate, (int, float)): return (float(coordinate), None) result = pattern.coordinate.match(coordinate) if result: return (float(result.group(1)), result.group(3)) else: raise ValueError("Invalid format: '%s'" % coordinate) def split_angle(angle): """ Split angle into `<number>` and `<angle>` identifier. :returns: <2-tuple> (number, angle-identifier) or (number, None) if no angle-identifier is present or angle is an int or float. """ if isinstance(angle, (int, float)): return (float(angle), None) result = pattern.angle.match(angle) if result: return (float(result.group(1)), result.group(3)) else: raise ValueError("Invalid format: '%s'" % angle) def rect_top_left_corner(insert, size, pos='top-left'): """ Calculate top-left corner of a rectangle. **insert** and **size** must have the same units. :param 2-tuple insert: insert point :param 2-tuple size: (width, height) :param string pos: insert position ``'vert-horiz'`` :return: ``'top-left'`` corner of the rect :rtype: 2-tuple ========== ============================== pos valid values ========== ============================== **vert** ``'top | middle | bottom'`` **horiz** ``'left'|'center'|'right'`` ========== ============================== """ vert, horiz = pos.lower().split('-') x, xunit = split_coordinate(insert[0]) y, yunit = split_coordinate(insert[1]) width, wunit = split_coordinate(size[0]) height, hunit = split_coordinate(size[1]) if xunit != wunit: raise ValueError("x-coordinate and width has to have the same unit") if yunit != hunit: raise ValueError("y-coordinate and height has to have the same unit") if horiz == 'center': x = x - width / 2. elif horiz == 'right': x = x - width elif horiz != 'left': raise ValueError("Invalid horizontal position: '%s'" % horiz) if vert == 'middle': y = y - height / 2. elif vert == 'bottom': y = y - height elif vert != 'top': raise ValueError("Invalid vertical position: '%s'" % vert) if xunit: x = "%s%s" %(x, xunit) if yunit: y = "%s%s" %(y, yunit) return (x, y) class AutoID(object): _nextid = 1 def __init__(self, value=None): self._set_value(value) @classmethod def _set_value(cls, value=None): if value is not None: cls._nextid = value @classmethod def next_id(cls, value=None): cls._set_value(value) retval = "id%d" % cls._nextid cls._nextid += 1 return retval
Save
cmd:
run