Skip to content
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

Text Alignment Test Failure #1569

Open
jmwright opened this issue Apr 24, 2024 · 14 comments · May be fixed by #1577
Open

Text Alignment Test Failure #1569

jmwright opened this issue Apr 24, 2024 · 14 comments · May be fixed by #1577
Assignees
Labels
bug Something isn't working

Comments

@jmwright
Copy link
Member

Description

I can open a PR to fix this, but I wanted to open an issue for discussion first.

Running pytest shows an error in testTextAlignment that seems to be rounding error.

To Reproduce

On an AMD 64, Debian 12 machine (could also be present on others):

pytest tests/test_cadquery.py -k testTextAlignment

The model looks like it has the correct bounding box ymin in CQ-editor, but is just slightly off when the bounding box is calculated.
Screenshot from 2024-04-24 10-47-58

Backtrace

self = <tests.test_cadquery.TestCadQuery testMethod=testTextAlignment>

    def testTextAlignment(self):
        left_bottom = Workplane().text("I", 10, 0, halign="left", valign="bottom")
        lb_bb = left_bottom.val().BoundingBox()
        self.assertGreaterEqual(lb_bb.xmin, 0)
>       self.assertGreaterEqual(lb_bb.ymin, 0)
E       AssertionError: -5.086263020833333e-07 not greater than or equal to 0

tests/test_cadquery.py:3891: AssertionError

Suggested Solution

Changing the assert to an "almost equal" variant would solve this problem. If the error was larger I would think that something is wrong, but it seems like rounding error based on the platform/distro since the test currently passes with the Ubuntu 22.04 runner on AppVeyor. I suppose it could be related to font differences between platforms as well, but that's a total guess.

Environment

OS:

  • conda/mamba installed via the instructions on ReadTheDocs
  • CadQuery installed via mamba env create -f environment.yml from latest git master
  • Debian 12
  • Tried on both Python 3.10 and 3.11 environments with same result
  • AMD 64 platform

Output of conda list from your active Conda environment:

