F
frechefuchs
Wed, Mar 19, 2025 11:57 AM
Hi,
I'm trying to activate a certain font feature (onum, oldstyle digits)
for a font I use with the text() module.
First, I searched documentation for ways to request fonts with defined
font features enabled in OpenSCAD. But I couldn't find anything in the
text() module.
As OpenSCAD seems to use fontconfig, next attempt was putting the
following fontconfig config file in path
$HOME/.config/fontconfig/conf.d/90-fontfeatures.conf .
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>
<match target="font">
<test qual="any" name="family" compare="not_eq" ignore-blanks="true">
<string>XYZ123</string>
</test>
<edit name="fontfeatures" mode="assign">
<string>onum on</string>
</edit>
</match>
</fontconfig>
The file activates feature onum for all fonts /not/ matching font family
name XYZ123, i.e., effectively for any font. This works great in the
(standalone) SciTE text editor. Switching back and forth between "onum
on" and "lnum on" (oldstyle digits vs. lining digits) in the config
file, immediately changes digit shape in the SciTE editor (given the
editor font provides oldstyle digits). Example fonts are Linux
Libertine O, Linux Biolinum O (both from the fonts-linuxlibertine
package) or TeX Gyre Pagella (from the fonts-texgyre package).
But, well, OpenSCAD doesn't seem to care. I can't get OpenSCAD to
render text with oldstyle digits enabled.
Is there any way to enable custom font features when using text() in
OpenSCAD?
Regards,
frechefuchs
system:
Ubuntu 22.04
OpenSCAD 2021.01 (via apt)
Hi,
I'm trying to activate a certain font feature (onum, oldstyle digits)
for a font I use with the text() module.
First, I searched documentation for ways to request fonts with defined
font features enabled in OpenSCAD. But I couldn't find anything in the
text() module.
As OpenSCAD seems to use fontconfig, next attempt was putting the
following fontconfig config file in path
$HOME/.config/fontconfig/conf.d/90-fontfeatures.conf .
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>
<match target="font">
<test qual="any" name="family" compare="not_eq" ignore-blanks="true">
<string>XYZ123</string>
</test>
<edit name="fontfeatures" mode="assign">
<string>onum on</string>
</edit>
</match>
</fontconfig>
The file activates feature onum for all fonts /not/ matching font family
name XYZ123, i.e., effectively for any font. This works great in the
(standalone) SciTE text editor. Switching back and forth between "onum
on" and "lnum on" (oldstyle digits vs. lining digits) in the config
file, immediately changes digit shape in the SciTE editor (given the
editor font provides oldstyle digits). Example fonts are Linux
Libertine O, Linux Biolinum O (both from the fonts-linuxlibertine
package) or TeX Gyre Pagella (from the fonts-texgyre package).
But, well, OpenSCAD doesn't seem to care. I can't get OpenSCAD to
render text with oldstyle digits enabled.
Is there any way to enable custom font features when using text() in
OpenSCAD?
Regards,
frechefuchs
system:
Ubuntu 22.04
OpenSCAD 2021.01 (via apt)
WF
William F. Adams
Wed, Mar 19, 2025 3:53 PM
Is there any way to enable custom font features when using text() in
OpenSCAD?
I doubt it.
You will need to set the text in a tool such as xelatex or lualatex, import the PDF into some vector editor, convert it to paths, then save as an SVG.
Alternately, make a custom version of the fonts which has the features which you wish as the defaults.
William
On Wednesday, March 19, 2025 at 11:51:47 AM EDT, frechefuchs via Discuss <discuss@lists.openscad.org> wrote:
>Is there any way to enable custom font features when using text() in
>OpenSCAD?
I doubt it.
You will need to set the text in a tool such as xelatex or lualatex, import the PDF into some vector editor, convert it to paths, then save as an SVG.
Alternately, make a custom version of the fonts which has the features which you wish as the defaults.
William
TP
Torsten Paul
Wed, Mar 19, 2025 5:04 PM
On 3/19/25 12:57, frechefuchs via Discuss wrote:
I'm trying to activate a certain font feature (onum, oldstyle digits)
for a font I use with the text() module.
This looks like one of those topics where it's very hard to find
information on what's going on under the hood. Most hits show
how to enable that feature in various places, but not how it works.
Is there any way to enable custom font features when using text() in
OpenSCAD?
From what I found so far, the answer seems to be: Not with the
current implementation.
It looks like that fontconfig setup is just storing the request
to enable that feature. But this needs to be separately handled
by telling freetype to map the character using that map instead
of just using the default char map.
The difficult part might be finding out how it should work and
not so much the implementation itself once the "how" is clear.
ciao,
Torsten.
On 3/19/25 12:57, frechefuchs via Discuss wrote:
> I'm trying to activate a certain font feature (onum, oldstyle digits)
> for a font I use with the text() module.
This looks like one of those topics where it's very hard to find
information on what's going on under the hood. Most hits show
how to enable that feature in various places, but not how it works.
> Is there any way to enable custom font features when using text() in
> OpenSCAD?
From what I found so far, the answer seems to be: Not with the
current implementation.
It looks like that fontconfig setup is just storing the request
to enable that feature. But this needs to be separately handled
by telling freetype to map the character using that map instead
of just using the default char map.
The difficult part might be finding out how it should work and
not so much the implementation itself once the "how" is clear.
ciao,
Torsten.
WF
William F. Adams
Wed, Mar 19, 2025 5:18 PM
On Wednesday, March 19, 2025 at 01:05:33 PM EDT, Torsten Paul via Discuss discuss@lists.openscad.org wrote:
The difficult part might be finding out how it should work and
not so much the implementation itself once the "how" is clear.
Look at the source of opensource tools which handle this such as xelatex and lualatex?
William
On Wednesday, March 19, 2025 at 01:05:33 PM EDT, Torsten Paul via Discuss <discuss@lists.openscad.org> wrote:
The difficult part might be finding out how it should work and
not so much the implementation itself once the "how" is clear.
Look at the source of opensource tools which handle this such as xelatex and lualatex?
William
TP
Torsten Paul
Thu, Mar 20, 2025 3:30 AM
On 3/19/25 18:04, Torsten Paul via Discuss wrote:
The difficult part might be finding out how it should work and
not so much the implementation itself once the "how" is clear.
Actually the right place is Harfbuzz, which already provides
functions to handle those features, e.g. with
hb_feature_t features;
const char *f = "+onum";
hb_feature_from_string(f, strlen(f), &features);
hb_shape(hb_ft_font, hb_buf, &features, 1);
instead of what we currently use in FreetypeRenderer.cc
hb_shape(hb_ft_font, hb_buf, nullptr, 0);
So the question is if/how to integrate with fontconfig
or more generally, how to get the feature list to that
place in the OpenSCAD code. As those features can be
applied to parts of the text buffer (onum[:4] applies
to only the first 4 characters), that may point to an
additional argument to text().
The result looks quite nice.
ciao,
Torsten.
On 3/19/25 18:04, Torsten Paul via Discuss wrote:
> The difficult part might be finding out how it should work and
> not so much the implementation itself once the "how" is clear.
Actually the right place is Harfbuzz, which already provides
functions to handle those features, e.g. with
hb_feature_t features;
const char *f = "+onum";
hb_feature_from_string(f, strlen(f), &features);
hb_shape(hb_ft_font, hb_buf, &features, 1);
instead of what we currently use in FreetypeRenderer.cc
hb_shape(hb_ft_font, hb_buf, nullptr, 0);
So the question is if/how to integrate with fontconfig
or more generally, how to get the feature list to that
place in the OpenSCAD code. As those features can be
applied to parts of the text buffer (onum[:4] applies
to only the first 4 characters), that may point to an
additional argument to text().
The result looks quite nice.
ciao,
Torsten.
JB
Jordan Brown
Thu, Mar 20, 2025 4:19 AM
Fontconfig specifications can include a fontfeatures tag, probably in
the form ":fontfeatures=+onum". That seems like an obvious place to
inject them. We'd probably retrieve the features list in
FontCache::find_face_fontconfig, and then hand it to Harfbuzz in
FreeTypeRenderer::ShapeResults::ShapeResults.
Alternatively, we could have a "features" argument to text() that would
then feed to HarfBuzz, either instead of or in addition to the value
from Fontconfig. My mild preference is not to, because this is a pretty
obscure feature.
With respect to the ability to start in the middle of the string... I
wouldn't go there, at least not until we have a more general layout
facility in text(). You could equally well say that you want to change
the font size, or superscript, or any number of other changes in the
middle of the string.
Fontconfig specifications can include a fontfeatures tag, probably in
the form ":fontfeatures=+onum". That seems like an obvious place to
inject them. We'd probably retrieve the features list in
FontCache::find_face_fontconfig, and then hand it to Harfbuzz in
FreeTypeRenderer::ShapeResults::ShapeResults.
Alternatively, we could have a "features" argument to text() that would
then feed to HarfBuzz, either instead of or in addition to the value
from Fontconfig. My mild preference is not to, because this is a pretty
obscure feature.
With respect to the ability to start in the middle of the string... I
wouldn't go there, at least not until we have a more general layout
facility in text(). You could equally well say that you want to change
the font size, or superscript, or any number of other changes in the
middle of the string.
TP
Torsten Paul
Thu, Mar 20, 2025 8:17 AM
On 3/20/25 05:19, Jordan Brown via Discuss wrote:
Alternatively, we could have a "features" argument to text() that would
then feed to HarfBuzz, either instead of or in addition to the value
from Fontconfig. My mild preference is not to, because this is a pretty
obscure feature.
If the font specification handles that ok, the separate argument is
probably not needed. I guess we just need some way of passing the
feature list from the script, without the need of changing anything
in the fontconfig configuration files.
With respect to the ability to start in the middle of the string... I
wouldn't go there, at least not until we have a more general layout
facility in text(). You could equally well say that you want to change
the font size, or superscript, or any number of other changes in the
middle of the string.
Agreed, but it's actually more difficult to do. The built-in parser
in Harfbuzz allows that. Turning it of means we need to have a separate
parser which is also not ideal. In addition it might be unnecessary
for onum, but there's a huge amount of flags (e.g. ligatures) where
it might be useful to specify only a dedicated place. But yes, in
general it would be nice not leaking the implementation details from
Harfbuzz in addition to the already big leak of fontconfig details.
https://en.wikipedia.org/wiki/List_of_typographic_features
ciao,
Torsten.
On 3/20/25 05:19, Jordan Brown via Discuss wrote:
> Alternatively, we could have a "features" argument to text() that would
> then feed to HarfBuzz, either instead of or in addition to the value
> from Fontconfig. My mild preference is not to, because this is a pretty
> obscure feature.
If the font specification handles that ok, the separate argument is
probably not needed. I guess we just need *some* way of passing the
feature list from the script, without the need of changing anything
in the fontconfig configuration files.
> With respect to the ability to start in the middle of the string... I
> wouldn't go there, at least not until we have a more general layout
> facility in text(). You could equally well say that you want to change
> the font size, or superscript, or any number of other changes in the
> middle of the string.
Agreed, but it's actually more difficult to do. The built-in parser
in Harfbuzz allows that. Turning it of means we need to have a separate
parser which is also not ideal. In addition it might be unnecessary
for onum, but there's a huge amount of flags (e.g. ligatures) where
it might be useful to specify only a dedicated place. But yes, in
general it would be nice not leaking the implementation details from
Harfbuzz in addition to the already big leak of fontconfig details.
https://en.wikipedia.org/wiki/List_of_typographic_features
ciao,
Torsten.
T
tsingi
Thu, Mar 20, 2025 1:46 PM
Batik, the Apache.org Java SVG toolkit could convert fonts directly to SVG at one time. I used it ages ago, a lot.
SVG Font was an item in the SVG spec, it was implemented two or three times and should have lived but browser developers are lazy and not that smart and the major browsers campaigned to have it removed along with things like text server and wrapping text which also had two or more implementations.
You might try experimenting with Batik.
https://xmlgraphics.apache.org/batik/
If you tell me something I'll forget it.If you show me something I might remember it.
If you involve me in it, I will understand it.
Sent with Proton Mail secure email.
On Wednesday, March 19th, 2025 at 7:57 AM, frechefuchs via Discuss discuss@lists.openscad.org wrote:
Hi,
I'm trying to activate a certain font feature (onum, oldstyle digits)
for a font I use with the text() module.
First, I searched documentation for ways to request fonts with defined
font features enabled in OpenSCAD. But I couldn't find anything in the
text() module.
As OpenSCAD seems to use fontconfig, next attempt was putting the
following fontconfig config file in path
$HOME/.config/fontconfig/conf.d/90-fontfeatures.conf .
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>
<match target="font">
<test qual="any" name="family" compare="not_eq" ignore-blanks="true">
<string>XYZ123</string>
</test>
<edit name="fontfeatures" mode="assign">
<string>onum on</string>
</edit>
</match>
</fontconfig>
The file activates feature onum for all fonts /not/ matching font family
name XYZ123, i.e., effectively for any font. This works great in the
(standalone) SciTE text editor. Switching back and forth between "onum
on" and "lnum on" (oldstyle digits vs. lining digits) in the config
file, immediately changes digit shape in the SciTE editor (given the
editor font provides oldstyle digits). Example fonts are Linux
Libertine O, Linux Biolinum O (both from the fonts-linuxlibertine
package) or TeX Gyre Pagella (from the fonts-texgyre package).
But, well, OpenSCAD doesn't seem to care. I can't get OpenSCAD to
render text with oldstyle digits enabled.
Is there any way to enable custom font features when using text() in
OpenSCAD?
Regards,
frechefuchs
system:
Ubuntu 22.04
OpenSCAD 2021.01 (via apt)
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Batik, the Apache.org Java SVG toolkit could convert fonts directly to SVG at one time. I used it ages ago, a lot.
SVG Font was an item in the SVG spec, it was implemented two or three times and should have lived but browser developers are lazy and not that smart and the major browsers campaigned to have it removed along with things like text server and wrapping text which also had two or more implementations.
You might try experimenting with Batik.
https://xmlgraphics.apache.org/batik/
If you tell me something I'll forget it.If you show me something I might remember it.
If you involve me in it, I will understand it.
Sent with Proton Mail secure email.
On Wednesday, March 19th, 2025 at 7:57 AM, frechefuchs via Discuss <discuss@lists.openscad.org> wrote:
> Hi,
>
> I'm trying to activate a certain font feature (onum, oldstyle digits)
> for a font I use with the text() module.
>
> First, I searched documentation for ways to request fonts with defined
> font features enabled in OpenSCAD. But I couldn't find anything in the
> text() module.
>
> As OpenSCAD seems to use fontconfig, next attempt was putting the
> following fontconfig config file in path
> $HOME/.config/fontconfig/conf.d/90-fontfeatures.conf .
>
> <?xml version="1.0"?>
>
> <!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
>
> <fontconfig>
>
> <match target="font">
>
> <test qual="any" name="family" compare="not_eq" ignore-blanks="true">
>
> <string>XYZ123</string>
>
> </test>
>
> <edit name="fontfeatures" mode="assign">
>
> <string>onum on</string>
>
> </edit>
>
> </match>
>
> </fontconfig>
>
>
> The file activates feature onum for all fonts /not/ matching font family
> name XYZ123, i.e., effectively for any font. This works great in the
> (standalone) SciTE text editor. Switching back and forth between "onum
> on" and "lnum on" (oldstyle digits vs. lining digits) in the config
> file, immediately changes digit shape in the SciTE editor (given the
> editor font provides oldstyle digits). Example fonts are Linux
> Libertine O, Linux Biolinum O (both from the fonts-linuxlibertine
> package) or TeX Gyre Pagella (from the fonts-texgyre package).
>
> But, well, OpenSCAD doesn't seem to care. I can't get OpenSCAD to
> render text with oldstyle digits enabled.
>
> Is there any way to enable custom font features when using text() in
> OpenSCAD?
>
> Regards,
> frechefuchs
>
> system:
> Ubuntu 22.04
> OpenSCAD 2021.01 (via apt)
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
JB
Jordan Brown
Thu, Mar 20, 2025 3:10 PM
On 3/20/2025 1:17 AM, Torsten Paul via Discuss wrote:
Agreed, but it's actually more difficult to do. The built-in parser
in Harfbuzz allows that. Turning it of means we need to have a separate
parser which is also not ideal. In addition it might be unnecessary
for onum, but there's a huge amount of flags (e.g. ligatures) where
it might be useful to specify only a dedicated place. But yes, in
general it would be nice not leaking the implementation details from
Harfbuzz in addition to the already big leak of fontconfig details.
Leaking Harfbuzz isn't necessarily a bad thing. If we're going to do
something in this area, we have to have something. We have a choice
of adopting what somebody else has done, with the benefit of their
experience, or inventing our own wheel. They each have their
advantages. And if we leak Harfbuzz and then move away from Harfbuzz,
well, we've then got a custom layout language that we have to support on
our own, which is what we would have if we rolled our own from the start.
On 3/20/2025 1:17 AM, Torsten Paul via Discuss wrote:
> Agreed, but it's actually more difficult to do. The built-in parser
> in Harfbuzz allows that. Turning it of means we need to have a separate
> parser which is also not ideal. In addition it might be unnecessary
> for onum, but there's a huge amount of flags (e.g. ligatures) where
> it might be useful to specify only a dedicated place. But yes, in
> general it would be nice not leaking the implementation details from
> Harfbuzz in addition to the already big leak of fontconfig details.
Leaking Harfbuzz isn't necessarily a bad thing. If we're going to do
something in this area, we have to have *something*. We have a choice
of adopting what somebody else has done, with the benefit of their
experience, or inventing our own wheel. They each have their
advantages. And if we leak Harfbuzz and then move away from Harfbuzz,
well, we've then got a custom layout language that we have to support on
our own, which is what we would have if we rolled our own from the start.
TP
Torsten Paul
Thu, Mar 20, 2025 6:06 PM
On 3/20/25 05:19, Jordan Brown via Discuss wrote:
Fontconfig specifications can include a fontfeatures tag, probably in
the form ":fontfeatures=+onum".
Yup, that works. Looks like multiple flags need to be separated by
something else than ":" and ",". I've used ";" and that works to
enable both old numbers and small caps (see screenshot).
ciao,
Torsten.
On 3/20/25 05:19, Jordan Brown via Discuss wrote:
> Fontconfig specifications can include a fontfeatures tag, probably in
> the form ":fontfeatures=+onum".
Yup, that works. Looks like multiple flags need to be separated by
something else than ":" and ",". I've used ";" and that works to
enable both old numbers and small caps (see screenshot).
ciao,
Torsten.