diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8594760..6b7858a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,12 +21,13 @@ jobs: steps: - uses: actions/checkout@v7 - # A pinned snapshot, the OpenSCAD these examples are checked on. + # A pinned snapshot, the OpenSCAD these examples are checked on: 2026.10.15 or + # later, where textmetrics() is no longer experimental. - name: Install OpenSCAD snapshot and just # The AppImage and its checksum; update both together. env: - OPENSCAD_SNAPSHOT: OpenSCAD-2026.08.19-x86_64.AppImage - OPENSCAD_SHA256: fdd818025e890f465ffacffbe7d0c6fa3ebeb3f7c18ee860a909ab41396be643 + OPENSCAD_SNAPSHOT: OpenSCAD-2026.10.15-x86_64.AppImage + OPENSCAD_SHA256: 9d26e390d3a5c94f2e304d94d7b2eff77fb11fcd25829f2814de147ba92ac363 run: | set -euo pipefail sudo apt-get update -qq diff --git a/README.md b/README.md index 6ec95e2..aca943e 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,13 @@ examples/ torture_test_examples/ -- torture test example ``` +## OpenSCAD version + +The towers fit each section label to its face with `textmetrics()`, built in +from the OpenSCAD 2026.10.15 development snapshot. Earlier versions warn that +the function is missing or experimental and carve the labels at their full +size, which can run off the face. + ## Quality / rendering All examples set `$fn` based on `$preview`: diff --git a/src/flowtower.scad b/src/flowtower.scad index 1805b7a..e92fb3e 100644 --- a/src/flowtower.scad +++ b/src/flowtower.scad @@ -132,6 +132,12 @@ module generate_section( } // Generate the text that will be carved into the square section column +// The font size, at most `size`, at which `txt` is no wider than `width`. Where +// textmetrics() is missing (OpenSCAD 2021.01) it returns `size` unchanged. +function flow_label_size(txt, size, font, width) = + let (w = textmetrics(text=txt, size=size, font=font).size[0]) + is_undef(w) || w <= width ? size : size * width / w; + module generate_section_label( label, section_size, @@ -144,6 +150,12 @@ module generate_section_label( section_label_font_size ) { full_label = str(section_label_prefix, label, section_label_suffix); + // The label may span 90% of the face it is carved into. + label_width = section_size * 0.9; + label_size = flow_label_size(full_label, section_label_font_size, font, label_width); + fitted_width = textmetrics(text=full_label, size=label_size, font=font).size[0]; + assert(is_undef(fitted_width) || fitted_width <= label_width + 1e-3, + str("section label \"", full_label, "\" is wider than its face")); translate([-section_size / 2, -section_size, section_size / 2]) rotate([90, 0, 0]) translate([0, 0, -label_depth]) @@ -151,7 +163,7 @@ module generate_section_label( text( text=full_label, font=font, - size=section_label_font_size, + size=label_size, halign="center", valign="center" ); diff --git a/src/retracttower.scad b/src/retracttower.scad index 3bdcc7c..e3d7a1e 100644 --- a/src/retracttower.scad +++ b/src/retracttower.scad @@ -123,6 +123,12 @@ module generate_retract_round_column(cube_size, cap_size, cap_height, wall_thick } // Generate the section label carved into the square column +// The font size, at most `size`, at which `txt` is no wider than `width`. Where +// textmetrics() is missing (OpenSCAD 2021.01) it returns `size` unchanged. +function retract_label_size(txt, size, font, width) = + let (w = textmetrics(text=txt, size=size, font=font).size[0]) + is_undef(w) || w <= width ? size : size * width / w; + module generate_retract_section_label( label, section_label_prefix, @@ -135,6 +141,12 @@ module generate_retract_section_label( iota ) { full_label = str(section_label_prefix, label, section_label_suffix); + // The label may span 90% of the face it is carved into. + label_width = cube_size * 0.9; + label_size = retract_label_size(full_label, section_label_font_size, font, label_width); + fitted_width = textmetrics(text=full_label, size=label_size, font=font).size[0]; + assert(is_undef(fitted_width) || fitted_width <= label_width + 1e-3, + str("section label \"", full_label, "\" is wider than its face")); translate([-tower_width / 2 + cube_size / 2, -cube_size / 2 - iota, cube_size / 2]) rotate([90, 0, 0]) translate([0, 0, -label_depth]) @@ -142,7 +154,7 @@ module generate_retract_section_label( text( text=full_label, font=font, - size=section_label_font_size, + size=label_size, halign="center", valign="center" ); diff --git a/src/temptower.scad b/src/temptower.scad index eff92e2..c6dcb51 100644 --- a/src/temptower.scad +++ b/src/temptower.scad @@ -152,6 +152,12 @@ module generate_temp_right_bridge_support( } // Generate the section label carved into the left column +// The font size, at most `size`, at which `txt` is no wider than `width`. Where +// textmetrics() is missing (OpenSCAD 2021.01) it returns `size` unchanged. +function temp_label_size(txt, size, font, width) = + let (w = textmetrics(text=txt, size=size, font=font).size[0]) + is_undef(w) || w <= width ? size : size * width / w; + module generate_temp_section_label( label, section_label_prefix, @@ -164,6 +170,12 @@ module generate_temp_section_label( iota ) { full_label = str(section_label_prefix, label, section_label_suffix); + // The label may span 90% of the face it is carved into. + label_width = cube_size * 0.9; + label_size = temp_label_size(full_label, section_label_font_size, font, label_width); + fitted_width = textmetrics(text=full_label, size=label_size, font=font).size[0]; + assert(is_undef(fitted_width) || fitted_width <= label_width + 1e-3, + str("section label \"", full_label, "\" is wider than its face")); translate([-tower_width / 2 + cube_size / 2, -cube_size / 2 - iota, cube_size / 2]) rotate([90, 0, 0]) translate([0, 0, -label_depth]) @@ -171,7 +183,7 @@ module generate_temp_section_label( text( text=full_label, font=font, - size=section_label_font_size, + size=label_size, halign="center", valign="center" );