The fonts fallback process
Anyone with exposure to making web pages with CSS will be aware that we have to nominate styling that is applied to the text that we see on web sites and apps. Whilst vwRtx does not use CSS, the approach is similar, but very much more simple.
Within a vwRtx config font stying information is defined in 3 places:
- The hard-coded defaults inside vwRtx.
- In the main
config.font
object. - In the
textDef.fonts
list, used to describe multi-styled text.
A font object has around a dozen attributes. Must we always specify every attribute?
No. We can think of these font definitions as sparse - meaning we can omit attributes - because vwRtx uses a simple fall back approach to find the full picture of a font. This works by looking first for the nearest font to the text being styled, then falling back to the next, and so on.
For example, looking at a the case of the text in a textDef.paras.run
entry, the most significant font attributes are from the linked textDef.fonts
entry. But that entry may have gaps - perhaps the fontSize is omitted. Or the entry can itself be entirely omitted. To get the fontSize we look to the config.font
entry. If fontSize is also omitted from there then the attribute of the internal font is used (see below).
The benefit of this approach is in avoiding the need to be exhaustively explicit when defining font information. It also makes for smaller data serialisation size.
Font defaults
This is the value of the internal font that provides the defaults for omitted font information.
font: {
fontSize: "16px",
fontWeight:"normal",
fontVariant:"normal",
fontFamily:"Arial",
italic:"",
underline: "",
fill: "black",
stroke: "",
highlightColor: "",
strikeout: "",
letterSpacing: 0,
lineHeight: 1
}