Git Product home page Git Product logo

Comments (14)

lorenzncode avatar lorenzncode commented on June 3, 2024 1

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).

from cadquery.

jmwright avatar jmwright commented on June 3, 2024 1

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

from cadquery.

lorenzncode avatar lorenzncode commented on June 3, 2024 1

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

from cadquery.

jmwright avatar jmwright commented on June 3, 2024 1

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

from cadquery.

adam-urbanczyk avatar adam-urbanczyk commented on June 3, 2024

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

from cadquery.

jmwright avatar jmwright commented on June 3, 2024

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

from cadquery.

michaelgale avatar michaelgale commented on June 3, 2024

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.

from cadquery.

jmwright avatar jmwright commented on June 3, 2024

@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.

from cadquery.

adam-urbanczyk avatar adam-urbanczyk commented on June 3, 2024

@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?

from cadquery.

jmwright avatar jmwright commented on June 3, 2024

@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.

from cadquery.

lorenzncode avatar lorenzncode commented on June 3, 2024

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"),

from cadquery.

jmwright avatar jmwright commented on June 3, 2024

@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.

from cadquery.

jmwright avatar jmwright commented on June 3, 2024

@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.

from cadquery.

lorenzncode avatar lorenzncode commented on June 3, 2024

@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.

from cadquery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.