Repository navigation
Conversation
Clippy 0.1.98 flags two new lints that break the CI step
`cargo clippy --all-targets -- -D warnings` on stable:
- chunks_exact_to_as_chunks (attachments.rs): iterate the
/Names leaf with `as_chunks::<2>()`. The trailing odd element
is still skipped, as with `chunks_exact(2)`.
- collapsible_match (layout.rs): move the "no trailing space"
check into the TJ match guards. A failing guard falls through
to `_ => {}`, which is what the inner `if` did.
No behaviour change. `as_chunks` needs Rust 1.88 or newer.
docugraph ships a binary, so the lockfile belongs in the repo. Without it every build resolves dependencies again and a fixed commit does not pin rmcp, lopdf, tokio and the rest. The lock is the one resolved for 2832efa (182 packages, rmcp 3.3.0, lopdf 0.45.0, tokio 1.53.1) and matches Cargo.toml under `--locked`.
test_real_pdf_loading_and_extraction read a hardcoded Windows path and returned early when it was missing, so it reported "ok" without testing anything on every machine but one. Read the path from DOCUGRAPH_TEST_PDF instead and mark the test #[ignore] with a reason, so it shows up as ignored by default. Run it with `DOCUGRAPH_TEST_PDF=... cargo test -- --ignored`; a missing variable or file now fails loudly.
Now that Cargo.lock is tracked, fail CI when it is out of date with Cargo.toml instead of silently rewriting it. There is no separate build step: clippy is the first step that resolves dependencies and `cargo test` builds the crate, so both get --locked. Without it on clippy the lock would be rewritten before the test step runs.
Single-column pages went through lopdf's extract_text, which ignores real-valued TJ adjustments, appends a space after every TJ array and drops Td/Tm moves between fragments. PDFs that place words by position (Prince, fonts without a space glyph) came out with glued words and spaces in the middle of words. Place every fragment with the font's real glyph widths (/Widths, /W, /DW, MissingWidth, Type3 FontMatrix) and the text state (Tc, Tw, Tz, Tm, CTM). Read TJ adjustments below -100/1000 em as word gaps for both integers and reals, and join fragments in stream order with a newline when the baseline changes and a space when the gap exceeds 0.15 em. All pages now use extract_page_text: multi-column reading order when a gutter is detected, stream order otherwise. lopdf's extract_text stays as a fallback when the content stream cannot be decoded.
Generate PDFs with a font of known widths: TJ arrays with real and integer adjustments, kerning inside a word and a word split across two TJ operators; Td moves between words, one text object per word with separate punctuation, and a scaled text matrix. Also check the stream order join on synthetic fragments.
Owner
Author
|
Se descarta: los arreglos de docugraph los está haciendo el autor en su copia local y estos cambios chocarían con ellos. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problema
En PDFs que colocan las palabras por posición en lugar de con un glifo de espacio, el texto extraído sale con palabras pegadas y con espacios a mitad de palabra. Pasa con el libro de patrones de diseño (Prince 12.5): frente a
pdftotextsolo se recuperaba un 39 % de las palabras (mediana por página) y 396 de 436 páginas quedaban por debajo de 0,8. El libro de Git (XeTeX) salía bien.Causa: las páginas de una sola columna no pasaban por
layout.rs, sino porlopdf::Document::extract_text(parser.rs), que:-266.2423), así que se perdían;Td/Tmentre fragmentos, que es como Prince separa muchas palabras (a menudo con unBT/ETpor palabra).Git salía bien porque XeTeX usa desplazamientos enteros (-250) dentro de un único TJ por línea.
Cambios
src/document/layout.rs/Widths,/FirstCharyMissingWidthen fuentes simples,/Wy/DWen fuentes CID (Type0) yFontMatrixen Type3. Aplica el estado de texto (Tc,Tw,Tz, cuerpo) y la matriz de texto × CTM, así que cada fragmento tiene su posición y anchura reales en espacio de usuario. Si la fuente no trae anchuras, se mantiene la estimación anterior (0,52 em).join_fragments_in_stream_order: une los fragmentos en el orden del flujo. Pone salto de línea cuando cambia la línea base (más de medio cuerpo) y espacio cuando el hueco supera 0,15 em o hay un salto hacia atrás mayor que el cuerpo.group_fragments_into_lines(multicolumna) usa el mismo criterio en vez de 2 pt fijos.extract_page_text: orden de lectura multicolumna si detecta un canal y orden del flujo si no.extract_positioned_fragmentsyextract_page_text_spatialconservan su firma.Tjque solo contiene espacios ahora avanza la matriz de texto (antes se saltaba sin moverla), y"aplicaTw/Tc.src/document/parser.rsextract_page_text.lopdf::extract_textqueda solo de respaldo cuando el flujo no se puede decodificar o no hay texto.scan_page_security) no cambia.tests/text_word_spacing_test.rs(nuevo), con un PDF generado con una fuente de anchuras conocidas:Tdentre palabras, unBT/ETpor palabra con la puntuación aparte y una matrizTmescalada.Cómo se verificó
En local, con
nice -n 19 ionice -c3y-j 2(rustc 1.98):cargo fmt --all -- --check: sin diferencias (exit 0).cargo clippy --locked --all-targets -- -D warnings: exit 0, sin avisos.cargo test --locked: exit 0, 75 pasados, 0 fallos y 1 ignorado (el test del PDF real, condicionado por variable de entorno desde chore: fix clippy and commit lockfile #1). Los 3 tests nuevos pasan; los de multicolumna, tablas y texto oculto siguen verdes.["Singlifo deespacio ", "Patrones crea cionales "]en lugar de["Sin glifo de espacio", "Patrones", "creacionales"]["Holamundosinespacios", "Otra", "linea", ".", "Textoescalado"]en lugar de["Hola mundo sin espacios", "Otra linea.", "Texto escalado"]Con los dos libros reales (fuera del repo, caché en una carpeta temporal):
docugraph indexde los dos PDFs conDOCUGRAPH_CACHE_DIRdistinto para cada uno.pdftotext -raw, página a página.\w+, 3 letras o más, en minúsculas), la fracción de esas palabras que aparece en el texto de docugraph. Como medida de orden, además, la fracción de pares de palabras consecutivas depdftotextque aparecen seguidos en docugraph.Nota: la cifra de «32 %» de la auditoría salió de otro script. Con este método, el mismo código base da 0,393 (coincide con la verificación independiente: 0,393, mínimo 0,077 y 396 páginas).
Riesgos y límites
ET/T*.