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,159 @@
1
+ // Copyright 2025 the Parley Authors
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ //! Fontconfig numeric value conversions.
5
+ //!
6
+ //! The numeric values used here are based on the `fonts.conf` documentation:
7
+ //! <https://www.freedesktop.org/software/fontconfig/fontconfig-user.html>.
8
+
9
+ use crate::{FontStyle, FontWeight, FontWidth};
10
+
11
+ /// Conversion from Fontconfig numeric values.
12
+ ///
13
+ /// This is intentionally kept in `fontique` (rather than `parlance`) because it is a
14
+ /// Fontconfig-specific mapping.
15
+ ///
16
+ /// The numeric values used by these conversions are based on the `fonts.conf` documentation:
17
+ /// <https://www.freedesktop.org/software/fontconfig/fontconfig-user.html>.
18
+ pub trait FromFontconfig: Sized {
19
+ /// Creates a value from the corresponding Fontconfig numeric representation.
20
+ ///
21
+ /// The numeric values are determined based on the `fonts.conf` documentation:
22
+ /// <https://www.freedesktop.org/software/fontconfig/fontconfig-user.html>.
23
+ fn from_fontconfig(value: i32) -> Self;
24
+ }
25
+
26
+ impl FromFontconfig for FontWeight {
27
+ /// Creates a new weight attribute with the given value from Fontconfig.
28
+ ///
29
+ /// The values are determined based on the `fonts.conf` documentation:
30
+ /// <https://www.freedesktop.org/software/fontconfig/fontconfig-user.html>.
31
+ fn from_fontconfig(weight: i32) -> Self {
32
+ // A selection of OpenType weights (first) and their corresponding fontconfig value (second)
33
+ // Invariant: The fontconfig values are sorted.
34
+ const MAP: &[(i32, i32)] = &[
35
+ (0, 0),
36
+ (100, 0),
37
+ (200, 40),
38
+ (300, 50),
39
+ (350, 55),
40
+ (380, 75),
41
+ (400, 80),
42
+ (500, 100),
43
+ (600, 180),
44
+ (700, 200),
45
+ (800, 205),
46
+ (900, 210),
47
+ (950, 215),
48
+ ];
49
+
50
+ for i in 1..MAP.len() {
51
+ let (ot_b, fc_b) = MAP[i];
52
+ if weight == fc_b {
53
+ return Self::new(ot_b as f32);
54
+ }
55
+
56
+ // Linear interpolation if not an exact match.
57
+ if weight < fc_b {
58
+ let weight = weight as f32;
59
+ let fc_b = fc_b as f32;
60
+ let ot_b = ot_b as f32;
61
+
62
+ let (ot_a, fc_a) = MAP[i - 1];
63
+ let fc_a = fc_a as f32;
64
+ let ot_a = ot_a as f32;
65
+
66
+ let t = (weight - fc_a) / (fc_b - fc_a);
67
+ return Self::new(ot_a + (ot_b - ot_a) * t);
68
+ }
69
+ }
70
+
71
+ Self::EXTRA_BLACK
72
+ }
73
+ }
74
+
75
+ impl FromFontconfig for FontWidth {
76
+ /// Creates a new width attribute with the given value from Fontconfig.
77
+ ///
78
+ /// The values are determined based on the `fonts.conf` documentation:
79
+ /// <https://www.freedesktop.org/software/fontconfig/fontconfig-user.html>.
80
+ fn from_fontconfig(width: i32) -> Self {
81
+ match width {
82
+ 50 => Self::ULTRA_CONDENSED,
83
+ 63 => Self::EXTRA_CONDENSED,
84
+ 75 => Self::CONDENSED,
85
+ 87 => Self::SEMI_CONDENSED,
86
+ 100 => Self::NORMAL,
87
+ 113 => Self::SEMI_EXPANDED,
88
+ 125 => Self::EXPANDED,
89
+ 150 => Self::EXTRA_EXPANDED,
90
+ 200 => Self::ULTRA_EXPANDED,
91
+ _ => Self::from_ratio(width as f32 / 100.0),
92
+ }
93
+ }
94
+ }
95
+
96
+ impl FromFontconfig for FontStyle {
97
+ /// Creates a new style attribute with the given value from Fontconfig.
98
+ ///
99
+ /// The values are determined based on the `fonts.conf` documentation:
100
+ /// <https://www.freedesktop.org/software/fontconfig/fontconfig-user.html>.
101
+ fn from_fontconfig(slant: i32) -> Self {
102
+ match slant {
103
+ 100 => Self::Italic,
104
+ 110 => Self::Oblique(None),
105
+ _ => Self::Normal,
106
+ }
107
+ }
108
+ }
109
+
110
+ #[cfg(test)]
111
+ mod tests {
112
+ use super::FromFontconfig;
113
+ use crate::{FontStyle, FontWeight, FontWidth};
114
+ use alloc::string::ToString;
115
+
116
+ #[test]
117
+ fn fontwidth_from_fontconfig() {
118
+ fn check_fc(fc: i32, s: &str) {
119
+ let fs = FontWidth::from_fontconfig(fc);
120
+ assert_eq!(s, fs.to_string());
121
+ }
122
+
123
+ check_fc(50, "ultra-condensed");
124
+ check_fc(63, "extra-condensed");
125
+ check_fc(75, "condensed");
126
+ check_fc(87, "semi-condensed");
127
+ check_fc(100, "normal");
128
+ check_fc(113, "semi-expanded");
129
+ check_fc(125, "expanded");
130
+ check_fc(150, "extra-expanded");
131
+ check_fc(200, "ultra-expanded");
132
+ }
133
+
134
+ #[test]
135
+ fn fontstyle_from_fontconfig() {
136
+ fn check_fc(fc: i32, s: &str) {
137
+ let fs = FontStyle::from_fontconfig(fc);
138
+ assert_eq!(s, fs.to_string());
139
+ }
140
+
141
+ check_fc(0, "normal");
142
+ check_fc(100, "italic");
143
+ check_fc(110, "oblique");
144
+ }
145
+
146
+ #[test]
147
+ fn fontweight_from_fontconfig_interpolates_monotonically() {
148
+ let demilight = FontWeight::from_fontconfig(55);
149
+ assert!(demilight > FontWeight::LIGHT);
150
+ assert!(demilight < FontWeight::NORMAL);
151
+
152
+ let book = FontWeight::from_fontconfig(75);
153
+ assert!(book > demilight);
154
+ assert!(book < FontWeight::NORMAL);
155
+
156
+ let extrablack = FontWeight::from_fontconfig(215);
157
+ assert!(extrablack > FontWeight::BLACK);
158
+ }
159
+ }
@@ -0,0 +1,87 @@
1
+ // Copyright 2024 the Parley Authors
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ //! Font enumeration and fallback.
5
+
6
+ // LINEBENDER LINT SET - lib.rs - v4
7
+ // See https://linebender.org/wiki/canonical-lints/
8
+ // These lints shouldn't apply to examples or tests.
9
+ #![cfg_attr(not(test), warn(unused_crate_dependencies))]
10
+ // These lints shouldn't apply to examples.
11
+ #![warn(clippy::print_stdout, clippy::print_stderr)]
12
+ // Targeting e.g. 32-bit means structs containing usize can give false positives for 64-bit.
13
+ #![cfg_attr(target_pointer_width = "64", warn(clippy::trivially_copy_pass_by_ref))]
14
+ // END LINEBENDER LINT SET
15
+ #![cfg_attr(docsrs, feature(doc_cfg))]
16
+ #![no_std]
17
+ #![allow(unsafe_code, reason = "We access platform libraries using ffi.")]
18
+ #![allow(missing_docs, reason = "We have many as-yet undocumented items.")]
19
+ #![expect(
20
+ missing_debug_implementations,
21
+ unnameable_types,
22
+ unreachable_pub,
23
+ clippy::allow_attributes_without_reason,
24
+ clippy::cast_possible_truncation,
25
+ reason = "Deferred"
26
+ )]
27
+ #![allow(
28
+ single_use_lifetimes,
29
+ reason = "False positive: https://github.com/rust-lang/rust/issues/129255"
30
+ )]
31
+
32
+ #[cfg(not(any(feature = "std", feature = "libm")))]
33
+ compile_error!("fontique requires either the `std` or `libm` feature to be enabled");
34
+
35
+ extern crate alloc;
36
+
37
+ #[cfg(feature = "std")]
38
+ extern crate std;
39
+
40
+ mod attributes;
41
+ mod backend;
42
+ mod charmap;
43
+ mod collection;
44
+ mod fallback;
45
+ mod family;
46
+ mod family_name;
47
+ mod font;
48
+ mod generic;
49
+ mod impl_fontconfig;
50
+ mod matching;
51
+ mod scan;
52
+ mod script;
53
+ mod source;
54
+
55
+ mod source_cache;
56
+
57
+ pub use linebender_resource_handle::Blob;
58
+ pub use script::ScriptExt;
59
+
60
+ pub use attributes::Attributes;
61
+ pub use charmap::{Charmap, CharmapIndex};
62
+ pub use collection::{Collection, CollectionOptions, Query, QueryFamily, QueryFont, QueryStatus};
63
+ pub use fallback::FallbackKey;
64
+ pub use family::{FamilyId, FamilyInfo};
65
+ pub use font::{AxisInfo, FontInfo, FontInfoOverride, Synthesis};
66
+ pub use impl_fontconfig::FromFontconfig;
67
+ pub use parlance::{FontStyle, FontWeight, FontWidth, GenericFamily, Language, Script};
68
+ pub use source::{SourceId, SourceInfo, SourceKind};
69
+
70
+ #[cfg(all(feature = "system", target_vendor = "apple"))]
71
+ use objc2 as _;
72
+ pub use source_cache::{SourceCache, SourceCacheOptions};
73
+
74
+ #[cfg(not(target_has_atomic = "64"))]
75
+ use core::sync::atomic::AtomicU32 as AtomicCounter;
76
+ #[cfg(target_has_atomic = "64")]
77
+ use core::sync::atomic::AtomicU64 as AtomicCounter;
78
+
79
+ /// The integer type underlying [`AtomicCounter`].
80
+ ///
81
+ /// This is `u32` on platforms without 64-bit atomics (e.g. many 32-bit
82
+ /// targets) and `u64` elsewhere.
83
+ #[cfg(not(target_has_atomic = "64"))]
84
+ type CounterInt = u32;
85
+ /// The integer type underlying [`AtomicCounter`].
86
+ #[cfg(target_has_atomic = "64")]
87
+ type CounterInt = u64;