DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge asset-dedupe: files with different paths stay separate assets (#420)
aionggedaea097e8b8
diff --cc crates/doc/src/assets.rsindex 88adf3cdd,24ba5c243..3e4baf9f9--- a/crates/doc/src/assets.rs+++ b/crates/doc/src/assets.rs@@@ -15,16 -15,20 +15,20 @@@ use crate::{Asset, AssetId, Content, Doconst MAX_DEPTH: usize = 64;impl Asset {- /// Whether `other` holds the same file: the same type, page, PDF crop box and bytes. Assets- /// without bytes (a link that couldn't be read) are the same only when they link to the same- /// path.- /// Whether `other` holds the same file: the same type, page, link and bytes. Files at- /// different paths stay apart even with identical bytes, since each can be updated or- /// relinked on its own. Assets without bytes (a link that couldn't be read) are the same only- /// when they link to the same path.++ /// Whether `other` holds the same file: the same type, page, PDF crop box, link and bytes.++ /// Files at different paths stay apart even with identical bytes, since each can be updated++ /// or relinked on its own. Assets without bytes (a link that couldn't be read) are the same++ /// only when they link to the same path.pub fn same_file(&self, other: &Asset) -> bool {- if self.mime != other.mime || self.page != other.page {+ if self.mime != other.mime || self.page != other.page || self.pdf_crop != other.pdf_crop {return false;}+ if self.link != other.link {+ return false;+ }match (self.data.is_empty(), other.data.is_empty()) {- (false, false) => Arc::ptr_eq(&self.data, &other.data) || (self.data.len() == other.data.len() && *self.data == *other.data),- (true, true) => self.link.is_some() && self.link == other.link,+ (false, false) => self.same_bytes(other),+ (true, true) => self.link.is_some(),_ => false,}}@@@ -304,16 -297,9 +298,16 @@@ mod testsfn identical_files_share_one_asset() {let mut d = Document::new(&Default::default());let a = d.add_asset(asset(1, b"same"));- let b = d.add_asset(Asset { link: Some("/x/p.png".into()), ..asset(2, b"same") });+ let b = d.add_asset(asset(2, b"same"));let c = d.add_asset(asset(3, b"diff"));let p = d.add_asset(Asset { page: 1, ..asset(4, b"same") });+ // One PDF page shown with two crop boxes: two assets (the box is the asset's).+ let pdf = |id, pdf_crop| Asset { mime: "application/pdf".into(), pdf_crop, ..asset(id, b"%PDF") };+ let crop = d.add_asset(pdf(9, crate::PdfCrop::Crop));+ let art = d.add_asset(pdf(10, crate::PdfCrop::Art));+ assert_ne!(crop, art);+ assert_eq!(d.add_asset(pdf(11, crate::PdfCrop::Art)), art);+ d.assets.retain(|id, _| ![crop, art].contains(id));assert_eq!(a, b);assert_ne!(a, c);assert_ne!(a, p);