/usr/lib/python2.7/dist-packages/pyx/style.py is in python-pyx 0.12.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | # -*- encoding: utf-8 -*-
#
#
# Copyright (C) 2002-2012 Jörg Lehmann <joergl@users.sourceforge.net>
# Copyright (C) 2003-2006 Michael Schindler <m-schindler@users.sourceforge.net>
# Copyright (C) 2002-2012 André Wobst <wobsta@users.sourceforge.net>
#
# This file is part of PyX (http://pyx.sourceforge.net/).
#
# PyX is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PyX 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyX; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import math
import attr, unit, canvasitem
import bbox as bboxmodule
#
# base classes for stroke and fill styles
#
class strokestyle(canvasitem.canvasitem):
def bbox(self):
# TODO: see TODO in bbox method of canvasitem
return bboxmodule.empty()
class fillstyle(canvasitem.canvasitem):
def bbox(self):
# TODO: see TODO in bbox method of canvasitem
return bboxmodule.empty()
#
# common stroke styles
#
class linecap(attr.exclusiveattr, strokestyle):
"""linecap of paths"""
def __init__(self, value=0):
attr.exclusiveattr.__init__(self, linecap)
self.value = value
def processPS(self, file, writer, context, registry, bbox):
file.write("%d setlinecap\n" % self.value)
def processPDF(self, file, writer, context, registry, bbox):
file.write("%d J\n" % self.value)
linecap.butt = linecap(0)
linecap.round = linecap(1)
linecap.square = linecap(2)
linecap.clear = attr.clearclass(linecap)
class linejoin(attr.exclusiveattr, strokestyle):
"""linejoin of paths"""
def __init__(self, value=0):
attr.exclusiveattr.__init__(self, linejoin)
self.value = value
def processPS(self, file, writer, context, registry, bbox):
file.write("%d setlinejoin\n" % self.value)
def processPDF(self, file, writer, context, registry, bbox):
file.write("%d j\n" % self.value)
linejoin.miter = linejoin(0)
linejoin.round = linejoin(1)
linejoin.bevel = linejoin(2)
linejoin.clear = attr.clearclass(linejoin)
class miterlimit(attr.exclusiveattr, strokestyle):
"""miterlimit of paths"""
def __init__(self, value=10.0):
attr.exclusiveattr.__init__(self, miterlimit)
self.value = value
def processPS(self, file, writer, context, registry, bbox):
file.write("%f setmiterlimit\n" % self.value)
def processPDF(self, file, writer, context, registry, bbox):
file.write("%f M\n" % self.value)
miterlimit.lessthan180deg = miterlimit(1/math.sin(math.pi*180/360))
miterlimit.lessthan90deg = miterlimit(1/math.sin(math.pi*90/360))
miterlimit.lessthan60deg = miterlimit(1/math.sin(math.pi*60/360))
miterlimit.lessthan45deg = miterlimit(1/math.sin(math.pi*45/360))
miterlimit.lessthan11deg = miterlimit(10) # the default, approximately 11.4783 degress
miterlimit.clear = attr.clearclass(miterlimit)
_defaultlinewidth = 0.02 * unit.w_cm
_defaultlinewidth_pt = unit.topt(_defaultlinewidth)
class dash(attr.exclusiveattr, strokestyle):
"""dash of paths"""
def __init__(self, pattern=[], offset=0, rellengths=1):
"""set pattern with offset.
If rellengths is True, interpret all dash lengths relative to current linewidth.
"""
attr.exclusiveattr.__init__(self, dash)
self.pattern = pattern
self.offset = offset
self.rellengths = rellengths
def processPS(self, file, writer, context, registry, bbox):
if self.rellengths:
patternstring = " ".join(["%f" % (element * context.linewidth_pt/_defaultlinewidth_pt) for element in self.pattern])
else:
patternstring = " ".join(["%f" % element for element in self.pattern])
file.write("[%s] %d setdash\n" % (patternstring, self.offset))
def processPDF(self, file, writer, context, registry, bbox):
if self.rellengths:
patternstring = " ".join(["%f" % (element * context.linewidth_pt/_defaultlinewidth_pt) for element in self.pattern])
else:
patternstring = " ".join(["%f" % element for element in self.pattern])
file.write("[%s] %d d\n" % (patternstring, self.offset))
dash.clear = attr.clearclass(dash)
class linestyle(attr.exclusiveattr, strokestyle):
"""linestyle (linecap together with dash) of paths"""
def __init__(self, c=linecap.butt, d=dash([])):
# XXX better, but at the moment not supported by attr.exlusiveattr would be:
# XXX attr.exclusiveattr.__init__(self, [linestyle, linecap, dash])
attr.exclusiveattr.__init__(self, linestyle)
self.c = c
self.d = d
def processPS(self, file, writer, context, registry, bbox):
self.c.processPS(file, writer, context, registry, bbox)
self.d.processPS(file, writer, context, registry, bbox)
def processPDF(self, file, writer, context, registry, bbox):
self.c.processPDF(file, writer, context, registry, bbox)
self.d.processPDF(file, writer, context, registry, bbox)
linestyle.solid = linestyle(linecap.butt, dash([]))
linestyle.dashed = linestyle(linecap.butt, dash([2]))
linestyle.dotted = linestyle(linecap.round, dash([0, 2]))
linestyle.dashdotted = linestyle(linecap.round, dash([0, 2, 2, 2]))
linestyle.clear = attr.clearclass(linestyle)
class linewidth(attr.sortbeforeexclusiveattr, strokestyle):
"""linewidth of paths"""
def __init__(self, width):
attr.sortbeforeexclusiveattr.__init__(self, linewidth, [dash, linestyle])
self.width = width
def processPS(self, file, writer, context, registry, bbox):
file.write("%f setlinewidth\n" % unit.topt(self.width))
context.linewidth_pt = unit.topt(self.width)
def processPDF(self, file, writer, context, registry, bbox):
file.write("%f w\n" % unit.topt(self.width))
context.linewidth_pt = unit.topt(self.width)
linewidth.THIN = linewidth(_defaultlinewidth/math.sqrt(32))
linewidth.THIn = linewidth(_defaultlinewidth/math.sqrt(16))
linewidth.THin = linewidth(_defaultlinewidth/math.sqrt(8))
linewidth.Thin = linewidth(_defaultlinewidth/math.sqrt(4))
linewidth.thin = linewidth(_defaultlinewidth/math.sqrt(2))
linewidth.normal = linewidth(_defaultlinewidth)
linewidth.thick = linewidth(_defaultlinewidth*math.sqrt(2))
linewidth.Thick = linewidth(_defaultlinewidth*math.sqrt(4))
linewidth.THick = linewidth(_defaultlinewidth*math.sqrt(8))
linewidth.THIck = linewidth(_defaultlinewidth*math.sqrt(16))
linewidth.THICk = linewidth(_defaultlinewidth*math.sqrt(32))
linewidth.THICK = linewidth(_defaultlinewidth*math.sqrt(64))
linewidth.clear = attr.clearclass(linewidth)
class fillrule(attr.exclusiveattr):
"""defines the fill rule to be used"""
def __init__(self, even_odd):
attr.exclusiveattr.__init__(self, fillrule)
self.even_odd = even_odd
def processPS(self, file, writer, context, registry, bbox):
pass
def processPDF(self, file, writer, context, registry, bbox):
pass
fillrule.nonzero_winding = fillrule(0)
fillrule.even_odd = fillrule(1)
fillrule.clear = attr.clearclass(fillrule)
|