discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Is multiline text in bounding box possible?

T
Troberg
Thu, Mar 26, 2020 12:32 PM

I want to put some text, automatically wrapped within a bounding box.
Something like a module with a signature somewhat like this:

module textbox(text, font, textsize, xsize,ysize)

What I'm missing is any way to know the dimensions of a string.

I can't see a way to do this, but sometimes I'm stupid and missing something
obvious, so I'll throw the question out here.

--
Sent from: http://forum.openscad.org/

I want to put some text, automatically wrapped within a bounding box. Something like a module with a signature somewhat like this: module textbox(text, font, textsize, xsize,ysize) What I'm missing is any way to know the dimensions of a string. I can't see a way to do this, but sometimes I'm stupid and missing something obvious, so I'll throw the question out here. -- Sent from: http://forum.openscad.org/
M
MichaelAtOz
Thu, Mar 26, 2020 12:46 PM

Short answer, No.
Long answer has lots of font tech reasons.

Possibly for 2035 climate compliant version...


Admin - email* me if you need anything,  or if I've done something stupid...

  • click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

--
Sent from: http://forum.openscad.org/

Short answer, No. Long answer has lots of font tech reasons. Possibly for 2035 climate compliant version... ----- Admin - email* me if you need anything, or if I've done something stupid... * click on my MichaelAtOz label, there is a link to email me. Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. -- Sent from: http://forum.openscad.org/
CA
Carsten Arnholm
Thu, Mar 26, 2020 9:50 PM

On 26.03.2020 13:32, Troberg wrote:

I want to put some text, automatically wrapped within a bounding box.
Something like a module with a signature somewhat like this:

module textbox(text, font, textsize, xsize,ysize)

What I'm missing is any way to know the dimensions of a string.

I can't see a way to do this, but sometimes I'm stupid and missing something
obvious, so I'll throw the question out here.

You can't do that in OpenSCAD. In general you can't query the model for
information such as dimensions.

It is possible in other systems
https://gist.github.com/arnholm/23c482530fd1882c615f5e6e3c9eedca

Carsten Arnholm

On 26.03.2020 13:32, Troberg wrote: > I want to put some text, automatically wrapped within a bounding box. > Something like a module with a signature somewhat like this: > > module textbox(text, font, textsize, xsize,ysize) > > What I'm missing is any way to know the dimensions of a string. > > I can't see a way to do this, but sometimes I'm stupid and missing something > obvious, so I'll throw the question out here. You can't do that in OpenSCAD. In general you can't query the model for information such as dimensions. It is possible in other systems https://gist.github.com/arnholm/23c482530fd1882c615f5e6e3c9eedca Carsten Arnholm
TP
Torsten Paul
Thu, Mar 26, 2020 10:02 PM

On 26.03.20 22:50, Carsten Arnholm wrote:

I don't think this is doing what was asked for ("automatically
wrapped within a bounding box").

ciao,
Torsten.

On 26.03.20 22:50, Carsten Arnholm wrote: > It is possible in other systems > https://gist.github.com/arnholm/23c482530fd1882c615f5e6e3c9eedca I don't think this is doing what was asked for ("automatically wrapped within a bounding box"). ciao, Torsten.
CA
Carsten Arnholm
Thu, Mar 26, 2020 10:15 PM

On 26.03.2020 23:02, Torsten Paul wrote:

On 26.03.20 22:50, Carsten Arnholm wrote:

I don't think this is doing what was asked for ("automatically
wrapped within a bounding box").

Everyone is free to think what they want, but that's what

boundingbox@ b = txt2d.box();

does.

Carsten Arnholm

On 26.03.2020 23:02, Torsten Paul wrote: > On 26.03.20 22:50, Carsten Arnholm wrote: >> It is possible in other systems >> https://gist.github.com/arnholm/23c482530fd1882c615f5e6e3c9eedca > > I don't think this is doing what was asked for ("automatically > wrapped within a bounding box"). Everyone is free to think what they want, but that's what boundingbox@ b = txt2d.box(); does. Carsten Arnholm
TP
Torsten Paul
Thu, Mar 26, 2020 10:23 PM

On 26.03.20 23:15, Carsten Arnholm wrote:

On 26.03.2020 23:02, Torsten Paul wrote:

On 26.03.20 22:50, Carsten Arnholm wrote:

I don't think this is doing what was asked for ("automatically
wrapped within a bounding box").

Everyone is free to think what they want, but that's what

   boundingbox@ b = txt2d.box();

does.

Automatically wrapped means, the size of the box is given
and the text will automatically break the text to fit that
box from a single line string.
Basically doing a layout with a flexible number of lines
depending of the width of the defined box.

You say that's what that code line is doing?

ciao,
Torsten.

On 26.03.20 23:15, Carsten Arnholm wrote: > On 26.03.2020 23:02, Torsten Paul wrote: >> On 26.03.20 22:50, Carsten Arnholm wrote: >>> It is possible in other systems >>> https://gist.github.com/arnholm/23c482530fd1882c615f5e6e3c9eedca >> >> I don't think this is doing what was asked for ("automatically >> wrapped within a bounding box"). > > Everyone is free to think what they want, but that's what > >    boundingbox@ b = txt2d.box(); > > does. Automatically wrapped means, the size of the box is given and the text will automatically break the text to fit that box from a single line string. Basically doing a layout with a flexible number of lines depending of the width of the defined box. You say that's what that code line is doing? ciao, Torsten.
L
lar3ry
Thu, Mar 26, 2020 10:57 PM

Troberg wrote

I want to put some text, automatically wrapped within a bounding box.
Something like a module with a signature somewhat like this:

module textbox(text, font, textsize, xsize,ysize)

