[x3d-public] draft X3D 4.1 prose for font files and libraries

Michalis Kamburelis michalis.kambi at gmail.com
Sat Mar 1 17:54:32 PST 2025


A correction to my last mail:

I experimented, and I was wrong to claim that font family name, or style,
are not specified in the font file contents. They *are* or at least they
*can be*. Mea culpa, I learned something.

3 proofs that family name and style *are* inside font file:

1. I opened
https://fonts.gstatic.com/s/playwritecaguides/v1/MjQamj1kuP_soQ3o-rysO9Ci_8oJlIUUInI.woff2
and it *does* specify the family name "Playwrite CA Guides" inside. GNOME
file viewer shows this name, so evidently it comes from contents (because
URL and filename do not reveal anything), like WOFF header.

2. I tested renaming TTF files in
https://github.com/castle-engine/castle-engine/tree/master/src/fonts/data
trying to "confuse" the GNOME font viewer. But renaming
"DejaVuSerif-BoldItalic.ttf" to "MyFont-Italic.ttf" or even
"SomethingNonsense.ttf" doesn't have any effect -- GNOME font viewer stil
knows this is font family "DejaVu Serif" and style is "Bold Italic".
Evidently it comes from TTF header.

3. Finally, I looked can I get this information using FreeType API, which
is what we use in Castle Game Engine. Yes, we can -- FreeType FT_Face
structure (
https://freetype.org/freetype2/docs/reference/ft2-face_creation.html#ft_face
) contains fields family_name (string), style_name (string), style_flags
(integer which can be checked for bits like FT_STYLE_FLAG_ITALIC,
FT_STYLE_FLAG_BOLD). So I think I know how GNOME file viewer knows this.

It is still true that I didn't see designs that rely on this "font name and
style specified inside the font file contents". As you saw from
https://stackoverflow.com/questions/12812441/how-do-i-use-woff-fonts-for-my-website
, the CSS design allows to assign own family name and style to font files
-- not rely on family name from font file. That is also how we allow to use
fonts in Castle Game Engine, e.g. in
https://castle-engine.io/apidoc/html/CastleFonts.TCastleFontFamily.html you
specify yourself which font file goes to which slot (regular / bold /
italic / bold + italic).

And I still didn't see a "single font file" that can collect multiple
families or font styles. But, well, maybe I don't know something again :)
Does anyone has a test font file that contains multiple styles/families?

All in all, this means that I was wrong and FontLibrary is possible to
implement, in the exact way Don describes and shows in example. An X3D
browser can load all the fonts mentioned in the top-level FontLibrary, read
their family names and styles, and then the browser could use them (if
FontStyle.family and FontStyle.style indicate them).

Regards,
Michalis

niedz., 2 mar 2025 o 01:48 Michalis Kamburelis <michalis.kambi at gmail.com>
napisał(a):

