Skip to content

Commit 4a5eff0

Browse files
Fix single letter text handling (#1939)
* Fix single letter text handling Prevent unpacking of a single face into a wire
1 parent 7821121 commit 4a5eff0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

cadquery/occ_impl/shapes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5843,7 +5843,7 @@ def text(
58435843
font_i, NCollection_Utf8String(txt), theHAlign=theHAlign, theVAlign=theVAlign
58445844
)
58455845

5846-
return clean(compound(_compound_or_shape(rv).faces()).fuse())
5846+
return clean(compound(_compound_or_shape(rv).Faces()).fuse())
58475847

58485848

58495849
@text.register
@@ -5866,7 +5866,7 @@ def text(
58665866
L = spine.Length()
58675867

58685868
rv = []
5869-
for el in text(txt, size, font, path, kind, halign, valign):
5869+
for el in text(txt, size, font, path, kind, halign, valign).Faces():
58705870
pos = el.BoundingBox().center.x
58715871

58725872
# position
@@ -5900,7 +5900,7 @@ def text(
59005900
tmp = text(txt, size, spine, False, font, path, kind, halign, valign)
59015901

59025902
rv = []
5903-
for f in tmp.faces():
5903+
for f in tmp.Faces():
59045904
rv.append(f.project(base, f.normalAt()))
59055905

59065906
return _normalize(compound(rv))

tests/test_free_functions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ def test_text():
468468
# test single letter
469469
r6 = text("C", 1)
470470

471+
assert isinstance(r6, Face)
471472
assert len(r6.Faces()) == 1
472473
assert len(r6.Wires()) == 1
473474

@@ -479,6 +480,8 @@ def test_text():
479480
r7 = text("CQ", 1, spine) # normal
480481
r8 = text("CQ", 1, spine, planar=True) # planar
481482
r9 = text("CQ", 1, spine, cf) # projected
483+
r10 = text("C", 1, spine, planar=True) # single letter, planar
484+
r11 = text("C", 1, spine, cf) # single letter, projected
482485

483486
assert r7.faces(">>Z").Center().z > 0
484487
assert r7.faces("<<X").normalAt().dot(Vector(0, 0, 1)) == approx(0)
@@ -492,6 +495,14 @@ def test_text():
492495
assert r9.faces("<<X").normalAt().dot(Vector(0, 0, 1)) == approx(0)
493496
assert r9.faces("<<X").geomType() == "CYLINDER"
494497

498+
assert isinstance(r10, Face)
499+
assert len(r10.Faces()) == 1
500+
assert len(r10.Wires()) == 1
501+
502+
assert isinstance(r11, Face)
503+
assert len(r11.Faces()) == 1
504+
assert len(r11.Wires()) == 1
505+
495506

496507
#%% bool ops
497508
def test_operators():

0 commit comments

Comments
 (0)