From 32cc5aafb63874ed5961412e947594870fe1eaa8 Mon Sep 17 00:00:00 2001 From: Konstantin Pastbin Date: Tue, 17 Jan 2023 21:26:31 +0000 Subject: [PATCH] Add casing-width-add support Signed-off-by: Konstantin Pastbin --- src/libkomwm.py | 18 +++++++++++++++--- src/mapcss/Condition.py | 2 +- src/mapcss/StyleChooser.py | 3 --- src/mapcss/__init__.py | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/libkomwm.py b/src/libkomwm.py index 01bdefc..41dcf73 100644 --- a/src/libkomwm.py +++ b/src/libkomwm.py @@ -296,7 +296,7 @@ def komap_mapswithme(options): zstyle.sort(key = rule_sort_key) # For debug purpose. - # if str(cl) == 'entrance' and int(zoom) == 19: + # if str(cl) == 'highway-path' and int(zoom) == 19: # print(cl) # print(zstyle) @@ -354,11 +354,23 @@ def komap_mapswithme(options): elif st.get('-x-kot-layer') == 'bottom': st['z-index'] = float(st.get('z-index', 0)) - 15001. - if st.get('casing-width') not in (None, 0): # and (st.get('width') or st.get('fill-color')): + if st.get('casing-width') not in (None, 0) or st.get('casing-width-add') is not None: # and (st.get('width') or st.get('fill-color')): is_area_st = 'fill-color' in st if has_lines and not is_area_st and st.get('casing-linecap', 'butt') == 'butt': dr_line = LineRuleProto() - dr_line.width = (st.get('width', 0) * WIDTH_SCALE) + (st.get('casing-width') * WIDTH_SCALE * 2) + + # 'casing-width' has precedence over 'casing-width-add'. + if st.get('casing-width-add') is not None and st.get('casing-width') in (None, 0): + # Look for base width in other style objects (usually ::default). + base_width = 0 + for wst in zstyle: + if wst.get('width') not in (None, 0): + # Rail bridge styles use width from ::dash object instead of ::default. + if base_width == 0 or wst.get('object-id') != '::default': + base_width = wst.get('width', 0) + st['casing-width'] = base_width + st.get('casing-width-add') + + dr_line.width = round((st.get('width', 0) + st.get('casing-width') * 2) * WIDTH_SCALE, 2) dr_line.color = mwm_encode_color(colors, st, "casing") if '-x-me-casing-line-priority' in st: dr_line.priority = int(st.get('-x-me-casing-line-priority')) diff --git a/src/mapcss/Condition.py b/src/mapcss/Condition.py index 1612480..9bed7d4 100644 --- a/src/mapcss/Condition.py +++ b/src/mapcss/Condition.py @@ -75,7 +75,7 @@ class Condition: t = self.type params = self.params if t == 'eq' and params[0][:2] == "::": - return "::%s" % (params[1]) + return "%s" % (params[1]) if t == 'eq': return "%s=%s" % (params[0], params[1]) if t == 'ne': diff --git a/src/mapcss/StyleChooser.py b/src/mapcss/StyleChooser.py index 9291e6b..2444152 100644 --- a/src/mapcss/StyleChooser.py +++ b/src/mapcss/StyleChooser.py @@ -277,9 +277,6 @@ class StyleChooser: b = str(float(b) / 2) except: pass - if "text" == a[-4:]: - if b[:5] != "eval(": - b = "eval(tag(\"" + b + "\"))" if b[:5] == "eval(": b = Eval(b) self.has_evals = True diff --git a/src/mapcss/__init__.py b/src/mapcss/__init__.py index a5a84a3..d2bcfb1 100644 --- a/src/mapcss/__init__.py +++ b/src/mapcss/__init__.py @@ -22,7 +22,7 @@ from .StyleChooser import StyleChooser from .Condition import Condition -NEEDED_KEYS = set(["width", "casing-width", "fill-color", "fill-image", "icon-image", "text", "extrude", +NEEDED_KEYS = set(["width", "casing-width", "casing-width-add", "fill-color", "fill-image", "icon-image", "text", "extrude", "background-image", "background-color", "pattern-image", "shield-text", "symbol-shape"]) WHITESPACE = re.compile(r'\s+ ', re.S | re.X)