What I'm missing is any way to know the dimensions of a string.

I knew I saw it somewhere, and I finally found it. Unfortunately, I have not
been able to get it to work from either the Thingiverse link or the github
link, each for a different reason.
Perhaps soemone more knowledgeable than I can figure out the errors.

https://www.thingiverse.com/thing:3004457
https://github.com/arpruss/miscellaneous-scad

There is no demo in the github repository.

--
Sent from: http://forum.openscad.org/

Troberg wrote > I want to put some text, automatically wrapped within a bounding box. > Something like a module with a signature somewhat like this: > > module textbox(text, font, textsize, xsize,ysize) > > What I'm missing is any way to know the dimensions of a string. I knew I saw it somewhere, and I finally found it. Unfortunately, I have not been able to get it to work from either the Thingiverse link or the github link, each for a different reason. Perhaps soemone more knowledgeable than I can figure out the errors. https://www.thingiverse.com/thing:3004457 https://github.com/arpruss/miscellaneous-scad There is no demo in the github repository. -- Sent from: http://forum.openscad.org/
TP
Torsten Paul
Thu, Mar 26, 2020 11:14 PM

On 26.03.20 23:57, lar3ry wrote:

Nice. The example from Thingiverse works fine. You
need both the fontmetrics.scad and fontmetricsdata.scad
files.

With that:

use <fontmetrics.scad>

text="Lorem ipsum dolor sit amet, quibusdam integer ut condimentum id interdum, in convallis varius nibh consectetuer ut, sed mauris in ut
vel, phasellus non eu tortor quis ante. Nisl lobortis donec, blandit enim pulvinar a wisi suscipit ut, volutpat magna ad ornare metus orci,
id tempor dapibus sit sed ultricies. Magna nibh libero, viverra suspendisse auctor. Egestas magna nullam pulvinar consequat, a enim eu
ornare quis, lacus quis dui id quisque eros. Vitae dignissim dolor sociis, fusce elit a sit, eget posuere sit neque, vivamus enim luctus
etiam et, vitae pellentesque. Sed proin mauris consectetuer tempor auctor, et malesuada magna a torquent non et, mi arcu vitae ligula.";

drawWrappedText(text, font = "Liberation Sans", size = 10, spacing = 1, linespacing = 1, indent = 0, width = 250, halign = "left");

does exactly what it says, it wraps by word at the given
width.

ciao,
Torsten.

On 26.03.20 23:57, lar3ry wrote: > https://www.thingiverse.com/thing:3004457 > https://github.com/arpruss/miscellaneous-scad > > There is no demo in the github repository. Nice. The example from Thingiverse works fine. You need both the fontmetrics.scad and fontmetricsdata.scad files. With that: use <fontmetrics.scad> text="Lorem ipsum dolor sit amet, quibusdam integer ut condimentum id interdum, in convallis varius nibh consectetuer ut, sed mauris in ut vel, phasellus non eu tortor quis ante. Nisl lobortis donec, blandit enim pulvinar a wisi suscipit ut, volutpat magna ad ornare metus orci, id tempor dapibus sit sed ultricies. Magna nibh libero, viverra suspendisse auctor. Egestas magna nullam pulvinar consequat, a enim eu ornare quis, lacus quis dui id quisque eros. Vitae dignissim dolor sociis, fusce elit a sit, eget posuere sit neque, vivamus enim luctus etiam et, vitae pellentesque. Sed proin mauris consectetuer tempor auctor, et malesuada magna a torquent non et, mi arcu vitae ligula."; drawWrappedText(text, font = "Liberation Sans", size = 10, spacing = 1, linespacing = 1, indent = 0, width = 250, halign = "left"); does exactly what it says, it wraps by word at the given width. ciao, Torsten.
L
lar3ry
Fri, Mar 27, 2020 12:58 AM

Nice. The example from Thingiverse works fine. You
need both the fontmetrics.scad and fontmetricsdata.scad
files.

Ahh... I just checked, and I had downloaded it in July 1018, so it was
obviously out of date.
It failed with a 'variable size not specified as parameter'

There is a lot of interesting looking stuff on the github repository.

--
Sent from: http://forum.openscad.org/

> Nice. The example from Thingiverse works fine. You > need both the fontmetrics.scad and fontmetricsdata.scad > files. Ahh... I just checked, and I had downloaded it in July 1018, so it was obviously out of date. It failed with a 'variable size not specified as parameter' There is a lot of interesting looking stuff on the github repository. -- Sent from: http://forum.openscad.org/
JB
Jordan Brown
Fri, Mar 27, 2020 3:30 AM

On 3/26/2020 2:50 PM, Carsten Arnholm wrote:

You can't do that in OpenSCAD. In general you can't query the model
for information such as dimensions.

This is kind of a special case.  Although you can't ask anything about
the results of the text() operator, you could have a function that did
the same underlying font processing and gave you text metric
information without ever getting to the geometry processing.

Just like you can't get the bounding box of a polygon, but you can get
the bounding box of the array of points that you feed to polygon().

Not that you can do it today, but it's not the same as the general
problem of querying geometry.

Michael says it's hard to do internally.  I don't know anything about Qt
so I don't know.

On 3/26/2020 2:50 PM, Carsten Arnholm wrote: > You can't do that in OpenSCAD. In general you can't query the model > for information such as dimensions. This is kind of a special case.  Although you can't ask anything about the results of the text() operator, you could have a function that did the same underlying *font* processing and gave you text metric information without ever getting to the geometry processing. Just like you can't get the bounding box of a polygon, but you can get the bounding box of the array of points that you feed to polygon(). Not that you can do it today, but it's not the same as the general problem of querying geometry. Michael says it's hard to do internally.  I don't know anything about Qt so I don't know.