diff --git a/Cargo.lock b/Cargo.lock index a259e0fe5e..af60a84c79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1298,6 +1298,16 @@ dependencies = [ "objc2-app-kit 0.3.2", ] +[[package]] +name = "craft-mime" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=f29e82f1a7a009e68312bd2e84adab72be23344d#f29e82f1a7a009e68312bd2e84adab72be23344d" +dependencies = [ + "chrono", + "craft-codepage", + "encoding_rs", +] + [[package]] name = "craft-opc" version = "0.1.0" @@ -4699,6 +4709,7 @@ dependencies = [ name = "pdfcraft-export" version = "0.21.1" dependencies = [ + "craft-mime", "craft-opc", "craft-rtf", "craft-xml", diff --git a/Cargo.toml b/Cargo.toml index 8bd2a5fb8c..0d9ed6c189 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,8 @@ craft-pdf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0" # The writer the RTF export maps onto (storytold/craft-libs#793), at storytold/craft-libs#1467: # its font and colour lookups take constant time, as PdfCraft's own writer did. craft-rtf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "f29e82f1a7a009e68312bd2e84adab72be23344d" } +# Shared Base64 encoder; use the existing RTF revision to reuse its codepage dependency. +craft-mime = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "f29e82f1a7a009e68312bd2e84adab72be23344d" } craft-csv = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "e2dc681a3" } craft-xml = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "e2dc681a3" } craft-image-codecs = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "e2dc681a3" } diff --git a/crates/export/Cargo.toml b/crates/export/Cargo.toml index f4164d46ff..4ff2f0dfb9 100644 --- a/crates/export/Cargo.toml +++ b/crates/export/Cargo.toml @@ -11,6 +11,7 @@ repository.workspace = true workspace = true [dependencies] +craft-mime.workspace = true craft-opc.workspace = true craft-rtf.workspace = true craft-xml.workspace = true diff --git a/crates/export/src/as_html.rs b/crates/export/src/as_html.rs index e2b3379ac2..7d70359edd 100644 --- a/crates/export/src/as_html.rs +++ b/crates/export/src/as_html.rs @@ -57,18 +57,7 @@ pub(crate) fn esc(s: &str) -> String { o } -pub(crate) fn base64(data: &[u8]) -> String { - const A: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - let mut s = String::with_capacity(data.len().div_ceil(3) * 4); - for c in data.chunks(3) { - let n = (c[0] as u32) << 16 | (*c.get(1).unwrap_or(&0) as u32) << 8 | *c.get(2).unwrap_or(&0) as u32; - s.push(A[(n >> 18) as usize & 63] as char); - s.push(A[(n >> 12) as usize & 63] as char); - s.push(if c.len() > 1 { A[(n >> 6) as usize & 63] as char } else { '=' }); - s.push(if c.len() > 2 { A[n as usize & 63] as char } else { '=' }); - } - s -} +pub(crate) use craft_mime::transfer::base64; /// One HTML file: headings and paragraphs, tables as real `