本文整理汇总了Python中simplestyle.parseColor函数的典型用法代码示例。如果您正苦于以下问题:Python parseColor函数的具体用法?Python parseColor怎么用?Python parseColor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseColor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decode_vector
def decode_vector(self, img):
self.data = [None] * (self.size ** 2)
self.transform = img.attrib['transform']
self.pos = (float('inf'), float('inf'))
pixels = img.xpath('//svg:rect', namespaces=inkex.NSS)
paths = img.xpath('//svg:path', namespaces=inkex.NSS)
# Because svg groups have no set x,y coords we have to decern the
# position from the contents which we can then use as an offset when
# reconstructing the image.
for pixel in pixels + paths:
pos = (inkex.unittouu(pixel.attrib['x']),
inkex.unittouu(pixel.attrib['y']))
self.pos[0] = self.pos[0] if self.pos[0] < pos[0] else pos[0]
self.pos[1] = self.pos[1] if self.pos[1] < pos[1] else pos[1]
for pixel in pixels:
style = simplestyle.parseStyle(pixel.attrib['style'])
pos = (inkex.unittouu(pixel.attrib['x']) - self.pos[0],
inkex.unittouu(pixel.attrib['y']) - self.pos[1])
index = pos2index(self.size, *pos)
self.data[index] = simplestyle.parseColor(style['fill'])
last_point = (0, 0)
for path in paths:
for offset in re.findall('m\s(?P<x>-?\d+),(?P<y>-?\d+).*?z'):
style = simplestyle.parseStyle(pixel.attrib['style'])
pos = (inkex.unittouu(path.attrib['x']) - self.pos[0] + last_point[0],
inkex.unittouu(path.attrib['y']) - self.pos[1] + last_point[1])
index = pos2index(self.size, *pos)
self.data[index] = simplestyle.parseColor(style['fill'])
last_point[0] += offset[0]
last_point[1] += offset[1]
示例2: representK
def representK(value):
# returns CMS color if available
if ( re.search("icc-color", value.group()) ):
return simplestyle.formatColor3f(float(1.00 - float(re.split('[,\)\s]+',value.group())[5])), float(1.00 - float(re.split('[,\)\s]+',value.group())[5])), float(1.00 - float(re.split('[,\)\s]+',value.group())[5])))
red = float(simplestyle.parseColor(str(value.group()))[0]/255.00)
green = float(simplestyle.parseColor(str(value.group()))[1]/255.00)
blue = float(simplestyle.parseColor(str(value.group()))[2]/255.00)
return simplestyle.formatColor3f(float(1.00 - calculateCMYK(red, green, blue)[3]), float(1.00 - calculateCMYK(red, green, blue)[3]), float(1.00 - calculateCMYK(red, green, blue)[3]))
示例3: process_shape
def process_shape(self, node, mat):
rgb = (0,0,0) # stroke color
fillcolor = None # fill color
stroke = 1 # pen width in printer pixels
# Very NB : If the pen width is greater than 1 then the output will Not be a vector output !
style = node.get('style')
if style:
style = simplestyle.parseStyle(style)
if style.has_key('stroke'):
if style['stroke'] and style['stroke'] != 'none' and style['stroke'][0:3] != 'url':
rgb = simplestyle.parseColor(style['stroke'])
if style.has_key('stroke-width'):
stroke = self.unittouu(style['stroke-width'])
stroke = int(stroke*self.scale)
if style.has_key('fill'):
if style['fill'] and style['fill'] != 'none' and style['fill'][0:3] != 'url':
fill = simplestyle.parseColor(style['fill'])
fillcolor = fill[0] + 256*fill[1] + 256*256*fill[2]
color = rgb[0] + 256*rgb[1] + 256*256*rgb[2]
if node.tag == inkex.addNS('path','svg'):
d = node.get('d')
if not d:
return
p = cubicsuperpath.parsePath(d)
elif node.tag == inkex.addNS('rect','svg'):
x = float(node.get('x'))
y = float(node.get('y'))
width = float(node.get('width'))
height = float(node.get('height'))
p = [[[x, y],[x, y],[x, y]]]
p.append([[x + width, y],[x + width, y],[x + width, y]])
p.append([[x + width, y + height],[x + width, y + height],[x + width, y + height]])
p.append([[x, y + height],[x, y + height],[x, y + height]])
p.append([[x, y],[x, y],[x, y]])
p = [p]
else:
return
trans = node.get('transform')
if trans:
mat = simpletransform.composeTransform(mat, simpletransform.parseTransform(trans))
simpletransform.applyTransformToPath(mat, p)
hPen = mygdi.CreatePen(0, stroke, color)
mygdi.SelectObject(self.hDC, hPen)
self.emit_path(p)
if fillcolor is not None:
brush = LOGBRUSH(0, fillcolor, 0)
hBrush = mygdi.CreateBrushIndirect(addressof(brush))
mygdi.SelectObject(self.hDC, hBrush)
mygdi.BeginPath(self.hDC)
self.emit_path(p)
mygdi.EndPath(self.hDC)
mygdi.FillPath(self.hDC)
return
示例4: getColor
def getColor(self, rgb, a):
r, g, b = simplestyle.parseColor(rgb)
a = float(a)
if a < 1:
return "'rgba(%d, %d, %d, %.1f)'" % (r, g, b, a)
else:
return "'rgb(%d, %d, %d)'" % (r, g, b)
示例5: effect
def effect(self):
object2path.ObjectToPath.effect(self)
transformMatrix = [[1,0,0],[0,1,0]]
dims = self.determine_dims(transformMatrix)
[x,y,X,Y] = dims
width = X - x
height = Y - y
# Longest side is vertical
if width > height:
scale = 480.0 / height
if scale * width > 999.0:
inkex.errormsg("Plot area is to large (%f > 999)." % scale*height)
exit()
transformMatrix = parseTransform('translate(%f,%f)' % (-x,-y))
transformMatrix = composeTransform(parseTransform('rotate(-90)'), transformMatrix)
transformMatrix = composeTransform(parseTransform('scale(%f,%f)' % (scale,scale)), transformMatrix)
else:
scale = 480.0 / width
if scale * height > 999.0:
inkex.errormsg("Plot area is to large (%f > 999)." % scale*height)
exit()
transformMatrix = parseTransform('translate(%f,%f)' % (-x,-y))
transformMatrix = composeTransform(parseTransform('rotate(180)'), transformMatrix)
transformMatrix = composeTransform(parseTransform('translate(%f,0)' % width), transformMatrix)
transformMatrix = composeTransform(parseTransform('scale(%f,%f)' % (-scale,scale)), transformMatrix)
transformMatrix = composeTransform(parseTransform('translate(480,0)'), transformMatrix)
paths = []
for [path, node] in self.processPaths(transformMatrix):
color = (0, 0, 0)
style = node.get('style')
if style:
style = simplestyle.parseStyle(style)
if 'stroke' in style:
if style['stroke'] and style['stroke'] != 'none':
color = simplestyle.parseColor(style['stroke'])
points = []
for point in self.processPath(path):
points.append(point)
paths.append({'color':color, 'points':points})
dims = self.determine_dims(transformMatrix)
if self.options.debug:
print >>sys.stderr, "VC1520 debug info"
print >>sys.stderr, "-----------------"
print >>sys.stderr, "plot area: minX:%d, minY:%d, maxX:%d, maxY:%d" % tuple(dims)
print >>sys.stderr, "nr paths: %d" % len(paths)
i = 0
print >>sys.stderr, "path;color;points"
for path in paths:
print >>sys.stderr, "%d;%s;%d" % (i,self.find_color(path['color']),len(path['points']))
i += 1
for path in paths:
print >>sys.stderr, path
else:
self.plot(paths, dims[1])
示例6: parse_color
def parse_color(self, color_text):
"""Parse the color text input from the extension dialog."""
try:
if color_text and color_text.lower() != 'none':
return simplestyle.formatColoria(simplestyle.parseColor(color_text))
except:
pass
return 'none'
示例7: process_shape
def process_shape(self, node, mat):
rgb = (0,0,0)
style = node.get('style')
if style:
style = simplestyle.parseStyle(style)
if style.has_key('stroke'):
if style['stroke'] and style['stroke'] != 'none' and style['stroke'][0:3] != 'url':
rgb = simplestyle.parseColor(style['stroke'])
hsl = coloreffect.ColorEffect.rgb_to_hsl(coloreffect.ColorEffect(),rgb[0]/255.0,rgb[1]/255.0,rgb[2]/255.0)
self.closed = 0 # only for LWPOLYLINE
self.color = 7 # default is black
if hsl[2]:
#self.color = 1 + (int(6*hsl[0] + 0.5) % 6) # use 6 hues
self.color = 1 + (int(10*hsl[0] + 0.5) % 10) # use 6 hues
if node.tag == inkex.addNS('path','svg'):
d = node.get('d')
if not d:
return
if (d[-1] == 'z' or d[-1] == 'Z'):
self.closed = 1
p = cubicsuperpath.parsePath(d)
elif node.tag == inkex.addNS('rect','svg'):
self.closed = 1
x = float(node.get('x'))
y = float(node.get('y'))
width = float(node.get('width'))
height = float(node.get('height'))
p = [[[x, y],[x, y],[x, y]]]
p.append([[x + width, y],[x + width, y],[x + width, y]])
p.append([[x + width, y + height],[x + width, y + height],[x + width, y + height]])
p.append([[x, y + height],[x, y + height],[x, y + height]])
p.append([[x, y],[x, y],[x, y]])
p = [p]
else:
return
trans = node.get('transform')
if trans:
mat = simpletransform.composeTransform(mat, simpletransform.parseTransform(trans))
simpletransform.applyTransformToPath(mat, p)
for sub in p:
for i in range(len(sub)-1):
s = sub[i]
e = sub[i+1]
if s[1] == s[2] and e[0] == e[1]:
if (self.options.POLY == 'true'):
self.LWPOLY_line([s[1],e[1]])
else:
self.dxf_line([s[1],e[1]])
elif (self.options.ROBO == 'true'):
self.ROBO_spline([s[1],s[2],e[0],e[1]])
else:
self.dxf_spline([s[1],s[2],e[0],e[1]])
示例8: extract_color
def extract_color(style, color_attrib, *opacity_attribs):
if color_attrib in style.keys():
if style[color_attrib] == "none":
return [1, 1, 1, 0]
c = simplestyle.parseColor(style[color_attrib])
else:
c = (0, 0, 0)
# Convert color scales and adjust gamma
color = [pow(c[0] / 255.0, sif.gamma), pow(c[1] / 255.0, sif.gamma), pow(c[2] / 255.0, sif.gamma), 1.0]
for opacity in opacity_attribs:
if opacity in style.keys():
color[3] = color[3] * float(style[opacity])
return color
示例9: process_prop
def process_prop(self,col):
#debug('got:'+col)
if simplestyle.isColor(col):
c=simplestyle.parseColor(col)
col='#'+self.colmod(c[0],c[1],c[2])
#debug('made:'+col)
# if col.startswith('url(#'):
# id = col[len('url(#'):col.find(')')]
# newid = '%s-%d' % (id, int(random.random() * 1000))
# #inkex.debug('ID:' + id )
# path = '//*[@id="%s"]' % id
# for node in self.document.xpath(path, namespaces=inkex.NSS):
# self.process_gradient(node, newid)
# col = 'url(#%s)' % newid
return col
示例10: process_prop
def process_prop(self,col):
#debug('got:'+col)
if simplestyle.isColor(col):
c=simplestyle.parseColor(col)
col='#'+self.colmod(c[0],c[1],c[2])
#debug('made:'+col)
if col.startswith('url(#'):
id = col[len('url(#'):col.find(')')]
newid = '%s-%d' % (id, int(random.random() * 1000))
#inkex.debug('ID:' + id )
path = '//*[@id="%s"]' % id
for node in xml.xpath.Evaluate(path,self.document):
self.process_gradient(node, newid)
col = 'url(#%s)' % newid
return col
示例11: process_prop
def process_prop(self, col, hsbcoeffs, hsbo_cf):
#debug('got:'+col)
if simplestyle.isColor(col):
c=simplestyle.parseColor(col)
col='#'+colmod(c[0],c[1],c[2], hsbcoeffs, hsbo_cf)
#debug('made:'+col)
if col.startswith('url(#'):
id = col[len('url(#'):col.find(')')]
newid = self.newid(self.svg_prefixfromtag(id))
#inkex.debug('ID:' + id )
path = '//*[@id="%s"]' % id
for node in self.document.xpath(path, namespaces=inkex.NSS):
process_gradient(self, node, newid, hsbcoeffs)
col = 'url(#%s)' % newid
return col
示例12: effect
def effect(self):
self.layersProcessed = []
self.paletteRGB = crayola_classic #in the future: Offer additional choices
for paintColor in self.paletteRGB:
c = simplestyle.parseColor(paintColor)
self.paletteYUV.append(self.rgbToYUV(c[0], c[1], c[2]))
self.layerLabels.append("layerNotFound")
self.scanForLayerNames(self.document.getroot()) #Recursively scan through document for named layers.
# inkex.errormsg('layerLabels: ' + str(self.layerLabels))
self.getAttribs(self.document.getroot()) #Recursively scan through file, snap & label things that have color attributes.
#If option is selected, try to move colors into layers. Requires that everything is UNGROUPED first. :D
if (self.options.snapLayers):
#Now, walk through the palette, adding any new named layers that are needed
for i in xrange(len(self.paletteRGB)):
if (self.layerLabels[i] == "layerNotFound"):
# Create a group <g> element under the document root
layer = inkex.etree.SubElement( self.document.getroot(), inkex.addNS( 'g', 'svg' ) )
# Add Inkscape layer attributes to this new group
layer.set( inkex.addNS('groupmode', 'inkscape' ), 'layer' )
layer.set( inkex.addNS( 'label', 'inkscape' ), crayola_classic_names[i] )
self.layerLabels[i] = crayola_classic_names[i]
for child in self.document.getroot():
# inkex.errormsg('wcb-color-layer: ' + str(child.get('wcb-color-layer')))
if ( child.get( inkex.addNS( 'groupmode', 'inkscape' ) ) == 'layer' ): #if it's a layer...
strLayerNameTmp = str(child.get(inkex.addNS( 'label', 'inkscape' )))
# inkex.errormsg('Layer Name: ' + strLayerNameTmp)
if (strLayerNameTmp in self.layerLabels):
#this is one of the named layers that we're using.
layerNumberInt = self.layerLabels.index(strLayerNameTmp)
if not (strLayerNameTmp in self.layersProcessed):
self.layersProcessed.append(strLayerNameTmp)
# inkex.errormsg('Processed Layer Name: ' + strLayerNameTmp)
self.MoveColoredNodes(self.document.getroot(), child, layerNumberInt)
示例13: process_prop
def process_prop(self, col):
#inkex.debug('got:'+col+str(type(col)))
if simplestyle.isColor(col):
c=simplestyle.parseColor(col)
col='#'+self.colmod(c[0], c[1], c[2])
#inkex.debug('made:'+col)
elif col.startswith('url(#'):
id = col[len('url(#'):col.find(')')]
newid = '%s-%d' % (id, int(random.random() * 1000))
#inkex.debug('ID:' + id )
path = '//*[@id="%s"]' % id
for node in self.document.xpath(path, namespaces=inkex.NSS):
self.process_gradient(node, newid)
col = 'url(#%s)' % newid
# what remains should be opacity
else:
col = self.opacmod(col)
#inkex.debug('col:'+str(col))
return col
示例14: test_hexcolor3digit
def test_hexcolor3digit(self):
"Parse '#fff'"
col = parseColor("#fff")
self.failUnlessEqual((255, 255, 255), col)
示例15: effect
def effect(self):
object2path.ObjectToPath.effect(self)
self.dxf += self.dxf_add_codes([('999', 'Inkscape export via OpenSCAD DXF Export')])
self.dxf += dxf_templates.r14_header
scale = 25.4/90.0
h = self.unittouu(self.document.getroot().xpath('@height',namespaces=inkex.NSS)[0])
path = '//svg:path'
pm = pathmodifier.PathModifier()
layers = []
dxf_body = ''
for node in self.document.getroot().xpath(path,namespaces=inkex.NSS):
pm.objectToPath(node, True)
layer = node.getparent().get(inkex.addNS('label', 'inkscape'))
if layer == None:
layer = 'Layer 1'
layer = layer.replace(' ', '_')
if layer not in layers:
layers.append(layer)
self.layer_dims[layer] = {
'minX':None,
'minY':None,
'maxX':None,
'maxY':None
}
d = node.get('d')
color = (0,0,0)
style = node.get('style')
if style:
style = simplestyle.parseStyle(style)
if style.has_key('stroke'):
if style['stroke'] and style['stroke'] != 'none':
color = simplestyle.parseColor(style['stroke'])
p = cubicsuperpath.parsePath(d)
t = node.get('transform')
if t != None:
m = simpletransform.parseTransform(t)
simpletransform.applyTransformToPath(m,p)
m = [[scale,0,0],[0,-scale,h*scale]]
simpletransform.applyTransformToPath(m,p)
dxf_body += self.dxf_path_to_lines(layer, p, color)
self.dxf += self.dxf_add_codes([
('0', 'TABLE'),
('2', 'LAYER'),
('5', '2'),
('330', '0'),
('100', 'AcDbSymbolTable'),
# group code 70 tells a reader how many table records to expect (e.g. pre-allocate memory for).
# It must be greater or equal to the actual number of records
('70', str(len(layers)))
])
# Add dimensions for total width and height
dxf_dims = self.dxf_add_dimension('total_width',
[self.global_dims['minX'], self.global_dims['maxX']])
dxf_dims += self.dxf_add_dimension('total_height',
None, [self.global_dims['minY'], self.global_dims['maxY']])
for layer in layers:
self.dxf += self.dxf_add_codes([
('0', 'LAYER'),
('5', '10'),
('330', '2'),
('100', 'AcDbSymbolTableRecord'),
('100', 'AcDbLayerTableRecord'),
('2', layer),
('70', '0'),
('62', '7'),
('6', 'CONTINUOUS')
])
# Add dimensions for layer width and height
dxf_dims += self.dxf_add_dimension(layer + '_width',
[self.layer_dims[layer]['minX'], self.layer_dims[layer]['maxX']], None, layer)
dxf_dims += self.dxf_add_dimension(layer + '_height',
None, [self.layer_dims[layer]['minY'], self.layer_dims[layer]['maxY']], layer)
self.dxf += self.dxf_add_codes([
('0', 'ENDTAB'),
('0', 'ENDSEC')
])
self.dxf += dxf_templates.r14_style
self.dxf += dxf_dims
self.dxf += dxf_body
self.dxf += dxf_templates.r14_footer