typst_assets/
lib.rs

1//! Assets for the Typst compiler.
2//!
3//! These are not part of the main compiler crate to keep its size down.
4
5macro_rules! asset {
6    ($path:literal) => {
7        include_bytes!(concat!("../files/", $path)).as_slice()
8    };
9}
10
11pub mod html;
12
13/// ICU data.
14pub mod icu {
15    /// Generated by the following command:
16    ///
17    /// ```sh
18    /// icu4x-datagen --locales full \
19    ///               --format blob \
20    ///               --keys-for-bin target/debug/typst \
21    ///               --out typst-assets/files/icu/icu.postcard \
22    ///               --overwrite
23    /// ```
24    ///
25    /// Install icu_datagen with
26    /// `cargo install --git https://github.com/unicode-org/icu4x icu_datagen --locked`.
27    pub const ICU: &[u8] = asset!("icu/icu.postcard");
28
29    /// Generated by the following command:
30    ///
31    /// ```sh
32    /// icu4x-datagen-cj --locales zh ja \
33    ///                  --format blob \
34    ///                  --keys segmenter/line@1 \
35    ///                  --out typst-assets/files/icu/icu_cj_segment.postcard \
36    ///                  --overwrite
37    /// ```
38    ///
39    /// Install a separate, patched icu_datagen with
40    /// `cargo install --git https://github.com/typst/icu4x icu_datagen --locked --branch cj-patch`
41    ///
42    /// Make sure that the `cj-patch` branch is up-to-date with the latest
43    /// icu4x upstream changes!
44    pub const ICU_CJ_SEGMENT: &[u8] = asset!("icu/icu_cj_segment.postcard");
45}
46
47/// ICC profiles.
48pub mod icc {
49    /// The ICC profile used to convert from CMYK to RGB.
50    ///
51    /// This is a minimal CMYK profile that only contains the necessary
52    /// information to convert from CMYK to RGB. It is based on the CGATS TR
53    /// 001-1995 specification. See
54    /// <https://github.com/saucecontrol/Compact-ICC-Profiles#cmyk>.
55    pub const CMYK_TO_XYZ: &[u8] = asset!("icc/CMYK-to-XYZ.icc");
56    pub const S_GREY_V4: &[u8] = asset!("icc/sGrey-v4.icc");
57    pub const S_RGB_V4: &[u8] = asset!("icc/sRGB-v4.icc");
58}
59
60/// PDF standard fonts.
61pub mod pdf {
62    /// Foxit Ding Bats Font.
63    pub const DING_BATS: &[u8] = asset!("fonts/FoxitDingbats.pfb");
64    /// Foxit Symbol Font.
65    pub const SYMBOL: &[u8] = asset!("fonts/FoxitSymbol.pfb");
66
67    /// Foxit Fixed font.
68    pub const FIXED: &[u8] = asset!("fonts/FoxitFixed.pfb");
69    /// Foxit Fixed Bold font.
70    pub const FIXED_BOLD: &[u8] = asset!("fonts/FoxitFixedBold.pfb");
71    /// Foxit Fixed Bold Italic font.
72    pub const FIXED_BOLD_ITALIC: &[u8] = asset!("fonts/FoxitFixedBoldItalic.pfb");
73    /// Foxit Fixed Italic font.
74    pub const FIXED_ITALIC: &[u8] = asset!("fonts/FoxitFixedItalic.pfb");
75
76    /// Foxit Sans font.
77    pub const SANS: &[u8] = asset!("fonts/FoxitSans.pfb");
78    /// Foxit Sans Bold font.
79    pub const SANS_BOLD: &[u8] = asset!("fonts/FoxitSansBold.pfb");
80    /// Foxit Sans Bold Italic font.
81    pub const SANS_BOLD_ITALIC: &[u8] = asset!("fonts/FoxitSansBoldItalic.pfb");
82    /// Foxit Sans Italic font.
83    pub const SANS_ITALIC: &[u8] = asset!("fonts/FoxitSansItalic.pfb");
84
85    /// Foxit Serif font.
86    pub const SERIF: &[u8] = asset!("fonts/FoxitSerif.pfb");
87    /// Foxit Serif Bold font.
88    pub const SERIF_BOLD: &[u8] = asset!("fonts/FoxitSerifBold.pfb");
89    /// Foxit Serif Bold Italic font.
90    pub const SERIF_BOLD_ITALIC: &[u8] = asset!("fonts/FoxitSerifBoldItalic.pfb");
91    /// Foxit Serif Italic font.
92    pub const SERIF_ITALIC: &[u8] = asset!("fonts/FoxitSerifItalic.pfb");
93}
94
95/// Bundled fonts.
96///
97/// This returns an empty iterator if the `fonts` feature is disabled.
98pub fn fonts() -> impl Iterator<Item = &'static [u8]> {
99    #[cfg(not(feature = "fonts"))]
100    return [].into_iter();
101
102    #[cfg(feature = "fonts")]
103    [
104        asset!("fonts/LibertinusSerif-Regular.otf"),
105        asset!("fonts/LibertinusSerif-Bold.otf"),
106        asset!("fonts/LibertinusSerif-Italic.otf"),
107        asset!("fonts/LibertinusSerif-BoldItalic.otf"),
108        asset!("fonts/LibertinusSerif-Semibold.otf"),
109        asset!("fonts/LibertinusSerif-SemiboldItalic.otf"),
110        asset!("fonts/NewCMMath-Bold.otf"),
111        asset!("fonts/NewCMMath-Book.otf"),
112        asset!("fonts/NewCMMath-Regular.otf"),
113        asset!("fonts/NewCM10-Regular.otf"),
114        asset!("fonts/NewCM10-Bold.otf"),
115        asset!("fonts/NewCM10-Italic.otf"),
116        asset!("fonts/NewCM10-BoldItalic.otf"),
117        asset!("fonts/DejaVuSansMono-Bold.ttf"),
118        asset!("fonts/DejaVuSansMono-BoldOblique.ttf"),
119        asset!("fonts/DejaVuSansMono-Oblique.ttf"),
120        asset!("fonts/DejaVuSansMono.ttf"),
121    ]
122    .into_iter()
123}