Skip to content

Commit c715181

Browse files
committed
Rename settings to write_settings
1 parent aad07d4 commit c715181

5 files changed

Lines changed: 39 additions & 26 deletions

File tree

src/chunk.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
use super::*;
22

3+
/// Settings that should be applied while writing a PDF file.
34
#[derive(Debug, Clone, Copy)]
45
pub struct WriteSettings {
6+
/// Whether to enable pretty-writing. In this case, `pdf-writer` will serialize PDFs in such
7+
/// a way that they are easier to read by humans by applying more padding and indentation, at
8+
/// the cost of higher file sizes. If disabled, `pdf-writer` will serialize objects as compactly
9+
/// as possible, leading to better file sizes but making it harder to inspect the file manually.
510
pub pretty: bool,
611
}
712

813
impl Default for WriteSettings {
914
fn default() -> Self {
10-
Self { pretty: false }
15+
Self { pretty: true }
1116
}
1217
}
1318

@@ -25,7 +30,7 @@ impl Default for WriteSettings {
2530
pub struct Chunk {
2631
pub(crate) buf: Buf,
2732
pub(crate) offsets: Vec<(Ref, usize)>,
28-
pub(crate) settings: WriteSettings,
33+
pub(crate) write_settings: WriteSettings,
2934
}
3035

3136
impl Chunk {
@@ -40,14 +45,14 @@ impl Chunk {
4045
Self {
4146
buf: Buf::with_capacity(capacity),
4247
offsets: vec![],
43-
settings: Default::default(),
48+
write_settings: Default::default(),
4449
}
4550
}
4651

4752
/// TODO
48-
pub fn new_with(settings: WriteSettings) -> Self {
53+
pub fn new_with(write_settings: WriteSettings) -> Self {
4954
let mut chunk = Self::new();
50-
chunk.settings = settings;
55+
chunk.write_settings = write_settings;
5156

5257
chunk
5358
}
@@ -172,7 +177,7 @@ impl Chunk {
172177
/// Start writing an indirectly referenceable object.
173178
pub fn indirect(&mut self, id: Ref) -> Obj<'_> {
174179
self.offsets.push((id, self.buf.len()));
175-
Obj::indirect(&mut self.buf, id, self.settings)
180+
Obj::indirect(&mut self.buf, id, self.write_settings)
176181
}
177182

178183
/// Start writing an indirectly referenceable stream.

src/content.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::object::TextStrLike;
55
/// A builder for a content stream.
66
pub struct Content {
77
buf: Buf,
8-
settings: WriteSettings,
8+
write_settings: WriteSettings,
99
q_depth: usize,
1010
}
1111

@@ -19,9 +19,9 @@ impl Content {
1919
}
2020

2121
/// TODO
22-
pub fn new_with(settings: WriteSettings) -> Self {
22+
pub fn new_with(write_settings: WriteSettings) -> Self {
2323
let mut content = Self::new();
24-
content.settings = settings;
24+
content.write_settings = write_settings;
2525

2626
content
2727
}
@@ -31,14 +31,14 @@ impl Content {
3131
Self {
3232
buf: Buf::with_capacity(capacity),
3333
q_depth: 0,
34-
settings: Default::default(),
34+
write_settings: Default::default(),
3535
}
3636
}
3737

3838
/// Start writing an arbitrary operation.
3939
#[inline]
4040
pub fn op<'a>(&'a mut self, operator: &'a str) -> Operation<'a> {
41-
Operation::start(&mut self.buf, operator, self.settings)
41+
Operation::start(&mut self.buf, operator, self.write_settings)
4242
}
4343

4444
/// Return the buffer of the content stream.
@@ -65,13 +65,17 @@ pub struct Operation<'a> {
6565
buf: &'a mut Buf,
6666
op: &'a str,
6767
first: bool,
68-
settings: WriteSettings,
68+
write_settings: WriteSettings,
6969
}
7070

7171
impl<'a> Operation<'a> {
7272
#[inline]
73-
pub(crate) fn start(buf: &'a mut Buf, op: &'a str, settings: WriteSettings) -> Self {
74-
Self { buf, op, first: true, settings }
73+
pub(crate) fn start(
74+
buf: &'a mut Buf,
75+
op: &'a str,
76+
write_settings: WriteSettings,
77+
) -> Self {
78+
Self { buf, op, first: true, write_settings }
7579
}
7680

7781
/// Write a primitive operand.
@@ -102,7 +106,7 @@ impl<'a> Operation<'a> {
102106
}
103107
self.first = false;
104108
// TODO: Refine padding?
105-
Obj::direct(self.buf, 0, self.settings, false)
109+
Obj::direct(self.buf, 0, self.write_settings, false)
106110
}
107111
}
108112

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl Pdf {
298298
///
299299
/// Panics if any indirect reference id was used twice.
300300
pub fn finish(self) -> Vec<u8> {
301-
let Chunk { mut buf, mut offsets, settings } = self.chunk;
301+
let Chunk { mut buf, mut offsets, write_settings } = self.chunk;
302302

303303
offsets.sort();
304304

@@ -346,7 +346,7 @@ impl Pdf {
346346
// Write the trailer dictionary.
347347
buf.extend(b"trailer\n");
348348

349-
let mut trailer = Obj::direct(&mut buf, 0, settings, false).dict();
349+
let mut trailer = Obj::direct(&mut buf, 0, write_settings, false).dict();
350350
trailer.pair(Name(b"Size"), xref_len);
351351

352352
if let Some(catalog_id) = self.catalog_id {

src/object.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ pub struct Obj<'a> {
603603
buf: &'a mut Buf,
604604
indirect: bool,
605605
indent: u8,
606-
settings: WriteSettings,
606+
write_settings: WriteSettings,
607607
needs_padding: bool,
608608
}
609609

@@ -613,28 +613,32 @@ impl<'a> Obj<'a> {
613613
pub(crate) fn direct(
614614
buf: &'a mut Buf,
615615
indent: u8,
616-
settings: WriteSettings,
616+
write_settings: WriteSettings,
617617
needs_padding: bool,
618618
) -> Self {
619619
Self {
620620
buf,
621621
indirect: false,
622622
indent,
623-
settings,
623+
write_settings,
624624
needs_padding,
625625
}
626626
}
627627

628628
/// Start a new indirect object.
629629
#[inline]
630-
pub(crate) fn indirect(buf: &'a mut Buf, id: Ref, settings: WriteSettings) -> Self {
630+
pub(crate) fn indirect(
631+
buf: &'a mut Buf,
632+
id: Ref,
633+
write_settings: WriteSettings,
634+
) -> Self {
631635
buf.push_int(id.get());
632636
buf.extend(b" 0 obj\n");
633637
Self {
634638
buf,
635639
indirect: true,
636640
indent: 0,
637-
settings,
641+
write_settings,
638642
needs_padding: false,
639643
}
640644
}
@@ -650,7 +654,7 @@ impl<'a> Obj<'a> {
650654
if self.indirect {
651655
self.buf.extend(b"\nendobj\n");
652656

653-
if self.settings.pretty {
657+
if self.write_settings.pretty {
654658
self.buf.extend(b"\n");
655659
}
656660
}
@@ -720,7 +724,7 @@ writer!(Array: |obj| {
720724
buf: obj.buf,
721725
indirect: obj.indirect,
722726
indent: obj.indent,
723-
settings: obj.settings,
727+
settings: obj.write_settings,
724728
len: 0,
725729
}
726730
});
@@ -880,7 +884,7 @@ writer!(Dict: |obj| {
880884
buf: obj.buf,
881885
indirect: obj.indirect,
882886
indent: obj.indent.saturating_add(2),
883-
settings: obj.settings,
887+
settings: obj.write_settings,
884888
len: 0,
885889
}
886890
});

src/renumber.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn renumber(source: &Chunk, target: &mut Chunk, mapping: &mut dyn FnMut(Ref)
2020
patch_object(slice, &mut target.buf, mapping);
2121
target.buf.extend(b"\nendobj\n");
2222

23-
if target.settings.pretty {
23+
if target.write_settings.pretty {
2424
target.buf.extend(b"\n");
2525
}
2626
}

0 commit comments

Comments
 (0)