refactor: add PageExtraction type alias for extraction return tuples
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
f7afc0c439
commit
7d73c6a1ce
@@ -7,7 +7,7 @@ use crate::text_utils::{
|
||||
decode_text_string, effective_font_size, expand_ligatures, is_bold_font, is_italic_font,
|
||||
};
|
||||
use crate::tounicode::FontCMaps;
|
||||
use crate::types::{ItemType, PdfLine, PdfRect, TextItem};
|
||||
use crate::types::{ItemType, PageExtraction, PdfLine, PdfRect, TextItem};
|
||||
use crate::PdfError;
|
||||
use log::trace;
|
||||
use lopdf::{Document, Encoding, Object, ObjectId};
|
||||
@@ -25,7 +25,7 @@ pub(crate) fn extract_page_text_items(
|
||||
page_id: ObjectId,
|
||||
page_num: u32,
|
||||
font_cmaps: &FontCMaps,
|
||||
) -> Result<(Vec<TextItem>, Vec<PdfRect>, Vec<PdfLine>), PdfError> {
|
||||
) -> Result<PageExtraction, PdfError> {
|
||||
use lopdf::content::Content;
|
||||
|
||||
let mut items = Vec::new();
|
||||
|
||||
@@ -10,7 +10,7 @@ mod xobjects;
|
||||
|
||||
use crate::text_utils::is_rtl_text;
|
||||
use crate::tounicode::FontCMaps;
|
||||
use crate::types::{PdfLine, PdfRect, TextItem};
|
||||
use crate::types::{PageExtraction, TextItem};
|
||||
use crate::PdfError;
|
||||
use log::debug;
|
||||
use lopdf::{Document, Object, ObjectId};
|
||||
@@ -86,7 +86,7 @@ pub fn extract_text_with_positions_pages<P: AsRef<Path>>(
|
||||
pub(crate) fn extract_text_with_positions_and_rects<P: AsRef<Path>>(
|
||||
path: P,
|
||||
page_filter: Option<&HashSet<u32>>,
|
||||
) -> Result<(Vec<TextItem>, Vec<PdfRect>, Vec<PdfLine>), PdfError> {
|
||||
) -> Result<PageExtraction, PdfError> {
|
||||
crate::validate_pdf_file(&path)?;
|
||||
let doc = match Document::load(&path) {
|
||||
Ok(d) => d,
|
||||
@@ -117,7 +117,7 @@ pub fn extract_text_with_positions_mem_pages(
|
||||
pub(crate) fn extract_text_with_positions_mem_and_rects(
|
||||
buffer: &[u8],
|
||||
page_filter: Option<&HashSet<u32>>,
|
||||
) -> Result<(Vec<TextItem>, Vec<PdfRect>, Vec<PdfLine>), PdfError> {
|
||||
) -> Result<PageExtraction, PdfError> {
|
||||
crate::validate_pdf_bytes(buffer)?;
|
||||
let doc = match Document::load_mem(buffer) {
|
||||
Ok(d) => d,
|
||||
@@ -139,7 +139,7 @@ pub(crate) fn extract_positioned_text_from_doc(
|
||||
doc: &Document,
|
||||
font_cmaps: &FontCMaps,
|
||||
page_filter: Option<&HashSet<u32>>,
|
||||
) -> Result<(Vec<TextItem>, Vec<PdfRect>, Vec<PdfLine>), PdfError> {
|
||||
) -> Result<PageExtraction, PdfError> {
|
||||
let pages = doc.get_pages();
|
||||
let mut all_items = Vec::new();
|
||||
let mut all_rects = Vec::new();
|
||||
|
||||
@@ -8,6 +8,9 @@ use std::collections::HashMap;
|
||||
|
||||
use crate::text_utils::should_join_items;
|
||||
|
||||
/// Result tuple returned by page-level text extraction: text items, rectangles, and line segments.
|
||||
pub(crate) type PageExtraction = (Vec<TextItem>, Vec<PdfRect>, Vec<PdfLine>);
|
||||
|
||||
// ── Font types (crate-internal) ──────────────────────────────────────
|
||||
|
||||
/// Font encoding map: maps byte codes to Unicode characters
|
||||
|
||||
Reference in New Issue
Block a user