Skip to content

Commit

Permalink
tools: RGBA color support
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Clements committed Oct 27, 2013
1 parent b2350d4 commit 114816a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tools/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ def __fsAttrs(self, fill=None, stroke=None, stroke_width=None):
ats += ' fill="none"'
else:
ats += ' fill="%s"' % self.__rgb2css(fill)
if len(fill) == 4:
ats += ' fill-opacity="%g"' % fill[3]
if stroke is not None:
ats += ' stroke="%s"' % self.__rgb2css(stroke)
if len(stroke) == 4:
ats += ' stroke-opacity="%g"' % stroke[3]
if stroke_width is not None:
ats += ' stroke-width="%s"' % stroke_width
return ats

def __rgb2css(self, rgb):
r, g, b = rgb
r, g, b = rgb[:3]
return '#%02x%02x%02x' % (int(r * 255), int(g * 255), int(b * 255))

def translate(self, x, y):
Expand Down

0 comments on commit 114816a

Please sign in to comment.