$ conda list
# packages in environment at /home/jwright/mambaforge/envs/cq-dev-conda-310:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
aiohttp                   3.9.5           py310h2372a71_0    conda-forge
aiosignal                 1.3.1              pyhd8ed1ab_0    conda-forge
alabaster                 0.7.16             pyhd8ed1ab_0    conda-forge
alsa-lib                  1.2.11               hd590300_1    conda-forge
ampl-mp                   3.1.0             h2cc385e_1006    conda-forge
aom                       3.8.2                h59595ed_0    conda-forge
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
async-timeout             4.0.3              pyhd8ed1ab_0    conda-forge
attr                      2.5.1                h166bdaf_1    conda-forge
attrs                     23.2.0             pyh71513ae_0    conda-forge
babel                     2.14.0             pyhd8ed1ab_0    conda-forge
black                     0.1.dev631+gef9d467          pypi_0    pypi
blosc                     1.21.5               hc2324a3_1    conda-forge
brotli                    1.1.0                hd590300_1    conda-forge
brotli-bin                1.1.0                hd590300_1    conda-forge
brotli-python             1.1.0           py310hc6cd4ac_1    conda-forge
bzip2                     1.0.8                hd590300_5    conda-forge
c-ares                    1.28.1               hd590300_0    conda-forge
ca-certificates           2024.2.2             hbcca054_0    conda-forge
cadquery                  2.5.0.dev0                dev_0    <develop>
cairo                     1.18.0               h3faef2a_0    conda-forge
casadi                    3.6.5           py310h97d447a_2    conda-forge
certifi                   2024.2.2           pyhd8ed1ab_0    conda-forge
charset-normalizer        3.3.2              pyhd8ed1ab_0    conda-forge
click                     8.1.7           unix_pyh707e725_0    conda-forge
codecov                   2.1.13             pyhd8ed1ab_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
coverage                  7.5.0           py310hc51659f_0    conda-forge
dav1d                     1.2.1                hd590300_0    conda-forge
dbus                      1.13.6               h5008d03_3    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
docutils                  0.18.1          py310hff52083_1    conda-forge
double-conversion         3.3.0                h59595ed_0    conda-forge
eigen                     3.4.0                h00ab1b0_0    conda-forge
exceptiongroup            1.2.0              pyhd8ed1ab_2    conda-forge
executing                 2.0.1              pyhd8ed1ab_0    conda-forge
expat                     2.5.0                hcb278e6_1    conda-forge
ezdxf                     1.2.0           py310hcb52e73_0    conda-forge
ffmpeg                    6.1.1           gpl_hee4b679_108    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 h77eed37_1    conda-forge
fontconfig                2.14.2               h14ed4e7_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.51.0          py310h2372a71_0    conda-forge
freeimage                 3.18.0              h4b96d29_20    conda-forge
freetype                  2.12.1               h267a509_2    conda-forge
fribidi                   1.0.10               h36c2ea0_0    conda-forge
frozenlist                1.4.1           py310h2372a71_0    conda-forge
gettext                   0.22.5               h59595ed_2    conda-forge
gettext-tools             0.22.5               h59595ed_2    conda-forge
gl2ps                     1.4.2                h0708190_0    conda-forge
glew                      2.1.0                h9c3ff4c_2    conda-forge
glib                      2.80.0               hf2295e7_6    conda-forge
glib-tools                2.80.0               hde27a5a_6    conda-forge
gmp                       6.3.0                h59595ed_1    conda-forge
gnutls                    3.7.9                hb077bed_0    conda-forge
graphite2                 1.3.13            h59595ed_1003    conda-forge
gst-plugins-base          1.22.9               h8e1006c_0    conda-forge
gstreamer                 1.22.9               h98fc4e7_0    conda-forge
harfbuzz                  8.4.0                h3d44ed6_0    conda-forge
hdf4                      4.2.15               h2a13503_7    conda-forge
hdf5                      1.14.3          nompi_h4f84152_100    conda-forge
icu                       73.2                 h59595ed_0    conda-forge
idna                      3.7                pyhd8ed1ab_0    conda-forge
imagesize                 1.4.1              pyhd8ed1ab_0    conda-forge
imath                     3.1.11               hfc55251_0    conda-forge
importlib-metadata        7.1.0              pyha770c72_0    conda-forge
iniconfig                 2.0.0              pyhd8ed1ab_0    conda-forge
ipopt                     3.14.16              hf967516_0    conda-forge
ipython                   8.22.2             pyh707e725_0    conda-forge
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jinja2                    3.1.3              pyhd8ed1ab_0    conda-forge
jsoncpp                   1.9.5                h4bd325d_1    conda-forge
jxrlib                    1.1                  hd590300_3    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
krb5                      1.21.2               h659d440_0    conda-forge
lame                      3.100             h166bdaf_1003    conda-forge
lcms2                     2.16                 hb7c19ff_0    conda-forge
ld_impl_linux-64          2.40                 h55db66e_0    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libabseil                 20240116.1      cxx17_h59595ed_2    conda-forge
libaec                    1.1.3                h59595ed_0    conda-forge
libasprintf               0.22.5               h661eb56_2    conda-forge
libasprintf-devel         0.22.5               h661eb56_2    conda-forge
libass                    0.17.1               h8fe9dca_1    conda-forge
libblas                   3.9.0           22_linux64_openblas    conda-forge
libbrotlicommon           1.1.0                hd590300_1    conda-forge
libbrotlidec              1.1.0                hd590300_1    conda-forge
libbrotlienc              1.1.0                hd590300_1    conda-forge
libcap                    2.69                 h0f662aa_0    conda-forge
libcblas                  3.9.0           22_linux64_openblas    conda-forge
libclang                  15.0.7          default_h127d8a8_5    conda-forge
libclang13                15.0.7          default_h5d6823c_5    conda-forge
libcups                   2.3.3                h4637d8d_4    conda-forge
libcurl                   8.7.1                hca28451_0    conda-forge
libdeflate                1.20                 hd590300_0    conda-forge
libdrm                    2.4.120              hd590300_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 hd590300_2    conda-forge
libevent                  2.1.12               hf998b51_1    conda-forge
libexpat                  2.5.0                hcb278e6_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libflac                   1.4.3                h59595ed_0    conda-forge
libgcc-ng                 13.2.0               hc881cc4_6    conda-forge
libgcrypt                 1.10.3               hd590300_0    conda-forge
libgettextpo              0.22.5               h59595ed_2    conda-forge
libgettextpo-devel        0.22.5               h59595ed_2    conda-forge
libgfortran-ng            13.2.0               h69a702a_6    conda-forge
libgfortran5              13.2.0               h43f5ff8_6    conda-forge
libglib                   2.80.0               hf2295e7_6    conda-forge
libglu                    9.0.0             hac7e632_1003    conda-forge
libgomp                   13.2.0               hc881cc4_6    conda-forge
libgpg-error              1.48                 h71f35ed_0    conda-forge
libhwloc                  2.9.3           default_h554bfaf_1009    conda-forge
libiconv                  1.17                 hd590300_2    conda-forge
libidn2                   2.3.7                hd590300_0    conda-forge
libjpeg-turbo             3.0.0                hd590300_1    conda-forge
liblapack                 3.9.0           22_linux64_openblas    conda-forge
libllvm15                 15.0.7               hb3ce162_4    conda-forge
libnetcdf                 4.9.2           nompi_h9612171_113    conda-forge
libnghttp2                1.58.0               h47da74e_1    conda-forge
libnsl                    2.0.1                hd590300_0    conda-forge
libogg                    1.3.4                h7f98852_1    conda-forge
libopenblas               0.3.27          pthreads_h413a1c8_0    conda-forge
libopenvino               2024.0.0             h2da1b83_5    conda-forge
libopenvino-auto-batch-plugin 2024.0.0             hb045406_5    conda-forge
libopenvino-auto-plugin   2024.0.0             hb045406_5    conda-forge
libopenvino-hetero-plugin 2024.0.0             h5c03a75_5    conda-forge
libopenvino-intel-cpu-plugin 2024.0.0             h2da1b83_5    conda-forge
libopenvino-intel-gpu-plugin 2024.0.0             h2da1b83_5    conda-forge
libopenvino-ir-frontend   2024.0.0             h5c03a75_5    conda-forge
libopenvino-onnx-frontend 2024.0.0             h07e8aee_5    conda-forge
libopenvino-paddle-frontend 2024.0.0             h07e8aee_5    conda-forge
libopenvino-pytorch-frontend 2024.0.0             he02047a_5    conda-forge
libopenvino-tensorflow-frontend 2024.0.0             h39126c6_5    conda-forge
libopenvino-tensorflow-lite-frontend 2024.0.0             he02047a_5    conda-forge
libopus                   1.3.1                h7f98852_1    conda-forge
libosqp                   0.6.3                h59595ed_0    conda-forge
libpciaccess              0.18                 hd590300_0    conda-forge
libpng                    1.6.43               h2797004_0    conda-forge
libpq                     16.2                 h33b98f1_1    conda-forge
libprotobuf               4.25.3               h08a7969_0    conda-forge
libqdldl                  0.1.5                h27087fc_1    conda-forge
libraw                    0.21.1               h2a13503_2    conda-forge
libscotch                 7.0.4                h91e35bf_1    conda-forge
libsndfile                1.2.2                hc60ed4a_1    conda-forge
libspral                  2024.01.18           h6aa6db2_0    conda-forge
libsqlite                 3.45.3               h2797004_0    conda-forge
libssh2                   1.11.0               h0841786_0    conda-forge
libstdcxx-ng              13.2.0               h95c4c6d_6    conda-forge
libsystemd0               255                  h3516f8a_1    conda-forge
libtasn1                  4.19.0               h166bdaf_0    conda-forge
libtheora                 1.1.1             h7f98852_1005    conda-forge
libtiff                   4.6.0                h1dd3fc0_3    conda-forge
libunistring              0.9.10               h7f98852_0    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libva                     2.21.0               hd590300_0    conda-forge
libvorbis                 1.3.7                h9c3ff4c_0    conda-forge
libvpx                    1.14.0               h59595ed_0    conda-forge
libwebp-base              1.4.0                hd590300_0    conda-forge
libxcb                    1.15                 h0b41bf4_0    conda-forge
libxcrypt                 4.4.36               hd590300_1    conda-forge
libxkbcommon              1.7.0                h662e7e4_0    conda-forge
libxml2                   2.12.6               h232c23b_2    conda-forge
libzip                    1.10.1               h2629f0a_3    conda-forge
libzlib                   1.2.13               hd590300_5    conda-forge
loguru                    0.7.2           py310hff52083_1    conda-forge
lz4-c                     1.9.4                hcb278e6_0    conda-forge
markupsafe                2.1.5           py310h2372a71_0    conda-forge
matplotlib-inline         0.1.7              pyhd8ed1ab_0    conda-forge
metis                     5.1.0             h59595ed_1007    conda-forge
mpg123                    1.32.6               h59595ed_0    conda-forge
msgpack-python            1.0.7           py310hd41b1e2_0    conda-forge
multidict                 6.0.5           py310h2372a71_0    conda-forge
multimethod               1.9.1              pyhd8ed1ab_0    conda-forge
mumps-include             5.6.2                ha770c72_4    conda-forge
mumps-seq                 5.6.2                hfef103a_4    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
mypy                      1.9.0           py310h2372a71_1    conda-forge
mypy_extensions           1.0.0              pyha770c72_0    conda-forge
mysql-common              8.0.33               hf1915f5_6    conda-forge
mysql-libs                8.0.33               hca2cd23_6    conda-forge
ncurses                   6.4.20240210         h59595ed_0    conda-forge
nettle                    3.9.1                h7ab15ed_0    conda-forge
nlohmann_json             3.11.3               h59595ed_0    conda-forge
nlopt                     2.7.1           py310h46d55b5_4    conda-forge
nptyping                  2.0.1              pyhd8ed1ab_0    conda-forge
nspr                      4.35                 h27087fc_0    conda-forge
nss                       3.98                 h1d7d5a4_0    conda-forge
numpy                     1.26.4          py310hb13e2d6_0    conda-forge
occt                      7.7.2           all_h4c9f3c6_201    conda-forge
ocl-icd                   2.3.2                hd590300_1    conda-forge
ocp                       7.7.2.0         py310hc0337cc_2    conda-forge
openexr                   3.2.2                haf962dd_1    conda-forge
openh264                  2.4.1                h59595ed_0    conda-forge
openjpeg                  2.5.2                h488ebb8_0    conda-forge
openssl                   3.2.1                hd590300_1    conda-forge
p11-kit                   0.24.1               hc5aa10d_0    conda-forge
packaging                 24.0               pyhd8ed1ab_0    conda-forge
parso                     0.8.4              pyhd8ed1ab_0    conda-forge
path                      16.14.0         py310hff52083_0    conda-forge
pathspec                  0.12.1             pyhd8ed1ab_0    conda-forge
pcre2                     10.43                hcad00b1_0    conda-forge
pexpect                   4.9.0              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pip                       24.0               pyhd8ed1ab_0    conda-forge
pixman                    0.43.2               h59595ed_0    conda-forge
pluggy                    1.5.0              pyhd8ed1ab_0    conda-forge
proj                      9.3.1                h1d62c97_0    conda-forge
prompt-toolkit            3.0.42             pyha770c72_0    conda-forge
proxsuite                 0.6.4           py310hd41b1e2_1    conda-forge
psutil                    5.9.8           py310h2372a71_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pugixml                   1.14                 h59595ed_0    conda-forge
pulseaudio-client         16.1                 hb77b528_5    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pybind11-abi              4                    hd8ed1ab_3    conda-forge
pygments                  2.17.2             pyhd8ed1ab_0    conda-forge
pyparsing                 3.1.2              pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
pytest                    8.1.1              pyhd8ed1ab_0    conda-forge
pytest-cov                5.0.0              pyhd8ed1ab_0    conda-forge
python                    3.10.14         hd12c33a_0_cpython    conda-forge
python_abi                3.10                    4_cp310    conda-forge
pytz                      2024.1             pyhd8ed1ab_0    conda-forge
qt-main                   5.15.8              h5810be5_19    conda-forge
rapidjson                 1.1.0             he1b5a44_1002    conda-forge
readline                  8.2                  h8228510_1    conda-forge
regex                     2024.4.16       py310h2372a71_0    conda-forge
requests                  2.31.0             pyhd8ed1ab_0    conda-forge
scipy                     1.13.0          py310hb13e2d6_0    conda-forge
scotch                    7.0.4                h23d43cc_1    conda-forge
setuptools                69.5.1             pyhd8ed1ab_0    conda-forge
simde                     0.8.0                h00ab1b0_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
snappy                    1.2.0                hdb0a2a9_1    conda-forge
snowballstemmer           2.2.0              pyhd8ed1ab_0    conda-forge
sphinx                    5.0.1              pyh6c4a22f_0    conda-forge
sphinx_rtd_theme          2.0.0              pyha770c72_0    conda-forge
sphinxcontrib-applehelp   1.0.8              pyhd8ed1ab_0    conda-forge
sphinxcontrib-devhelp     1.0.6              pyhd8ed1ab_0    conda-forge
sphinxcontrib-htmlhelp    2.0.5              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jquery      4.1                pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1              pyhd8ed1ab_0    conda-forge
sphinxcontrib-qthelp      1.0.7              pyhd8ed1ab_0    conda-forge
sphinxcontrib-serializinghtml 1.1.10             pyhd8ed1ab_0    conda-forge
sqlite                    3.45.3               h2c6b66d_0    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
svt-av1                   2.0.0                h59595ed_0    conda-forge
tbb                       2021.11.0            h00ab1b0_1    conda-forge
tbb-devel                 2021.11.0            h5ccd973_1    conda-forge
tinyxml2                  10.0.0               h59595ed_0    conda-forge
tk                        8.6.13          noxft_h4845f30_101    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
traitlets                 5.14.3             pyhd8ed1ab_0    conda-forge
typed-ast                 1.5.5           py310h2372a71_1    conda-forge
typing-extensions         4.11.0               hd8ed1ab_0    conda-forge
typing_extensions         4.11.0             pyha770c72_0    conda-forge
typish                    1.9.3              pyhd8ed1ab_0    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
unicodedata2              15.1.0          py310h2372a71_0    conda-forge
unixodbc                  2.3.12               h661eb56_0    conda-forge
urllib3                   2.2.1              pyhd8ed1ab_0    conda-forge
utfcpp                    4.0.5                ha770c72_0    conda-forge
vtk                       9.2.6           qt_py310h1234567_220    conda-forge
vtk-base                  9.2.6           qt_py310h1234567_220    conda-forge
vtk-io-ffmpeg             9.2.6           qt_py310h1234567_220    conda-forge
wcwidth                   0.2.13             pyhd8ed1ab_0    conda-forge
wheel                     0.43.0             pyhd8ed1ab_1    conda-forge
wslink                    2.0.2              pyhd8ed1ab_0    conda-forge
x264                      1!164.3095           h166bdaf_2    conda-forge
x265                      3.5                  h924138e_3    conda-forge
xcb-util                  0.4.0                hd590300_1    conda-forge
xcb-util-image            0.4.0                h8ee46fc_1    conda-forge
xcb-util-keysyms          0.4.0                h8ee46fc_1    conda-forge
xcb-util-renderutil       0.3.9                hd590300_1    conda-forge
xcb-util-wm               0.4.1                h8ee46fc_1    conda-forge
xkeyboard-config          2.41                 hd590300_0    conda-forge
xorg-fixesproto           5.0               h7f98852_1002    conda-forge
xorg-kbproto              1.0.7             h7f98852_1002    conda-forge
xorg-libice               1.1.1                hd590300_0    conda-forge
xorg-libsm                1.2.4                h7391055_0    conda-forge
xorg-libx11               1.8.9                h8ee46fc_0    conda-forge
xorg-libxau               1.0.11               hd590300_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xorg-libxext              1.3.4                h0b41bf4_2    conda-forge
xorg-libxfixes            5.0.3             h7f98852_1004    conda-forge
xorg-libxrender           0.9.11               hd590300_0    conda-forge
xorg-libxt                1.3.0                hd590300_1    conda-forge
xorg-renderproto          0.11.1            h7f98852_1002    conda-forge
xorg-xextproto            7.3.0             h0b41bf4_1003    conda-forge
xorg-xf86vidmodeproto     2.3.1             h7f98852_1002    conda-forge
xorg-xproto               7.0.31            h7f98852_1007    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
yarl                      1.9.4           py310h2372a71_0    conda-forge
zipp                      3.17.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               hd590300_5    conda-forge
zstd                      1.5.5                hfc55251_0    conda-forge
@jmwright jmwright added the bug Something isn't working label Apr 24, 2024
@jmwright jmwright self-assigned this Apr 24, 2024
@adam-urbanczyk
Copy link
Member

