A fast, helpful, and open-source document parser
wip
Logan Markewich89cef49dd6a3
diff --git a/Cargo.lock b/Cargo.lockindex bd414a8..2530b72 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -16,7 +16,7 @@ checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"dependencies = ["cfg-if","cipher",- "cpufeatures",+ "cpufeatures 0.2.17",][[package]]@@ -93,6 +93,18 @@ dependencies = ["derive_arbitrary",]+[[package]]+name = "arrayref"+version = "0.3.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"++[[package]]+name = "arrayvec"+version = "0.7.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f02882884d3e1bc524fb12c79f107f6ad0e1cfd498c536ffb494301740995dfe"+[[package]]name = "atomic-waker"version = "1.1.2"@@ -159,6 +171,20 @@ version = "2.11.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"+[[package]]+name = "blake3"+version = "1.8.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0aa83c34e62843d924f905e0f5c866eb1dd6545fc4d719e803d9ba6030371fce"+dependencies = [+ "arrayref",+ "arrayvec",+ "cc",+ "cfg-if",+ "constant_time_eq 0.4.2",+ "cpufeatures 0.3.0",+]+[[package]]name = "block-buffer"version = "0.10.4"@@ -363,6 +389,12 @@ version = "0.3.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6"+[[package]]+name = "constant_time_eq"+version = "0.4.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"+[[package]]name = "convert_case"version = "0.6.0"@@ -407,6 +439,15 @@ dependencies = ["libc",]+[[package]]+name = "cpufeatures"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"+dependencies = [+ "libc",+]+[[package]]name = "crc"version = "3.4.0"@@ -1245,6 +1286,7 @@ dependencies = [name = "liteparse-pdfium"version = "1.2.0"dependencies = [+ "blake3","liteparse-pdfium-sys",]@@ -2271,7 +2313,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"dependencies = ["cfg-if",- "cpufeatures",+ "cpufeatures 0.2.17","digest",]@@ -3323,7 +3365,7 @@ dependencies = ["aes","arbitrary","bzip2",- "constant_time_eq",+ "constant_time_eq 0.3.1","crc32fast","crossbeam-utils","deflate64",diff --git a/crates/pdfium-sys/src/dynamic.rs b/crates/pdfium-sys/src/dynamic.rsindex cb87bda..5581f3a 100644--- a/crates/pdfium-sys/src/dynamic.rs+++ b/crates/pdfium-sys/src/dynamic.rs@@ -233,6 +233,12 @@ pub struct PdfiumBindings {pub FPDFFont_GetGlyphWidth: unsafe extern "C" fn(FPDF_FONT, u32, f32, *mut f32) -> FPDF_BOOL,pub FPDFFont_GetGlyphWidthFromCharCode:unsafe extern "C" fn(FPDF_FONT, u32, f32, *mut f32) -> FPDF_BOOL,+ pub FPDFFont_GetGlyphPathFromCharCode:+ unsafe extern "C" fn(FPDF_FONT, u32, f32) -> FPDF_GLYPHPATH,+ pub FPDFGlyphPath_CountGlyphSegments:+ unsafe extern "C" fn(FPDF_GLYPHPATH) -> std::os::raw::c_int,+ pub FPDFGlyphPath_GetGlyphPathSegment:+ unsafe extern "C" fn(FPDF_GLYPHPATH, std::os::raw::c_int) -> FPDF_PATHSEGMENT,pub FPDFFont_HasToUnicode: unsafe extern "C" fn(FPDF_FONT) -> FPDF_BOOL,pub FPDFFont_GetCharGlyphName: unsafe extern "C" fn(FPDF_FONT,@@ -400,6 +406,9 @@ impl PdfiumBindings {FPDFFont_GetDescent: load_fn!(lib, "FPDFFont_GetDescent"),FPDFFont_GetGlyphWidth: load_fn!(lib, "FPDFFont_GetGlyphWidth"),FPDFFont_GetGlyphWidthFromCharCode: load_fn!(lib, "FPDFFont_GetGlyphWidthFromCharCode"),+ FPDFFont_GetGlyphPathFromCharCode: load_fn!(lib, "FPDFFont_GetGlyphPathFromCharCode"),+ FPDFGlyphPath_CountGlyphSegments: load_fn!(lib, "FPDFGlyphPath_CountGlyphSegments"),+ FPDFGlyphPath_GetGlyphPathSegment: load_fn!(lib, "FPDFGlyphPath_GetGlyphPathSegment"),FPDFFont_HasToUnicode: load_fn!(lib, "FPDFFont_HasToUnicode"),FPDFFont_GetCharGlyphName: load_fn!(lib, "FPDFFont_GetCharGlyphName"),FPDFFont_GetEncoding: load_fn!(lib, "FPDFFont_GetEncoding"),diff --git a/crates/pdfium/Cargo.toml b/crates/pdfium/Cargo.tomlindex b542514..5e13aa1 100644--- a/crates/pdfium/Cargo.toml+++ b/crates/pdfium/Cargo.toml@@ -8,3 +8,6 @@ description = "Safe Rust wrapper around PDFium for liteparse"[dependencies]pdfium-sys = { package = "liteparse-pdfium-sys", version = "1.2.0", path = "../pdfium-sys" }++[dev-dependencies]+blake3 = "1"diff --git a/crates/pdfium/src/font.rs b/crates/pdfium/src/font.rsindex 181c9be..0f44d01 100644--- a/crates/pdfium/src/font.rs+++ b/crates/pdfium/src/font.rs@@ -117,6 +117,54 @@ impl Font {if ok != 0 { Some(width) } else { None }}+ /// Walk the vector outline of the glyph for `char_code`, returning one+ /// entry per path segment as `(segment_type, x, y)`. `segment_type` is the+ /// raw PDFium `FPDF_SEGMENT_*` value (LINETO=0, BEZIERTO=1, MOVETO=2).+ /// Segments with type `FPDF_SEGMENT_UNKNOWN` (-1) are skipped, and a point+ /// that cannot be read is reported as `(type, 0.0, 0.0)` — matching the+ /// platform's `hashGlyphPath` packing convention so a downstream hash of+ /// these segments reproduces the platform font DB's `pathHash` key.+ ///+ /// Returns `None` when the font has no outline for this char code+ /// (e.g. whitespace / non-rendered glyph), distinct from `Some(vec![])`.+ pub fn glyph_path_segments(+ &self,+ char_code: u32,+ font_size: f32,+ ) -> Option<Vec<(i32, f32, f32)>> {+ let glyph_path = unsafe {+ ffi!(FPDFFont_GetGlyphPathFromCharCode(+ self.handle,+ char_code,+ font_size+ ))+ };+ if glyph_path.is_null() {+ return None;+ }+ let count = unsafe { ffi!(FPDFGlyphPath_CountGlyphSegments(glyph_path)) };+ let mut segments = Vec::new();+ for i in 0..count {+ let segment = unsafe { ffi!(FPDFGlyphPath_GetGlyphPathSegment(glyph_path, i)) };+ if segment.is_null() {+ break;+ }+ let seg_type = unsafe { ffi!(FPDFPathSegment_GetType(segment)) };+ if seg_type == pdfium_sys::FPDF_SEGMENT_UNKNOWN {+ continue;+ }+ let mut x: f32 = 0.0;+ let mut y: f32 = 0.0;+ let ok = unsafe { ffi!(FPDFPathSegment_GetPoint(segment, &mut x, &mut y)) };+ if ok == 0 {+ x = 0.0;+ y = 0.0;+ }+ segments.push((seg_type, x, y));+ }+ Some(segments)+ }+/// Get glyph width using a Unicode codepoint.pub fn glyph_width(&self, unicode: u32, font_size: f32) -> Option<f32> {let mut width: f32 = 0.0;