Having trouble figuring out line spacing factor

This forum is for 'Work-in-Progress' QCAD user developed script Add Ons and Plug-ins.

Please use this forum to request/submit your script Add-Ons & Plug-in idea's.

Moderators: andrew, Husky, J-J

Post Reply
wdfortee
Junior Member
Posts: 10
Joined: Fri Mar 23, 2018 3:18 pm

Having trouble figuring out line spacing factor

Post by wdfortee » Thu Aug 20, 2020 3:22 am

I'm using QCAD Pro 3.21.3 on Windows 10 x64 and ECMAScript.

I'm trying to create a widget that can create text from list, but I need to allow for single or multi line text. I'm calculating text size based on a given text area.

The problem I'm having is trying to figure out how to pre-calculate the line spacing for the multi line text. I haven't dug into the actual C++ code yet to see how this was calculated in the hopes someone on here would already know. I've got a few examples to follow and just can't seem to find common factor in "mm" for line spacing. All height totals coming from using "Misc->Draw->Draw Bounding Box".
  • Using RomanS2:
    • 2 Line Text - Line Spacing = 1.4
      • Text = 5: Total Height = 15.0801mm
      • Text = 4: Total Height = 12.2456mm
      • Text = 3: Total Height = 9.1909mm
    • 3 Line Text - Line Spacing = 1
      • Text = 4: Total Height = 15.5201mm
      • Text = 3.6: Total Height = 13.9681mm
      • Text = 3.5: Total Height = 13.5801mm
Any help is appreciated. I can probably get away with just assuming/hard coding, but would prefer to rely on calculation used to create in the first place.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Having trouble figuring out line spacing factor

Post by andrew » Thu Aug 20, 2020 7:24 am

Multi line text can contain formatting including height changes at any point as well as subscript / superscript. Line spacing depends on the font and formatting used. There is no simple factor involved.

It might be easier to simply create the multi line text and then get the required data from it.

CVH
Premier Member
Posts: 3416
Joined: Wed Sep 27, 2017 4:17 pm

Re: Having trouble figuring out line spacing factor

Post by CVH » Thu Aug 20, 2020 8:29 am

Hi,
RomanS2 is a CXF font. Coded in base 9, none limiting. e_geek
Meaning that a glyph is coded 9 units high but that it can cross these limits.
That is for the capital 'A'. Some info here: https://qcad.org/en/tutorial-editing-cxf-fonts
If I am not mistaken, the same is done for other fonts:
Qcad queries the height of the capital 'A' and uses a factor to make it 9 high.

CXF font are line-art fonts, meaning the lines take the displayed lineweight.
That doesn't alter the glyph's dimensions but displays different in hairline or in 1mm ISO.
TTF fonts are pockets, the boundary nor the fill have a lineweight.
(Untill you explode them and the boundary becomes line-art)

The only script example I can think of that handles fonts and glyph's is scripts\Misc\MiscDraw\TextAlong\TextAlong.js
Here are some other example code: https://www.qcad.org/rsforum/viewtopic.php?f=30&t=6125

Surely your text use more than literals 'A' so a text line its cross-height differs depending your actual text.
That's why '2 Line Text - Line Spacing = 1.4' or '3 Line Text - Line Spacing = 1' do not tell us a lot. :roll:

Tested on the fly with only literals 'A' I come to baseline spacing = TextHeight x LineSpacing x 1.44
and text line spacing = TextHeight x LineSpacing x 1.44 - TextHeight
We should not mind risers and descenders in text formatting.

With your examples at hand, it should be not that hard to figure it out.
Please provide your examples.

Andrew's answer was way shorter and caught me in speed.

Regards,
CVH

wdfortee
Junior Member
Posts: 10
Joined: Fri Mar 23, 2018 3:18 pm

Re: Having trouble figuring out line spacing factor

Post by wdfortee » Thu Aug 20, 2020 9:07 pm

Ok, what I'm hearing is basically text is a pain to deal with. But, I plugged in ((Text Height x Line Spacing x 1.44) - Text Height) and get the right answer each time within hundreths of millimeters. I must be a newb at not only coding, but maths as well. I was already planning on using getBoundingBox method to scale X to the print area.

Thanks for the help, I'm not exactly sure how you even came up with it.

