@reintent/scene/measure
Measuring: where every semantic thing is, in scene units, and how much room a text takes.
Geometry comes from the shapes themselves (SVG bounding boxes), each owned by the nearest data-sem: occlusion is ignored, so the man behind the door still has his whole box. What can be seen of each thing comes from the pick buffer (@reintent/scene/pick). Atmosphere is measured on its own, for the verifier to ask about any that covers most of the frame. A text is measured in the DOM, off screen, or approximately where there is no DOM.
Interfaces
AtmosphereBox
Defined in: packages/scene/src/measure.ts
A piece of atmosphere: how much of the frame it covers, and whether it stays on its thing.
Properties
Box
Defined in: packages/scene/src/measure.ts
A box in scene units.
Properties
| Property | Type | Description |
|---|---|---|
px | number | Pixels (visible boxes), in scene units squared; 0 for geometry. |
x0 | number | - |
x1 | number | - |
y0 | number | - |
y1 | number | - |
TextSize
Defined in: packages/scene/src/measure.ts
How much room a text takes, in CSS pixels.
Properties
Type Aliases
TextMeasurer
type TextMeasurer = (text, style, maxWidth) => TextSize;Defined in: packages/scene/src/measure.ts
Measures a text in a style (CSS properties, camel-cased: fontSize, lineHeight, textWrap, …),
at most maxWidth wide.
Parameters
| Parameter | Type |
|---|---|
text | string |
style | Readonly<Record<string, string>> |
maxWidth | number |
Returns
Functions
approxTextSize()
function approxTextSize(
text,
size,
maxWidth,
lineHeight?
): TextSize;Defined in: packages/scene/src/measure.ts
A text's size without a DOM (in Node, in a test, in a Worker): a CJK character a full em, any other
about half, broken into lines at maxWidth, each line lineHeight ems.
Parameters
| Parameter | Type | Default value |
|---|---|---|
text | string | undefined |
size | number | undefined |
maxWidth | number | undefined |
lineHeight | number | 1.3 |
Returns
Example
import { approxTextSize } from '@reintent/scene/measure';
console.log(approxTextSize('别再为每块屏幕各做一份', 20, 120));
// → { w: 120, h: 52 }createTextMeasurer()
function createTextMeasurer(doc?): TextMeasurer;Defined in: packages/scene/src/measure.ts
A text measurer on the DOM: one probe, off screen, which takes each text in its style and is read
for its box; each answer is kept. A balanced text (textWrap: 'balance') with lines of its own is
set a block per line, so each balances by itself: the browser does not balance across a forced
break.
Parameters
| Parameter | Type | Default value |
|---|---|---|
doc | Document | document |
Returns
measureAtmosphere()
function measureAtmosphere(svg): AtmosphereBox[];Defined in: packages/scene/src/measure.ts
Every piece of atmosphere (<Atmosphere>, data-sem-post): how much of the frame it covers, and
whether it stays on the thing it belongs to. Atmosphere is left out of everything else, so it is
where an undeclared thing could hide.
Parameters
| Parameter | Type |
|---|---|
svg | SVGSVGElement |
Returns
measureGeometry()
function measureGeometry(svg): Map<string, Box>;Defined in: packages/scene/src/measure.ts
Every semantic path's box, from the shapes drawn under it, in scene units: a part's box, and its thing's (a box for each of the path's prefixes). Atmosphere and paint servers are left out.
Parameters
| Parameter | Type |
|---|---|
svg | SVGSVGElement |
Returns
Map<string, Box>
sceneToClient()
function sceneToClient(svg): [number, number, number, number, number, number];Defined in: packages/scene/src/measure.ts
Scene units → the svg's client pixels (what the viewer sees), as [a, b, c, d, e, f].
Parameters
| Parameter | Type |
|---|---|
svg | SVGSVGElement |
Returns
[number, number, number, number, number, number]
Last updated on
Edit on GitHub