From 1465e92249ad393726c1d5641f77ad6ea64a1a92 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> Date: Tue, 20 Aug 2024 21:24:22 +0200 Subject: [PATCH] Write procedure sets --- src/resource.rs | 27 ++++++------------ tests/snapshots/ext_g_state/all_set.txt | 3 ++ tests/snapshots/mask/alpha.txt | 1 + tests/snapshots/mask/luminosity.txt | 1 + tests/snapshots/outline/simple.txt | 29 +++++++++++++------- tests/snapshots/page/page_label_complex.txt | 27 ++++++++++++------ tests/snapshots/page/page_with_resources.txt | 1 + tests/snapshots/page/simple_page.txt | 3 ++ 8 files changed, 55 insertions(+), 37 deletions(-) diff --git a/src/resource.rs b/src/resource.rs index 3877c128..d2a3140b 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -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>; @@ -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); } } diff --git a/tests/snapshots/ext_g_state/all_set.txt b/tests/snapshots/ext_g_state/all_set.txt index d86d426c..f21d80bc 100644 --- a/tests/snapshots/ext_g_state/all_set.txt +++ b/tests/snapshots/ext_g_state/all_set.txt @@ -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 diff --git a/tests/snapshots/mask/alpha.txt b/tests/snapshots/mask/alpha.txt index 9dd3a08e..1dbca7ca 100644 --- a/tests/snapshots/mask/alpha.txt +++ b/tests/snapshots/mask/alpha.txt @@ -29,6 +29,7 @@ endobj /Type /XObject /Subtype /Form /Resources << + /ProcSet [/PDF /Text /ImageC /ImageB] /ExtGState << /g0 5 0 R >> diff --git a/tests/snapshots/mask/luminosity.txt b/tests/snapshots/mask/luminosity.txt index 10cb2088..cdbbcdef 100644 --- a/tests/snapshots/mask/luminosity.txt +++ b/tests/snapshots/mask/luminosity.txt @@ -29,6 +29,7 @@ endobj /Type /XObject /Subtype /Form /Resources << + /ProcSet [/PDF /Text /ImageC /ImageB] /ExtGState << /g0 5 0 R >> diff --git a/tests/snapshots/outline/simple.txt b/tests/snapshots/outline/simple.txt index 473fcd50..69c2168f 100644 --- a/tests/snapshots/outline/simple.txt +++ b/tests/snapshots/outline/simple.txt @@ -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 @@ -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 @@ -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 @@ -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 \ No newline at end of file diff --git a/tests/snapshots/page/page_label_complex.txt b/tests/snapshots/page/page_label_complex.txt index 8253af29..83b87d74 100644 --- a/tests/snapshots/page/page_label_complex.txt +++ b/tests/snapshots/page/page_label_complex.txt @@ -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 @@ -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 @@ -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 @@ -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 \ No newline at end of file diff --git a/tests/snapshots/page/page_with_resources.txt b/tests/snapshots/page/page_with_resources.txt index 221157e4..7ff9b082 100644 --- a/tests/snapshots/page/page_with_resources.txt +++ b/tests/snapshots/page/page_with_resources.txt @@ -49,6 +49,7 @@ endobj << /Type /Page /Resources << + /ProcSet [/PDF /Text /ImageC /ImageB] /ColorSpace << /c0 5 0 R >> diff --git a/tests/snapshots/page/simple_page.txt b/tests/snapshots/page/simple_page.txt index f06a3b4c..0af4f5dd 100644 --- a/tests/snapshots/page/simple_page.txt +++ b/tests/snapshots/page/simple_page.txt @@ -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