diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml index f03598c..9d671a0 100644 --- a/k8s/deployment.yaml +++ b/k8s/deployment.yaml @@ -15,7 +15,7 @@ spec: spec: containers: - name: m1730-generator - image: git.baumann.gr/adebaumann/m1730-generator:0.85 + image: git.baumann.gr/adebaumann/m1730-generator:0.86 imagePullPolicy: Always ports: - containerPort: 5000 diff --git a/web/app.py b/web/app.py index 09dac35..efb0c83 100644 --- a/web/app.py +++ b/web/app.py @@ -9,7 +9,7 @@ from fontTools.pens.svgPathPen import SVGPathPen app = Flask(__name__) -VERSION = "0.85" +VERSION = "0.86" _LOGO_PATH = pathlib.Path(__file__).parent / 'static' / 'logo.png' _LOGO_B64 = base64.b64encode(_LOGO_PATH.read_bytes()).decode() @@ -74,6 +74,7 @@ _FRAC_SIDE = 0.12 _UNIT_BOX_X0, _UNIT_BOX_X1 = 39.6, 57.4 _UNIT_BOX_Y0, _UNIT_BOX_Y1 = 92.8, 114.8 +_UNIT_BOX_HALF_Y1 = (_UNIT_BOX_Y0 + _UNIT_BOX_Y1) / 2 # 103.8 — upper half of panel def _glyph_svg(ch: str, x: float, y: float, fs: float, fill: str, fd: _FontData): @@ -244,9 +245,10 @@ def _has_markup(s: str) -> bool: return any(c in s for c in '^_') or ('{' in s and '}' in s) -def _markup_unit_svg(unit: str, fd: _FontData, fill='#1a1a1a') -> str: +def _markup_unit_svg(unit: str, fd: _FontData, fill='#1a1a1a', box_y1=None) -> str: nodes = _parse_markup(unit) - x0, x1, y0, y1 = _UNIT_BOX_X0, _UNIT_BOX_X1, _UNIT_BOX_Y0, _UNIT_BOX_Y1 + x0, x1 = _UNIT_BOX_X0, _UNIT_BOX_X1 + y0, y1 = _UNIT_BOX_Y0, (box_y1 if box_y1 is not None else _UNIT_BOX_Y1) xc, yc = (x0 + x1) / 2, (y0 + y1) / 2 w1 = _measure(nodes, 1.0, fd) @@ -316,8 +318,9 @@ def _fmt(v: float) -> str: def generate_svg(unit, min_val, max_val, range_label, big_ticks, small_ticks, label_count, use_paths=True, scale_type='linear', custom_labels=None, label_size=9, - font_key=None): + font_key=None, half_height_unit=False): fd = _FONTS.get(font_key) or _FONTS.get(_DEFAULT_FONT) or next(iter(_FONTS.values())) + unit_box_y1 = _UNIT_BOX_HALF_Y1 if half_height_unit else None if scale_type == 'log': if min_val <= 0 or max_val <= 0: @@ -424,13 +427,12 @@ def generate_svg(unit, min_val, max_val, range_label, big_ticks, small_ticks, la ' M 58.443978,107.54692 H 183.64409 v 6.19963 H 58.443978 Z" />' ) - if _has_markup(unit): - unit_svg = ' ' + _markup_unit_svg(unit, fd) - elif use_paths: - unit_svg = ' ' + _text_to_paths( - unit, 41.455711, 109.03796, _unit_font_size(unit, fd), fd, - wrap_transform=f'scale({_UNIT_SCALE_X},1.0364155)' - ) + # Paths mode and any unit needing special handling (markup, half-height): + # use _markup_unit_svg which fits actual ink bounds to the box, giving + # correct sizing for all fonts. Text mode for plain normal-height units + # keeps live nodes; half-height always uses paths for correct centering. + if use_paths or _has_markup(unit) or half_height_unit: + unit_svg = ' ' + _markup_unit_svg(unit, fd, box_y1=unit_box_y1) else: fs = _unit_font_size(unit, fd) unit_svg = ( @@ -503,7 +505,8 @@ def generate(): label_count = max(2, int(request.form.get('label_count', 6))) use_paths = request.form.get('output_mode', 'paths') == 'paths' scale_type = request.form.get('scale_type', 'linear') - font_key = request.form.get('font', _DEFAULT_FONT) + font_key = request.form.get('font', _DEFAULT_FONT) + half_height_unit = request.form.get('half_height_unit') == '1' if request.form.get('max_is_inf') == '1': max_val = math.inf @@ -513,7 +516,7 @@ def generate(): try: svg = generate_svg(unit, min_val, max_val, range_label, big_ticks, small_ticks, label_count, use_paths, scale_type, custom_labels, label_size, - font_key) + font_key, half_height_unit) except ValueError as err: return Response(str(err), status=400, mimetype='text/plain') return Response(svg, mimetype='image/svg+xml') diff --git a/web/templates/index.html b/web/templates/index.html index 98e6e4b..079d306 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -302,6 +302,14 @@ Markup: cm^2 · H_2O · {1/2} fraction · nests, e.g. {m/s^2} +
+
+ + +
+ +
@@ -511,6 +519,15 @@ document.getElementById('font-select').addEventListener('change', doGenerate); + document.querySelectorAll('[data-unit-height]').forEach(btn => { + btn.addEventListener('click', () => { + document.querySelectorAll('[data-unit-height]').forEach(b => b.classList.remove('active')); + btn.classList.add('active'); + document.getElementById('half-height-unit').value = btn.dataset.unitHeight === 'half' ? '1' : '0'; + doGenerate(); + }); + }); + doGenerate();