1pub const MILLIMETERS_PER_INCH: f32 = 25.4;
2pub const CENTIMETERS_PER_INCH: f32 = 2.54;
3pub const POINTS_PER_INCH: f32 = 72.0;
4pub const PICAS_PER_INCH: f32 = 6.0;
5const BASE_DPI: f32 = 300.0;
6
7#[inline]
8pub fn pt_to_px(pt: f32, dpi: u16) -> f32 {
9 pt * (dpi as f32 / POINTS_PER_INCH)
10}
11
12#[inline]
13pub fn pc_to_px(pc: f32, dpi: u16) -> f32 {
14 pc * (dpi as f32 / PICAS_PER_INCH)
15}
16
17#[inline]
18pub fn in_to_px(inc: f32, dpi: u16) -> f32 {
19 inc * (dpi as f32)
20}
21
22#[inline]
23pub fn mm_to_px(mm: f32, dpi: u16) -> f32 {
24 mm * (dpi as f32 / MILLIMETERS_PER_INCH)
25}
26
27#[inline]
28pub fn scale_by_dpi_raw(x: f32, dpi: u16) -> f32 {
29 x * (dpi as f32) / BASE_DPI
30}
31
32#[inline]
33pub fn scale_by_dpi(x: f32, dpi: u16) -> f32 {
34 scale_by_dpi_raw(x, dpi).round().max(1.0)
35}