Skip to content

Commit

Permalink
tidy up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Oct 30, 2024
1 parent ccb54f4 commit 71b7593
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/buf.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::Primitive;
use std::ops::{Deref, DerefMut};

/// Track the limits of data types used in a buffer.
#[derive(Clone, PartialEq, Debug, Default)]
pub struct Limits {
int: i32,
Expand All @@ -12,6 +13,7 @@ pub struct Limits {
}

impl Limits {
/// Create a new `Limits` struct with all values initialized to zero.
pub fn new() -> Self {
Self::default()
}
Expand Down Expand Up @@ -40,30 +42,38 @@ impl Limits {
self.dict_entries = self.dict_entries.max(len);
}

/// Get the absolute value of the largest positive/negative integer number.
pub fn int(&self) -> i32 {
self.int
}

/// Get the absolute value of the largest positive/negative real number.
pub fn real(&self) -> f32 {
self.real
}

/// Get the maximum length of any used name.
pub fn name_len(&self) -> usize {
self.name_len
}

/// Get the maximum length of any used array.
pub fn array_len(&self) -> usize {
self.array_len
}

/// Get the maximum number of entries in any dictionary.
pub fn dict_entries(&self) -> usize {
self.dict_entries
}

/// Get the maximum length of any used string.
pub fn str_len(&self) -> usize {
self.str_len
}

/// Merge two `Limits` with each other, taking the maximum
/// of each field from both.
pub fn merge(&mut self, other: &Limits) {
self.register_int(other.int);
self.register_real(other.real);
Expand All @@ -74,6 +84,7 @@ impl Limits {
}
}

/// A buffer of arbitrary PDF content.
#[derive(Clone, PartialEq, Debug)]
pub struct Buf {
buf: Vec<u8>,
Expand Down Expand Up @@ -106,10 +117,12 @@ impl Buf {
}
}

/// Get the underlying bytes of the buffer.
pub fn to_bytes(self) -> Vec<u8> {
self.buf
}

/// Return the limits of the buffer.
pub fn limits(&self) -> &Limits {
&self.limits
}
Expand Down
1 change: 1 addition & 0 deletions src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl Chunk {
self.buf.as_slice()
}

/// Return the limits of the chunk.
pub fn limits(&self) -> &Limits {
self.buf.limits()
}
Expand Down
5 changes: 3 additions & 2 deletions src/font.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;
use crate::buf::Buf;
use std::marker::PhantomData;
use crate::buf::Buf;

use super::*;

/// Writer for a _Type-1 font dictionary_.
///
Expand Down
10 changes: 5 additions & 5 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,18 @@ impl<'a> PostScriptOp<'a> {
}

fn write(&self, buf: &mut Buf) {
match self {
Self::Real(r) => buf.push_decimal(*r),
Self::Integer(i) => buf.push_val(*i),
match *self {
Self::Real(r) => buf.push_decimal(r),
Self::Integer(i) => buf.push_val(i),
Self::If(ops) => {
Self::write_slice(&ops, buf);
buf.push(b' ');
buf.extend_slice(self.operator());
}
Self::IfElse(ops1, ops2) => {
Self::write_slice(&ops1, buf);
Self::write_slice(ops1, buf);
buf.push(b' ');
Self::write_slice(&ops2, buf);
Self::write_slice(ops2, buf);
buf.push(b' ');
buf.extend_slice(self.operator());
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ valid PDFs.
*/

#![forbid(unsafe_code)]
// #![deny(missing_docs)]
#![deny(missing_docs)]
#![allow(clippy::wrong_self_convention)]

#[macro_use]
Expand Down
3 changes: 2 additions & 1 deletion src/object.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use super::*;
use crate::buf::Buf;
use std::convert::TryFrom;
use std::marker::PhantomData;
use std::mem::ManuallyDrop;
use std::num::NonZeroI32;

use super::*;

/// A primitive PDF object.
pub trait Primitive {
/// Write the object into a buffer.
Expand Down

0 comments on commit 71b7593

Please sign in to comment.