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

Tilman Hausherr edited comment on PDFBOX-6340 at 11/25/26, 10:04 AM:
---------------------------------------------------------------------

I don't have the time right now, and yesterday I was also carried away while 
looking for a related problem.
Beads can be displayed in PDFDebugger. However there's a bug. This is in 
DebugTextStripper near the {{if (DebugTextOverlay.this.showTextStripperBeads)}} 
section. This is mostly fixed by switching the usage of flipAT and transAT, 
i.e. doing the flip first.  However the bead in the 180° file isn't displayed 
correctly. The suspicion is of course on {{transAT}} but this one is also used 
for the cyan shapes and these are properly placed. However the mouse 
coordinates are also not displayed properly for 180° (the top y coordinate is 
-10 but should be 10, so this is to blame and should be fixed first. Changing 
{{y1 = (int) (y - offsetY);}} to {{y1 = (int) (y + offsetY);}} in PagePane 
fixes it and now the bead in the 180° file appears correctly.


was (Author: tilman):
I don't have the time right now, and yesterday I was also carried away while 
looking for a related problem.
Beads can be displayed in PDFDebugger. However there's a bug. This is in 
DebugTextStripper near the {{if (DebugTextOverlay.this.showTextStripperBeads)}} 
section. This is mostly fixed by switching the usage of flipAT and transAT, 
i.e. doing the flip first.  However the bead in the 180° file isn't displayed 
correctly. The suspicion is of course on {{transAT}} but this one is also used 
for the cyan shapes and these are properly placed. However the mouse 
coordinates are also not displayed properly for 180° (the top y coordinate is 
-10 but should be 10, so maybe this is to blame and should be fixed first.

> 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
>
> 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