Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/pdf-canvas/src/canvas_external_object_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl<B: CanvasBackend> XObjectOps for PdfCanvas<'_, B> {
.resources
.ok_or(PdfCanvasError::MissingPageResources)?;

match resources.xobjects.get(xobject_name) {
match resources.xobject(xobject_name) {
Some(XObject::Image(image)) => self.render_image_xobject(image),
Some(XObject::Form(form)) => self.render_content_stream(
&form.content_stream.operations,
Expand Down
3 changes: 1 addition & 2 deletions crates/pdf-canvas/src/canvas_graphics_state_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ impl<B: CanvasBackend> GraphicsStateOps for PdfCanvas<'_, B> {
.ok_or(PdfCanvasError::MissingPageResources)?;

let states = resources
.external_graphics_states
.get(dict_name)
.external_graphics_state(dict_name)
.ok_or_else(|| PdfCanvasError::GraphicsStateNotFound(dict_name.to_string()))?;

for state in &states.params {
Expand Down
2 changes: 1 addition & 1 deletion crates/pdf-canvas/src/canvas_text_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<B: CanvasBackend> TextStateOps for PdfCanvas<'_, B> {
self.current_state_mut()?.text_state.font_size = size;

if let Some(resources) = self.current_state()?.resources
&& let Some(font) = resources.fonts.get(font_name)
&& let Some(font) = resources.font(font_name)
{
self.current_state_mut()?.text_state.font = Some(font);
return Ok(());
Expand Down
4 changes: 2 additions & 2 deletions crates/pdf-canvas/src/pdf_canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl<'a, B: CanvasBackend> PdfCanvas<'a, B> {
let Some(pattern) = self
.current_state()?
.resources
.and_then(|r| r.patterns.get(pattern_name))
.and_then(|r| r.pattern(pattern_name))
else {
return Err(PdfCanvasError::PatternNotFound(pattern_name.to_string()));
};
Expand All @@ -483,7 +483,7 @@ impl<'a, B: CanvasBackend> PdfCanvas<'a, B> {
let Some(pattern) = self
.current_state()?
.resources
.and_then(|r| r.patterns.get(pattern_name))
.and_then(|r| r.pattern(pattern_name))
else {
return Err(PdfCanvasError::PatternNotFound(pattern_name.to_string()));
};
Expand Down
2 changes: 1 addition & 1 deletion crates/pdf-canvas/src/shading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl<B: CanvasBackend> ShadingOps for PdfCanvas<'_, B> {
fn paint_shading(&mut self, shading_name: &str) -> Result<(), Self::ErrorType> {
let state = self.current_state()?;

let Some(shading) = state.resources.and_then(|r| r.shadings.get(shading_name)) else {
let Some(shading) = state.resources.and_then(|r| r.shading(shading_name)) else {
return Err(PdfCanvasError::PatternNotFound(shading_name.to_string()));
};

Expand Down
11 changes: 6 additions & 5 deletions crates/pdf-content-stream/src/pdf_operator/operands.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{borrow::Cow, rc::Rc};

use pdf_object::{ObjectVariant, dictionary::Dictionary, object_resolver::UnimplementedResolver};
use pdf_object::{
dictionary::Dictionary, object_resolver::UnimplementedResolver, object_variant::ObjectVariant,
};
use std::borrow::Cow;

use crate::{TextElement, error::PdfOperatorError};

Expand Down Expand Up @@ -65,9 +66,9 @@ impl<'a> Operands<'a> {
})
}

pub fn get_dictionary(&mut self) -> Result<Rc<Dictionary>, PdfOperatorError> {
pub fn get_dictionary(&mut self) -> Result<Box<Dictionary>, PdfOperatorError> {
self.take_and_map("Dictionary", |value| match value {
ObjectVariant::Dictionary(dict) => Ok(std::rc::Rc::clone(dict)),
ObjectVariant::Dictionary(dict) => Ok(dict.clone()),
_ => Err(PdfOperatorError::InvalidOperandType {
expected_type: "Dictionary",
found_type: value.name(),
Expand Down
3 changes: 2 additions & 1 deletion crates/pdf-content-stream/src/pdf_operator/variants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use pdf_object::object_resolver::UnimplementedResolver;
use pdf_object::object_variant::ObjectVariant;
use pdf_parser::{parser::PdfParser, traits::CommentParser};
use pdf_tokenizer::PdfToken;

Expand Down Expand Up @@ -162,7 +163,7 @@ impl PdfOperatorVariant {
/// before parsing.
fn parse_operator(
name: &str,
operands: &mut Vec<pdf_object::ObjectVariant>,
operands: &mut Vec<ObjectVariant>,
) -> Result<PdfOperatorVariant, PdfOperatorError> {
let Some(descriptor) = get_operation_descriptor(name) else {
return Err(PdfOperatorError::UnknownOperator(name.to_string()));
Expand Down
1 change: 1 addition & 0 deletions crates/pdf-document/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024"

[dependencies]
pdf-object-collection = { path = "../pdf-object-collection" }
pdf-object = { path = "../pdf-object" }
pdf-parser = { path = "../pdf-parser" }
pdf-page = { path = "../pdf-page" }
Expand Down
3 changes: 0 additions & 3 deletions crates/pdf-document/src/document.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use pdf_object::object_collection::ObjectCollection;
use pdf_page::page::PdfPage;

/// Represents a PDF document.
pub struct PdfDocument {
/// The collection of all objects in the PDF document.
pub objects: ObjectCollection,
/// The pages in the PDF document.
pub pages: Vec<PdfPage>,
}
Expand Down
5 changes: 3 additions & 2 deletions crates/pdf-document/src/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,15 @@ impl EncryptDictionary {
mod tests {
use super::*;
use pdf_object::{
ObjectVariant, dictionary::Dictionary, object_resolver::UnimplementedResolver,
dictionary::Dictionary, object_resolver::UnimplementedResolver,
object_variant::ObjectVariant,
};
use std::collections::BTreeMap;

fn make_dictionary(entries: Vec<(&str, ObjectVariant)>) -> Dictionary {
let mut map = BTreeMap::new();
for (key, value) in entries {
map.insert(key.to_string(), Box::new(value));
map.insert(key.to_string(), value);
}
Dictionary::new(map)
}
Expand Down
Loading
Loading