Skip to content

Commit 4d6d700

Browse files
committed
Only set outline if it's not empty
1 parent 8bbff37 commit 4d6d700

File tree

4 files changed

+73
-43
lines changed

4 files changed

+73
-43
lines changed

crates/krilla/src/object/outline.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ pub struct Outline {
3333
children: Vec<OutlineNode>,
3434
}
3535

36+
impl Outline {
37+
pub(crate) fn is_empty(&self) -> bool {
38+
self.children.is_empty()
39+
}
40+
}
41+
3642
impl Default for Outline {
3743
fn default() -> Self {
3844
Self::new()

crates/krilla/src/serialize.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ impl SerializeContext {
247247
}
248248

249249
pub(crate) fn set_outline(&mut self, outline: Outline) {
250-
self.global_objects.outline = MaybeTaken::new(Some(outline));
250+
if !outline.is_empty() {
251+
self.global_objects.outline = MaybeTaken::new(Some(outline));
252+
}
251253
}
252254

253255
pub(crate) fn set_metadata(&mut self, metadata: Metadata) {

crates/krilla/src/validation/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,11 @@ impl Validator {
508508
mod tests {
509509
use crate::action::LinkAction;
510510
use crate::annotation::{Annotation, LinkAnnotation, Target};
511+
use crate::destination::XyzDestination;
511512
use crate::error::KrillaError;
512513
use crate::font::{Font, GlyphId, GlyphUnits, KrillaGlyph};
513514
use crate::metadata::Metadata;
514-
use crate::outline::Outline;
515+
use crate::outline::{Outline, OutlineNode};
515516
use crate::page::Page;
516517
use crate::paint::{LinearGradient, SpreadMethod};
517518
use crate::path::{Fill, FillRule};
@@ -995,7 +996,11 @@ mod tests {
995996
.title("a nice title".to_string());
996997
document.set_metadata(metadata);
997998

998-
let outline = Outline::new();
999+
let mut outline = Outline::new();
1000+
outline.push_child(OutlineNode::new(
1001+
"Test".to_string(),
1002+
XyzDestination::new(0, Point::from_xy(0.0, 0.0)),
1003+
));
9991004
document.set_outline(outline);
10001005
}
10011006

refs/snapshots/validation_pdfua1_attributes.txt

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,74 +5,89 @@
55
<<
66
/Type /Pages
77
/Count 1
8-
/Kids [8 0 R]
8+
/Kids [10 0 R]
99
>>
1010
endobj
1111

1212
2 0 obj
1313
<<
1414
/Type /Outlines
15+
/First 3 0 R
16+
/Last 3 0 R
17+
/Count 1
1518
>>
1619
endobj
1720

1821
3 0 obj
22+
<<
23+
/Parent 2 0 R
24+
/Title (Test)
25+
/Dest 9 0 R
26+
>>
27+
endobj
28+
29+
4 0 obj
1930
<<
2031
/Type /StructTreeRoot
2132
/RoleMap <<
2233
/Datetime /Span
2334
/Terms /Part
2435
/Title /H1
2536
>>
26-
/K [5 0 R]
37+
/K [6 0 R]
2738
/ParentTree <<
28-
/Nums [0 4 0 R]
39+
/Nums [0 5 0 R]
2940
>>
3041
/ParentTreeNextKey 1
3142
>>
3243
endobj
3344

34-
4 0 obj
35-
[7 0 R 6 0 R]
45+
5 0 obj
46+
[8 0 R 7 0 R]
3647
endobj
3748

38-
5 0 obj
49+
6 0 obj
3950
<<
4051
/Type /StructElem
4152
/S /Document
42-
/P 3 0 R
43-
/K [7 0 R 6 0 R]
53+
/P 4 0 R
54+
/K [8 0 R 7 0 R]
4455
>>
4556
endobj
4657

47-
6 0 obj
58+
7 0 obj
4859
<<
4960
/Type /StructElem
5061
/S /TH
51-
/P 5 0 R
62+
/P 6 0 R
5263
/A [<<
5364
/O /Table
5465
/Scope /Row
5566
>>]
5667
/K [1]
57-
/Pg 8 0 R
68+
/Pg 10 0 R
5869
>>
5970
endobj
6071

61-
7 0 obj
72+
8 0 obj
6273
<<
6374
/Type /StructElem
6475
/S /L
65-
/P 5 0 R
76+
/P 6 0 R
6677
/A [<<
6778
/O /List
6879
/ListNumbering /Circle
6980
>>]
7081
/K [0]
71-
/Pg 8 0 R
82+
/Pg 10 0 R
7283
>>
7384
endobj
7485

75-
8 0 obj
86+
9 0 obj
87+
[10 0 R /XYZ 0 842 0]
88+
endobj
89+
90+
10 0 obj
7691
<<
7792
/Type /Page
7893
/Resources <<
@@ -81,11 +96,11 @@ endobj
8196
/MediaBox [0 0 595 842]
8297
/StructParents 0
8398
/Parent 1 0 R
84-
/Contents 9 0 R
99+
/Contents 11 0 R
85100
>>
86101
endobj
87102

88-
9 0 obj
103+
11 0 obj
89104
<<
90105
/Length 201
91106
>>
@@ -122,30 +137,30 @@ EMC
122137
endstream
123138
endobj
124139

125-
10 0 obj
140+
12 0 obj
126141
<<
127142
/Title (a nice title)
128143
>>
129144
endobj
130145

131-
11 0 obj
146+
13 0 obj
132147
<<
133148
/Length 961
134149
/Type /Metadata
135150
/Subtype /XML
136151
>>
137152
stream
138-
<?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"?>
153+
<?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"?>
139154
endstream
140155
endobj
141156

142-
12 0 obj
157+
14 0 obj
143158
<<
144159
/Type /Catalog
145160
/Pages 1 0 R
146-
/Metadata 11 0 R
161+
/Metadata 13 0 R
147162
/Lang (en)
148-
/StructTreeRoot 3 0 R
163+
/StructTreeRoot 4 0 R
149164
/MarkInfo <<
150165
/Marked true
151166
/Suspects false
@@ -158,27 +173,29 @@ endobj
158173
endobj
159174

160175
xref
161-
0 13
176+
0 15
162177
0000000000 65535 f
163178
0000000016 00000 n
164-
0000000080 00000 n
165-
0000000120 00000 n
166-
0000000315 00000 n
167-
0000000345 00000 n
168-
0000000432 00000 n
169-
0000000560 00000 n
170-
0000000697 00000 n
171-
0000000875 00000 n
172-
0000001130 00000 n
173-
0000001177 00000 n
174-
0000002227 00000 n
179+
0000000081 00000 n
180+
0000000161 00000 n
181+
0000000229 00000 n
182+
0000000424 00000 n
183+
0000000454 00000 n
184+
0000000541 00000 n
185+
0000000670 00000 n
186+
0000000808 00000 n
187+
0000000846 00000 n
188+
0000001026 00000 n
189+
0000001282 00000 n
190+
0000001329 00000 n
191+
0000002379 00000 n
175192
trailer
176193
<<
177-
/Size 13
178-
/Root 12 0 R
179-
/Info 10 0 R
180-
/ID [(7t1JAG/css3tUUA6/AmdMA==) (7t1JAG/css3tUUA6/AmdMA==)]
194+
/Size 15
195+
/Root 14 0 R
196+
/Info 12 0 R
197+
/ID [(fLu8RnbyO5J0/UMUrJ4ToA==) (fLu8RnbyO5J0/UMUrJ4ToA==)]
181198
>>
182199
startxref
183-
2468
200+
2620
184201
%%EOF

0 commit comments

Comments
 (0)