I'm sorry I didn't include more information in the OP, but it looks like I would have just sounded more dumb if I put my calculation for arriving at the different factors per amount of lines of text.

Side note, the project is to import a pdf using XPDF's pdftotext and using Regexp's, find the text needed, display in QTableWidget Widget, generate text entities, export to gcode and print tags on an engraving machine. Haven't seen anything other than commercial products to do anything similar and they're way out of budget. Thanks again.

CVH
Premier Member
Posts: 3416
Joined: Wed Sep 27, 2017 4:17 pm

Re: Having trouble figuring out line spacing factor

Post by CVH » Thu Aug 20, 2020 10:58 pm

wdfortee wrote:
Thu Aug 20, 2020 9:07 pm
Thanks for the help, I'm not exactly sure how you even came up with it.
  • 4 rows of capitals 'A' in RomanS 1 high Line Factor 1 align Base-Left ; placed at a major grid point
    copy 4 times aside using major grid refs ; changed Line Factor to 1.0,1.1,1.2,1.3,1.4
    copy these 1 down ; changed height to 2
    copy 1 of these 1 down; changed height to 1.23 ; changed Line Factor to 2.0375 (something fuzzy to test)
    App prefs ; Modify ; Explode pref. ; Explode multiline text to single line text active
    OK ; QQ ; Select text ; Explode.
    Now you can measure up the distance between the base lines at the first 'A' of the rows for the two sets of 5 text blocks.
    Excel ; table it ; insert plot X-Y(Scatter) ; seems linear ; select curves ; add linear Trendline with equation
    the relation between 1 & 2 high is obvious; derive equation
    test 1.23 x 2.0375 x 1.44 = 3.60882; verify >> =match :P
This is for RomanS in unit mm and metric.
Check it out for other CFX fonts, TTF might fit too. :?:

wdfortee wrote:
Thu Aug 20, 2020 9:07 pm
export to gcode and print tags on an engraving machine.
Highly interested. Artistic, 3D & plain CNC engraver myself.
Learned the trade 6 years ago from my mentor, a neighbor that ended his business and retired.
After 3 generation of engravers, you can figure.
Saved the most robust flatbed table, about 500 x 700 mm net, Jäger spindle 60k revs, Deckel SO grider, and tons of other stuff.
95% of the machines and tools were trashed.
Engraver points 6mm - down to sub 0.1mm. Mills up to 12mm with a 3.5kW addon spindle.
Even have a Deckel G1L Pantograph gathering dust.
His older brother, an ex-engraver too, mentioned recently 'The student surpasses his masters'
I had 3 masters.

What we both miss the most is affordable soft. :!:

Regards,
CVH

wdfortee
Junior Member
Posts: 10
Joined: Fri Mar 23, 2018 3:18 pm

Re: Having trouble figuring out line spacing factor

Post by wdfortee » Thu Aug 20, 2020 11:55 pm

Once again, I am extremely greatful for the help. Especially after you took the time to explain the process you took to figure out 1.44.
Highly interested. Artistic, 3D & plain CNC engraver myself.
Learned the trade 6 years ago from my mentor, a neighbor that ended his business and retired.
After 3 generation of engravers, you can figure.
Saved the most robust flatbed table, about 500 x 700 mm net, Jäger spindle 60k revs, Deckel SO grider, and tons of other stuff.
95% of the machines and tools were trashed.
Engraver points 6mm - down to sub 0.1mm. Mills up to 12mm with a 3.5kW addon spindle.
Even have a Deckel G1L Pantograph gathering dust.
His older brother, an ex-engraver too, mentioned recently 'The student surpasses his masters'
I had 3 masters.
Well, I definitely don't think I qualify as an engraver based on the level of your experience. I just threw together the basic components of a diy 3D printer, loaded an arduino with grbl, beefed up the standard drive system with SFU1204 ball screws, hiwin linear rails for X & Y, lead screw and linear rails for z for .001mm accuracy and a 48V 400W 12,000rpm spindle w/ ER11 Collet. Engraver is only 280 x 320 mm. I'm engraving different size aluminum plates that are only 42mm x 20mm max. I just have to engrave lots of them and we were previously using a Gravograph IM3.

Post Reply

Return to “QCAD 'Script Add-On & Plug-in challenge' - Work in Progress”