<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
There's probably a bug on this but I think the font look up code may
need some work<br>
<br>
I think the CSS code may be using family + weight but then it
reaches<br>
com/sun/javafx/font/PrismFontLoader.java<br>
<br>
// REMIND. Some day need to have better granularity.<br>
<br>
boolean bold = weight != null &&<br>
weight.ordinal() >=
FontWeight.BOLD.ordinal();<br>
<br>
And we don't have an API to return the FontWeight so you can't
figure it out for yourself.<br>
I really should fix all of the above.<br>
<br>
Is the CSS code part all good though ?<br>
<br>
Looking at CssParser I'm not sure what its doing is the intention of
bolder and lighter<br>
} else if ("bolder".equals(ident)) {<br>
weight = FontWeight.BOLD.name();<br>
} else if ("lighter".equals(ident)) {<br>
weight = FontWeight.LIGHT.name();<br>
<br>
I assume they are meant to say find something *relative*, not
*absolute*<br>
Perhaps in the absence of the API to find the real weight it wasn't
implementable ?<br>
<br>
-phil<br>
<br>
<div class="moz-cite-prefix">On 5/29/25 11:33 AM, Dirk Lemmermann
wrote:<br>
</div>
<blockquote type="cite" cite="mid:EE896AC8-C343-40F7-8B3C-78288214E3B6@gmail.com">
I think what I really want is that this feature „simply“ works as
documented. I have not looked at the implementation of the font
support, yet, but it feels like this shouldn’t be too hard to
implement correctly. If somebody knows more about the problem I
would love to hear about it.
<div><br>
</div>
<div>The official JavaFX CSS reference documentation at <a href="https://openjfx.io/javadoc/24/javafx.graphics/javafx/scene/doc-files/cssref.html" moz-do-not-send="true" class="moz-txt-link-freetext">https://openjfx.io/javadoc/24/javafx.graphics/javafx/scene/doc-files/cssref.html</a> lists
font weights (integers) as possible values:</div>
<div>
<div><br>
</div>
<div><span class="grammar" style="font-family: "Lucida Console", Monaco, monospace; font-size: 14px; color: rgb(0, 51, 153);"><font-weight></span><span style="font-family: Helvetica, Arial, sans-serif; font-size: 14px;"> The
font's weight, using the following syntax:</span><br style="font-family: Helvetica, Arial, sans-serif; font-size: 14px;">
<span class="grammar" style="font-family: "Lucida Console", Monaco, monospace; font-size: 14px; color: rgb(0, 51, 153);">[
normal | bold | bolder | lighter | 100 | 200 | 300 | 400 |
500 | 600 | 700 | 800 | 900 ]</span></div>
<div><br>
</div>
<div>
<div> If this will never be supported then I think the docs
need to reflect that.</div>
<div><br>
</div>
<div>Again, the main benefit of this working properly would be
that applications wouldn’t have to use the workaround
anymore where the font family name will be used directly in
all the places where a piece of text has a different weight
than the default one.</div>
<div><br>
</div>
<div>Dirk</div>
</div>
</div>
<div><br>
<blockquote type="cite">
<div>Am 29.05.2025 um 20:03 schrieb John Hendrikx
<a class="moz-txt-link-rfc2396E" href="mailto:john.hendrikx@gmail.com"><john.hendrikx@gmail.com></a>:</div>
<br class="Apple-interchange-newline">
<div>
<div>
<p><br>
</p>
<div class="moz-cite-prefix">On 29/05/2025 18:23, Dirk
Lemmermann wrote:<br>
</div>
<blockquote type="cite" cite="mid:41D3226C-3A6A-4C5A-B9DA-0F1565DA06E1@gmail.com">
<pre class="moz-quote-pre" wrap="">Hi everyone,
Is there any chance we can get font weight working properly so that I can use a font with medium boldness and use it by declaring: -fx-font-weight: bolder; or by declaring -fx-font-weight: 600;? I know I can work around it by using the font family name, e.g. „Rubik Medium“ but this makes it impossible to replace the font at runtime, which is a requirement I am facing right now in order to support users with dyslexia. I was also considering using a variable but this is not supported for font family names (e,g, „-my-font; „Rubik Medium“).</pre>
</blockquote>
Just curious, how would a variable help here for the
problem having the font selectable at runtime?<br>
<blockquote type="cite" cite="mid:41D3226C-3A6A-4C5A-B9DA-0F1565DA06E1@gmail.com">
<pre class="moz-quote-pre" wrap="">Any other work arounds I am missing?</pre>
</blockquote>
<p>I don't have any easy solutions here, and I'm unsure
what is involved in actually making -fx-font-weight work
better.<br>
</p>
<p>So, all I can offer is something very ugly like having
the user select a font, then generating a CSS file, and
setting that on the root node; if you keep the styles
for font selection separate it may be doable as you'd
probably could get away with just replacing a single
stylesheet then (ie. mark a TextField with ".font-large"
specifically and define what that means in the custom
CSS file). This is a bit anti-CSS as you'd prefer to
mark such nodes only with their intended function, and
determine a suitable font based on that, but styles in
FX don't compose.<br>
</p>
<p>If you're willing to go in the direction of generating
all CSS files based on LESS or SCSS (at runtime mind
you, I hate doing this during a build), more is
possible:<br>
</p>
<p>What I've been doing myself (although I don't allow
runtime selection) is to allow users to modify CSS
files; using LESS or SCSS one can neatly pack all font
related stuff into a single file, so I've sort of solved
this by having a `fonts.less` (see below). I then mark
styles with one of the custom styles (.light, .regular,
etc) to indicate what final font they'll be using.
However, to make this work even at run time, I'd have to
regenerate all derived CSS files (but as I said, I can
do this at runtime anyway) -- so the effort is in then
primarily in auto-generating a base fonts CSS file given
some user selection, then replacing all stylesheets that
were set throughout the application (or just restarting
the application).</p>
<p>For now a user could do this manually by only editing
`fonts.less` and then (re)starting the application.<br>
</p>
<p>Here is the fonts.less file I was talking about (note:
there is also a Linux variant as fonts work differently
on different platforms as well... perhaps MacOS needs a
modified one also, but I never tried there)</p>
<p>fonts.less:<br>
</p>
<div style="background-color:#ffffff;padding:0px 0px 0px 2px;">
<div style="background-color: rgb(255, 255, 255); font-family: Consolas; font-size: 11pt; white-space: pre;"><div style="margin: 0px;">/*</div><div style="margin: 0px;"> * The <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span> font supports many variations. To get the correct variation</div><div style="margin: 0px;"> * in JavaFX, select them as follows:</div><div style="margin: 0px;"> * </div><div style="margin: 0px;"> * - Black = <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Blk</span></div><div style="margin: 0px;"> * - Bold = <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span> + font-weight: bold</div><div style="margin: 0px;"> * - <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Semi</span> Bold = <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span> SemBd</div><div style="margin: 0px;"> * - Medium = <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span> Med</div><div style="margin: 0px;"> * - Regular = <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span> + font-weight: normal</div><div style="margin: 0px;"> * - Light = <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span> Light</div><div style="margin: 0px;"> *</div><div style="margin: 0px;"> * Note that these names are for Windows. Other platforms can use</div><div style="margin: 0px;"> * slightly different names.</div><div style="margin: 0px;"> */</div><p style="margin:0;">
</p><div style="margin: 0px;">.light {</div><div style="margin: 0px;"> -fx-font-family: "<span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span> Light";</div><div style="margin: 0px;"> -fx-font-weight: normal;</div><div style="margin: 0px;">}</div><p style="margin:0;">
</p><div style="margin: 0px;">.regular {</div><div style="margin: 0px;"> -fx-font-family: "<span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span>";</div><div style="margin: 0px;"> -fx-font-weight: normal;</div><div style="margin: 0px;">}</div><p style="margin:0;">
</p><div style="margin: 0px;">.medium {</div><div style="margin: 0px;"> -fx-font-family: "<span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span> Med";</div><div style="margin: 0px;"> -fx-font-weight: bold;</div><div style="margin: 0px;">}</div><p style="margin:0;">
</p><div style="margin: 0px;">.semi-bold {</div><div style="margin: 0px;"> -fx-font-family: "<span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span> SemBd";</div><div style="margin: 0px;"> -fx-font-weight: bold;</div><div style="margin: 0px;">}</div><p style="margin:0;">
</p><div style="margin: 0px;">.bold {</div><div style="margin: 0px;"> -fx-font-family: "<span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span>";</div><div style="margin: 0px;"> -fx-font-weight: bold;</div><div style="margin: 0px;">}</div><p style="margin:0;">
</p><div style="margin: 0px;">.black {</div><div style="margin: 0px;"> -fx-font-family: "<span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Noto</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Sans</span> <span style="text-decoration:underline;text-decoration-color:#ff8040;text-decoration-style:wavy;">Blk</span>";</div><div style="margin: 0px;"> -fx-font-weight: bold;</div><div style="margin: 0px;">}</div><p style="margin:0;">
</p><div style="margin: 0px;">fonts-linux.less:
</div><p style="margin:0;">
</p><div style="margin: 0px;">.light {
-fx-font-family: "Noto Sans Light";
-fx-font-weight: normal;
}
.regular {
-fx-font-family: "Noto Sans";
-fx-font-weight: normal;
}
.medium {
-fx-font-family: "Noto Sans Medium";
-fx-font-weight: normal;
}
.semi-bold {
-fx-font-family: "Noto Sans SemiBold";
-fx-font-weight: normal;
}
.bold {
-fx-font-family: "Noto Sans";
-fx-font-weight: bold;
}
.black {
-fx-font-family: "Noto Sans Black";
-fx-font-weight: normal;
}
And using it for some arbitrary style is then done (also with LESS) like:</div><p style="margin:0;">
</p><div style="background-color:#ffffff;padding:0px 0px 0px 2px;"><div style="background-color: rgb(255, 255, 255); font-family: Consolas; font-size: 11pt; white-space: pre;"><div style="margin: 0px;">.style-p3-extra-light {</div><div style="margin: 0px;"> -fx-font-size: 15;</div><div style="margin: 0px;"> .light;</div><div style="margin: 0px;">}</div><p style="margin:0;">
</p><div style="margin: 0px;">Not what you hoped for I think :)</div><p style="margin:0;">
</p><div style="margin: 0px;">--John
</div></div></div></div>
</div>
<div><br class="webkit-block-placeholder">
</div>
<blockquote type="cite" cite="mid:41D3226C-3A6A-4C5A-B9DA-0F1565DA06E1@gmail.com">
<pre class="moz-quote-pre" wrap="">Dirk
</pre>
</blockquote>
</div>
</div>
</blockquote>
</div>
<br>
</blockquote>
<br>
</body>
</html>