From 078f5994c4c2f4fcbb7f1838cecae7b0a1ca195c Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 14 Nov 2026 04:37:22 +0000 Subject: [PATCH] Build: restore designcraft_format::write for recovery; render decodes without naming the image crate --- crates/format/src/lib.rs | 10 ++++++++++ crates/idml/src/export/item.rs | 4 +--- crates/render/src/decode.rs | 10 +++++----- crates/textimport/src/docx.rs | 4 +--- crates/textimport/src/docx/tests.rs | 3 ++- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/crates/format/src/lib.rs b/crates/format/src/lib.rs index bcfacd976..a05a8baa7 100644 --- a/crates/format/src/lib.rs +++ b/crates/format/src/lib.rs @@ -36,6 +36,16 @@ pub fn save_with_preview(doc: &Document, preview: Option<&[u8]>) -> Result(out: &mut W, doc: &Document, preview: Option<&[u8]>) -> Result<(), FormatError> { + let bytes = save_with_preview(doc, preview)?; + for chunk in bytes.chunks(1 << 20) { + out.write_all(chunk).map_err(|e| FormatError::Io(e.to_string()))?; + } + Ok(()) +} + /// Required native format version for a document. Kept for app-side compatibility; inference is /// performed by the shared codec over the serialized neutral document schema. #[cfg(test)] diff --git a/crates/idml/src/export/item.rs b/crates/idml/src/export/item.rs index bfcc0619c..fd5731133 100644 --- a/crates/idml/src/export/item.rs +++ b/crates/idml/src/export/item.rs @@ -1,7 +1,5 @@ use super::common::{affine_s, bool_s, pct, uid, with_props}; -use super::{ - Affine, ColumnsKind, Content, El, Ex, Item, Node, OBJECT_BUILTINS, PathData, Shape, TextFrameOptions, base64_encode, names, num, pt, -}; +use super::{Affine, ColumnsKind, Content, El, Ex, Item, Node, OBJECT_BUILTINS, PathData, Shape, TextFrameOptions, base64_encode, names, num, pt}; impl<'a> Ex<'a> { pub(super) fn item_el(&mut self, it: &Item, xf: Affine) -> El { diff --git a/crates/render/src/decode.rs b/crates/render/src/decode.rs index f6bc7339b..cc4d9f859 100644 --- a/crates/render/src/decode.rs +++ b/crates/render/src/decode.rs @@ -18,22 +18,22 @@ pub fn decode_pixmap_page(bytes: &[u8], page: u32) -> Option { let (px, w, h) = designcraft_images::render_svg(bytes, 3000)?; return Some(Pixmap::from_parts(premul_pixels(px), w.min(u16::MAX as u32) as u16, h.min(u16::MAX as u32) as u16)); } - premultiplied(designcraft_images::decode_rgba(bytes)?) + let img = designcraft_images::decode_rgba(bytes)?; + premultiplied(img.width(), img.height(), img.into_raw()) } /// [`decode_pixmap`] of a JPEG at 1/2^`shrink` of its size, `shrink` 1 to /// [`designcraft_images::MAX_REDUCED_SHRINK`], without a full-size decode. `None` where only a /// full decode applies (other formats, CMYK JPEGs). pub(crate) fn decode_pixmap_reduced(bytes: &[u8], shrink: u8) -> Option { - premultiplied(designcraft_images::decode_rgba_reduced(bytes, shrink)?) + let img = designcraft_images::decode_rgba_reduced(bytes, shrink)?; + premultiplied(img.width(), img.height(), img.into_raw()) } -fn premultiplied(img: image::RgbaImage) -> Option { - let (w, h) = img.dimensions(); +fn premultiplied(w: u32, h: u32, mut px: Vec) -> Option { if w == 0 || h == 0 || w > u16::MAX as u32 || h > u16::MAX as u32 { return None; } - let mut px = img.into_raw(); px.truncate(w as usize * h as usize * 4); Some(Pixmap::from_parts(premultiply(px), w as u16, h as u16)) } diff --git a/crates/textimport/src/docx.rs b/crates/textimport/src/docx.rs index b59426f25..b7bd274df 100644 --- a/crates/textimport/src/docx.rs +++ b/crates/textimport/src/docx.rs @@ -6,9 +6,7 @@ use std::collections::{HashMap, HashSet}; use craft_wordmodel::Block; use craft_wordmodel::numbering::LevelSuffix; use craft_wordmodel::para::{InlineObject, NoteKind, Paragraph}; -use craft_wordmodel::props::{ - Align as WordAlign, CharProps as WordCharProps, NumRef, ParaProps as WordParaProps, Underline, VertAlign, -}; +use craft_wordmodel::props::{Align as WordAlign, CharProps as WordCharProps, NumRef, ParaProps as WordParaProps, Underline, VertAlign}; use craft_wordmodel::section::NumFormat; use craft_wordmodel::styles::{StyleKind, StyleSheet}; use designcraft_doc::story::{BASIC_PARAGRAPH, NO_CHAR_STYLE}; diff --git a/crates/textimport/src/docx/tests.rs b/crates/textimport/src/docx/tests.rs index c7fb3ff28..d49b2a2cc 100644 --- a/crates/textimport/src/docx/tests.rs +++ b/crates/textimport/src/docx/tests.rs @@ -60,7 +60,8 @@ fn docx_parts(parts: &[(&str, &str)]) -> Vec { } if !rels.is_empty() { w.start_file("word/_rels/document.xml.rels", o).unwrap(); - let rels_doc = format!(r#"{}"#, rels.join("")); + let rels_doc = + format!(r#"{}"#, rels.join("")); w.write_all(rels_doc.as_bytes()).unwrap(); } w.finish().unwrap().into_inner()