JFLib

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 Unit a unit code of the attribute U

    • Inches -- IN: inches
    • InchesFrac -- IN_F: inches shown as fractions
    • Feet -- FT: feet
    • FeetInches -- F_I: feet and inches
    • Yards -- YD: yards
    • Miles -- MI: miles
    • MilesFrac -- MI_F: miles shown as fractions
    • NauticalMiles -- NM: nautical miles (1852 m)
    • Millimeters -- MM: millimetres
    • Centimeters -- CM: centimetres
    • Meters -- M: metres
    • Kilometers -- KM: kilometres
    • Points -- PT: points (1/72 in)
    • Picas -- P: picas (12 pt)
    • PicasPoints -- P_PT: picas and points
    • Didots -- D: didots
    • Ciceros -- C: ciceros (12 didots)
    • CicerosDidots -- C_D: ciceros and didots
    • DrawingLength -- DL: the page's drawing unit
    • PageLength -- DP: the page's page unit
    • TextLength -- DT: the text unit (points)
    • Degrees -- DEG: degrees
    • DegreesMinSec -- AD: degrees, minutes, seconds
    • Radians -- RAD: radians
    • DefaultAngle -- DA: the default angle unit
    • Days -- ED: elapsed days
    • Hours -- EH: elapsed hours
    • Minutes -- EM: elapsed minutes
    • Seconds -- ES: elapsed seconds
    • Weeks -- EW: elapsed weeks
    • DefaultDuration -- DE: the default duration unit
    • Date -- DATE: a date (days)
    • Acres -- AC: acres
    • Hectares -- HA: hectares
    • Percent -- PER: per cent (the value is a fraction: 0.5 is 50 %)
    • Currency -- CY: currency
    • Bool -- BOOL: a truth value
    • Color -- COLOR: a colour (index or RGB)
    • Str -- STR: a string
    • Guid -- GUID: a GUID string
    • Point -- PNT: a two-dimensional point
    • Nurbs -- NURBS: the result of a NURBS() formula
    • Polyline -- POLYLINE: the result of a POLYLINE() formula
    • Number -- NUM: a plain number
    • Other(Sym) -- a code the crate does not know, kept as written
  • enum Dimension what a unit measures

    • Length -- internal unit: inches
    • Angle -- internal unit: radians
    • Duration -- internal unit: days
    • Date -- internal unit: days since 30 December 1899
    • Area -- internal unit: square inches
    • Number -- a plain number (per cent as a fraction, currency)
    • Typed -- strings, colours, truth values, points, NURBS and polylines: no conversion
    • Unknown -- 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) -> Dimension what the unit measures

  • fn 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) -> f64 a value given in this unit -> the internal value V stores (unchanged without a factor)

  • fn from_internal(self, internal: f64) -> f64 an internal value -> the value in this unit (unchanged without a factor)

  • fn convert(value: f64, from: Unit, to: Unit) -> Option<f64> value in unit from -> unit to; None when the dimensions differ or a unit has no factor

  • struct Implicit what the implicit units stand for on a page (its drawing, page, text, angle and duration units); resolve replaces DL, DP, DT, DA and DE by them

    • drawing: Unit -- DL: the drawing unit (shown lengths of the drawing)
    • page: Unit -- DP: the page unit
    • text: Unit -- DT: the text unit
    • angle: Unit -- DA: the angle unit
    • duration: Unit -- DE: the duration unit

impl Implicit

  • fn resolve(&self, unit: Unit) -> Unit the explicit unit behind unit (other units unchanged)

Source: docs/API.md in the JFLib repository.