1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! Font types.
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use zng_task::channel::IpcBytes;
use zng_unit::Px;
use crate::{config::FontAntiAliasing, declare_id};
declare_id! {
/// Font resource in a renderer cache.
///
/// The View Process defines the ID.
pub struct FontFaceId(_);
/// Sized font in a renderer.
///
/// The View Process defines the ID.
pub struct FontId(_);
}
/// Extra font options.
#[derive(Default, Debug, PartialEq, Clone, Deserialize, Serialize)]
#[non_exhaustive]
pub struct FontOptions {
/// Font render mode.
///
/// Default value must be already resolved here, it falls back to Subpixel.
pub aa: FontAntiAliasing,
/// If synthetic bold is enabled.
pub synthetic_bold: bool,
/// If synthetic skew is enabled.
pub synthetic_oblique: bool,
}
impl FontOptions {
/// New font options.
pub fn new(aa: FontAntiAliasing, synthetic_bold: bool, synthetic_oblique: bool) -> Self {
Self {
aa,
synthetic_bold,
synthetic_oblique,
}
}
}
/// Extra font options send with text glyphs.
pub type GlyphOptions = FontOptions;
/// Font feature name, `*b"hlig"` for example.
pub type FontVariationName = [u8; 4];
/// Glyph index with position.
#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
#[non_exhaustive]
pub struct GlyphInstance {
/// Glyph id.
pub index: GlyphIndex,
/// Glyph position.
pub point: euclid::Point2D<f32, Px>,
}
impl GlyphInstance {
/// New glyph.
pub fn new(index: GlyphIndex, point: euclid::Point2D<f32, Px>) -> Self {
Self { index, point }
}
}
/// Glyph index in a font.
pub type GlyphIndex = u32;
/// Represents font face data.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum IpcFontBytes {
/// Custom font bytes.
Bytes(IpcBytes),
/// Font file path in a restricted system fonts directory.
///
/// The path must be safe for potential memory mapping. If the file is
/// as restricted as the current executable if can be considered safe.
System(PathBuf),
}