diagram_core/src/render/text.rs#
Source: lib/diagram_core/src/render/text.rs
text -- a shape's text laid out in its text block (JD4): runs of characters, paragraphs,
wrapping, alignment, the text block's transform and margins
Measure what the layout asks of fonts: the advance of a text at a
font size of 1 inch, ascent and descent; the drawing side
(diagram_view) measures with the fonts it draws with
ApproxMeasure half an em per character (tests, no fonts at hand)
TextItem { xform, runs } lines of runs in the text frame (paper inches, y up) and
the frame's map to the page; decorations and the text
background come as their own stroke and fill items
measure_text(&mut m, &face, size, text, max_width) -> (w, h) (JD7) a text in one format
wrapped as a shape's text wraps: the widest line and the
lines' height (the formula engine's TEXTWIDTH/TEXTHEIGHT
through diagram_view's Metrics)
The text comes as the file keeps it (Text: characters between cp, pp, tp and fld marks,
JD3): a cp mark selects the Character row for what follows, a pp mark the Paragraph row; a
field Visio wrote with its text inside shows that text, one without text inside (a field of
JFDiagrammer) its Field row's value in its format (field.rs); LF ends a paragraph,
U+2028 breaks a line inside one, the last LF of a text is Visio's end mark and makes no empty
paragraph. Character cells: Font, Size, Color, ColorTrans, Style (1 bold, 2 italic,
4 underline, 8 small caps), Case (1 all caps, 2 initial caps), Pos (1 superscript,
2 subscript), Strikethru, DblUnderline, Overline, FontScale, Letterspace. Paragraph cells:
IndFirst, IndLeft, IndRight, SpLine (below 0: a multiple of the font size, above 0: inches,
0: 120 %), SpBefore, SpAfter, HorzAlign (0 left, 1 centre, 2 right, 3 justified and 4
distributed drawn left), Bullet and BulletStr. Text block cells: the four margins,
VerticalAlign (0 top, 1 middle, 2 bottom), TextBkgnd (0 none, else a colour; a number is a
colour index plus one), TextDirection (1: vertical), DefaultTabStop. Lines wrap at spaces
(a word wider than the line at characters); text that does not fit overflows the block
the way VerticalAlign says.
struct Face<'a>a font as the text asks for it: the family the file names, bold, italicfamily: &'a strbold: boolitalic: bool
trait Measurewhat the layout needs of fontsfn advance(&mut self, face: &Face, text: &str) -> f64the advance oftext(one line, no control characters) at a font size of 1 inch, in inchesfn metrics(&mut self, _face: &Face) -> (f64, f64)ascent and descent in em, both positive
struct ApproxMeasurehalf an em per character, a fifth for a spacestruct TextItema shape's text, laid outxform: Xform-- the text frame (paper inches, y up, its origin at the block's bottom left corner) to the page: a turn and a move, never a mirror (a flipped shape's text stays readable)runs: Vec<TextRun>
struct TextRuna piece of one line in one formatat: [f64; 2]-- where its baseline starts (frame)text: Stringfamily: String-- the font family as the file names it (the drawing side substitutes)bold: boolitalic: boolsize: f64-- the font size (em) in inchescolor: u32-- 0xAARRGGBBscale_x: f64-- FontScale: how much wider the glyphs are (1: as they are)spacing: f64-- Letterspace: added after every character (inches)width: f64-- the measured advance with scale and spacing (inches)
fn measure_text(m: &mut dyn Measure, face: &Face, size: f64, text: &str, max_width: Option<f64>) -> (f64, f64)the size of a text in one format as a shape's text block sets it: (the widest line, the height of all lines), inches. Paragraphs end at LF (the text's last LF is Visio's end mark), U+2028 breaks a line, lines wrap atmax_widththe way the layout wraps them (at spaces and after hyphens, a word wider than the line at characters), tabs go to stops 0.5 in apart; a line is 120 % of the size high (SpLine's default). An empty text is one empty line.