[ 
https://issues.apache.org/jira/browse/PDFBOX-6340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150844#comment-18150844
 ] 

Valery Bokov commented on PDFBOX-6340:
--------------------------------------

1. Beads are drawn in the wrong place in PDFDebugger. This is in 
DebugTextStripper.stripPage in DebugTextOverlay.java:108-110. It moves the bead 
rectangle by the cropbox offset first and flips it upside down second:

Shape s = r.toGeneralPath().createTransformedShape(transAT);
s = flipAT.createTransformedShape(s);

That puts y at height - y - cropLLY, but it should be cropURY - y, which is 
height - y + cropLLY. Beads are drawn too high by twice the cropbox's bottom 
offset. It's the same kind of mistake as in our PDFTextStripper bug. Doing the 
flip first fixes it, which is the order the code already uses for the glyph 
outlines a few lines below (lines 229-230). Those are the "cyan shapes" he says 
are placed correctly.

2. The status bar shows the wrong mouse y at 180°. In PagePane.mouseMoved, the 
180° case used y - offsetY. Only that case is wrong: when the page is upside 
down, the top of the screen is the bottom of the page, so it should be y + 
offsetY. That's why the 180° bead looked misplaced to him. The bead was fine, 
but the coordinates he checked it against were wrong. This second bug was 
already fixed by you, [~tilman].

> 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
>            Priority: Major
>              Labels: pull-request-available, test
>         Attachments: bead-rot0.pdf, bead-rot180.pdf, bead-rot270.pdf, 
> bead-rot90.pdf
>
>
> 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]

Reply via email to