diagram_core/src/units.rs#
Source: lib/diagram_core/src/units.rs
units -- the unit codes of a cell (attribute U) and conversion to the internal units
Unit::parse("MM") / u.code() the code as the file writes it; Unit::Other keeps codes the
crate does not know
u.dimension() Length, Angle, Duration, Date, Area, Number, Text ...
u.to_internal(25.4) -> 1.0 a value in the unit -> the value V stores (inches, radians,
days, square inches); u.from_internal(1.0) -> 25.4
convert(x, from, to) between two units of one dimension
Implicit { drawing, page, text, angle, duration } what DL, DP, DT, DA, DE stand for on a page
The file keeps every value in internal units: lengths in inches, angles in radians, durations
and dates in days; U only says how the value is shown and typed in (FEATURES.md 1.6, [MS-VSDX]
Cell_Type). A text size of 8 pt is V="0.1111" U="PT", an angle of 270 degrees
V="4.7124" U="DEG". DL, DP, DT, DA and DE are "the page's drawing, page, text, angle and
duration unit": without the page they convert like inches, inches, points, radians and days.
Ciceros and didots use the Didot point of 0.376065 mm (1157 dd = 1238 pt of 1/72.27 in).
enum Unita unit code of the attribute UInches-- IN: inchesInchesFrac-- IN_F: inches shown as fractionsFeet-- FT: feetFeetInches-- F_I: feet and inchesYards-- YD: yardsMiles-- MI: milesMilesFrac-- MI_F: miles shown as fractionsNauticalMiles-- NM: nautical miles (1852 m)Millimeters-- MM: millimetresCentimeters-- CM: centimetresMeters-- M: metresKilometers-- KM: kilometresPoints-- PT: points (1/72 in)Picas-- P: picas (12 pt)PicasPoints-- P_PT: picas and pointsDidots-- D: didotsCiceros-- C: ciceros (12 didots)CicerosDidots-- C_D: ciceros and didotsDrawingLength-- DL: the page's drawing unitPageLength-- DP: the page's page unitTextLength-- DT: the text unit (points)Degrees-- DEG: degreesDegreesMinSec-- AD: degrees, minutes, secondsRadians-- RAD: radiansDefaultAngle-- DA: the default angle unitDays-- ED: elapsed daysHours-- EH: elapsed hoursMinutes-- EM: elapsed minutesSeconds-- ES: elapsed secondsWeeks-- EW: elapsed weeksDefaultDuration-- DE: the default duration unitDate-- DATE: a date (days)Acres-- AC: acresHectares-- HA: hectaresPercent-- PER: per cent (the value is a fraction: 0.5 is 50 %)Currency-- CY: currencyBool-- BOOL: a truth valueColor-- COLOR: a colour (index or RGB)Str-- STR: a stringGuid-- GUID: a GUID stringPoint-- PNT: a two-dimensional pointNurbs-- NURBS: the result of a NURBS() formulaPolyline-- POLYLINE: the result of a POLYLINE() formulaNumber-- NUM: a plain numberOther(Sym)-- a code the crate does not know, kept as written
enum Dimensionwhat a unit measuresLength-- internal unit: inchesAngle-- internal unit: radiansDuration-- internal unit: daysDate-- internal unit: days since 30 December 1899Area-- internal unit: square inchesNumber-- a plain number (per cent as a fraction, currency)Typed-- strings, colours, truth values, points, NURBS and polylines: no conversionUnknown-- an unknown unit
impl Unit
fn parse(code: &str) -> Option<Unit>the unit of a known code (None: unknown, keep it as Unit::Other)fn code(self) -> Option<&'static str>the code as the file writes it (None for Other: its Sym holds the code)fn dimension(self) -> Dimensionwhat the unit measuresfn factor(self) -> Option<f64>how many internal units one of this unit is (None: the unit has no factor)fn to_internal(self, value: f64) -> f64a value given in this unit -> the internal value V stores (unchanged without a factor)fn from_internal(self, internal: f64) -> f64an internal value -> the value in this unit (unchanged without a factor)fn convert(value: f64, from: Unit, to: Unit) -> Option<f64>valuein unitfrom-> unitto; None when the dimensions differ or a unit has no factorstruct Implicitwhat the implicit units stand for on a page (its drawing, page, text, angle and duration units);resolvereplaces DL, DP, DT, DA and DE by themdrawing: Unit-- DL: the drawing unit (shown lengths of the drawing)page: Unit-- DP: the page unittext: Unit-- DT: the text unitangle: Unit-- DA: the angle unitduration: Unit-- DE: the duration unit
impl Implicit
fn resolve(&self, unit: Unit) -> Unitthe explicit unit behindunit(other units unchanged)