Valery Bokov created PDFBOX-6340:
------------------------------------
Summary: Bead rectangles use the wrong coordinates in
PDFTextStripper
Key: PDFBOX-6340
URL: https://issues.apache.org/jira/browse/PDFBOX-6340
Project: PDFBox
Issue Type: Bug
Components: Text extraction
Affects Versions: 3.0.8 PDFBox, 4.0.0
Reporter: Valery Bokov
With `setShouldSeparateByBeads(true)` (the default), text that is inside a bead
(article thread) can be
put into the wrong article when the page has a cropbox that differs from the
media box, or a `/Rotate`.
Example: media box 0 0 600 800, cropbox 0 0 600 700, a bead at 40 600 240 680
and text at (50, 650)
inside it. The text ends up in the article before the bead instead of in the
bead. The same happens on
a page with `/Rotate 90` and no cropbox.
### Cause
`processTextPosition()` compares the bead rectangles with
`TextPosition.getX()`/`getY()`, which are
relative to the cropbox, rotated like the page and have y=0 at the top.
`fillBeadRectangles()`:
- flipped y with the *media box* (`mediaBox.getUpperRightY() - y`) and then
subtracted the cropbox
origin, which gives `mediaBox.URY - cropBox.LLY - y` instead of `cropBox.URY -
y`. These are only
equal when the cropbox has the same margin at the top and at the bottom of the
media box.
- ignored the page rotation.
### Fix
Both corners of each bead rectangle are transformed with a new helper,
`toGlyphCoordinates()`, which
uses the same formulas as `TextPosition` (`getXRot()`, `getYLowerLeftRot()`)
for 0, 90, 180 and 270
degrees. Because a rotation swaps or flips the corners, the rectangle is
rebuilt from the min/max of
the transformed corners. The media box is no longer used.
### Test
`TestTextStripper#testBeadWithCropBoxAndRotation` builds a page with media box
0 0 600 800, cropbox
20 10 580 710, a bead and text inside it, for each rotation (0, 90, 180, 270).
With `[`/`]` as article
start/end it expects `[][IN][]` (before the bead, the bead, after the bead). It
fails without the fix.
`TestTextStripper` (including `testExtract`), `BidiTest` and
`PDFTextStripperByAreaTest` pass.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]