[x3d-public] text size clarification
andreasplesch at gmail.com
Sat Oct 26 11:51:47 PDT 2019
x3dom relies on browser font rendering. For example, it uses the
canvas.textBaseline (for minor alignment) and canvas.textAlign (for
major alignment) canvas2d DOM properties to control how and where text
is rendered: https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-textbaseline
Explorer and Chrome have different ideas on where a 'top' baseLine should be:
(For me, Edge shows the top baseline a bit higher than Chrome, and
firefox is between the two).
[Since middle baseline seems to be more consistent across browser, I
modified x3dom to use it for middle minor alignment:
But this seems to fair not much better browsers. It may depend on the
out how html renders font into a canvas (svg is probably similar, css
There is no guarantee that the size of rendered glyphs adhere much to
the requested size, even if requested in pixels. The idea is that the
size is the size of an em square
This is why there is a way to measure actual rendered size:
Here is what https://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/text.html#FontStyle
says about the size field:
"The size field specifies the nominal height, in the local coordinate
system of the Text node, of glyphs rendered and determines the spacing
of adjacent lines of text. Values of the size field shall be greater
A nominal height.
"The spacing field determines the line spacing between adjacent lines
of text. The distance between the baseline of each line of text is
(spacing × size) in the appropriate direction (depending on other
fields described below). The effects of the size and spacing field are
depicted in Figure 15.2 (spacing greater than 1.0). Values of the
spacing field shall be non-negative."
spacing x size is vertical distance between lines.
I think the assumption is that a spacing of 1.0, the default, should
provide enough vertical space for non-overlapping, legible text.
Should there be such specific guidance in the spec. ? So this goes
back how large glyphs of size 1.0 are.
If size 1.0 means the size of an 'X' or 'M', a spacing of 1.0 would
mean overlaps for descenders like 'g' with the line below. Should this
be spelled out ?
So size 1.0 more reasonably means the size of a capital letter plus
some space at the top and at the bottom. The baseline then is not at
the bottom of a line.
A short sentence like "A default FontStyle node must result in clearly
legible, non-overlapping text." may suffice.
Here is a comparison of text rendering relative to a unit square at a
local origin of various browsers:
There are all kinds of problems.
Another question is unicode and non-ascii characters. Does x3d have an
opinion on text encoding ? Is it unicode in all x3d encodings ?
On Thu, Oct 24, 2019 at 6:56 PM Brutzman, Donald (Don) (CIV)
<brutzman at nps.edu> wrote:
> Curiously when tested in 2 browsers, X3DOM did not size the inset or layout text equivalently. Image attached for Internet Explorer and Firefox (Windows 10).
> On 10/24/2019 3:48 PM, Brutzman, Donald (Don) (CIV) wrote:
> > On 8/19/2019 6:46 AM, Andreas Plesch wrote:
> >> https://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/text.html#f-Textsizeandspacingfields
> >> shows how text is sized with the size field.
> >> The example text does not have any letters which reach below the baseline, such as g,j,p, or y, or underscore _. The figure implies that a spacing of 1 would mean that such letters overlap with the line of text below. But this is in conflict with the assumption that as the default value a spacing of 1 should give a readable display for most content.
> >> So should the baseline rather be at the level of the underscore _ ?
> >> Does a size of 1 mean the letter X is ca. 1 unit tall ?
> >> Or does it mean that _X in combination is ca. 1 unit tall ?
> >> Here is how dev. x3dom sizes letters. The square is a unit square, centered at the origin:
> >> https://raw.githack.com/x3dom/x3dom/master/test/regression-suite/test/cases/text/text.html
> >> -Andreas
> >> --
> >> Andreas Plesch
> >> Waltham, MA 02453
> > Apologies for missing this note 2 months ago (just before flying to Japan for ISO X3D meeting). Apparently everyone else did too.
> > Andreas, might you have suggested prose for a spec revision?
> > Also wondering how X_ITE, view3dscene and FreeWrl handle this.
> > Also wondering how HTML5.2 handles this.
> > Now entered as Mantis issue 1265
> > https://www.web3d.org/member-only/mantis/view.php?id=1265
> > Nicholas, I seem to recall your addressing font spacing as part of IRVE at some point... and so you have good fortune to be assigned issue responsibility (for how everyone will view 3D text, for approximately forever). Hope that is OK! 8)
> > all the best, Don
> 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 http://faculty.nps.edu/brutzman
Waltham, MA 02453
More information about the x3d-public