summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/text/font/exceptions.rs
blob: 00038c50c7adf27d1c74892ef55f58484893ab23 (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
use serde::Deserialize;

use super::{FontStretch, FontStyle, FontWeight};

pub fn find_exception(postscript_name: &str) -> Option<&'static Exception> {
    EXCEPTION_MAP.get(postscript_name)
}

#[derive(Debug, Default, Deserialize)]
pub struct Exception {
    pub family: Option<&'static str>,
    pub style: Option<FontStyle>,
    pub weight: Option<FontWeight>,
    pub stretch: Option<FontStretch>,
}

impl Exception {
    const fn new() -> Self {
        Self {
            family: None,
            style: None,
            weight: None,
            stretch: None,
        }
    }

    const fn family(self, family: &'static str) -> Self {
        Self { family: Some(family), ..self }
    }

    const fn style(self, style: FontStyle) -> Self {
        Self { style: Some(style), ..self }
    }

    const fn weight(self, weight: u16) -> Self {
        Self { weight: Some(FontWeight(weight)), ..self }
    }

    #[allow(unused)] // left for future use
    const fn stretch(self, stretch: u16) -> Self {
        Self { stretch: Some(FontStretch(stretch)), ..self }
    }
}

/// A map which keys are PostScript name and values are override entries.
static EXCEPTION_MAP: phf::Map<&'static str, Exception> = phf::phf_map! {
    // The old version of Arial-Black, published by Microsoft in 1996 in their
    // "core fonts for the web" project, has a wrong weight of 400.
    // See https://corefonts.sourceforge.net/.
    "Arial-Black" => Exception::new()
        .weight(900),
    // Archivo Narrow is different from Archivo and Archivo Black. Since Archivo Black
    // seems identical to Archivo weight 900, only differentiate between Archivo and
    // Archivo Narrow.
    "ArchivoNarrow-Regular" => Exception::new()
        .family("Archivo Narrow"),
    "ArchivoNarrow-Italic" => Exception::new()
        .family("Archivo Narrow"),
    "ArchivoNarrow-Bold" => Exception::new()
        .family("Archivo Narrow"),
    "ArchivoNarrow-BoldItalic" => Exception::new()
        .family("Archivo Narrow"),
    // Fandol fonts designed for Chinese typesetting.
    // See https://ctan.org/tex-archive/fonts/fandol/.
    "FandolHei-Bold" => Exception::new()
        .weight(700),
    "FandolSong-Bold" => Exception::new()
        .weight(700),
    // Noto fonts
    "NotoNaskhArabicUISemi-Bold" => Exception::new()
        .family("Noto Naskh Arabic UI")
        .weight(600),
    "NotoSansSoraSompengSemi-Bold" => Exception::new()
        .family("Noto Sans Sora Sompeng")
        .weight(600),
    "NotoSans-DisplayBlackItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayCondensedBlackItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayCondensedBold" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayCondensedBoldItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayCondensedExtraBoldItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayCondensedExtraLightItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayCondensedItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayCondensedLightItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayCondensedMediumItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayCondensedSemiBoldItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayCondensedThinItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraBoldItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraCondensedBlackItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraCondensedBold" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraCondensedBoldItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraCondensedExtraBoldItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraCondensedExtraLightItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraCondensedItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraCondensedLightItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraCondensedMediumItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraCondensedSemiBoldItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraCondensedThinItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayExtraLightItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayLightItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayMediumItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplaySemiBoldItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplaySemiCondensedBlackItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplaySemiCondensedBold" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplaySemiCondensedBoldItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplaySemiCondensedExtraBoldItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplaySemiCondensedExtraLightItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplaySemiCondensedItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplaySemiCondensedLightItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplaySemiCondensedMediumItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplaySemiCondensedSemiBoldItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplaySemiCondensedThinItalic" => Exception::new()
        .family("Noto Sans Display"),
    "NotoSans-DisplayThinItalic" => Exception::new()
        .family("Noto Sans Display"),
    // The following three postscript names are only used in the version 2.007
    // of the Noto Sans font. Other versions, while have different postscript
    // name, happen to have correct metadata.
    "NotoSerif-DisplayCondensedBold" => Exception::new()
        .family("Noto Serif Display"),
    "NotoSerif-DisplayExtraCondensedBold" => Exception::new()
        .family("Noto Serif Display"),
    "NotoSerif-DisplaySemiCondensedBold" => Exception::new()
        .family("Noto Serif Display"),
    // New Computer Modern
    "NewCM08-Book" => Exception::new()
        .family("New Computer Modern 08")
        .weight(450),
    "NewCM08-BookItalic" => Exception::new()
        .family("New Computer Modern 08")
        .weight(450),
    "NewCM08-Italic" => Exception::new()
        .family("New Computer Modern 08"),
    "NewCM08-Regular" => Exception::new()
        .family("New Computer Modern 08"),
    "NewCM10-Bold" => Exception::new()
        .family("New Computer Modern"),
    "NewCM10-BoldItalic" => Exception::new()
        .family("New Computer Modern"),
    "NewCM10-Book" => Exception::new()
        .family("New Computer Modern")
        .weight(450),
    "NewCM10-BookItalic" => Exception::new()
        .family("New Computer Modern")
        .weight(450),
    "NewCM10-Italic" => Exception::new()
        .family("New Computer Modern"),
    "NewCM10-Regular" => Exception::new()
        .family("New Computer Modern"),
    "NewCMMath-Bold" => Exception::new()
        .family("New Computer Modern Math"),
    "NewCMMath-Book" => Exception::new()
        .family("New Computer Modern Math")
        .weight(450),
    "NewCMMath-Regular" => Exception::new()
        .family("New Computer Modern Math"),
    "NewCMMono10-Bold" => Exception::new()
        .family("New Computer Modern Mono"),
    "NewCMMono10-BoldOblique" => Exception::new()
        .family("New Computer Modern Mono"),
    "NewCMMono10-Book" => Exception::new()
        .family("New Computer Modern Mono")
        .weight(450),
    "NewCMMono10-BookItalic" => Exception::new()
        .family("New Computer Modern Mono")
        .weight(450),
    "NewCMMono10-Italic" => Exception::new()
        .family("New Computer Modern Mono"),
    "NewCMMono10-Regular" => Exception::new()
        .family("New Computer Modern Mono"),
    "NewCMSans08-Book" => Exception::new()
        .family("New Computer Modern Sans 08")
        .weight(450),
    "NewCMSans08-BookOblique" => Exception::new()
        .family("New Computer Modern Sans 08")
        .weight(450),
    "NewCMSans08-Oblique" => Exception::new()
        .family("New Computer Modern Sans 08"),
    "NewCMSans08-Regular" => Exception::new()
        .family("New Computer Modern Sans 08"),
    "NewCMSans10-Bold" => Exception::new()
        .family("New Computer Modern Sans"),
    "NewCMSans10-BoldOblique" => Exception::new()
        .family("New Computer Modern Sans"),
    "NewCMSans10-Book" => Exception::new()
        .family("New Computer Modern Sans")
        .weight(450),
    "NewCMSans10-BookOblique" => Exception::new()
        .family("New Computer Modern Sans")
        .weight(450)
        .style(FontStyle::Oblique),
    "NewCMSans10-Oblique" => Exception::new()
        .family("New Computer Modern Sans")
        .style(FontStyle::Oblique),
    "NewCMSans10-Regular" => Exception::new()
        .family("New Computer Modern Sans"),
    "NewCMSansMath-Regular" => Exception::new()
        .family("New Computer Modern Sans Math"),
    "NewCMUncial08-Bold" => Exception::new()
        .family("New Computer Modern Uncial 08"),
    "NewCMUncial08-Book" => Exception::new()
        .family("New Computer Modern Uncial 08")
        .weight(450),
    "NewCMUncial08-Regular" => Exception::new()
        .family("New Computer Modern Uncial 08"),
    "NewCMUncial10-Bold" => Exception::new()
        .family("New Computer Modern Uncial"),
    "NewCMUncial10-Book" => Exception::new()
        .family("New Computer Modern Uncial")
        .weight(450),
    "NewCMUncial10-Regular" => Exception::new()
        .family("New Computer Modern Uncial"),
    // Latin Modern
    "LMMono8-Regular" => Exception::new()
        .family("Latin Modern Mono 8"),
    "LMMono9-Regular" => Exception::new()
        .family("Latin Modern Mono 9"),
    "LMMono12-Regular" => Exception::new()
        .family("Latin Modern Mono 12"),
    "LMMonoLt10-BoldOblique" => Exception::new()
        .style(FontStyle::Oblique),
    "LMMonoLt10-Regular" => Exception::new()
        .weight(300),
    "LMMonoLt10-Oblique" => Exception::new()
        .weight(300)
        .style(FontStyle::Oblique),
    "LMMonoLtCond10-Regular" => Exception::new()
        .weight(300)
        .stretch(666),
    "LMMonoLtCond10-Oblique" => Exception::new()
        .weight(300)
        .style(FontStyle::Oblique)
        .stretch(666),
    "LMMonoPropLt10-Regular" => Exception::new()
        .weight(300),
    "LMMonoPropLt10-Oblique" => Exception::new()
        .weight(300),
    "LMRoman5-Regular" => Exception::new()
        .family("Latin Modern Roman 5"),
    "LMRoman6-Regular" => Exception::new()
        .family("Latin Modern Roman 6"),
    "LMRoman7-Regular" => Exception::new()
        .family("Latin Modern Roman 7"),
    "LMRoman8-Regular" => Exception::new()
        .family("Latin Modern Roman 8"),
    "LMRoman9-Regular" => Exception::new()
        .family("Latin Modern Roman 9"),
    "LMRoman12-Regular" => Exception::new()
        .family("Latin Modern Roman 12"),
    "LMRoman17-Regular" => Exception::new()
        .family("Latin Modern Roman 17"),
    "LMRoman7-Italic" => Exception::new()
        .family("Latin Modern Roman 7"),
    "LMRoman8-Italic" => Exception::new()
        .family("Latin Modern Roman 8"),
    "LMRoman9-Italic" => Exception::new()
        .family("Latin Modern Roman 9"),
    "LMRoman12-Italic" => Exception::new()
        .family("Latin Modern Roman 12"),
    "LMRoman5-Bold" => Exception::new()
        .family("Latin Modern Roman 5"),
    "LMRoman6-Bold" => Exception::new()
        .family("Latin Modern Roman 6"),
    "LMRoman7-Bold" => Exception::new()
        .family("Latin Modern Roman 7"),
    "LMRoman8-Bold" => Exception::new()
        .family("Latin Modern Roman 8"),
    "LMRoman9-Bold" => Exception::new()
        .family("Latin Modern Roman 9"),
    "LMRoman12-Bold" => Exception::new()
        .family("Latin Modern Roman 12"),
    "LMRomanSlant8-Regular" => Exception::new()
        .family("Latin Modern Roman 8"),
    "LMRomanSlant9-Regular" => Exception::new()
        .family("Latin Modern Roman 9"),
    "LMRomanSlant12-Regular" => Exception::new()
        .family("Latin Modern Roman 12"),
    "LMRomanSlant17-Regular" => Exception::new()
        .family("Latin Modern Roman 17"),
    "LMSans8-Regular" => Exception::new()
        .family("Latin Modern Sans 8"),
    "LMSans9-Regular" => Exception::new()
        .family("Latin Modern Sans 9"),
    "LMSans12-Regular" => Exception::new()
        .family("Latin Modern Sans 12"),
    "LMSans17-Regular" => Exception::new()
        .family("Latin Modern Sans 17"),
    "LMSans8-Oblique" => Exception::new()
        .family("Latin Modern Sans 8"),
    "LMSans9-Oblique" => Exception::new()
        .family("Latin Modern Sans 9"),
    "LMSans12-Oblique" => Exception::new()
        .family("Latin Modern Sans 12"),
    "LMSans17-Oblique" => Exception::new()
        .family("Latin Modern Sans 17"),
    // STKaiti is a set of Kai fonts. Their weight values need to be corrected
    // according to their PostScript names.
    "STKaitiSC-Regular" => Exception::new().weight(400),
    "STKaitiTC-Regular" => Exception::new().weight(400),
    "STKaitiSC-Bold" => Exception::new().weight(700),
    "STKaitiTC-Bold" => Exception::new().weight(700),
    "STKaitiSC-Black" => Exception::new().weight(900),
    "STKaitiTC-Black" => Exception::new().weight(900),
};