-
Notifications
You must be signed in to change notification settings - Fork 291
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
Improve text alignment #1455
Improve text alignment #1455
Conversation
Oh man, those |
The spacing is defined by the font. Shouldn't the font spacing be respected? import cadquery as cq
font1 = "/usr/share/fonts/liberation-mono/LiberationMono-Regular.ttf"
font2 = "/usr/share/fonts/google-droid-sans-fonts/DroidSans.ttf"
a = cq.Workplane().text("A", 20, 2, halign="left", valign="bottom", fontPath=font1)
i = cq.Workplane().text("I", 20, 2, halign="left", valign="bottom", fontPath=font2)
I think it's OK. SVG export provides |
759f935
to
830e713
Compare
Perhaps! I think there's definitely a case to be made that left aligning should respect that spacing, but it was unexpected when I wanted to center a letter on a face and it wasn't actually centered. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1455 +/- ##
==========================================
+ Coverage 94.35% 94.37% +0.01%
==========================================
Files 28 28
Lines 5809 5809
Branches 993 993
==========================================
+ Hits 5481 5482 +1
Misses 197 197
+ Partials 131 130 -1 ☔ View full report in Codecov by Sentry. |
Changes for The PR halign left, right behavior does not match with other tools. I would suggest to revert the changes for left, right. Regarding valign, I would suggest not remove the current bottom (it might be renamed say "bottom-base" then add the new bottom change). The
|
The complexity of the testTextAlignment test has been significantly reduced. There's no longer need to separately calculate bounding boxes, leading to more readable and maintainable code. Added assertions validate alignment based on bounding box coordinates and a defined tolerance level.
The changes refactor the text alignment code in the shapes module of CADquery, by leveraging the Graphic3d attributes from the OCC library. This approach eliminates the need for explicit bounding box calculations, thereby simplifying the code and increasing maintainability. The new code delegates the alignment calculations to the underlying OCC library, providing a more efficient solution.
Good news! We can rely on OCCP to do the alignment for us instead of using a bounding box based method. I've just pushed a couple of commits that should do what's needed. |
Marking as draft while I work on the test failure that popped up. |
This commit simplifies the testTextAlignment method in the test_cadquery module. It focuses on making the assertions clearer and more direct. Also, it removes the usage of ill-defined tolerances and switches to using the assertAlmostEqual method.
This commit updates the expected volume value in the exporter test within the "test_exporters.py" file. This change aligns the test result with the accurate calculation, ensuring the test's validity and improving its reliability.
Good to go now. |
@adam-urbanczyk @lorenzncode It sounds like this is ready for formal review, correct? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice that the solution is based on what OCCT provides!
Since @lorenzncode has previously stated approval of this PR, I'll go ahead and improve it and get it merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @egrim
I found some unexpected text alignment results when cutting text into the faces of a cube and took a swing at improving the results. Here's some code the shows the issue by creating a box and cutting a hole in the center of the
>Z
face for a reference point. It then cuts the letter "I" into that same face with various alignment options:Here is the output before and after the proposed change in this PR.
bottom_left
before:bottom_left
after:centered
before:centered
after:top_right
before:top_right
after: