Skip to content

Commit f48faf9

Browse files
committed
Rename WriteSettings to just Settings
1 parent 4536d3b commit f48faf9

6 files changed

Lines changed: 45 additions & 53 deletions

File tree

src/chunk.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ use super::*;
22

33
/// Settings that should be applied while writing a PDF file.
44
#[derive(Debug, Clone, Copy)]
5-
pub struct WriteSettings {
5+
pub struct Settings {
66
/// Whether to enable pretty-writing. In this case, `pdf-writer` will serialize PDFs in such
77
/// a way that they are easier to read by humans by applying more padding and indentation, at
88
/// the cost of larger file sizes. If disabled, `pdf-writer` will serialize objects as compactly
99
/// as possible, leading to better file sizes but making it harder to inspect the file manually.
1010
pub pretty: bool,
1111
}
1212

13-
impl Default for WriteSettings {
13+
impl Default for Settings {
1414
fn default() -> Self {
1515
Self { pretty: true }
1616
}
@@ -30,7 +30,7 @@ impl Default for WriteSettings {
3030
pub struct Chunk {
3131
pub(crate) buf: Buf,
3232
pub(crate) offsets: Vec<(Ref, usize)>,
33-
pub(crate) write_settings: WriteSettings,
33+
pub(crate) settings: Settings,
3434
}
3535

3636
impl Chunk {
@@ -45,14 +45,14 @@ impl Chunk {
4545
Self {
4646
buf: Buf::with_capacity(capacity),
4747
offsets: vec![],
48-
write_settings: Default::default(),
48+
settings: Default::default(),
4949
}
5050
}
5151

5252
/// Create a new chunk with the given write settings.
53-
pub fn with_settings(write_settings: WriteSettings) -> Self {
53+
pub fn with_settings(settings: Settings) -> Self {
5454
let mut chunk = Self::new();
55-
chunk.write_settings = write_settings;
55+
chunk.settings = settings;
5656

5757
chunk
5858
}
@@ -182,7 +182,7 @@ impl Chunk {
182182
/// Start writing an indirectly referenceable object.
183183
pub fn indirect(&mut self, id: Ref) -> Obj<'_> {
184184
self.offsets.push((id, self.buf.len()));
185-
Obj::indirect(&mut self.buf, id, self.write_settings)
185+
Obj::indirect(&mut self.buf, id, self.settings)
186186
}
187187

188188
/// Start writing an indirectly referenceable stream.

src/content.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use super::*;
2-
use crate::chunk::WriteSettings;
2+
use crate::chunk::Settings;
33
use crate::object::{is_delimiter_character, TextStrLike};
44

55
/// A builder for a content stream.
66
pub struct Content {
77
buf: Buf,
8-
write_settings: WriteSettings,
8+
settings: Settings,
99
q_depth: usize,
1010
}
1111

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

2121
/// Create a new content stream with the given write settings.
22-
pub fn with_settings(write_settings: WriteSettings) -> Self {
22+
pub fn with_settings(settings: Settings) -> Self {
2323
let mut content = Self::new();
24-
content.write_settings = write_settings;
24+
content.settings = settings;
2525

2626
content
2727
}
@@ -31,14 +31,14 @@ impl Content {
3131
Self {
3232
buf: Buf::with_capacity(capacity),
3333
q_depth: 0,
34-
write_settings: Default::default(),
34+
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.write_settings)
41+
Operation::start(&mut self.buf, operator, self.settings)
4242
}
4343

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

7171
impl<'a> Operation<'a> {
7272
#[inline]
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 }
73+
pub(crate) fn start(buf: &'a mut Buf, op: &'a str, settings: Settings) -> Self {
74+
Self { buf, op, first: true, settings }
7975
}
8076

8177
/// Write a primitive operand.
@@ -108,7 +104,7 @@ impl<'a> Operation<'a> {
108104
// Similarly to how chunks are handled, we always add padding when pretty-writing
109105
// is enabled, and only lazily add padding depending on whether it's really necessary
110106
// if not.
111-
let needs_padding = if self.write_settings.pretty {
107+
let needs_padding = if self.settings.pretty {
112108
if !self.buf.is_empty() {
113109
self.buf.push(pad_byte);
114110
}
@@ -119,7 +115,7 @@ impl<'a> Operation<'a> {
119115
};
120116

121117
self.first = false;
122-
Obj::direct(self.buf, 0, self.write_settings, needs_padding)
118+
Obj::direct(self.buf, 0, self.settings, needs_padding)
123119
}
124120
}
125121

@@ -130,7 +126,7 @@ impl Drop for Operation<'_> {
130126

131127
// For example, in case we previously wrote a BT operator and then a [] operand in the
132128
// next operation, we don't need to pad them.
133-
if (self.write_settings.pretty
129+
if (self.settings.pretty
134130
|| self.buf.last().is_some_and(|b| !is_delimiter_character(*b)))
135131
&& !self.buf.is_empty()
136132
{
@@ -1751,7 +1747,7 @@ mod tests {
17511747

17521748
#[test]
17531749
fn test_content_array_no_pretty() {
1754-
let mut content = Content::with_settings(WriteSettings { pretty: false });
1750+
let mut content = Content::with_settings(Settings { pretty: false });
17551751

17561752
content.set_font(Name(b"F1"), 12.0);
17571753
content.set_font(Name(b"F2"), 15.0);
@@ -1775,7 +1771,7 @@ mod tests {
17751771

17761772
#[test]
17771773
fn test_content_dict_no_pretty() {
1778-
let mut content = Content::with_settings(WriteSettings { pretty: false });
1774+
let mut content = Content::with_settings(Settings { pretty: false });
17791775

17801776
let mut mc = content.begin_marked_content_with_properties(Name(b"Test"));
17811777
let mut properties = mc.properties();

src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ use std::fmt::{self, Debug, Formatter};
203203
use std::io::Write;
204204
use std::ops::{Deref, DerefMut};
205205

206-
use crate::chunk::WriteSettings;
206+
use crate::chunk::Settings;
207207

208208
use self::writers::*;
209209

@@ -230,9 +230,9 @@ impl Pdf {
230230
}
231231

232232
/// Create a new PDF with the given write settings.
233-
pub fn with_settings(write_settings: WriteSettings) -> Self {
233+
pub fn with_settings(settings: Settings) -> Self {
234234
let mut pdf = Self::new();
235-
pdf.write_settings = write_settings;
235+
pdf.settings = settings;
236236

237237
pdf
238238
}
@@ -308,7 +308,7 @@ impl Pdf {
308308
///
309309
/// Panics if any indirect reference id was used twice.
310310
pub fn finish(self) -> Vec<u8> {
311-
let Chunk { mut buf, mut offsets, write_settings } = self.chunk;
311+
let Chunk { mut buf, mut offsets, settings } = self.chunk;
312312

313313
offsets.sort();
314314

@@ -356,7 +356,7 @@ impl Pdf {
356356
// Write the trailer dictionary.
357357
buf.extend(b"trailer\n");
358358

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

362362
if let Some(catalog_id) = self.catalog_id {
@@ -422,11 +422,11 @@ mod tests {
422422
}
423423

424424
/// Return the slice of bytes written during the execution of `f`.
425-
pub fn slice<F>(f: F, write_settings: WriteSettings) -> Vec<u8>
425+
pub fn slice<F>(f: F, settings: Settings) -> Vec<u8>
426426
where
427427
F: FnOnce(&mut Pdf),
428428
{
429-
let mut w = Pdf::with_settings(write_settings);
429+
let mut w = Pdf::with_settings(settings);
430430
let start = w.len();
431431
f(&mut w);
432432
let end = w.len();
@@ -435,12 +435,12 @@ mod tests {
435435
}
436436

437437
/// Return the slice of bytes written for an object.
438-
pub fn slice_obj<F>(f: F, write_settings: WriteSettings) -> Vec<u8>
438+
pub fn slice_obj<F>(f: F, settings: Settings) -> Vec<u8>
439439
where
440440
F: FnOnce(Obj<'_>),
441441
{
442-
let buf = slice(|w| f(w.indirect(Ref::new(1))), write_settings);
443-
if write_settings.pretty {
442+
let buf = slice(|w| f(w.indirect(Ref::new(1))), settings);
443+
if settings.pretty {
444444
buf[8..buf.len() - 9].to_vec()
445445
} else {
446446
buf[8..buf.len() - 8].to_vec()

src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ macro_rules! test {
1919
#[cfg(test)]
2020
macro_rules! test_obj {
2121
(|$obj:ident| $write:expr, $($tts:tt)*) => {{
22-
test!(crate::tests::slice_obj(|$obj| { $write; }, crate::WriteSettings::default()), $($tts)*)
22+
test!(crate::tests::slice_obj(|$obj| { $write; }, crate::Settings::default()), $($tts)*)
2323
}}
2424
}
2525

2626
/// Test how an object is written, without pretty-printing.
2727
#[cfg(test)]
2828
macro_rules! test_obj_no_pretty {
2929
(|$obj:ident| $write:expr, $($tts:tt)*) => {{
30-
test!(crate::tests::slice_obj(|$obj| { $write; }, crate::WriteSettings { pretty: false }), $($tts)*)
30+
test!(crate::tests::slice_obj(|$obj| { $write; }, crate::Settings { pretty: false }), $($tts)*)
3131
}}
3232
}
3333

src/object.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::mem::ManuallyDrop;
44
use std::num::NonZeroI32;
55

66
use super::*;
7-
use crate::chunk::WriteSettings;
7+
use crate::chunk::Settings;
88

99
/// A primitive PDF object.
1010
pub trait Primitive {
@@ -608,7 +608,7 @@ pub struct Obj<'a> {
608608
buf: &'a mut Buf,
609609
indirect: bool,
610610
indent: u8,
611-
write_settings: WriteSettings,
611+
settings: Settings,
612612
needs_padding: bool,
613613
}
614614

@@ -618,32 +618,28 @@ impl<'a> Obj<'a> {
618618
pub(crate) fn direct(
619619
buf: &'a mut Buf,
620620
indent: u8,
621-
write_settings: WriteSettings,
621+
settings: Settings,
622622
needs_padding: bool,
623623
) -> Self {
624624
Self {
625625
buf,
626626
indirect: false,
627627
indent,
628-
write_settings,
628+
settings,
629629
needs_padding,
630630
}
631631
}
632632

633633
/// Start a new indirect object.
634634
#[inline]
635-
pub(crate) fn indirect(
636-
buf: &'a mut Buf,
637-
id: Ref,
638-
write_settings: WriteSettings,
639-
) -> Self {
635+
pub(crate) fn indirect(buf: &'a mut Buf, id: Ref, settings: Settings) -> Self {
640636
buf.push_int(id.get());
641637
buf.extend(b" 0 obj\n");
642638
Self {
643639
buf,
644640
indirect: true,
645641
indent: 0,
646-
write_settings,
642+
settings,
647643
needs_padding: false,
648644
}
649645
}
@@ -671,7 +667,7 @@ impl<'a> Obj<'a> {
671667
if self.indirect {
672668
self.buf.extend(b"\nendobj\n");
673669

674-
if self.write_settings.pretty {
670+
if self.settings.pretty {
675671
self.buf.extend(b"\n");
676672
}
677673
}
@@ -734,7 +730,7 @@ pub struct Array<'a> {
734730
buf: &'a mut Buf,
735731
indirect: bool,
736732
indent: u8,
737-
settings: WriteSettings,
733+
settings: Settings,
738734
len: i32,
739735
}
740736

@@ -744,7 +740,7 @@ writer!(Array: |obj| {
744740
buf: obj.buf,
745741
indirect: obj.indirect,
746742
indent: obj.indent,
747-
settings: obj.write_settings,
743+
settings: obj.settings,
748744
len: 0,
749745
}
750746
});
@@ -896,7 +892,7 @@ pub struct Dict<'a> {
896892
buf: &'a mut Buf,
897893
indirect: bool,
898894
indent: u8,
899-
settings: WriteSettings,
895+
settings: Settings,
900896
len: i32,
901897
}
902898

@@ -906,7 +902,7 @@ writer!(Dict: |obj| {
906902
buf: obj.buf,
907903
indirect: obj.indirect,
908904
indent: obj.indent.saturating_add(2),
909-
settings: obj.write_settings,
905+
settings: obj.settings,
910906
len: 0,
911907
}
912908
});

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.write_settings.pretty {
23+
if target.settings.pretty {
2424
target.buf.extend(b"\n");
2525
}
2626
}

0 commit comments

Comments
 (0)