Class StringBounderEmbeddedFont

java.lang.Object
net.sourceforge.plantuml.klimt.drawing.font.StringBounderEmbeddedFont
All Implemented Interfaces:
StringBounder

public class StringBounderEmbeddedFont extends Object implements StringBounder
Measures text with the metrics of the fonts embedded in PlantUML (Liberation Sans), without AWT, so that the TeaVM C build lays out exactly as the JVM does on Windows, and draws with the very same fonts.

It reproduces what StringBounderAwt gives on Windows, where Java maps its logical font "SansSerif" to Arial (whose metrics are Liberation Sans's):

  • a character is as wide as its glyph's advance (fractional metrics: no rounding, no kerning, no ligatures);
  • a logical font is a composite: its line also makes room for the fonts it falls back on for other scripts, which raise its ascent and descent to at least LOGICAL_MIN_ASCENT and LOGICAL_MIN_DESCENT; and the characters it does not take from Arial (those Arial lacks, and those of Arial's exclusion ranges in Java's fontconfig.properties, such as dashes and typographic quotes) have the widths Java gives them on Windows, measured once by tools/font-metrics/MeasureLogicalFonts.java;
  • a font named Arial (or Liberation Sans) is a physical font: its own line height, and its missing glyph for the characters it lacks.
Other families (serif, monospace...) are measured as "SansSerif" for now: only Liberation Sans is embedded.

Known difference: when a text contains a character of a complex script (combining marks U+0300-036F, Hebrew, Arabic, Indic, Thai, bidi controls...), Java2D shapes the whole text with HarfBuzz, which can move a mark's base or hide a soft hyphen. Other text (precomposed accents, Greek, Cyrillic...) measures exactly as with Java2D.