use-type-unit 0.0.1

Primitive typographic unit helpers
Documentation
  • Coverage
  • 5.56%
    1 out of 18 items documented1 out of 8 items with examples
  • Size
  • Source code size: 5.64 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 389.28 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • RustUse/use-typography
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • CloudBranch

Primitive typographic unit helpers.

These helpers convert between common typographic units using explicit root and parent font sizes where required.

Examples

use use_type_unit::{TypeUnit, em_to_px, pt_to_px, px_to_pt, rem_to_px};

assert!((pt_to_px(12.0).unwrap() - 15.999_996).abs() < 1.0e-12);
assert!((px_to_pt(16.0).unwrap() - 12.000_003_000_000_75).abs() < 1.0e-12);
assert!((rem_to_px(1.25, 16.0).unwrap() - 20.0).abs() < 1.0e-12);
assert!((em_to_px(1.5, 18.0).unwrap() - 27.0).abs() < 1.0e-12);
assert!((TypeUnit::Pt(12.0).to_px(16.0, 18.0).unwrap() - 15.999_996).abs() < 1.0e-12);