Login  Register

Re: Lines pattern scaling

Posted by dxli on Dec 21, 2024; 4:27pm
URL: https://forum.librecad.org/Lines-pattern-scaling-tp5725741p5725862.html

just checked the latest master.

I can see patterns are actually scaling with the entities.

This is wrong, so your fix is needed to make the pattern size defined in the viewing space, so the sizes stay roughly the same when zoomming in/out.

johnfound wrote
dxli wrote
1. in rs_linetypepattern.cpp, it is stated the patterns are defined in pixels. I few we may have to redefine this one. Better to make LibreCAD patterns defined in physical distances, like mm/inches. By defining line patterns in display/rendering space allows zooming in/out, with roughly the same line pattern appearance;
Actually, the patterns are not defined in pixels and I think they never was. In the official versions, they are converted to pixels by multiplying with some constant and displayed this way.

In my version, they are interpreted as a millimeters and displayed this way.

dxli wrote
2. Qt line patterns are defined in line widths, and line width is taken as 1 pixels, if defined to be 0;
3. If we define LibreCAD line patterns in mm,
    p_Qt = p_LC * dpmm/(lineWidth)

with p_Qt and p_LC as the pattern values for QPen and LibreCAD (rs_linetypepattern), dpmm as the standard dots per mm, and lineWidth the line width in pixels.
This formula is not working in the current implementation, because there dpmm is simply a constant, somehow related to the screen/paper size. For correct work, we need dpmm = (pixes_size_on_the_screen/object_mm_size). But if so, then for some line dpmm = lineWidth_px/lineWidth_mm and then the formula becomes:

p_Qt = p_LC_mm/lineWidth_mm

My changes, provide exactly this - correct conversion from mm (in rs_linetypepattern.cpp) to relative units, needed by Qt.
Here is a link to rs_painter.cpp/ RS_Painter::SetPen() in my version:  

The conversion

How the k constant is computed

And you can check it simply by pulling the recent commit from my working repo: jf_fixes branch and test it.

If you don't want to mess with fossil, here is a download link for the source: LibreCad_jf_fixes.tar.gz