Skip to content

A fast, helpful, and open-source document parser

SpanCell carries an optional bbox, symmetric with Cell

Logan Markewich82f365710486
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bbb9a29..f625a3e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -52,12 +52,7 @@ jobs:
if: runner.os == 'Linux'
run: |
sudo apt-get update
- # Fonts: liteparse-ooxml layout tests need real font faces — 25 of
- # them fail in a fontless environment (measurer, list_label,
- # floating, build::block). Liberation + DejaVu is the set the musl
- # test run validated; macOS/Windows runners ship system fonts.
- sudo apt-get install -y libtesseract-dev libleptonica-dev \
- fonts-liberation fonts-dejavu-core
+ sudo apt-get install -y libtesseract-dev libleptonica-dev
- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
diff --git a/.github/workflows/release-crates.yml b/.github/workflows/release-crates.yml
index 08ca2c5..2e42439 100644
--- a/.github/workflows/release-crates.yml
+++ b/.github/workflows/release-crates.yml
@@ -67,10 +67,6 @@ jobs:
}
publish_if_new liteparse-pdfium-sys
publish_if_new liteparse-pdfium
- # Must precede liteparse: it is a path dependency of the `docx-native`
- # feature, and cargo refuses to publish a crate whose path deps are
- # unpublished — optional or not.
- publish_if_new liteparse-ooxml
publish_if_new liteparse
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
diff --git a/README.md b/README.md
index 112fa45..aaaf091 100644
--- a/README.md
+++ b/README.md
@@ -530,34 +530,6 @@ choco install libreoffice-fresh
> _On Windows, you may need to add LibreOffice's program directory (usually `C:\Program Files\LibreOffice\program`) to your PATH._
-#### Fonts (optional, affects DOCX geometry)
-
-DOCX files carry no coordinates, so LiteParse lays them out itself and measures the
-glyphs to decide where each word lands. A bounding box is therefore only as accurate
-as the font behind it — when a document asks for a font you don't have, the measure
-falls back to a generic sans and coordinates shift, differently on different machines.
-Text and structure are unaffected; this only matters for visual citations, screenshot
-highlighting, or cross-host geometry comparisons.
-
-```bash
-./scripts/install-fonts.sh # metric clones + common open fonts
-./scripts/install-fonts.sh --metric # metric clones only
-./scripts/install-fonts.sh --dry-run # print the commands, install nothing
-```
-
-Installs only freely-redistributable fonts: metric-compatible clones of the Microsoft
-faces (Carlito for Calibri, Caladea for Cambria, Liberation/Croscore for Arial, Times
-New Roman and Courier New), plus common open families like Open Sans, Lato and Roboto.
-The clones share the originals' advance widths exactly, so geometry becomes
-reproducible on any host with the same set.
-
-It does not install Calibri, Aptos, Corbel or Franklin Gothic — those are
-Microsoft-licensed. The clones cover Calibri and Cambria exactly; the others have no
-free metric equivalent and stay approximate without Microsoft Office installed.
-
-> _On a 45-document corpus this took the share of text measured against a generic
-> fallback from 64% to 14%._
-
#### Images (native support)
- **Formats**: `.jpg`, `.jpeg`, `.png`, `.gif`, `.bmp`, `.tiff`, `.webp`, `.svg`
diff --git a/crates/liteparse/src/layout.rs b/crates/liteparse/src/layout.rs
index 569a2bb..3187110 100644
--- a/crates/liteparse/src/layout.rs
+++ b/crates/liteparse/src/layout.rs
@@ -51,7 +51,7 @@ impl From<&SpanCell> for LayoutCell {
fn from(c: &SpanCell) -> Self {
LayoutCell {
text: c.text.clone(),
- bbox: None,
+ bbox: c.bbox.clone(),
colspan: (c.colspan > 1).then_some(c.colspan),
rowspan: (c.rowspan > 1).then_some(c.rowspan),
}
diff --git a/crates/liteparse/src/markdown_layout/blocks.rs b/crates/liteparse/src/markdown_layout/blocks.rs
index d0c155e..4bdb06c 100644
--- a/crates/liteparse/src/markdown_layout/blocks.rs
+++ b/crates/liteparse/src/markdown_layout/blocks.rs
@@ -80,13 +80,19 @@ impl PartialEq<String> for Cell {
/// One cell of a [`Block::MergedTable`]. `colspan`/`rowspan` are 1 for an
/// ordinary cell; the cells they cover are absent from `rows` rather than
/// present-and-empty, matching HTML's occupancy model. Distinct from [`Cell`]:
-/// that type carries the page geometry a cell was *read from*, this one the
-/// merge structure a producer *declared*.
-#[derive(Debug, Clone, PartialEq, Eq)]
+/// that type describes a cell a classifier *read off the page*, this one a
+/// merge structure a producer *declared* — but both carry the region the cell
+/// occupies when the producer knows it, so merged tables ground exactly like
+/// plain ones.
+#[derive(Debug, Clone)]
pub struct SpanCell {
pub text: String,
pub colspan: u16,
pub rowspan: u16,
+ /// Region the cell occupies on the page (the *whole* merged region for a
+ /// spanning cell), in the same viewport space as `text_items`. `None` when
+ /// the producer has no geometry for it.
+ pub bbox: Option<Rect>,
}
impl SpanCell {
@@ -96,6 +102,7 @@ impl SpanCell {
text: text.into(),
colspan: 1,
rowspan: 1,
+ bbox: None,
}
}
@@ -107,14 +114,32 @@ impl SpanCell {
text: text.into(),
colspan: colspan.max(1),
rowspan: rowspan.max(1),
+ bbox: None,
}
}
+ /// Attach the region this cell occupies.
+ pub fn with_bbox(mut self, bbox: Rect) -> Self {
+ self.bbox = Some(bbox);
+ self
+ }
+
fn is_plain(&self) -> bool {
self.colspan <= 1 && self.rowspan <= 1
}
}
+// Like `Cell`, geometry is derived metadata, not identity: two cells with the
+// same text and spans are the same table structure whether or not either one
+// knows its coordinates, and assertions compare against plain literals.
+impl PartialEq for SpanCell {
+ fn eq(&self, other: &Self) -> bool {
+ self.text == other.text && self.colspan == other.colspan && self.rowspan == other.rowspan
+ }
+}
+
+impl Eq for SpanCell {}
+
/// Coarse block representation: the output of page classification, consumed by
/// `render_blocks` to produce the final markdown string.
#[derive(Debug, Clone)]