Skip to content

Commit

Permalink
Write procedure sets
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Aug 20, 2024
1 parent 22c0c86 commit 1465e92
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 37 deletions.
27 changes: 9 additions & 18 deletions src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use pdf_writer::{Chunk, Dict, Finish, Ref};
use std::collections::HashMap;
use std::fmt::Debug;
use std::hash::Hash;
use pdf_writer::types::ProcSet;

pub trait ResourceTrait: Object {
fn get_dict<'a>(resources: &'a mut Resources) -> Dict<'a>;
Expand Down Expand Up @@ -219,24 +220,14 @@ impl ResourceDictionary {
where
T: ResourcesExt,
{
if !self.is_empty() {
let resources = &mut parent.resources();
write_resource_type(sc, resources, self.color_spaces, false);
write_resource_type(sc, resources, self.ext_g_states, false);
write_resource_type(sc, resources, self.patterns, false);
write_resource_type(sc, resources, self.x_objects, false);
write_resource_type(sc, resources, self.shadings, false);
write_resource_type(sc, resources, self.fonts, true);
}
}

pub fn is_empty(&self) -> bool {
self.color_spaces.is_empty()
&& self.ext_g_states.is_empty()
&& self.patterns.is_empty()
&& self.x_objects.is_empty()
&& self.shadings.is_empty()
&& self.fonts.is_empty()
let resources = &mut parent.resources();
resources.proc_sets([ProcSet::Pdf, ProcSet::Text, ProcSet::ImageColor, ProcSet::ImageGrayscale]);
write_resource_type(sc, resources, self.color_spaces, false);
write_resource_type(sc, resources, self.ext_g_states, false);
write_resource_type(sc, resources, self.patterns, false);
write_resource_type(sc, resources, self.x_objects, false);
write_resource_type(sc, resources, self.shadings, false);
write_resource_type(sc, resources, self.fonts, true);
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/snapshots/ext_g_state/all_set.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ endobj
/Length 0
/Type /XObject
/Subtype /Form
/Resources <<
/ProcSet [/PDF /Text /ImageC /ImageB]
>>
/BBox [0 0 0 0]
/Group <<
/Type /Group
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/mask/alpha.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ endobj
/Type /XObject
/Subtype /Form
/Resources <<
/ProcSet [/PDF /Text /ImageC /ImageB]
/ExtGState <<
/g0 5 0 R
>>
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/mask/luminosity.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ endobj
/Type /XObject
/Subtype /Form
/Resources <<
/ProcSet [/PDF /Text /ImageC /ImageB]
/ExtGState <<
/g0 5 0 R
>>
Expand Down
29 changes: 19 additions & 10 deletions tests/snapshots/outline/simple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ endobj
3 0 obj
<<
/Type /Page
/Resources <<
/ProcSet [/PDF /Text /ImageC /ImageB]
>>
/MediaBox [0 0 200 200]
/Parent 2 0 R
/Contents 4 0 R
Expand Down Expand Up @@ -48,6 +51,9 @@ endobj
5 0 obj
<<
/Type /Page
/Resources <<
/ProcSet [/PDF /Text /ImageC /ImageB]
>>
/MediaBox [0 0 200 500]
/Parent 2 0 R
/Contents 6 0 R
Expand All @@ -66,6 +72,9 @@ endobj
7 0 obj
<<
/Type /Page
/Resources <<
/ProcSet [/PDF /Text /ImageC /ImageB]
>>
/MediaBox [0 0 250 700]
/Parent 2 0 R
/Contents 8 0 R
Expand Down Expand Up @@ -125,20 +134,20 @@ xref
0000000016 00000 n
0000000088 00000 n
0000000164 00000 n
0000000260 00000 n
0000000398 00000 n
0000000494 00000 n
0000000546 00000 n
0000000642 00000 n
0000000694 00000 n
0000000776 00000 n
0000001010 00000 n
0000000922 00000 n
0000000323 00000 n
0000000461 00000 n
0000000620 00000 n
0000000672 00000 n
0000000831 00000 n
0000000883 00000 n
0000000965 00000 n
0000001199 00000 n
0000001111 00000 n
trailer
<<
/Size 13
/Root 1 0 R
>>
startxref
1119
1308
%%EOF
27 changes: 18 additions & 9 deletions tests/snapshots/page/page_label_complex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ endobj
3 0 obj
<<
/Type /Page
/Resources <<
/ProcSet [/PDF /Text /ImageC /ImageB]
>>
/MediaBox [0 0 200 200]
/Parent 2 0 R
/Contents 4 0 R
Expand All @@ -38,6 +41,9 @@ endobj
5 0 obj
<<
/Type /Page
/Resources <<
/ProcSet [/PDF /Text /ImageC /ImageB]
>>
/MediaBox [0 0 250 200]
/Parent 2 0 R
/Contents 6 0 R
Expand All @@ -56,6 +62,9 @@ endobj
7 0 obj
<<
/Type /Page
/Resources <<
/ProcSet [/PDF /Text /ImageC /ImageB]
>>
/MediaBox [0 0 200 200]
/Parent 2 0 R
/Contents 8 0 R
Expand Down Expand Up @@ -97,19 +106,19 @@ xref
0000000016 00000 n
0000000090 00000 n
0000000166 00000 n
0000000262 00000 n
0000000314 00000 n
0000000410 00000 n
0000000462 00000 n
0000000558 00000 n
0000000710 00000 n
0000000610 00000 n
0000000652 00000 n
0000000325 00000 n
0000000377 00000 n
0000000536 00000 n
0000000588 00000 n
0000000747 00000 n
0000000899 00000 n
0000000799 00000 n
0000000841 00000 n
trailer
<<
/Size 12
/Root 1 0 R
>>
startxref
760
949
%%EOF
1 change: 1 addition & 0 deletions tests/snapshots/page/page_with_resources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ endobj
<<
/Type /Page
/Resources <<
/ProcSet [/PDF /Text /ImageC /ImageB]
/ColorSpace <<
/c0 5 0 R
>>
Expand Down
3 changes: 3 additions & 0 deletions tests/snapshots/page/simple_page.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ endobj
3 0 obj
<<
/Type /Page
/Resources <<
/ProcSet [/PDF /Text /ImageC /ImageB]
>>
/MediaBox [0 0 200 200]
/Parent 2 0 R
/Contents 4 0 R
Expand Down

0 comments on commit 1465e92

Please sign in to comment.