Skip to main content

use_typography/
lib.rs

1#![forbid(unsafe_code)]
2//! Thin facade for the `use-typography` workspace.
3//!
4//! The crate reexports the focused typography crates directly so consumers
5//! can opt into one dependency while still using the smaller APIs.
6//!
7//! # Examples
8//!
9//! ```rust
10//! use use_typography::*;
11//!
12//! let font = FontSize::new(18.0).unwrap();
13//! let line_height = LineHeight::new(18.0, 27.0).unwrap();
14//! let scale = modular_scale(18.0, ScaleRatio::MajorThird, -1, 1).unwrap();
15//!
16//! assert!((font.rem(16.0).unwrap() - 1.125).abs() < 1.0e-12);
17//! assert!((line_height.ratio() - 1.5).abs() < 1.0e-12);
18//! assert_eq!(scale.len(), 3);
19//! ```
20
21pub use use_font_size;
22pub use use_font_size::{
23    em_to_px as font_size_em_to_px, px_to_em, px_to_rem, rem_to_px as font_size_rem_to_px,
24    FontSize, FontSizeError,
25};
26pub use use_line_height;
27pub use use_line_height::{
28    is_readable_line_height, line_height_px, line_height_ratio, LineHeight, LineHeightError,
29};
30pub use use_measure;
31pub use use_measure::{
32    characters_per_line, container_width_for_measure, is_readable_measure, Measure, MeasureError,
33};
34pub use use_modular_scale;
35pub use use_modular_scale::{modular_scale, scale_down, scale_up, ModularScaleError, ScaleRatio};
36pub use use_spacing_scale;
37pub use use_spacing_scale::{spacing_step, spacing_steps, SpacingScale, SpacingScaleError};
38pub use use_text_block;
39pub use use_text_block::{estimated_line_count, estimated_text_height, TextBlock, TextBlockError};
40pub use use_type_rhythm;
41pub use use_type_rhythm::{baseline_grid, snap_to_baseline, TypeRhythm, TypeRhythmError};
42pub use use_type_unit;
43pub use use_type_unit::{em_to_px, pt_to_px, px_to_pt, rem_to_px, TypeUnit, TypeUnitError};
44
45#[cfg(test)]
46mod tests {
47    use super::{
48        baseline_grid, modular_scale, FontSize, LineHeight, ScaleRatio, TextBlock, TypeRhythm,
49        TypeUnit,
50    };
51
52    #[test]
53    fn facade_reexports_workspace_apis() {
54        let font = FontSize::new(18.0).unwrap();
55        let line_height = LineHeight::new(18.0, 27.0).unwrap();
56        let scale = modular_scale(18.0, ScaleRatio::MajorThird, -1, 1).unwrap();
57        let block = TextBlock::new(480.0, 18.0, 27.0, 120).unwrap();
58        let rhythm = TypeRhythm::new(18.0, 27.0).unwrap();
59
60        assert!((font.rem(16.0).unwrap() - 1.125).abs() < 1.0e-12);
61        assert!((line_height.ratio() - 1.5).abs() < 1.0e-12);
62        assert_eq!(scale.len(), 3);
63        assert_eq!(block.estimated_line_count(8.0).unwrap(), 2);
64        assert_eq!(
65            baseline_grid(rhythm.baseline_unit(), 3).unwrap(),
66            vec![27.0, 54.0, 81.0]
67        );
68        assert!((TypeUnit::Rem(1.5).to_px(16.0, 18.0).unwrap() - 24.0).abs() < 1.0e-12);
69    }
70}