~danieljabailey/inkscape/arc_node_editor

« back to all changes in this revision

Viewing changes to share/extensions/coloreffect.py

  • Committer: tavmjong-free
  • Date: 2016-05-08 07:44:05 UTC
  • mfrom: (14873.1.1 gtk3)
  • Revision ID: tavmjong@free.fr-20160508074405-rm6tiapoq1ugamph
Start of GTK3 external style sheet support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import sys, copy, simplestyle, inkex
22
22
import random
23
23
 
24
 
color_props_fill = ('fill', 'stop-color',  'flood-color', 'lighting-color')
 
24
color_props_fill = ('fill', 'stop-color', 'flood-color', 'lighting-color')
25
25
color_props_stroke = ('stroke',)
26
 
opacity_props = ('opacity',) #'stop-opacity', 'fill-opacity', 'stroke-opacity' don't work with clones
27
26
color_props = color_props_fill + color_props_stroke
28
27
 
29
28
 
64
63
        #
65
64
        # The processing here is just something simple that should usually work,
66
65
        # without trying too hard to get everything right.
67
 
        # (Won't work for the pathological case that someone escapes a property
 
66
        # (Won't work for the pathalogical case that someone escapes a property
68
67
        # name, probably does the wrong thing if colon or semicolon is used inside
69
68
        # a comment or string value.)
70
69
        style = node.get('style') # fixme: this will break for presentation attributes!
71
70
        if style:
72
71
            #inkex.debug('old style:'+style)
73
72
            declarations = style.split(';')
74
 
            opacity_in_style = False
75
73
            for i,decl in enumerate(declarations):
76
74
                parts = decl.split(':', 2)
77
75
                if len(parts) == 2:
82
80
                        new_val = self.process_prop(val)
83
81
                        if new_val != val:
84
82
                            declarations[i] = prop + ':' + new_val
85
 
                    elif prop in opacity_props:
86
 
                        opacity_in_style = True
87
 
                        val = val.strip()
88
 
                        new_val = self.process_prop(val)
89
 
                        if new_val != val:
90
 
                            declarations[i] = prop + ':' + new_val
91
 
            if not opacity_in_style:
92
 
                new_val = self.process_prop("1")
93
 
                declarations.append('opacity' + ':' + new_val)
94
83
            #inkex.debug('new style:'+';'.join(declarations))
95
84
            node.set('style', ';'.join(declarations))
96
85
 
97
 
  def process_prop(self, col):
98
 
    #inkex.debug('got:'+col+str(type(col)))
 
86
  def process_prop(self,col):
 
87
    #debug('got:'+col)
99
88
    if simplestyle.isColor(col):
100
89
      c=simplestyle.parseColor(col)
101
 
      col='#'+self.colmod(c[0], c[1], c[2])
102
 
      #inkex.debug('made:'+col)
103
 
    elif col.startswith('url(#'):
 
90
      col='#'+self.colmod(c[0],c[1],c[2])
 
91
      #debug('made:'+col)
 
92
    if col.startswith('url(#'):
104
93
      id = col[len('url(#'):col.find(')')]
105
94
      newid = '%s-%d' % (id, int(random.random() * 1000))
106
95
      #inkex.debug('ID:' + id )
108
97
      for node in self.document.xpath(path, namespaces=inkex.NSS):
109
98
        self.process_gradient(node, newid)
110
99
      col = 'url(#%s)' % newid
111
 
    # what remains should be opacity
112
 
    else:
113
 
      col = self.opacmod(col)
114
 
      
115
 
    #inkex.debug('col:'+str(col))
116
100
    return col
117
101
 
118
102
  def process_gradient(self, node, newid):
144
128
 
145
129
  def colmod(self,r,g,b):
146
130
    pass
147
 
  
148
 
  def opacmod(self, opacity):
149
 
    return opacity
150
131
 
151
132
  def rgb_to_hsl(self,r, g, b):
152
133
    rgb_max = max (max (r, g), b)
207
188
        rgb[2] = self.hue_2_rgb (v1, v2, h*6 - 2.0)
208
189
    return rgb
209
190
 
210
 
  
211
191
# vi: set autoindent shiftwidth=2 tabstop=8 expandtab softtabstop=2 :