typst_assets/
lib.rs

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
85
86
//! Assets for the Typst compiler.
//!
//! These are not part of the main compiler crate to keep its size down.

macro_rules! asset {
    ($path:literal) => {
        include_bytes!(concat!("../files/", $path)).as_slice()
    };
}

/// ICU data.
pub mod icu {
    /// Generated by the following command:
    ///
    /// ```sh
    /// icu4x-datagen --locales full \
    ///               --format blob \
    ///               --keys-for-bin target/debug/typst \
    ///               --out typst-assets/files/icu/icu.postcard \
    ///               --overwrite
    /// ```
    ///
    /// Install icu_datagen with
    /// `cargo install --git https://github.com/unicode-org/icu4x icu_datagen --locked`.
    pub const ICU: &[u8] = asset!("icu/icu.postcard");

    /// Generated by the following command:
    ///
    /// ```sh
    /// icu4x-datagen-cj --locales zh ja \
    ///                  --format blob \
    ///                  --keys segmenter/line@1 \
    ///                  --out typst-assets/files/icu/icu_cj_segment.postcard \
    ///                  --overwrite
    /// ```
    ///
    /// Install a separate, patched icu_datagen with
    /// `cargo install --git https://github.com/typst/icu4x icu_datagen --locked --branch cj-patch`
    ///
    /// Make sure that the `cj-patch` branch is up-to-date with the latest
    /// icu4x upstream changes!
    pub const ICU_CJ_SEGMENT: &[u8] = asset!("icu/icu_cj_segment.postcard");
}

/// ICC profiles.
pub mod icc {
    /// The ICC profile used to convert from CMYK to RGB.
    ///
    /// This is a minimal CMYK profile that only contains the necessary
    /// information to convert from CMYK to RGB. It is based on the CGATS TR
    /// 001-1995 specification. See
    /// <https://github.com/saucecontrol/Compact-ICC-Profiles#cmyk>.
    pub const CMYK_TO_XYZ: &[u8] = asset!("icc/CMYK-to-XYZ.icc");
    pub const S_GREY_V4: &[u8] = asset!("icc/sGrey-v4.icc");
    pub const S_RGB_V4: &[u8] = asset!("icc/sRGB-v4.icc");
}

/// Bundled fonts.
///
/// This returns an empty iterator if the `fonts` feature is disabled.
pub fn fonts() -> impl Iterator<Item = &'static [u8]> {
    #[cfg(not(feature = "fonts"))]
    return [].into_iter();

    #[cfg(feature = "fonts")]
    [
        asset!("fonts/LibertinusSerif-Regular.otf"),
        asset!("fonts/LibertinusSerif-Bold.otf"),
        asset!("fonts/LibertinusSerif-Italic.otf"),
        asset!("fonts/LibertinusSerif-BoldItalic.otf"),
        asset!("fonts/LibertinusSerif-Semibold.otf"),
        asset!("fonts/LibertinusSerif-SemiboldItalic.otf"),
        asset!("fonts/NewCMMath-Bold.otf"),
        asset!("fonts/NewCMMath-Book.otf"),
        asset!("fonts/NewCMMath-Regular.otf"),
        asset!("fonts/NewCM10-Regular.otf"),
        asset!("fonts/NewCM10-Bold.otf"),
        asset!("fonts/NewCM10-Italic.otf"),
        asset!("fonts/NewCM10-BoldItalic.otf"),
        asset!("fonts/DejaVuSansMono-Bold.ttf"),
        asset!("fonts/DejaVuSansMono-BoldOblique.ttf"),
        asset!("fonts/DejaVuSansMono-Oblique.ttf"),
        asset!("fonts/DejaVuSansMono.ttf"),
    ]
    .into_iter()
}