imprimatur 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -5
- data/Cargo.lock +4 -3
- data/Cargo.toml +2 -1
- data/README.md +18 -7
- data/ext/imprimatur_native/cli/Cargo.toml +1 -1
- data/ext/imprimatur_native/cli/src/cli/markdown.rs +17 -5
- data/ext/imprimatur_native/core/Cargo.toml +3 -2
- data/ext/imprimatur_native/core/README.md +6 -1
- data/ext/imprimatur_native/core/src/read/budget.rs +15 -0
- data/ext/imprimatur_native/core/src/read/content.rs +1 -0
- data/ext/imprimatur_native/core/src/read/json.rs +1 -1
- data/ext/imprimatur_native/core/src/read/markdown.rs +8 -1
- data/ext/imprimatur_native/core/src/read/pdf/bounded.rs +94 -35
- data/ext/imprimatur_native/core/src/read/pdf/document/labels.rs +152 -0
- data/ext/imprimatur_native/core/src/read/pdf/document.rs +1 -0
- data/ext/imprimatur_native/core/src/read/pdf/isolation/protocol.rs +145 -76
- data/ext/imprimatur_native/core/src/read/pdf/isolation/stream.rs +113 -0
- data/ext/imprimatur_native/core/src/read/pdf/isolation/system.rs +27 -0
- data/ext/imprimatur_native/core/src/read/pdf/isolation/worker.rs +49 -18
- data/ext/imprimatur_native/core/src/read/pdf/isolation.rs +117 -28
- data/ext/imprimatur_native/core/src/read/pdf/layout.rs +190 -54
- data/ext/imprimatur_native/core/src/read/pdf.rs +2 -1
- data/ext/imprimatur_native/ffi/Cargo.toml +1 -1
- data/ext/imprimatur_native/ffi/src/lib.rs +2 -2
- data/ext/imprimatur_native/ffi/src/pdf.rs +20 -5
- data/lib/imprimatur/pdf_reader.rb +6 -4
- data/lib/imprimatur/version.rb +1 -1
- metadata +3 -1
|
@@ -9,9 +9,17 @@ use crate::read::without_gvl;
|
|
|
9
9
|
|
|
10
10
|
type Keywords = (Option<usize>, Option<u64>, Option<f64>);
|
|
11
11
|
|
|
12
|
-
pub fn info(
|
|
12
|
+
pub fn info(
|
|
13
|
+
ruby: &Ruby,
|
|
14
|
+
document: RString,
|
|
15
|
+
keywords: Keywords,
|
|
16
|
+
worker: String,
|
|
17
|
+
memory_bytes: u64,
|
|
18
|
+
) -> Result<RString, Error> {
|
|
19
|
+
let worker = PathBuf::from(worker);
|
|
20
|
+
let process = process_limits(memory_bytes);
|
|
13
21
|
let value = without_gvl(ruby, document, keywords, |data, limits| {
|
|
14
|
-
let info = pdf::
|
|
22
|
+
let info = pdf::isolation::info_isolated(&worker, data, limits, &process)?;
|
|
15
23
|
Ok(json!({ "page_count": info.page_count, "encrypted": info.encrypted }).to_string())
|
|
16
24
|
})?;
|
|
17
25
|
Ok(ruby.str_new(&value))
|
|
@@ -22,12 +30,16 @@ pub fn pages(
|
|
|
22
30
|
document: RString,
|
|
23
31
|
keywords: Keywords,
|
|
24
32
|
options: (u32, u32, usize, usize, usize),
|
|
33
|
+
worker: String,
|
|
34
|
+
memory_bytes: u64,
|
|
25
35
|
) -> Result<RString, Error> {
|
|
26
36
|
let (first_page, last_page, max_pages, max_page_bytes, max_output_bytes) = options;
|
|
27
37
|
let options =
|
|
28
38
|
pdf::ReadOptions { first_page, last_page, max_pages, max_page_bytes, max_output_bytes };
|
|
39
|
+
let worker = PathBuf::from(worker);
|
|
40
|
+
let process = process_limits(memory_bytes);
|
|
29
41
|
let value = without_gvl(ruby, document, keywords, |data, limits| {
|
|
30
|
-
let result = pdf::
|
|
42
|
+
let result = pdf::isolation::pages_isolated(&worker, data, &options, limits, &process)?;
|
|
31
43
|
let pages: Vec<_> = result
|
|
32
44
|
.pages
|
|
33
45
|
.into_iter()
|
|
@@ -63,11 +75,14 @@ pub fn render(
|
|
|
63
75
|
let (page, max_side, max_pixels, max_output_bytes, grayscale) = options;
|
|
64
76
|
let worker = PathBuf::from(worker);
|
|
65
77
|
let options = pdf::RenderOptions { max_side, max_pixels, max_output_bytes, grayscale };
|
|
66
|
-
let process =
|
|
67
|
-
pdf::isolation::ProcessLimits { memory_bytes, ..pdf::isolation::ProcessLimits::default() };
|
|
78
|
+
let process = process_limits(memory_bytes);
|
|
68
79
|
let data = without_gvl(ruby, document, keywords, |data: &[u8], limits: &Limits| {
|
|
69
80
|
pdf::isolation::render_page_isolated(&worker, data, page, &options, limits, &process)
|
|
70
81
|
.map(|image| image.data)
|
|
71
82
|
})?;
|
|
72
83
|
Ok(ruby.str_from_slice(&data))
|
|
73
84
|
}
|
|
85
|
+
|
|
86
|
+
fn process_limits(memory_bytes: u64) -> pdf::isolation::ProcessLimits {
|
|
87
|
+
pdf::isolation::ProcessLimits { memory_bytes, ..pdf::isolation::ProcessLimits::default() }
|
|
88
|
+
}
|
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
module Imprimatur
|
|
4
4
|
# Keyword handling only; parsing, limits and rendering live in the native core.
|
|
5
5
|
module PdfReader
|
|
6
|
-
def self.info(document, max_bytes: nil, **limits)
|
|
7
|
-
JSON.parse(Native.pdf_info(Reader.read(document, max_bytes), Reader.limits(max_bytes:, **limits)
|
|
6
|
+
def self.info(document, memory_bytes: 1024 * 1024 * 1024, max_bytes: nil, **limits)
|
|
7
|
+
JSON.parse(Native.pdf_info(Reader.read(document, max_bytes), Reader.limits(max_bytes:, **limits),
|
|
8
|
+
RENDER_WORKER, memory_bytes),
|
|
8
9
|
symbolize_names: true)
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def self.pages(document, first_page: 1, last_page: 0xFFFFFFFF, max_pages: 500,
|
|
12
13
|
max_page_bytes: 256 * 1024, max_output_bytes: 8 * 1024 * 1024,
|
|
13
|
-
max_bytes: nil, **limits)
|
|
14
|
+
memory_bytes: 1024 * 1024 * 1024, max_bytes: nil, **limits)
|
|
14
15
|
options = [first_page, last_page, max_pages, max_page_bytes, max_output_bytes]
|
|
15
|
-
JSON.parse(Native.pdf_pages(Reader.read(document, max_bytes), Reader.limits(max_bytes:, **limits),
|
|
16
|
+
JSON.parse(Native.pdf_pages(Reader.read(document, max_bytes), Reader.limits(max_bytes:, **limits),
|
|
17
|
+
options, RENDER_WORKER, memory_bytes),
|
|
16
18
|
symbolize_names: true)
|
|
17
19
|
end
|
|
18
20
|
|
data/lib/imprimatur/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: imprimatur
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Abdelkader Boudih
|
|
@@ -106,6 +106,7 @@ files:
|
|
|
106
106
|
- ext/imprimatur_native/core/src/read/pdf/content/state.rs
|
|
107
107
|
- ext/imprimatur_native/core/src/read/pdf/crypt.rs
|
|
108
108
|
- ext/imprimatur_native/core/src/read/pdf/document.rs
|
|
109
|
+
- ext/imprimatur_native/core/src/read/pdf/document/labels.rs
|
|
109
110
|
- ext/imprimatur_native/core/src/read/pdf/document/pages.rs
|
|
110
111
|
- ext/imprimatur_native/core/src/read/pdf/filter.rs
|
|
111
112
|
- ext/imprimatur_native/core/src/read/pdf/font.rs
|
|
@@ -114,6 +115,7 @@ files:
|
|
|
114
115
|
- ext/imprimatur_native/core/src/read/pdf/images.rs
|
|
115
116
|
- ext/imprimatur_native/core/src/read/pdf/isolation.rs
|
|
116
117
|
- ext/imprimatur_native/core/src/read/pdf/isolation/protocol.rs
|
|
118
|
+
- ext/imprimatur_native/core/src/read/pdf/isolation/stream.rs
|
|
117
119
|
- ext/imprimatur_native/core/src/read/pdf/isolation/system.rs
|
|
118
120
|
- ext/imprimatur_native/core/src/read/pdf/isolation/worker.rs
|
|
119
121
|
- ext/imprimatur_native/core/src/read/pdf/layout.rs
|