[ 
https://issues.apache.org/jira/browse/PDFBOX-6346?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Valery Bokov updated PDFBOX-6346:
---------------------------------
    Description: 
*Problem*

_charactersByArticle_ has one list per article of a page (before, in and after 
each bead), but it
never shrinks. A page with fewer beads than an earlier page keeps the extra 
lists, and _writePage()_ writes an empty article for each of them. With `[`/`]` 
as article start/end, a page without beads that follows a page with two beads 
gives

[][][][][three]

instead of {_}[three]{_}. With {_}setAddMoreFormatting(true){_}, where article 
start and end are line
separators, this shows up as extra empty lines.

*Cause*

In {_}processPage(){_}, the _remove( i )_ branch can't be reached: it's in the 
_else_ of {_}i < originalSize{_}, and since {_}i < 
Math.max(numberOfArticleSections, originalSize){_}, i >= originalSize means 
numberOfArticleSections > originalSize, so `numberOfArticleSections < 
originalSize` is always false. The TODO next to it ("Looks like decrement (--i) 
needed ... never reached in tests?!") noticed this, but a decrement wouldn't 
help.

*Fix*

The loop is replaced: lists beyond the number needed are removed with 
`subList(...).clear()`, the remaining lists are cleared, and missing lists are 
added. The list now has exactly one entry per article of the current page, so 
text outside all beads also goes into the real "after the last bead" list 
(`charactersByArticle.size() - 1`) instead of a leftover one.

`PDFTextStripperByArea` sets its own list for each region and page, and 
`PDFText2HTML` only reads it, so neither is affected.

*Test*

`TestTextStripper#testFewerBeadsThanPreviousPage` extracts a page with two 
beads followed by a page without beads and expects 
`[][one][][two][]\n[three]\n`. It fails without the fix. `TestTextStripper`, 
`BidiTest` and `PDFTextStripperByAreaTest` pass.

  was:
*Problem*

_charactersByArticle_ has one list per article of a page (before, in and after 
each bead), but it
never shrinks. A page with fewer beads than an earlier page keeps the extra 
lists, and _writePage()_ writes an empty article for each of them. With `[`/`]` 
as article start/end, a page without beads that follows a page with two beads 
gives

[][][][][three]

instead of {_}[three]{_}. With {_}setAddMoreFormatting(true){_}, where article 
start and end are line
separators, this shows up as extra empty lines.

*Cause*

In {_}processPage(){_}, the _remove(i)_ branch can't be reached: it's in the 
_else_ of {_}i < originalSize{_}, and since {_}i < 
Math.max(numberOfArticleSections, originalSize){_}, i >= originalSize means 
`numberOfArticleSections > originalSize`, so `numberOfArticleSections < 
originalSize` is always false. The TODO next to it ("Looks like decrement (--i) 
needed ... never reached in tests?!") noticed this, but a decrement wouldn't 
help.

*Fix*

The loop is replaced: lists beyond the number needed are removed with 
`subList(...).clear()`, the remaining lists are cleared, and missing lists are 
added. The list now has exactly one entry per article of the current page, so 
text outside all beads also goes into the real "after the last bead" list 
(`charactersByArticle.size() - 1`) instead of a leftover one.

`PDFTextStripperByArea` sets its own list for each region and page, and 
`PDFText2HTML` only reads it, so neither is affected.

*Test*

`TestTextStripper#testFewerBeadsThanPreviousPage` extracts a page with two 
beads followed by a page without beads and expects 
`[][one][][two][]\n[three]\n`. It fails without the fix. `TestTextStripper`, 
`BidiTest` and `PDFTextStripperByAreaTest` pass.


> The article list never shrinks
> ------------------------------
>
>                 Key: PDFBOX-6346
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6346
>             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
>
> *Problem*
> _charactersByArticle_ has one list per article of a page (before, in and 
> after each bead), but it
> never shrinks. A page with fewer beads than an earlier page keeps the extra 
> lists, and _writePage()_ writes an empty article for each of them. With 
> `[`/`]` as article start/end, a page without beads that follows a page with 
> two beads gives
> [][][][][three]
> instead of {_}[three]{_}. With {_}setAddMoreFormatting(true){_}, where 
> article start and end are line
> separators, this shows up as extra empty lines.
> *Cause*
> In {_}processPage(){_}, the _remove( i )_ branch can't be reached: it's in 
> the _else_ of {_}i < originalSize{_}, and since {_}i < 
> Math.max(numberOfArticleSections, originalSize){_}, i >= originalSize means 
> numberOfArticleSections > originalSize, so `numberOfArticleSections < 
> originalSize` is always false. The TODO next to it ("Looks like decrement 
> (--i) needed ... never reached in tests?!") noticed this, but a decrement 
> wouldn't help.
> *Fix*
> The loop is replaced: lists beyond the number needed are removed with 
> `subList(...).clear()`, the remaining lists are cleared, and missing lists 
> are added. The list now has exactly one entry per article of the current 
> page, so text outside all beads also goes into the real "after the last bead" 
> list (`charactersByArticle.size() - 1`) instead of a leftover one.
> `PDFTextStripperByArea` sets its own list for each region and page, and 
> `PDFText2HTML` only reads it, so neither is affected.
> *Test*
> `TestTextStripper#testFewerBeadsThanPreviousPage` extracts a page with two 
> beads followed by a page without beads and expects 
> `[][one][][two][]\n[three]\n`. It fails without the fix. `TestTextStripper`, 
> `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