Skip to main content

parse_width

Function parse_width 

Source
pub fn parse_width(width: &str) -> Option<ParsedWidth>
Expand description

Parses a CSS-like width string into OOXML width components.

Supported formats:

  • "2cm" – centimetres (1 cm = 567 twips)
  • "80px" – pixels at 96 DPI (1 px = 15 twips, rounding 15.09)
  • "30%" – percentage (OOXML pct unit = 1/50 of a percent, so 30% = 1500)
  • "auto" – automatic width

Returns None for unrecognised or empty input.

§Examples

use easydoc_writer::util::parse_width;
use docx_rs::WidthType;

let w = parse_width("2cm").unwrap();
assert_eq!(w.value, 1134);
assert_eq!(w.width_type, WidthType::Dxa);