> Don,
>
> It seems there are some assumptions in your design that don't match what I
> experience when actually loading fonts :)
>
> - The "font file" like TTF / OTF / WOFF is really just one font, that is:
> it is a set of glyphs for *one* particular family and *one* style
> combination.
>
> - And the name of that family, and the style, is not even specified inside
> this font file. It's only, only by loose conventions, usually somehow
> reflected in the font filename. E.g. we can guess that
> "DejaVuSerif-BoldItalic.ttf" contains font family "DejaVuSerif" and the
> style is "BOLDITALIC", but that's really only a loose convention, people
> name their fonts in whatever way they want.
>
> - The "font file" is not a collection of font definitions, it's not a
> collection of font styles, and it doesn't even say what is the "family
> name" inside. Your design of FontLibrary seems to assume otherwise.Your
> example shows FontLibrary with URLs using
> "MjQamj1kuP_soQ3o-rysO9Ci_8oJlIUUInI.woff2" and then FontStyle.family
> saying "Playwright_CA_Guides". But there's no connection between these 2
> things.
>
> See the references I posted in my answers, e.g. about WOFF in CSS:
> https://stackoverflow.com/questions/12812441/how-do-i-use-woff-fonts-for-my-website
> :
>
> """
> @font-face {
>   font-family: "myfont";
>   src: url("fonts/awesome-font.woff") format('woff');
> }
>
> @font-face {
>   font-family: "myfont";
>   src: url("fonts/awesome-font-bold.woff") format('woff');
>   font-weight: bold;
> }
>
> @font-face {
>   font-family: "myfont";
>   src: url("fonts/awesome-font-boldoblique.woff") format('woff');
>   font-weight: bold;
>   font-style: italic;
> }
>
> @font-face {
>   font-family: "myfont";
>   src: url("fonts/awesome-font-oblique.woff") format('woff');
>   font-style: italic;
> }
>
>
> ...
>
> .mydiv {
>   font-family: myfont;
> }
> """
>
> So you have 4 WOFF files. Each one defines a different style. The above
> CSS definition makes them all available under a family name "myfont" (which
> is just an invented family name, to connect the usage in .mydiv with 4 font
> files mentioned above).
>
> Maybe I don't know something, maybe there are other font "collections",
> but I didn't see them or use them. Reading WOFF spec (
> https://www.w3.org/TR/WOFF2/ ) doesn't seem to contradict what I'm
> saying. And all my usage of TTF / OTF / WOFF files only confirms it. One
> file = one family with one style.
>
> Regards,
> Michalis
>
> sob., 1 mar 2025 o 23:38 Brutzman, Donald (Don) (CIV) via x3d-public <
> x3d-public at web3d.org> napisał(a):
>
>> The current design-phase draft prose assumes that
>>
>>    - FontLibrary loads font files and has them available for use by
>>    FontStyle and ScreenFontStyle,
>>    - FontStyle does not load any files,
>>    - FontStyle definition of 'family' field will look through all of the
>>    available fonts to find the correctly matching family.
>>
>> If that is not possible, then it would seem we need another design
>> (perhaps the cyan text) that can closely couple a single
>> perhaps-no-name font file with a corresponding FontStyle.
>>
>> My understanding is that a font file can contain multiple fonts, and
>> optionally multiple styles for each font.  If so, then some kind of
>> disambiguation by name must be possible, correct?
>>
>> From this perspective, does it seem that two types of font files are
>> possible?
>>
>>    - Those containing a single perhaps-no-name font family, or
>>    - Those containing multiple named font families.
>>
>> Perhaps we need to look at multiple font specifications in detail?  Here
>> is the primary specification, WOFF2:
>>
>>    - W3C WOFF File Format 2.0, section 3. Overall file structure and
>>    basic data types
>>    - "The structure of WOFF2 files is similar to that of SFNT and WOFF
>>    1.0 font files, in that there is a header followed by a table directory,
>>    followed by the data for those tables. The SFNT structure is described
>>    fully in the TrueType [TrueType], OpenType [OpenType], and ISO "Open Font
>>    Format" [OFF] specifications."
>>    - "A complete WOFF2 file consists of several blocks of data: a
>>    48-byte header, immediately followed (in this order) by a variable-size
>>    Table Directory, an optional Collection Directory (present only if the
>>    input font file is a font collection), a compressed font data block, an
>>    optional block of Extended Metadata, and an optional block of Private Data."
>>    - "WOFF2 File
>>    - WOFF2Header File header with basic font type and version, along
>>       with offsets to metadata and private data blocks.
>>       - TableDirectory Directory of font tables, containing size and
>>       other info. "
>>       - https://www.w3.org/TR/WOFF2/#FileStructure
>>    -
>>    WOFF File Format 2.0 - World Wide Web Consortium (W3C)
>>    <https://www.w3.org/TR/WOFF2/#FileStructure>
>>    3. Overall file structure and basic data types. The structure of
>>    WOFF2 files is similar to that of SFNT and WOFF 1.0 font files, in that
>>    there is a header followed by a table directory, followed by the data for
>>    those tables.
>>    www.w3.org
>>
>>
>> all the best, Don
>>
>> --
>>
>> Don Brutzman  Naval Postgraduate School, Code USW/Br
>> brutzman at nps.edu
>>
>> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA
>> +1.831.656.2149
>>
>> X3D graphics, virtual worlds, navy robotics
>> https://faculty.nps.edu/brutzman
>>
>>
>>
>> ------------------------------
>> *From:* x3d-public <x3d-public-bounces at web3d.org> on behalf of Holger
>> Seelig via x3d-public <x3d-public at web3d.org>
>> *Sent:* Saturday, March 1, 2025 2:12 PM
>> *To:* X3D <x3d-public at web3d.org>
>> *Cc:* Holger Seelig <holger.seelig at yahoo.de>
>> *Subject:* Re: [x3d-public] draft X3D 4.1 prose for font files and
>> libraries
>>
>> I would also like to point out once again that a font file (WOFF, OTF,
>> TTF) does not automatically contain the name or family name of the font. A
>> name can therefore only be extracted from the URL. Which is certainly not
>> desirable.
>>
>> It is therefore not clear how to deduce a font file from the field
>> `FontStyle.family`.
>>
>> Best regards,
>> Holger
>>
>> --
>> Holger Seelig
>> Leipzig, Germany
>>
>> holger.seelig at yahoo.de
>> https://create3000.github.io/x_ite/
>>
>> Am 27.02.2025 um 13:26 schrieb Andreas Plesch via x3d-public <
>> x3d-public at web3d.org>:
>>
>> Since I wanted to do this for some time as it really makes webfonts much
>> more usable with x3dom, I came up with a first implementation of the url
>> field:
>>
>>
>> https://andreasplesch.github.io/Library/Viewer/index.html?url=https://gist.githubusercontent.com/andreasplesch/dc9111dcd106f1a69d567ceca8f52701/raw/8cdf9764f11e08b5f541dee487fc0811bb0cf927/FontHaveFunWithX3D.x3d
>>
>> This is experimental and only for the viewer.
>>
>> All loading can be done now by x3dom. Both the style and family fields
>> are essentially ignored if a url MFString is available. Multiple urls can
>> be provided as fallbacks. The url field accepts input and can be changed
>> dynamically.
>>
>> Here are other examples which show how css in the html can be used for
>> webfont loading.
>>
>> https://andreasplesch.github.io/x3dom/test/functional/text_fonts.html
>>
>> That can have advantages as this then provides all of the very many css
>> options to x3d. For example, it is straightforward to copy and paste the
>> css provided by google fonts. The link between css and x3d becomes the
>> font-family name plus style plus weight. No changes to the spec. are needed.
>>
>> The simplest solution other than a url field I can think of is a new Font
>> node which can only represent one font file with a single font and
>> overrides family and style fields. That node can then be DEF/USEd between
>> Text nodes. Perhaps there could be an additional FontLibray node which can
>> hold multiple Font nodes but I am not sure if this is necessary.
>>
>> In theory, it would be possible to add style (normal, italic) and weight
>> (quite a few classes, and numeric) fields to such a Font node. These would
>> define what the font provides. Then the FontStyle fields could be used
>> to either select the closest match for rendering, or do synthesis which can
>> be useful as some fonts do not have bold or italic versions. But all this
>> is really the responsibility of the author anyways, and not necessary.
>>
>> Andreas
>>
>> On Wed, Feb 26, 2025 at 10:51 PM Michalis Kamburelis <
>> michalis.kambi at gmail.com> wrote:
>>
>> Andreas Plesch wrote:
>> > https://www.w3.org/TR/WOFF2/ is a compressed version of WOFF which
>> seems popular on the web due to smaller file sizes. For example, it is used
>> by the Google free Font service. I do not know if there are js/pascal/c
>> etc. loading libraries for woff2 but it should at least be recommended.
>>
>> CGE (Pascal) just uses FreeType for font reading, so we should support
>> everything that FreeType handles :) And it does support WOFF 2
>> according to https://www.phoronix.com/news/FreeType-2.10.2-Released .
>>
>> >
>> > From what I can tell WOFF and WOFF2 do not need to include font family
>> name information inside the file. So I think that means if such a file is
>> provided it will take precedence over the family field. Holger's
>> overloading suggestion implicitly did this.
>> >
>> > A web browser will synthesize bold and italic versions from a normal
>> font version. Should this become a requirement for x3d as well ? Probably
>> not. If authors want to use a bold version for certain, they need to
>> provide corresponding font files.
>>
>> I see Andres comments align nicely with mine, posted 5 mins ago :)
>>
>> I also don't think X3D browsers should have the requirement to
>> synthesize bold and italic versions from a normal font version. If
>> FreeType doesn't do this (and I don't think it can) then it's not
>> something I would ever implement, frankly. I'm not even sure how good
>> are WWW browsers at doing this "synthesizing". The recommendation for
>> using fonts, that I always seen followed, is that you need 4 font
>> files (regular, bold, italic, bold+italic) if you want to provide all
>> the options. The font authors seems to generally agree -- most fonts
>> come with 4 such files.
>>
>> And as Andreas said, the spec should say that "url" overrides "family".
>>
>> Regards,
>> Michalis
>>
>>
>>
>> _______________________________________________
>> x3d-public mailing list
>> x3d-public at web3d.org
>> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>>
>>
>> _______________________________________________
>> x3d-public mailing list
>> x3d-public at web3d.org
>> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20250302/c42d942f/attachment-0001.html>


More information about the x3d-public mailing list