Skip to content

Fixed font-related test error on some platforms #1577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions tests/test_cadquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
# system modules
import math, os.path, time, tempfile
from pathlib import Path
from random import random
from random import randrange
from itertools import product
Expand All @@ -24,7 +25,8 @@
)

# test data directory
testdataDir = os.path.join(os.path.dirname(__file__), "testdata")
testdataDir = Path(__file__).parent.joinpath("testdata")
testFont = str(testdataDir / "OpenSans-Regular.ttf")

# where unit test output will be saved
OUTDIR = tempfile.gettempdir()
Expand Down Expand Up @@ -3843,7 +3845,7 @@ def testText(self):
"CQ 2.0",
0.5,
0.05,
fontPath=os.path.join(testdataDir, "OpenSans-Regular.ttf"),
fontPath=testFont,
cut=False,
combine=False,
halign="right",
Expand All @@ -3863,7 +3865,7 @@ def testText(self):
"CQ 2.0",
0.5,
0.05,
fontPath=os.path.join(testdataDir, "OpenSans-Irregular.ttf"),
fontPath=testFont,
cut=False,
combine=False,
halign="right",
Expand All @@ -3885,17 +3887,23 @@ def testText(self):
)

def testTextAlignment(self):
left_bottom = Workplane().text("I", 10, 0, halign="left", valign="bottom")
left_bottom = Workplane().text(
"I", 10, 0, halign="left", valign="bottom", fontPath=testFont,
)
lb_bb = left_bottom.val().BoundingBox()
self.assertGreaterEqual(lb_bb.xmin, 0)
self.assertGreaterEqual(lb_bb.ymin, 0)

centers = Workplane().text("I", 10, 0, halign="center", valign="center")
centers = Workplane().text(
"I", 10, 0, halign="center", valign="center", fontPath=testFont,
)
c_bb = centers.val().BoundingBox()
self.assertAlmostEqual(c_bb.center.x, 0, places=0)
self.assertAlmostEqual(c_bb.center.y, 0, places=0)

right_top = Workplane().text("I", 10, 0, halign="right", valign="top")
right_top = Workplane().text(
"I", 10, 0, halign="right", valign="top", fontPath=testFont,
)
rt_bb = right_top.val().BoundingBox()
self.assertLessEqual(rt_bb.xmax, 0)
self.assertLessEqual(rt_bb.ymax, 0)
Expand Down