discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

3D keychains and cutting out the "whitespace" of text?

R
rickan
Thu, Nov 5, 2020 2:59 AM

rickan wrote

Now I've looked into this I find that PostScript and OpenSCAD scale the
fonts differently. OpenSCAD scales them to a the height you specify and
PostScript seems to scale them to a line spacing. So making this work is
not
so easy and you might have to tweak it for each font you use.

Now I've looked into it even further I've written a postscript file that
automatically finds the OpenSCAD scale for the specified font and then finds
the length of the specified string and prints it out:

/fn fn cvn def
fn findfont 1 scalefont setfont
0 0 moveto (yk) true charpath flattenpath pathbbox 1 exch div /fsf exch def
pop pop pop
fn findfont fsf scalefont setfont
is stringwidth pop ==

Name the above file OSsw.ps or choose your own name and and change the name
in the script below to what you choose. The length is for a text height of 1
so if you want a different height you'll have to scale what the above
produces accordingly however most convenient.

And here's a bash script as an example how to use it in a script:

#!/bin/bash

String for which length is wanted is first argument

PostScript font name second argument

Youll need quotes around a string with spaces.

Both arguments are required.

Run gs -sis=<string> -sfn=<FontName> OSsw.ps to check the font name.

gs will default to it's own choice if it can't find yours and the message

announcing that is suppressed in this script.

On a system running fontconfig use fc-match -v to find the PostScript

name of a font. Example:

$ fc-match -v DeJaVuSans:style=oblique | grep postscriptname

$     postscriptname: "DejaVuSans-Oblique"(w)

Use OpenSCAD Hellp > Font List to get the pattern for fc-match

Remove the spaces from the font name listed by OpenSCAD.

sw=gs -q -dBATCH -dNOPAUSE -sis="$1" -sfn=$2 OSsw.ps
echo The width of $1 in font $2 is $sw

Now it is possible to construct an OpenSCAD command line to execute

in a script similar to this one using $1, $2, and $sw

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

rickan wrote > Now I've looked into this I find that PostScript and OpenSCAD scale the > fonts differently. OpenSCAD scales them to a the height you specify and > PostScript seems to scale them to a line spacing. So making this work is > not > so easy and you might have to tweak it for each font you use. Now I've looked into it even further I've written a postscript file that automatically finds the OpenSCAD scale for the specified font and then finds the length of the specified string and prints it out: /fn fn cvn def fn findfont 1 scalefont setfont 0 0 moveto (yk) true charpath flattenpath pathbbox 1 exch div /fsf exch def pop pop pop fn findfont fsf scalefont setfont is stringwidth pop == Name the above file OSsw.ps or choose your own name and and change the name in the script below to what you choose. The length is for a text height of 1 so if you want a different height you'll have to scale what the above produces accordingly however most convenient. And here's a bash script as an example how to use it in a script: #!/bin/bash # String for which length is wanted is first argument # PostScript font name second argument # Youll need quotes around a string with spaces. # Both arguments are required. # Run gs -sis=<string> -sfn=<FontName> OSsw.ps to check the font name. # gs will default to it's own choice if it can't find yours and the message # announcing that is suppressed in this script. # On a system running fontconfig use fc-match -v to find the PostScript # name of a font. Example: # $ fc-match -v DeJaVuSans:style=oblique | grep postscriptname # $ postscriptname: "DejaVuSans-Oblique"(w) # Use OpenSCAD Hellp > Font List to get the pattern for fc-match # Remove the spaces from the font name listed by OpenSCAD. sw=`gs -q -dBATCH -dNOPAUSE -sis="$1" -sfn=$2 OSsw.ps` echo The width of $1 in font $2 is $sw # Now it is possible to construct an OpenSCAD command line to execute # in a script similar to this one using $1, $2, and $sw -- Sent from: http://forum.openscad.org/
P
playmeforafool
Thu, Nov 5, 2020 3:01 AM

Thanks.  I didn't even notice those examples under the File menu!

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

Thanks. I didn't even notice those examples under the File menu! -- Sent from: http://forum.openscad.org/