JFLib

diagram_core/src/formula/color.rs#

Source: lib/diagram_core/src/formula/color.rs

color -- colours as formulas see them: indices of the document's colour table and RGB, the
HSL scale of 0..240, and the tint and shade functions (FX-08)

  Color::Index(n) / Color::Rgb(r, g, b)     V writes an index as a number, RGB as "#rrggbb"
  Color::parse("#4d1e1a")
  rgb_to_hsl(r, g, b) -> (h, s, l)          0..240 each, Windows' ColorRGBToHLS (HLSMAX 240)
  hsl_to_rgb(h, s, l)                       its inverse (ColorHLSToRGB), integer rounding
  tint / shade / tone / blend / mso_tint / mso_shade

The 24 built-in indices are Visio's default colour table; a document's Colors element
(ColorEntry IX RGB) overrides them, and indices past 23 exist only there.
  • enum Color a colour value
    • Index(u32) -- an index into the document's colour table (0 black, 1 white ...)
    • Rgb(u8, u8, u8) -- red, green, blue

impl Color

  • fn parse(text: &str) -> Option<Color> "#rrggbb" (any case) as an RGB colour

  • fn hex(r: u8, g: u8, b: u8) -> String "#rrggbb" in lower case, as Visio writes V

  • fn rgb_to_hsl(r: u8, g: u8, b: u8) -> (i32, i32, i32) RGB -> hue, saturation, luminosity on 0..240 (Windows ColorRGBToHLS)

  • fn hsl_to_rgb(h: i32, s: i32, l: i32) -> (u8, u8, u8) hue, saturation, luminosity on 0..240 -> RGB (Windows ColorHLSToRGB); out-of-range arguments are clamped

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