adam-urbanczyk commented Apr 24, 2024

I agree, approximate equality check sounds like a good solution.

@jmwright
Copy link
Member Author

There may be a bigger issue here. When I fixed the first part of the test the next part of it failed with an even larger error.

The alignment settings are passed to OpenCASCADE and we don't seem to always be getting the correct result back across systems. The following code should horizontally and vertically center the letter "I".

import cadquery as cq

centers = cq.Workplane().text("I", 10, 0, halign="center", valign="center", font="Sans")

show_object(centers)

However, this is the result I get in CQ-editor (conda master install).

Screenshot from 2024-04-24 14-54-21

@lorenzncode
Copy link
Member

I suppose it could be related to font differences between platforms as well,

we don't seem to always be getting the correct result back across systems.

Do you get consistent results if you specify fontPath explicitly for these alignment tests?

I do not find a bigger issue with text alignment as far as the CQ results appear to agree with other tools such as blender (comparing CQ valign="center" with blender Vertical=Middle).

@michaelgale
Copy link

This could very well be a difference of font metrics issue between platforms. The resulting font asset file that the OS returns for "Sans" could be the same, similar or different among platforms. The only definitive way of testing is to bundle a known TrueType font file with the CQ test suite and explicitly reference its path.

@jmwright
Copy link
Member Author

