Skip to content

Keep minus signs that Cambridge fonts draw with unmapped glyphs - #301

Draft
thesanogoeffect wants to merge 1 commit into
mainfrom
claude/project-thread-7o68t3
Draft

thesanogoeffect wants to merge 1 commit into
mainfrom
claude/project-thread-7o68t3

Conversation

@thesanogoeffect

@thesanogoeffect thesanogoeffect commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Requested by Jakub · project thread

Hotfix candidate for 0.9.3, found by the new text benchmark (bibr-validation textbench/, branch claude/project-thread-7o68t3).

Problem

Cambridge's fonts (Psychological Medicine) draw the minus sign with a glyph they leave unmapped. pdfium reports it as a control character (U+0001, in one paper U+0003), which bibr strips, or which fails the native-text gate and sends the region to OCR. Negative statistics lose their sign: "t(41) = −2.31" can come out as "t(41) = 2.31". For Metacheck that flips the sign of a reported effect.

Fix

When the page's char records are built (_page_char_records), a control glyph (C0, except NUL, STX and the whitespace controls) whose tight box is a thin bar along its baseline is read as U+2212. The bar must be at least 6 times as long as it is thick, measured along FPDFText_GetCharAngle, so a landscape table on a turned page counts and a tall TeX extension piece does not. The record gets the new flag REC_UNMAPPED_MINUS, and the trace keeps the raw code. The default native-text regions, the --fast text layer and the document layer's record text all read these records.

Evidence (JATS text benchmark, 299 born-digital papers)

Negative statistics found character for character in the 18 Cambridge papers with the glyph:

kept
page text, before 14 of 98
page text, after 98 of 98
bibr 0.9.3 default 44 of 98
bibr 0.9.3 --fast 10 of 98
GROBID 0.9.1 14 of 98
DocPluck 14 of 98
  • Records before and after on all 299 PDFs: 676 characters change, in 22 papers (18 Cambridge, minus signs in the equations of 3 Nature Communications papers, 1 Frontiers figure). Every change is a control character becoming "−"; nothing else changes.
  • All 547 changed characters that are followed by a number appear as "−" and that number in the publisher's XML. The rest are table signs ("+ − −"), "Mean − 1 SD", "(−)" and equation minus signs.

Tests

  • New tests/ocr/test_unmapped_minus.py (18 tests): a Type 3 font fixture that reproduces the unmapped glyphs (a bar at code 1, a square at code 5), the record flag and trace, the native-text gate, a /Rotate 90 page, and the shape rule.
  • tests/test_native_text.py, tests/ocr, tests/document: 1,656 passed. tests/structure and the export tests: 1,741 passed (both without slow). The full suite has not run.
  • ruff check, ruff format --check and scripts/check_public_tree.py pass.

Not done

No end-to-end bibr chew run: the cloud session can't fetch the layout models. Re-running bibr default and --fast on the 18 Cambridge papers on declan would confirm the end-to-end gain.


Generated by Claude Code

Cambridge's fonts (Psychological Medicine) draw the minus sign with a glyph
they leave unmapped, so pdfium reports it as a control character (U+0001 or
U+0003). bibr stripped it or sent the region to OCR, and negative statistics
lost their sign: of the 98 negative statistics in 18 such papers of the JATS
text benchmark, 0.9.3 kept 44 and --fast 10.

A control glyph whose tight box is a thin bar along its baseline (at least 6
times as long as it is thick, measured along the char's angle so that a turned
table page counts) is now read as U+2212 when the page's char records are
built. The trace keeps the raw code and the record gets REC_UNMAPPED_MINUS.
On the benchmark's 299 papers this changes 676 characters in 22 papers; all
547 that are followed by a number are a minus in the publisher's XML, and the
page text of the 18 Cambridge papers now holds all 98 negative statistics.
@thesanogoeffect thesanogoeffect self-assigned this Nov 30, 2026
@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.02%. Comparing base (197447e) to head (870f3ff).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #301      +/-   ##
==========================================
- Coverage   91.03%   91.02%   -0.01%     
==========================================
  Files         345      345              
  Lines       74575    74604      +29     
  Branches    13933    13939       +6     
==========================================
+ Hits        67892    67911      +19     
- Misses       4115     4122       +7     
- Partials     2568     2571       +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant