diff --git a/src/mapcss/Rule.py b/src/mapcss/Rule.py index bc7b30e..3d44985 100644 --- a/src/mapcss/Rule.py +++ b/src/mapcss/Rule.py @@ -31,11 +31,14 @@ class Rule(): return "%s|z%s-%s %s"%(self.subject, self.minZoom, self.maxZoom, self.conditions) def test(self, obj, tags, zoom): - if not ((zoom >= self.minZoom) and (zoom <= self.maxZoom)): + if (zoom < self.minZoom) or (zoom > self.maxZoom): return False + if (self.subject != '') and not _test_feature_compatibility(obj, self.subject, tags): return False + subpart = "::default" + for condition in self.conditions: res = condition.test(tags) if not res: diff --git a/src/mapcss/StyleChooser.py b/src/mapcss/StyleChooser.py index 188a4b6..bab9d3b 100644 --- a/src/mapcss/StyleChooser.py +++ b/src/mapcss/StyleChooser.py @@ -101,10 +101,14 @@ class StyleChooser: if self.selzooms: if zoom < self.selzooms[0] or zoom > self.selzooms[1]: return sl + object_id = self.testChain(self.ruleChains,ftype,tags,zoom) + if not object_id: return sl + w = 0 + for r in self.styles: ra = {} for a,b in r.iteritems(): @@ -120,6 +124,7 @@ class StyleChooser: ra[a] = b r = ra ra = {} + for a, b in r.iteritems(): "checking and nicifying style table" if "color" in a: @@ -146,7 +151,6 @@ class StyleChooser: ra[a] = [] else: ra[a]=b - ra["layer"] = float(tags.get("layer",0))*2000+ra.get("z-index",1) # calculating z-index #for k,v in ra.items(): # if a value is empty, we don't need it - renderer will do as default. # if not v: # del ra[k] @@ -240,5 +244,4 @@ class StyleChooser: b = Eval(b) ra[a] = b rb.append(ra) - # print rb self.styles = self.styles + rb diff --git a/src/mapcss/webcolors/webcolors.py b/src/mapcss/webcolors/webcolors.py index d210616..4b2643d 100644 --- a/src/mapcss/webcolors/webcolors.py +++ b/src/mapcss/webcolors/webcolors.py @@ -200,7 +200,7 @@ def _reversedict(d): """ return dict(zip(d.values(), d.keys())) -HEX_COLOR_RE = re.compile(r'^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$') +HEX_COLOR_RE = re.compile(r'^#([a-fA-F0-9]|[a-fA-F0-9]{3}|[a-fA-F0-9]{6})$') SUPPORTED_SPECIFICATIONS = ('html4', 'css2', 'css21', 'css3') @@ -455,6 +455,8 @@ def normalize_hex(hex_value): raise ValueError("'%s' is not a valid hexadecimal color value." % hex_value) if len(hex_digits) == 3: hex_digits = ''.join(map(lambda s: 2 * s, hex_digits)) + elif len(hex_digits) == 1: + hex_digits = hex_digits * 6 return '#%s' % hex_digits.lower() @@ -831,8 +833,6 @@ def rgb_percent_to_rgb(rgb_percent_triplet): """ return tuple(map(_percent_to_integer, rgb_percent_triplet)) - - def whatever_to_rgb(string): """ Converts CSS3 color or a hex into rgb triplet; hash of string if fails. @@ -854,14 +854,13 @@ def whatever_to_hex(string): if type(string) == tuple: return cairo_to_hex(string).upper() return rgb_to_hex(whatever_to_rgb(string)).upper() + def whatever_to_cairo(string): a = whatever_to_rgb(string) - return a[0]/255.,a[1]/255.,a[2]/255., + return a[0]/255.,a[1]/255.,a[2]/255. + def cairo_to_hex (cairo): - return rgb_to_hex((cairo[0]*255,cairo[1]*255,cairo[2]*255,)) - - - + return rgb_to_hex((cairo[0]*255.,cairo[1]*255.,cairo[2]*255.)) if __name__ == '__main__': import doctest