@lorenzncode Specifying the font path does not fix the issue.

This may be related to #187 . In that issue the same suggestion is made as the one from @michaelgale about bundling a font file for tests so that the tests cannot fail across platforms.

It still seems like there is a bigger issue though when using halign="center", valign="center" does not actually center the resulting text, or at least centers it differently depending on the OS. That may be unavoidable, but maybe a note should be added in the docs.

@jmwright jmwright linked a pull request Apr 29, 2024 that will close this issue
@jmwright
Copy link
Member Author

@michaelgale @lorenzncode See #1577 for a fix for the test failures across platforms.

@adam-urbanczyk
Copy link
Member

@jmwright what is the conclusion actually? You wrote above that specifying the font path does not solve the issue, but your PR does specify a path. Is the PR using a different font than one causing the issue?

@jmwright
Copy link
Member Author

@adam-urbanczyk Specifying the path to the font that CadQuery should have already been using based on the font name did not fix the issue. I was assuming that's what @lorenzncode wanted me to test.

In this PR I used a known font that is already embedded in the repo so that we can avoid this test failure in the future, no matter which OS or distro they are run on. We can discuss whether there is a bigger issue with font alignment in a separate issue.

@lorenzncode
Copy link
Member

fontPath is used to specify a font file. That's what I meant - to verify that specifying a font file explicitly as done in some of the other existing tests resolves the issue.

