Skip to content

Commit 278d44f

Browse files
committed
Restructure WASM API
1 parent 2ca3617 commit 278d44f

File tree

10 files changed

+440
-412
lines changed

10 files changed

+440
-412
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test_*
99
*.svg
1010
out.txt
1111
/pkg
12+
Cargo.lock
1213
.DS_Store
1314
web/pdfjs-4.7.76-legacy-dist
1415
web/pdfjs-4.7.76-legacy-dist/*

Cargo.toml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ categories = ["gui"]
1515
exclude = ["./assets/*", "./doc/*", "./examples/*"]
1616
autoexamples = false
1717
edition = "2021"
18-
build = "build.rs"
1918

2019
[lib]
2120
crate-type = ["cdylib", "rlib"]
@@ -28,27 +27,29 @@ time = { version = "0.3.25", default-features = false, features = ["std", "serde
2827
allsorts = { version = "0.15", git = "https://github.com/fschutt/allsorts", branch = "optional-brotli", default-features = false, features = ["flate2_rust"] }
2928
image = { version = "0.25", default-features = false }
3029
svg2pdf = { version = "0.12.0" }
31-
azul-css = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false }
32-
azul-css-parser = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false }
33-
azul-core = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false, features = ["std"] }
34-
azul-layout = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false, features = ["std", "text_layout"] }
35-
azul-text-layout = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false }
36-
azulc = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false, features = ["std", "xml", "text_layout", "font_loading"] }
37-
rust-fontconfig = { version = "0.1.13", default-features = false }
38-
xmlparser = { version = "0.13.6", default-features = false }
30+
base64 = "0.22.1"
3931
serde = { version = "1" }
4032
serde_derive = { version = "1" }
41-
serde_json = { version = "1" }
42-
wasm-bindgen = { version = "0.2", optional = true }
43-
base64 = "0.22.1"
44-
flate2 = "1.0.35"
33+
flate2 = "1.0.35" # for decompression of builtin fonts
34+
# feature=html, independent of feature=wasm
35+
azul-css = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false, optional = true }
36+
azul-css-parser = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false, optional = true }
37+
azul-core = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false, features = ["std"], optional = true }
38+
azul-layout = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false, features = ["std", "text_layout"], optional = true }
39+
azul-text-layout = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false, optional = true }
40+
azulc = { git = "https://github.com/fschutt/azul", rev = "a09ccbd5be6429f8c40c1acd5ebe05850a45380f", default-features = false, features = ["std", "xml", "text_layout", "font_loading"], optional = true }
41+
rust-fontconfig = { version = "0.1.13", default-features = false, optional = true }
42+
xmlparser = { version = "0.13.6", default-features = false, optional = true }
43+
serde_json = { version = "1", optional = true }
4544

4645
[target.'cfg(target_family = "wasm")'.dependencies]
4746
wasm-bindgen = { version = "0.2" }
47+
serde_json = { version = "1" }
4848

4949
[features]
50-
default = []
51-
wasm = ["wasm-bindgen"]
50+
default = ["html"]
51+
html = ["azul-css", "azul-css-parser", "azul-core", "azul-layout", "azul-text-layout", "azulc", "rust-fontconfig", "xmlparser", "serde_json"]
52+
js-sys = ["dep:js-sys"] # enables js-sys features on wasm
5253
gif = ["image/gif"]
5354
jpeg = ["image/jpeg"]
5455
png = ["image/png"]
@@ -61,7 +62,6 @@ hdr = ["image/hdr"]
6162
dds = ["image/dds"]
6263
webp = ["image/webp"]
6364
rayon = ["image/rayon"] # enables multithreading for decoding images
64-
js-sys = ["dep:js-sys", "wasm"] # enables js-sys features on wasm
6565

6666
[package.metadata.docs.rs]
6767
all-features = true
@@ -75,7 +75,7 @@ required-features = []
7575

7676
[[example]]
7777
name = "html"
78-
required-features = []
78+
required-features = ["html"]
7979

8080
# re-generates the /defaultfonts/*.ttf fonts
8181
[[example]]

build.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/.DS_Store

0 Bytes
Binary file not shown.

src/date.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#[cfg(not(target_arch = "wasm32"))]
1+
#[cfg(not(target_family = "wasm"))]
22
pub use time::{OffsetDateTime, UtcOffset};
33

44
/// wasm32-unknown-unknown polyfill
55
6-
#[cfg(all(feature = "js-sys", target_arch = "wasm32"))]
6+
#[cfg(all(feature = "js-sys", target_family = "wasm"))]
77
pub use self::js_sys_date::OffsetDateTime;
8-
#[cfg(all(feature = "js-sys", target_arch = "wasm32"))]
8+
#[cfg(all(feature = "js-sys", target_family = "wasm"))]
99
mod js_sys_date {
1010
use js_sys::Date;
1111
use time::Month;
@@ -110,9 +110,9 @@ mod js_sys_date {
110110
}
111111
}
112112

113-
#[cfg(all(not(feature = "js-sys"), target_arch = "wasm32"))]
113+
#[cfg(all(not(feature = "js-sys"), target_family = "wasm"))]
114114
pub use self::unix_epoch_stub_date::OffsetDateTime;
115-
#[cfg(all(not(feature = "js-sys"), target_arch = "wasm32"))]
115+
#[cfg(all(not(feature = "js-sys"), target_family = "wasm"))]
116116
mod unix_epoch_stub_date {
117117
use time::Month;
118118

@@ -200,15 +200,15 @@ mod unix_epoch_stub_date {
200200
}
201201
}
202202

203-
#[cfg(target_arch = "wasm32")]
203+
#[cfg(target_family = "wasm")]
204204
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
205205
pub struct UtcOffset {
206206
hours: i8,
207207
minutes: i8,
208208
seconds: i8,
209209
}
210210

211-
#[cfg(target_arch = "wasm32")]
211+
#[cfg(target_family = "wasm")]
212212
impl UtcOffset {
213213
pub const fn from_hms(hours: i8, minutes: i8, seconds: i8) -> Result<Self, &'static str> {
214214
Ok(Self {

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use serde_derive::{Deserialize, Serialize};
88
pub mod annotation;
99
pub mod cmap;
1010
pub mod text;
11+
#[cfg(target_family = "wasm")]
1112
pub mod wasm;
1213
pub use annotation::*;
1314
/// PDF standard handling
@@ -45,7 +46,9 @@ pub use svg::*;
4546
pub mod image;
4647
pub use image::*;
4748
/// HTML handling
49+
#[cfg(feature = "html")]
4850
pub mod html;
51+
#[cfg(feature = "html")]
4952
pub use html::*;
5053
/// Utility functions (random strings, numbers, timestamp formatting)
5154
pub(crate) mod utils;
@@ -215,7 +218,8 @@ impl PdfDocument {
215218
}
216219

217220
/// Renders HTML to pages
218-
pub fn html2pages(
221+
#[cfg(feature = "html")]
222+
pub fn html_to_pages(
219223
&mut self,
220224
html: &str,
221225
config: XmlRenderOptions,

0 commit comments

Comments
 (0)