Skip to content

Commit

Permalink
Enable PDF compression
Browse files Browse the repository at this point in the history
  • Loading branch information
staticintlucas committed Aug 12, 2023
1 parent f610174 commit 613e919
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ itertools = "0.10"
kle-serial = "0.2"
kurbo = "0.9"
log = "0.4"
miniz_oxide = "0.7"
pdf-writer = "0.8"
rgb = { version = "0.8", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive"] }
Expand Down
11 changes: 9 additions & 2 deletions src/drawing/pdf.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use kurbo::{PathEl, Point};
use pdf_writer::{Content, Finish, PdfWriter, Rect, Ref, TextStr};
use miniz_oxide::deflate::{compress_to_vec_zlib, CompressionLevel};
use pdf_writer::{Content, Filter, Finish, PdfWriter, Rect, Ref, TextStr};

use crate::drawing::Drawing;

use super::{KeyDrawing, Path};

const COMPRESSION_LEVEL: u8 = CompressionLevel::DefaultLevel as u8;

macro_rules! transform {
(($($x:expr, $y:expr),+), $origin:expr, $scale:expr) => {
// Negate Y since PDF has rising Y axis
Expand Down Expand Up @@ -57,7 +60,11 @@ pub(crate) fn draw(drawing: &Drawing) -> Vec<u8> {
draw_key(&mut content, key, drawing.bounds.height(), scale);
}

writer.stream(content_id, &content.finish());
let data = compress_to_vec_zlib(&content.finish(), COMPRESSION_LEVEL);
writer
.stream(content_id, &data)
.filter(Filter::FlateDecode)
.finish();

writer
.document_info(doc_info_id)
Expand Down

0 comments on commit 613e919

Please sign in to comment.