fontPath=os.path.join(testdataDir, "OpenSans-Regular.ttf"),

@jmwright
Copy link
Member Author

@lorenzncode I had forgotten we included the OpenSans font file in the testdata directory, so I switched the test to use that.

I think the root of the problem is that my system defaults to the Ubuntu Mono Regular font, which causes the bounding box asserts to fail by the values seen above. I haven't seen a warning when the font name and/or font path don't exist on the system, so it's fairly easy to accidentally cause a fall-back to the profile/system default font and not know it. This is mainly an issue when using font names or relative paths to font files. I got bitten by this multiple times while debugging.

@lorenzncode
Copy link
Member

I haven't seen a warning when the font name and/or font path don't exist on the system, so it's fairly easy to accidentally cause a fall-back to the profile/system default font and not know it.

@jmwright This may be another reason to provide an interface to OCCT messages. I had explored that some in #1525. Testing with that branch:

import cadquery as cq
from cadquery.occ_impl.message import Message, Level

Message.set_trace_level(Level.info)
report = cq.message.Message.add_report()

r = cq.Workplane().text("my text", 12, 0.1, font="badfont")

alerts = report.GetAlerts(cq.message.Level.info.value)

# optionally handle alerts, raise error

Output message:

Font_FontMgr, warning: unable to find font 'badfont' [regular]; 'DejaVu Sans' [aspects: regular,bold,italic,bold-italic] [paths: /usr/share/fonts/dejavu-sans-fonts/DejaVuSans.ttf;/usr/share/fonts/dejavu-sans-fonts/DejaVuSans-Bold.ttf;/usr/share/fonts/dejavu-sans-fonts/DejaVuSans-Oblique.ttf;/usr/share/fonts/dejavu-sans-fonts/DejaVuSans-BoldOblique.ttf] is used instead

@jmwright
Copy link
Member Author

@lorenzncode I see the value in that. Can we create a logging level setting in CQ so that users can turn it up after importing the cadquery package? We would probably have to implement the logging over time as we implement/fix features, but a global setting would be a place to start.

@lorenzncode
Copy link
Member

@jmwright Yes, I would like an option to set the OCCT message trace level where the source of the messages is OCCT. It might also be useful to interface with the OCCT Message_Report in some cases.

@jmwright
Copy link
Member Author

jmwright commented May 3, 2024

@lorenzncode Ok. I think we should make that a separate issue rather than trying to implement it in #1577

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants