resize text from write.scad

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

resize text from write.scad

peetersm
Hi, I am having some trouble figuring out how to automatically put user entered text into a box of given dimensions. I want the text to be as large as possible and fit at least one dimension perfectly...no slop. My trouble seems to be that some letters are above the normal letter size (like Q) and some letters go below the normal letter size (like y, or g, etc), and I don't know how to accommodate for some text that has no lower letters and some that would have lower letters (the user is putting in text).

I can get very close with the resize command but have these issues:
1. low letters cause the resized text to have a negative Y displacement.
2. if I want to avoid "stretching" I experimented with the resize auto setting, but it's unpredictable, for example resizing the X direction only works for 1-7 letters, if I have more letters it stops working. ALSO auto resize for Y only resizes based on the normal letter height and ignores tall and low letters.

here's a pic, and my code.
test-resize-text

//text size tester - make text fit inside box
use<write/Write.scad>

initals="PQyhtvsg";
monogram_thick=4;//how far the letter stick out of the flag
FontSize=10;

box_x=50;
box_y=10;
box_z=2;

letternum=len(initals);
echo("counted letters", letternum);

// NO scale - green background
translate([0,box_y*2,0]){
write(initals,h=FontSize,t=monogram_thick);
color("green")translate([0,0,-box_z])cube([box_x,box_y,box_z]);
}

//Just resize - red background
resize([box_x,box_y,0]) write(initals,h=FontSize,t=monogram_thick);
color("red")translate([0,0,-box_z])cube([box_x,box_y,box_z]);

// try auto scale Y - blue background
translate([0,-box_y*2,0]){
resize([0,box_y,0], auto=true) write(initals,h=FontSize,t=monogram_thick);
color("blue")translate([0,0,-box_z])cube([box_x,box_y,box_z]);
}

// try auto scale X - purple background
translate([0,-box_y*4,0]){
resize([box_x,0,0], auto=true) write(initals,h=FontSize,t=monogram_thick);
color("purple")translate([0,0,-box_z])cube([box_x,box_y,box_z]);
}
Reply | Threaded
Open this post in threaded view
|

Re: resize text from write.scad

MichaelAtOz
Administrator
// try auto scale X then scale Y - orange background
translate([0,-box_y*6,0]){
resize([0,box_y,0], auto=false)
resize([box_x,0,0], auto=true) write(initals,h=FontSize,t=monogram_thick);
color("orange")translate([0,-2,-box_z])cube([box_x,box_y,box_z]);
}

with the -2 translation you could have a function that checked whether low letters exist in the text and translate 0 or -2 depending.
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.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: resize text from write.scad

MichaelAtOz
Administrator
Note resize([box_x,box_y,0],auto=true) does the same as the two resize()'s.
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.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: resize text from write.scad

MichaelAtOz
Administrator
BTW. Just noticed j (lower J) is even taller than Q, I suspect it was meant to be lowered like y.
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.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: resize text from write.scad

peetersm
Thanks MichaelAtOz and your right lowercase j is pretty tall.
Doing some more testing this weekend. I see the fact that some letters go below or above the set "letter size" AND that I don't know how to get the size of the object is my issue.
Since I don't know how to figure out the height of an arbitrary text string, I can not figure out how to translate the text to fit inside my rectangle.
My hope was to be able to do the math so the user could just put in the text with out having the also adjust the text position.
The resize command somehow "knows" the total Y height of the text string and scales it properly (around the origin), but I don't know how to glean this info.


On Fri, Jul 4, 2014 at 6:00 PM, MichaelAtOz [via OpenSCAD] <[hidden email]> wrote:
BTW. Just noticed j (lower J) is even taller than Q, I suspect it was meant to be lowered like y.


If you reply to this email, your message will be added to the discussion below:
http://forum.openscad.org/resize-text-from-write-scad-tp8962p8971.html
To unsubscribe from resize text from write.scad, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: resize text from write.scad

nophead
Looks like Q sits too high rather than being too tall. It should be the same position and size as O and the cross should descend.


On 7 July 2014 09:59, peetersm <[hidden email]> wrote:
Thanks MichaelAtOz and your right lowercase j is pretty tall.
Doing some more testing this weekend. I see the fact that some letters go
below or above the set "letter size" AND that I don't know how to get the
size of the object is my issue.
Since I don't know how to figure out the height of an arbitrary text
string, I can not figure out how to translate the text to fit inside my
rectangle.
My hope was to be able to do the math so the user could just put in the
text with out having the also adjust the text position.
The resize command somehow "knows" the total Y height of the text string
and scales it properly (around the origin), but I don't know how to glean
this info.


On Fri, Jul 4, 2014 at 6:00 PM, MichaelAtOz [via OpenSCAD] <
[hidden email]> wrote:

> BTW. Just noticed j (lower J) is even taller than Q, I suspect it was
> meant to be lowered like y.
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
> http://forum.openscad.org/resize-text-from-write-scad-tp8962p8971.html
>  To unsubscribe from resize text from write.scad, click here
> < > .
> NAML
> <
http://forum.openscad.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://forum.openscad.org/resize-text-from-write-scad-tp8962p9014.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566