Skip to content

Commit

Permalink
Only set outline if it's not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Dec 17, 2024
1 parent 8bbff37 commit 4d6d700
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 43 deletions.
6 changes: 6 additions & 0 deletions crates/krilla/src/object/outline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ pub struct Outline {
children: Vec<OutlineNode>,
}

impl Outline {
pub(crate) fn is_empty(&self) -> bool {
self.children.is_empty()
}
}

impl Default for Outline {
fn default() -> Self {
Self::new()
Expand Down
4 changes: 3 additions & 1 deletion crates/krilla/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ impl SerializeContext {
}

pub(crate) fn set_outline(&mut self, outline: Outline) {
self.global_objects.outline = MaybeTaken::new(Some(outline));
if !outline.is_empty() {
self.global_objects.outline = MaybeTaken::new(Some(outline));
}
}

pub(crate) fn set_metadata(&mut self, metadata: Metadata) {
Expand Down
9 changes: 7 additions & 2 deletions crates/krilla/src/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,11 @@ impl Validator {
mod tests {
use crate::action::LinkAction;
use crate::annotation::{Annotation, LinkAnnotation, Target};
use crate::destination::XyzDestination;
use crate::error::KrillaError;
use crate::font::{Font, GlyphId, GlyphUnits, KrillaGlyph};
use crate::metadata::Metadata;
use crate::outline::Outline;
use crate::outline::{Outline, OutlineNode};
use crate::page::Page;
use crate::paint::{LinearGradient, SpreadMethod};
use crate::path::{Fill, FillRule};
Expand Down Expand Up @@ -995,7 +996,11 @@ mod tests {
.title("a nice title".to_string());
document.set_metadata(metadata);

let outline = Outline::new();
let mut outline = Outline::new();
outline.push_child(OutlineNode::new(
"Test".to_string(),
XyzDestination::new(0, Point::from_xy(0.0, 0.0)),
));
document.set_outline(outline);
}

Expand Down
97 changes: 57 additions & 40 deletions refs/snapshots/validation_pdfua1_attributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,89 @@
<<
/Type /Pages
/Count 1
/Kids [8 0 R]
/Kids [10 0 R]
>>
endobj

2 0 obj
<<
/Type /Outlines
/First 3 0 R
/Last 3 0 R
/Count 1
>>
endobj

3 0 obj
<<
/Parent 2 0 R
/Title (Test)
/Dest 9 0 R
>>
endobj

4 0 obj
<<
/Type /StructTreeRoot
/RoleMap <<
/Datetime /Span
/Terms /Part
/Title /H1
>>
/K [5 0 R]
/K [6 0 R]
/ParentTree <<
/Nums [0 4 0 R]
/Nums [0 5 0 R]
>>
/ParentTreeNextKey 1
>>
endobj

4 0 obj
[7 0 R 6 0 R]
5 0 obj
[8 0 R 7 0 R]
endobj

5 0 obj
6 0 obj
<<
/Type /StructElem
/S /Document
/P 3 0 R
/K [7 0 R 6 0 R]
/P 4 0 R
/K [8 0 R 7 0 R]
>>
endobj

6 0 obj
7 0 obj
<<
/Type /StructElem
/S /TH
/P 5 0 R
/P 6 0 R
/A [<<
/O /Table
/Scope /Row
>>]
/K [1]
/Pg 8 0 R
/Pg 10 0 R
>>
endobj

7 0 obj
8 0 obj
<<
/Type /StructElem
/S /L
/P 5 0 R
/P 6 0 R
/A [<<
/O /List
/ListNumbering /Circle
>>]
/K [0]
/Pg 8 0 R
/Pg 10 0 R
>>
endobj

8 0 obj
9 0 obj
[10 0 R /XYZ 0 842 0]
endobj

10 0 obj
<<
/Type /Page
/Resources <<
Expand All @@ -81,11 +96,11 @@ endobj
/MediaBox [0 0 595 842]
/StructParents 0
/Parent 1 0 R
/Contents 9 0 R
/Contents 11 0 R
>>
endobj

9 0 obj
11 0 obj
<<
/Length 201
>>
Expand Down Expand Up @@ -122,30 +137,30 @@ EMC
endstream
endobj

10 0 obj
12 0 obj
<<
/Title (a nice title)
>>
endobj

11 0 obj
13 0 obj
<<
/Length 961
/Type /Metadata
/Subtype /XML
>>
stream
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="xmp-writer"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:xmpTPg="http://ns.adobe.com/xap/1.0/t/pg/" xmlns:pdf="http://ns.adobe.com/pdf/1.3/" xmlns:pdfuaid="http://www.aiim.org/pdfua/ns/id/" ><dc:title><rdf:Alt><rdf:li xml:lang="x-default">a nice title</rdf:li></rdf:Alt></dc:title><dc:language><rdf:Bag><rdf:li>en</rdf:li></rdf:Bag></dc:language><pdfuaid:part>1</pdfuaid:part><xmpTPg:NPages>1</xmpTPg:NPages><dc:format>application/pdf</dc:format><xmpMM:InstanceID>7t1JAG/css3tUUA6/AmdMA==</xmpMM:InstanceID><xmpMM:DocumentID>7t1JAG/css3tUUA6/AmdMA==</xmpMM:DocumentID><xmpMM:RenditionClass>proof</xmpMM:RenditionClass><pdf:PDFVersion>1.7</pdf:PDFVersion></rdf:Description></rdf:RDF></x:xmpmeta><?xpacket end="r"?>
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="xmp-writer"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:xmpTPg="http://ns.adobe.com/xap/1.0/t/pg/" xmlns:pdf="http://ns.adobe.com/pdf/1.3/" xmlns:pdfuaid="http://www.aiim.org/pdfua/ns/id/" ><dc:title><rdf:Alt><rdf:li xml:lang="x-default">a nice title</rdf:li></rdf:Alt></dc:title><dc:language><rdf:Bag><rdf:li>en</rdf:li></rdf:Bag></dc:language><pdfuaid:part>1</pdfuaid:part><xmpTPg:NPages>1</xmpTPg:NPages><dc:format>application/pdf</dc:format><xmpMM:InstanceID>fLu8RnbyO5J0/UMUrJ4ToA==</xmpMM:InstanceID><xmpMM:DocumentID>fLu8RnbyO5J0/UMUrJ4ToA==</xmpMM:DocumentID><xmpMM:RenditionClass>proof</xmpMM:RenditionClass><pdf:PDFVersion>1.7</pdf:PDFVersion></rdf:Description></rdf:RDF></x:xmpmeta><?xpacket end="r"?>
endstream
endobj

12 0 obj
14 0 obj
<<
/Type /Catalog
/Pages 1 0 R
/Metadata 11 0 R
/Metadata 13 0 R
/Lang (en)
/StructTreeRoot 3 0 R
/StructTreeRoot 4 0 R
/MarkInfo <<
/Marked true
/Suspects false
Expand All @@ -158,27 +173,29 @@ endobj
endobj

xref
0 13
0 15
0000000000 65535 f
0000000016 00000 n
0000000080 00000 n
0000000120 00000 n
0000000315 00000 n
0000000345 00000 n
0000000432 00000 n
0000000560 00000 n
0000000697 00000 n
0000000875 00000 n
0000001130 00000 n
0000001177 00000 n
0000002227 00000 n
0000000081 00000 n
0000000161 00000 n
0000000229 00000 n
0000000424 00000 n
0000000454 00000 n
0000000541 00000 n
0000000670 00000 n
0000000808 00000 n
0000000846 00000 n
0000001026 00000 n
0000001282 00000 n
0000001329 00000 n
0000002379 00000 n
trailer
<<
/Size 13
/Root 12 0 R
/Info 10 0 R
/ID [(7t1JAG/css3tUUA6/AmdMA==) (7t1JAG/css3tUUA6/AmdMA==)]
/Size 15
/Root 14 0 R
/Info 12 0 R
/ID [(fLu8RnbyO5J0/UMUrJ4ToA==) (fLu8RnbyO5J0/UMUrJ4ToA==)]
>>
startxref
2468
2620
%%EOF

0 comments on commit 4d6d700

Please sign in to comment.