| 1 | //! What the page and the interface share: painting layers of glyphs, icons, paths, |
| 2 | //! images, rounded rectangles and pen strokes with wgpu, Direct3D 11 or OpenGL, each layer |
| 3 | //! with its own transform and clip, and editing text within a laid-out line. |
| 4 | |
| 5 | pub mod edit; |
| 6 | #[cfg(feature = "render")] |
| 7 | mod render; |
| 8 | |
| 9 | #[cfg(feature = "render")] |
| 10 | pub use render::*; |
| 11 | |
| 12 | /// Appends the installed `families` to every script's fallback in `collection`, after the |
| 13 | /// system's, so a character that neither the text's fonts nor its script's fallback draws |
| 14 | /// comes from the first of them that has it, as the system's own text does. |
| 15 | pub fn fall_back_to(collection: &mut parley::fontique::Collection, families: &[String]) { |
| 16 | use parley::fontique::{Script, ScriptExt}; |
| 17 | let extra: Vec<_> = families |
| 18 | .iter() |
| 19 | .filter_map(|name| collection.family_id(name)) |
| 20 | .collect(); |
| 21 | // Common, inherited and unknown characters keep runs of their own where no script's |
| 22 | // text surrounds them. |
| 23 | let scripts = Script::all_samples() |
| 24 | .iter() |
| 25 | .map(|(script, _)| *script) |
| 26 | .chain([*b"Zyyy", *b"Zinh", *b"Zzzz"].map(Script::from_bytes)); |
| 27 | for script in scripts { |
| 28 | let mut chain: Vec<_> = collection.fallback_families(script).collect(); |
| 29 | for family in &extra { |
| 30 | if !chain.contains(family) { |
| 31 | chain.push(*family); |
| 32 | } |
| 33 | } |
| 34 | collection.set_fallbacks(script, chain.into_iter()); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /// sRGB's encoding of a linear channel. |
| 39 | fn encode(linear: f32) -> f32 { |
| 40 | if linear <= 0.003_130_8 { |
| 41 | linear * 12.92 |
| 42 | } else { |
| 43 | 1.055 * linear.powf(1.0 / 2.4) - 0.055 |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /// The linear light of an sRGB-encoded channel. |
| 48 | fn linear(encoded: f32) -> f32 { |
| 49 | if encoded <= 0.040_45 { |
| 50 | encoded / 12.92 |
| 51 | } else { |
| 52 | ((encoded + 0.055) / 1.055).powf(2.4) |
| 53 | } |
| 54 | } |