blitz-pdf 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +23 -6
  2. package/THIRD_PARTY_NOTICES.md +18 -0
  3. package/dist/types.d.ts +2 -1
  4. package/dist/types.d.ts.map +1 -1
  5. package/licenses/Noto-OFL.txt +94 -0
  6. package/licenses/NotoCJK-OFL.txt +92 -0
  7. package/licenses/NotoEmoji-OFL.txt +93 -0
  8. package/licenses/Unifont-OFL.txt +90 -0
  9. package/licenses/font-sources.json +106 -0
  10. package/package.json +1 -1
  11. package/src/types.ts +2 -1
  12. package/vendor/README.md +19 -0
  13. package/vendor/fontique/Cargo.toml +194 -0
  14. package/vendor/fontique/LICENSE-APACHE +201 -0
  15. package/vendor/fontique/LICENSE-MIT +25 -0
  16. package/vendor/fontique/README.md +54 -0
  17. package/vendor/fontique/examples/generic_families.rs +37 -0
  18. package/vendor/fontique/src/attributes.rs +42 -0
  19. package/vendor/fontique/src/backend/android.rs +218 -0
  20. package/vendor/fontique/src/backend/coretext.rs +206 -0
  21. package/vendor/fontique/src/backend/dwrite.rs +395 -0
  22. package/vendor/fontique/src/backend/fontconfig.rs +844 -0
  23. package/vendor/fontique/src/backend/mod.rs +75 -0
  24. package/vendor/fontique/src/charmap.rs +127 -0
  25. package/vendor/fontique/src/collection/mod.rs +1016 -0
  26. package/vendor/fontique/src/collection/query.rs +392 -0
  27. package/vendor/fontique/src/fallback.rs +293 -0
  28. package/vendor/fontique/src/family.rs +111 -0
  29. package/vendor/fontique/src/family_name.rs +153 -0
  30. package/vendor/fontique/src/font.rs +562 -0
  31. package/vendor/fontique/src/generic.rs +36 -0
  32. package/vendor/fontique/src/impl_fontconfig.rs +159 -0
  33. package/vendor/fontique/src/lib.rs +87 -0
  34. package/vendor/fontique/src/matching.rs +483 -0
  35. package/vendor/fontique/src/scan.rs +312 -0
  36. package/vendor/fontique/src/script.rs +271 -0
  37. package/vendor/fontique/src/source.rs +108 -0
  38. package/vendor/fontique/src/source_cache.rs +254 -0
  39. package/wasm/blitz_pdf_bg.wasm +0 -0
