Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Aug 19, 2024
1 parent 44772a8 commit 492f059
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod document;
pub mod font;
mod graphics_state;
mod object;
mod outline;
pub mod paint;
pub mod path;
pub mod resource;
Expand Down
2 changes: 2 additions & 0 deletions src/object/ext_g_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ impl Object for ExtGState {
ext_st.blend_mode(bm);
}

ext_st.overprint(false);

if let Some(mask_ref) = mask_ref {
ext_st.pair(Name(b"SMask"), mask_ref);
}
Expand Down
1 change: 1 addition & 0 deletions src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod color_space;
pub mod ext_g_state;
pub mod image;
pub mod mask;
pub mod outline;
pub mod page;
pub mod shading_function;
pub mod shading_pattern;
Expand Down
49 changes: 49 additions & 0 deletions src/object/outline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use pdf_writer::{Chunk, Ref};
use tiny_skia_path::Point;
use crate::serialize::{Object, SerializerContext};

#[derive(Debug)]
pub struct Outline {
children: Vec<OutlineNode>,
}

impl Outline {
pub fn new() -> Self {
Self { children: vec![] }
}

pub fn push_child(&mut self, node: OutlineNode) {
self.children.push(node)
}
}

#[derive(Debug)]
struct OutlineNode {
children: Vec<Box<OutlineNode>>,
text: String,
page_index: u32,
pos: Point,
}

impl OutlineNode {
pub fn new(text: String, page_index: u32, pos: Point) -> Self {
Self {
children: vec![],
text,
page_index,
pos,
}
}

pub fn push_child(&mut self, node: OutlineNode) {
self.children.push(Box::new(node))
}


}

impl Object for Outline {
fn serialize_into(self, sc: &mut SerializerContext, root_ref: Ref) -> Chunk {
todo!()
}
}
8 changes: 6 additions & 2 deletions src/object/page.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::serialize::{Object, RegisterableObject, SerializerContext};
use crate::serialize::{Object, PageInfo, RegisterableObject, SerializerContext};
use crate::stream::Stream;
use crate::util::RectExt;
use pdf_writer::types::NumberingStyle;
Expand Down Expand Up @@ -55,7 +55,11 @@ impl Object for Page {

stream.finish();

sc.add_page_info(root_ref, self.page_label);
sc.add_page_info(PageInfo {
ref_: root_ref,
media_box: self.media_box,
page_label: self.page_label,
});

chunk
}
Expand Down
37 changes: 27 additions & 10 deletions src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use std::borrow::Cow;
use std::collections::HashMap;
use std::hash::Hash;
use std::sync::Arc;
use tiny_skia_path::Rect;
use crate::outline::Outline;

#[derive(Copy, Clone, Debug)]
pub struct SvgSettings {
Expand Down Expand Up @@ -81,8 +83,8 @@ pub struct SerializerContext {
catalog_ref: Ref,
page_tree_ref: Ref,
page_labels_ref: Option<Ref>,
page_refs: Vec<Ref>,
page_labels: Vec<PageLabel>,
page_infos: Vec<PageInfo>,
outline: Option<Outline>,
cached_mappings: HashMap<u128, Ref>,
chunks: Vec<Chunk>,
chunks_len: usize,
Expand All @@ -104,6 +106,13 @@ impl PDFGlyph {
}
}

#[derive(Debug)]
pub struct PageInfo {
pub ref_: Ref,
pub media_box: Rect,
pub page_label: PageLabel,
}

impl SerializerContext {
pub fn new(serialize_settings: SerializeSettings) -> Self {
let mut cur_ref = Ref::new(1);
Expand All @@ -116,22 +125,25 @@ impl SerializerContext {
chunks: Vec::new(),
page_tree_ref,
catalog_ref,
outline: None,
page_labels_ref: None,
page_refs: vec![],
page_labels: vec![],
page_infos: vec![],
chunks_len: 0,
font_map: HashMap::new(),
serialize_settings,
}
}

pub fn set_outline(&mut self, outline: Outline) {
self.outline = Some(outline);
}

pub fn page_tree_ref(&self) -> Ref {
self.page_tree_ref
}

pub fn add_page_info(&mut self, ref_: Ref, label: PageLabel) {
self.page_refs.push(ref_);
self.page_labels.push(label);
pub fn add_page_info(&mut self, page_info: PageInfo) {
self.page_infos.push(page_info);
}

pub fn new_ref(&mut self) -> Ref {
Expand Down Expand Up @@ -278,7 +290,12 @@ impl SerializerContext {

// Always needs to be called.
pub fn finish(mut self) -> Pdf {
if let Some(container) = PageLabelContainer::new(self.page_labels.clone()) {
if let Some(container) = PageLabelContainer::new(
self.page_infos
.iter()
.map(|i| i.page_label.clone())
.collect::<Vec<_>>(),
) {
self.page_labels_ref = Some(self.add(container));
}

Expand Down Expand Up @@ -312,8 +329,8 @@ impl SerializerContext {

page_tree_chunk
.pages(self.page_tree_ref)
.count(self.page_refs.len() as i32)
.kids(self.page_refs);
.count(self.page_infos.len() as i32)
.kids(self.page_infos.iter().map(|i| i.ref_));

self.chunks_len += page_tree_chunk.len();

Expand Down

0 comments on commit 492f059

Please sign in to comment.