mirror of
https://github.com/storytold/deckcraft.git
synced 2026-11-22 13:57:53 -06:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
187afbd4e5 |
Generated
+15
-10
@@ -853,6 +853,11 @@ dependencies = [
|
|||||||
"thiserror 2.0.21",
|
"thiserror 2.0.21",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "craft-codepage"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/storytold/craft-libs?rev=63196e66f3033a6623eb629af95a104d26986725#63196e66f3033a6623eb629af95a104d26986725"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "craft-fonts-build"
|
name = "craft-fonts-build"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -909,6 +914,15 @@ dependencies = [
|
|||||||
"thiserror 2.0.21",
|
"thiserror 2.0.21",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "craft-rtf"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/storytold/craft-libs?rev=63196e66f3033a6623eb629af95a104d26986725#63196e66f3033a6623eb629af95a104d26986725"
|
||||||
|
dependencies = [
|
||||||
|
"craft-codepage",
|
||||||
|
"encoding_rs",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "craft-ui"
|
name = "craft-ui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -986,15 +1000,6 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "craft-xml"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "git+https://github.com/storytold/craft-libs?rev=ea24422ae9859dc5da398d0462bc87f8e02e0d10#ea24422ae9859dc5da398d0462bc87f8e02e0d10"
|
|
||||||
dependencies = [
|
|
||||||
"quick-xml 0.41.0",
|
|
||||||
"thiserror 2.0.21",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.5.2"
|
version = "1.5.2"
|
||||||
@@ -1156,6 +1161,7 @@ dependencies = [
|
|||||||
name = "deckcraft-format"
|
name = "deckcraft-format"
|
||||||
version = "0.19.0"
|
version = "0.19.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"craft-rtf",
|
||||||
"deckcraft-model",
|
"deckcraft-model",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -1228,7 +1234,6 @@ dependencies = [
|
|||||||
name = "deckcraft-pptx"
|
name = "deckcraft-pptx"
|
||||||
version = "0.19.0"
|
version = "0.19.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"craft-xml",
|
|
||||||
"deckcraft-color",
|
"deckcraft-color",
|
||||||
"deckcraft-engine",
|
"deckcraft-engine",
|
||||||
"deckcraft-geom",
|
"deckcraft-geom",
|
||||||
|
|||||||
+1
-2
@@ -11,8 +11,6 @@ rust-version = "1.95"
|
|||||||
repository = "https://github.com/storytold/deckcraft"
|
repository = "https://github.com/storytold/deckcraft"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
# XML writer primitives; parser admission and OOXML policy stay app-local.
|
|
||||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "ea24422ae9859dc5da398d0462bc87f8e02e0d10", version = "0.1.0" }
|
|
||||||
# internal
|
# internal
|
||||||
deckcraft-geom = { path = "crates/geom" }
|
deckcraft-geom = { path = "crates/geom" }
|
||||||
deckcraft-color = { path = "crates/color" }
|
deckcraft-color = { path = "crates/color" }
|
||||||
@@ -51,6 +49,7 @@ vello_cpu = "0.2"
|
|||||||
vello_common = { version = "0.2", default-features = false }
|
vello_common = { version = "0.2", default-features = false }
|
||||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp", "gif", "tiff", "bmp"] }
|
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp", "gif", "tiff", "bmp"] }
|
||||||
# craft-media, craft-audio and craft-video share types and stay on one rev.
|
# craft-media, craft-audio and craft-video share types and stay on one rev.
|
||||||
|
craft-rtf = { git = "https://github.com/storytold/craft-libs", rev = "63196e66f3033a6623eb629af95a104d26986725", version = "=0.1.0" }
|
||||||
craft-media = { git = "https://github.com/storytold/craft-libs", rev = "63196e66f3033a6623eb629af95a104d26986725", version = "=0.1.0", default-features = false }
|
craft-media = { git = "https://github.com/storytold/craft-libs", rev = "63196e66f3033a6623eb629af95a104d26986725", version = "=0.1.0", default-features = false }
|
||||||
craft-audio = { git = "https://github.com/storytold/craft-libs", rev = "63196e66f3033a6623eb629af95a104d26986725", version = "=0.1.0", default-features = false, features = ["opus-decode"] }
|
craft-audio = { git = "https://github.com/storytold/craft-libs", rev = "63196e66f3033a6623eb629af95a104d26986725", version = "=0.1.0", default-features = false, features = ["opus-decode"] }
|
||||||
# H.264, HEVC, VP9 and AV1 decoders.
|
# H.264, HEVC, VP9 and AV1 decoders.
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ description = "DeckCraft native file format (.deckcraft: zip of a JSON manifest
|
|||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
craft-rtf = { workspace = true }
|
||||||
deckcraft-model = { workspace = true }
|
deckcraft-model = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
|||||||
+82
-29
@@ -10,24 +10,24 @@ use deckcraft_model::text::{Paragraph, RunKind};
|
|||||||
|
|
||||||
/// RTF-escape `s` (non-ASCII as `\uN?`, UTF-16, signed as RTF wants).
|
/// RTF-escape `s` (non-ASCII as `\uN?`, UTF-16, signed as RTF wants).
|
||||||
fn escape(out: &mut String, s: &str) {
|
fn escape(out: &mut String, s: &str) {
|
||||||
for c in s.chars() {
|
// Keep outline text literal: the shared writer also supports page/column breaks and
|
||||||
match c {
|
// shorthand controls that this app's deliberately small outline reader does not consume.
|
||||||
'\\' | '{' | '}' => {
|
// Delegate ordinary spans, including UTF-16 escaping, without allocating a second string.
|
||||||
out.push('\\');
|
let mut start = 0;
|
||||||
out.push(c);
|
for (i, c) in s.char_indices() {
|
||||||
}
|
let replacement = match c {
|
||||||
'\t' => out.push_str("\\tab "),
|
'\u{000C}' | '\u{000E}' => "",
|
||||||
'\u{b}' | '\n' => out.push_str("\\line "),
|
'\u{00A0}' => "\\u160?",
|
||||||
c if c.is_ascii() && !c.is_ascii_control() => out.push(c),
|
'\u{00AD}' => "\\u173?",
|
||||||
c if c.is_ascii() => {}
|
'\u{2011}' => "\\u8209?",
|
||||||
c => {
|
'\u{2028}' => "\\u8232?",
|
||||||
let mut buf = [0u16; 2];
|
_ => continue,
|
||||||
for u in c.encode_utf16(&mut buf) {
|
};
|
||||||
out.push_str(&format!("\\u{}?", *u as i16));
|
craft_rtf::push_esc(out, &s[start..i]);
|
||||||
}
|
out.push_str(replacement);
|
||||||
}
|
start = i + c.len_utf8();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
craft_rtf::push_esc(out, &s[start..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn runs(out: &mut String, p: &Paragraph) {
|
fn runs(out: &mut String, p: &Paragraph) {
|
||||||
@@ -297,7 +297,7 @@ impl Outline<'_> {
|
|||||||
&& let Some(h) = hex
|
&& let Some(h) = hex
|
||||||
&& h != 0
|
&& h != 0
|
||||||
{
|
{
|
||||||
self.line.push(cp1252(h));
|
self.line.push(craft_rtf::codepage::cp1252(h));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,22 +384,75 @@ fn finish_surrogates(s: String) -> String {
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cp1252(b: u8) -> char {
|
|
||||||
const HIGH: [char; 32] = [
|
|
||||||
'€', '\u{81}', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', '\u{8d}', 'Ž', '\u{8f}', '\u{90}', '‘', '’', '“', '”', '•', '–', '—',
|
|
||||||
'˜', '™', 'š', '›', 'œ', '\u{9d}', 'ž', 'Ÿ',
|
|
||||||
];
|
|
||||||
match b {
|
|
||||||
0x80..=0x9f => HIGH[(b - 0x80) as usize],
|
|
||||||
_ => b as char,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
#![allow(clippy::unwrap_used)]
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
// Frozen pre-cutover implementations are test oracles, not production parsers.
|
||||||
|
fn legacy_escape(out: &mut String, s: &str) {
|
||||||
|
for c in s.chars() {
|
||||||
|
match c {
|
||||||
|
'\\' | '{' | '}' => {
|
||||||
|
out.push('\\');
|
||||||
|
out.push(c);
|
||||||
|
}
|
||||||
|
'\t' => out.push_str("\\tab "),
|
||||||
|
'\u{b}' | '\n' => out.push_str("\\line "),
|
||||||
|
c if c.is_ascii() && !c.is_ascii_control() => out.push(c),
|
||||||
|
c if c.is_ascii() => {}
|
||||||
|
c => {
|
||||||
|
let mut buf = [0u16; 2];
|
||||||
|
for u in c.encode_utf16(&mut buf) {
|
||||||
|
out.push_str(&format!("\\u{}?", *u as i16));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn legacy_cp1252(b: u8) -> char {
|
||||||
|
const HIGH: [char; 32] = [
|
||||||
|
'€', '\u{81}', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', '\u{8d}', 'Ž', '\u{8f}', '\u{90}', '‘', '’', '“', '”', '•', '–',
|
||||||
|
'—', '˜', '™', 'š', '›', 'œ', '\u{9d}', 'ž', 'Ÿ',
|
||||||
|
];
|
||||||
|
match b {
|
||||||
|
0x80..=0x9f => HIGH[(b - 0x80) as usize],
|
||||||
|
_ => b as char,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn shared_escape_preserves_every_unicode_scalar() {
|
||||||
|
for value in 0..=0x10ffff {
|
||||||
|
let Some(c) = char::from_u32(value) else { continue };
|
||||||
|
let mut buf = [0; 4];
|
||||||
|
let text = c.encode_utf8(&mut buf);
|
||||||
|
let mut expected = String::new();
|
||||||
|
let mut actual = String::new();
|
||||||
|
legacy_escape(&mut expected, text);
|
||||||
|
escape(&mut actual, text);
|
||||||
|
assert_eq!(actual, expected, "U+{value:04X}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn shared_escape_preserves_mixed_spans_and_append() {
|
||||||
|
let text = "a\t中\u{a0}b\u{ad}c\u{2011}d\u{2028}e\u{c}f\u{e}g\n😀{}\\";
|
||||||
|
let mut expected = String::from("prefix:");
|
||||||
|
let mut actual = expected.clone();
|
||||||
|
legacy_escape(&mut expected, text);
|
||||||
|
escape(&mut actual, text);
|
||||||
|
assert_eq!(actual, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn shared_cp1252_preserves_all_bytes() {
|
||||||
|
for b in 0..=u8::MAX {
|
||||||
|
assert_eq!(craft_rtf::codepage::cp1252(b), legacy_cp1252(b));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A sign in a `\'hh` escape is not a hex digit and must be ignored.
|
/// A sign in a `\'hh` escape is not a hex digit and must be ignored.
|
||||||
#[test]
|
#[test]
|
||||||
fn hex_escape_rejects_sign() {
|
fn hex_escape_rejects_sign() {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ description = "DeckCraft PPTX: Office Open XML (PresentationML/DrawingML) import
|
|||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
craft-xml.workspace = true
|
|
||||||
deckcraft-model = { workspace = true }
|
deckcraft-model = { workspace = true }
|
||||||
deckcraft-geom = { workspace = true }
|
deckcraft-geom = { workspace = true }
|
||||||
deckcraft-color = { workspace = true }
|
deckcraft-color = { workspace = true }
|
||||||
|
|||||||
+39
-33
@@ -354,8 +354,45 @@ fn decode_utf16(bytes: &[u8]) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preserve the public writer helpers while sharing the XML 1.0 escaping rules.
|
/// Is `c` allowed in XML 1.0 text?
|
||||||
pub use craft_xml::{esc, esc_attr};
|
fn xml_char(c: char) -> bool {
|
||||||
|
matches!(c, '\t' | '\n' | '\r') || (c >= ' ' && c != '\u{FFFE}' && c != '\u{FFFF}')
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Escape text content (and drop characters XML 1.0 forbids).
|
||||||
|
pub fn esc(s: &str) -> String {
|
||||||
|
let mut o = String::with_capacity(s.len());
|
||||||
|
for c in s.chars() {
|
||||||
|
match c {
|
||||||
|
'&' => o.push_str("&"),
|
||||||
|
'<' => o.push_str("<"),
|
||||||
|
'>' => o.push_str(">"),
|
||||||
|
'\r' => o.push_str(" "),
|
||||||
|
c if xml_char(c) => o.push(c),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Escape an attribute value.
|
||||||
|
pub fn esc_attr(s: &str) -> String {
|
||||||
|
let mut o = String::with_capacity(s.len());
|
||||||
|
for c in s.chars() {
|
||||||
|
match c {
|
||||||
|
'&' => o.push_str("&"),
|
||||||
|
'<' => o.push_str("<"),
|
||||||
|
'>' => o.push_str(">"),
|
||||||
|
'"' => o.push_str("""),
|
||||||
|
'\n' => o.push_str(" "),
|
||||||
|
'\r' => o.push_str(" "),
|
||||||
|
'\t' => o.push_str("	"),
|
||||||
|
c if xml_char(c) => o.push(c),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o
|
||||||
|
}
|
||||||
|
|
||||||
/// A string builder for XML parts.
|
/// A string builder for XML parts.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -505,37 +542,6 @@ mod tests {
|
|||||||
assert_eq!(esc_attr("\"x\"\n"), ""x" ");
|
assert_eq!(esc_attr("\"x\"\n"), ""x" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn shared_escaping_preserves_xml_wire_bytes() {
|
|
||||||
let text = "&<>\"'\t\n\r\0\u{b}\u{fffe}\u{ffff}é😀 ";
|
|
||||||
assert_eq!(esc(text), "&<>\"'\t\n é😀&#13;");
|
|
||||||
assert_eq!(esc_attr(text), "&<>"'	 é😀&#13;");
|
|
||||||
assert_eq!(esc(""), "");
|
|
||||||
assert_eq!(esc_attr(""), "");
|
|
||||||
for code in 0..32 {
|
|
||||||
let c = char::from_u32(code).unwrap();
|
|
||||||
let text = c.to_string();
|
|
||||||
match c {
|
|
||||||
'\t' => {
|
|
||||||
assert_eq!(esc(&text), "\t");
|
|
||||||
assert_eq!(esc_attr(&text), "	");
|
|
||||||
}
|
|
||||||
'\n' => {
|
|
||||||
assert_eq!(esc(&text), "\n");
|
|
||||||
assert_eq!(esc_attr(&text), " ");
|
|
||||||
}
|
|
||||||
'\r' => {
|
|
||||||
assert_eq!(esc(&text), " ");
|
|
||||||
assert_eq!(esc_attr(&text), " ");
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
assert_eq!(esc(&text), "");
|
|
||||||
assert_eq!(esc_attr(&text), "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn roundtrip_serialize() {
|
fn roundtrip_serialize() {
|
||||||
let d = parse(b"<p:sp a=\"1\"><p:t>x & y</p:t><e/></p:sp>").unwrap();
|
let d = parse(b"<p:sp a=\"1\"><p:t>x & y</p:t><e/></p:sp>").unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user