@@ -0,0 +1,75 @@
1
+ // Copyright 2024 the Parley Authors
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ //! System backends.
5
+
6
+ #[cfg(all(feature = "system", target_os = "windows"))]
7
+ #[path = "dwrite.rs"]
8
+ mod system;
9
+
10
+ #[cfg(all(feature = "system", target_vendor = "apple"))]
11
+ #[path = "coretext.rs"]
12
+ mod system;
13
+
14
+ #[cfg(all(feature = "system", any(target_os = "linux", target_os = "freebsd")))]
15
+ #[path = "fontconfig.rs"]
16
+ mod system;
17
+
18
+ #[cfg(all(feature = "system", target_os = "android"))]
19
+ #[path = "android.rs"]
20
+ mod system;
21
+
22
+ #[allow(unused_imports)]
23
+ use super::{
24
+ FallbackKey, FamilyId, FamilyInfo, FontInfo, GenericFamily, Language, Script, ScriptExt,
25
+ SourceInfo,
26
+ family_name::{FamilyName, FamilyNameMap},
27
+ generic::GenericFamilyMap,
28
+ scan,
29
+ };
30
+
31
+ #[cfg(feature = "std")]
32
+ #[allow(unused_imports)]
33
+ use super::source::SourcePathMap;
34
+
35
+ pub(crate) use system::SystemFonts;
36
+
37
+ // Dummy system font backend for targets like wasm32-unknown-unknown
38
+ #[cfg(any(
39
+ not(feature = "system"),
40
+ not(any(
41
+ target_os = "windows",
42
+ target_os = "linux",
43
+ target_os = "freebsd",
44
+ target_os = "android",
45
+ target_vendor = "apple"
46
+ ))
47
+ ))]
48
+ mod system {
49
+ #[cfg(feature = "system")]
50
+ use super::{FallbackKey, FamilyId, FamilyInfo};
51
+ use super::{FamilyNameMap, GenericFamilyMap};
52
+ use alloc::sync::Arc;
53
+
54
+ #[derive(Default)]
55
+ pub(crate) struct SystemFonts {
56
+ pub(crate) name_map: Arc<FamilyNameMap>,
57
+ pub(crate) generic_families: Arc<GenericFamilyMap>,
58
+ }
59
+
60
+ impl SystemFonts {
61
+ pub(crate) fn new() -> Self {
62
+ Self::default()
63
+ }
64
+
65
+ #[cfg(feature = "system")]
66
+ pub(crate) fn family(&mut self, _id: FamilyId) -> Option<FamilyInfo> {
67
+ None
68
+ }
69
+
70
+ #[cfg(feature = "system")]
71
+ pub(crate) fn fallback(&mut self, _key: impl Into<FallbackKey>) -> Option<FamilyId> {
72
+ None
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,127 @@
1
+ // Copyright 2024 the Parley Authors
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ //! Mapping codepoints to nominal glyph identifiers.
5
+
6
+ // TODO(dfrg): move this code to read-fonts so it can be shared among other
7
+ // crates.
8
+
9
+ use read_fonts::{
10
+ FontData, FontRead, FontRef, TableProvider, TopLevelTable,
11
+ tables::cmap::{Cmap, CmapSubtable},
12
+ types::GlyphId,
13
+ };
14
+
15
+ /// Metadata for constructing a character map from font data.
16
+ #[derive(Copy, Clone, PartialEq, Eq, Debug)]
17
+ pub struct CharmapIndex {
18
+ subtable_offset: u32,
19
+ is_symbol: bool,
20
+ is_mac_roman: bool,
21
+ }
22
+
23
+ impl CharmapIndex {
24
+ pub(crate) fn new(font: &FontRef<'_>) -> Option<Self> {
25
+ let cmap = font.cmap().ok()?;
26
+ let cmap_offset = font
27
+ .table_directory()
28
+ .table_records()
29
+ .iter()
30
+ .find(|rec| rec.tag() == Cmap::TAG)
31
+ .map(|rec| rec.offset())?;
32
+ let (_, rec, _) = cmap.best_subtable()?;
33
+ let subtable_offset = cmap_offset.checked_add(rec.subtable_offset().to_u32())?;
34
+ Some(Self {
35
+ subtable_offset,
36
+ is_symbol: rec.is_symbol(),
37
+ is_mac_roman: rec.is_mac_roman(),
38
+ })
39
+ }
40
+
41
+ /// Creates a character map from the given font data.
42
+ pub fn charmap<'a>(&self, font_data: &'a [u8]) -> Option<Charmap<'a>> {
43
+ let subtable_data = font_data.get(self.subtable_offset as usize..)?;
44
+ let subtable = CmapSubtable::read(FontData::new(subtable_data)).ok()?;
45
+ Some(Charmap {
46
+ subtable,
47
+ is_symbol: self.is_symbol,
48
+ is_mac_roman: self.is_mac_roman,
49
+ })
50
+ }
51
+ }
52
+
53
+ /// Mapping from Unicode codepoints to nominal glyph identifiers.
54
+ #[derive(Clone)]
55
+ pub struct Charmap<'a> {
56
+ subtable: CmapSubtable<'a>,
57
+ is_symbol: bool,
58
+ is_mac_roman: bool,
59
+ }
60
+
61
+ impl Charmap<'_> {
62
+ /// Returns the glyph identifier for the given codepoint.
63
+ pub fn map(&self, codepoint: impl Into<u32>) -> Option<u32> {
64
+ const ASCII_MAX: u32 = 0x7F;
65
+ let mut c = codepoint.into();
66
+ // The Mac Roman encoding requires special processing for codepoints
67
+ // above the ASCII range.
68
+ if self.is_mac_roman && c > ASCII_MAX {
69
+ c = unicode_to_mac_roman(c);
70
+ }
71
+ let result = match &self.subtable {
72
+ CmapSubtable::Format0(table) => table.map_codepoint(c),
73
+ CmapSubtable::Format6(table) => table.map_codepoint(c),
74
+ CmapSubtable::Format10(table) => {
75
+ if let Some(index) = c.checked_sub(table.start_char_code()) {
76
+ table
77
+ .glyph_id_array()
78
+ .get(index as usize)
79
+ .map(|gid| GlyphId::from(gid.get()))
80
+ } else {
81
+ None
82
+ }
83
+ }
84
+ CmapSubtable::Format4(table) => table.map_codepoint(c),
85
+ CmapSubtable::Format12(table) => table.map_codepoint(c),
86
+ CmapSubtable::Format13(table) => table.map_codepoint(c),
87
+ _ => None,
88
+ };
89
+ if result.is_none() && self.is_symbol && c <= 0x00FF {
90
+ // For symbol-encoded OpenType fonts, we duplicate the
91
+ // U+F000..F0FF range at U+0000..U+00FF. That's what
92
+ // Windows seems to do, and that's hinted about at:
93
+ // https://docs.microsoft.com/en-us/typography/opentype/spec/recom
94
+ // under "Non-Standard (Symbol) Fonts".
95
+ return self.map(0xF000 + c);
96
+ }
97
+ result.map(|gid| gid.to_u32())
98
+ }
99
+ }
100
+
101
+ #[rustfmt::skip]
102
+ static UNICODE_TO_MAC_ROMAN: &[u16] = &[
103
+ 0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1,
104
+ 0x00E0, 0x00E2, 0x00E4, 0x00E3, 0x00E5, 0x00E7, 0x00E9, 0x00E8,
105
+ 0x00EA, 0x00EB, 0x00ED, 0x00EC, 0x00EE, 0x00EF, 0x00F1, 0x00F3,
106
+ 0x00F2, 0x00F4, 0x00F6, 0x00F5, 0x00FA, 0x00F9, 0x00FB, 0x00FC,
107
+ 0x2020, 0x00B0, 0x00A2, 0x00A3, 0x00A7, 0x2022, 0x00B6, 0x00DF,
108
+ 0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x2260, 0x00C6, 0x00D8,
109
+ 0x221E, 0x00B1, 0x2264, 0x2265, 0x00A5, 0x00B5, 0x2202, 0x2211,
110
+ 0x220F, 0x03C0, 0x222B, 0x00AA, 0x00BA, 0x03A9, 0x00E6, 0x00F8,
111
+ 0x00BF, 0x00A1, 0x00AC, 0x221A, 0x0192, 0x2248, 0x2206, 0x00AB,
112
+ 0x00BB, 0x2026, 0x00A0, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153,
113
+ 0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x25CA,
114
+ 0x00FF, 0x0178, 0x2044, 0x20AC, 0x2039, 0x203A, 0xFB01, 0xFB02,
115
+ 0x2021, 0x00B7, 0x201A, 0x201E, 0x2030, 0x00C2, 0x00CA, 0x00C1,
116
+ 0x00CB, 0x00C8, 0x00CD, 0x00CE, 0x00CF, 0x00CC, 0x00D3, 0x00D4,
117
+ 0xF8FF, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC,
118
+ 0x00AF, 0x02D8, 0x02D9, 0x02DA, 0x00B8, 0x02DD, 0x02DB, 0x02C7,
119
+ ];
120
+
121
+ fn unicode_to_mac_roman(c: u32) -> u32 {
122
+ let u = c as u16;
123
+ let Some(index) = UNICODE_TO_MAC_ROMAN.iter().position(|m| *m == u) else {
124
+ return 0;
125
+ };
126
+ (0x80 + index) as u32
127
+ }