kas_text/fonts/
mod.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License in the LICENSE-APACHE file or at:
4//     https://www.apache.org/licenses/LICENSE-2.0
5
6//! Font selection and loading
7//!
8//! Fonts are managed by the [`FontLibrary`], of which a static singleton
9//! exists and can be accessed via [`library()`].
10//!
11//! ### Font sizes
12//!
13//! Typically, font sizes are specified in "Points". Several other units and
14//! measures come into play here. Lets start with those dating back to the
15//! early printing press:
16//!
17//! -   1 *Point* = 1/72 inch (~0.35mm), by the usual DTP standard
18//! -   1 *Em* is the width of a capital `M` (inclusive of margin) in a font
19//! -   The *point size* of a font refers to the number of *points* per *em*
20//!     in this font
21//!
22//! Thus, with a "12 point font", one 'M' occupies 12/72 of an inch on paper.
23//!
24//! In digital typography, one must translate to/from pixel sizes. Here we have:
25//!
26//! -   DPI (Dots Per Inch) is the number of pixels per inch
27//! -   A *scale factor* is a measure of the number of pixels relative to a
28//!     standard DPI, usually 96
29//!
30//! We introduce two measures used by this library:
31//!
32//! -   DPP (Dots Per Point): `dpp = dpi / 72 = scale_factor × (96 / 72)`
33//! -   DPEM (Dots Per Em): `dpem = point_size × dpp`
34//!
35//! Warning: on MacOS and Apple systems, a *point* sometimes refers to a
36//! (virtual) pixel, yielding `dpp = 1` (or `dpp = 2` on Retina screens, or
37//! something else entirely on iPhones). On any system, DPI/DPP/scale factor
38//! values may be set according to the user's taste rather than physical
39//! measurements.
40//!
41//! Finally, note that digital font files have an internally defined unit
42//! known as the *font unit*. We introduce one final unit:
43//!
44//! -   [`crate::DPU`]: pixels per font unit
45
46use crate::GlyphId;
47
48mod attributes;
49mod face;
50mod library;
51mod resolver;
52
53pub use attributes::{FontStyle, FontWeight, FontWidth};
54pub use face::{FaceRef, ScaledFaceRef};
55pub use fontique::GenericFamily;
56pub use library::{library, FaceId, FaceStore, FontId, FontLibrary, InvalidFontId, NoFontMatch};
57pub use resolver::*;
58
59impl From<GlyphId> for ttf_parser::GlyphId {
60    fn from(id: GlyphId) -> Self {
61        ttf_parser::GlyphId(id.0)
62    }
63}