[
https://issues.apache.org/jira/browse/PDFBOX-6365?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Valery Bokov updated PDFBOX-6365:
---------------------------------
Description:
*Problem*
_createWord()_ decides from the *first* glyph of a word whether the whole word
is normalized
({_}normalizeWord(){_}: ligature decomposition, Arabic/Hebrew presentation
forms and visual-to-logical
reordering). A word that has both text from an `/ActualText` and other text is
handled wrongly:
1. Other text first, then an ActualText: the ActualText is normalized too, so
right-to-left ActualText is
reversed. _a_ followed by _ActualText(אב)_ gives _aבא_ instead of {_}aאב{_}.
2. ActualText first, then other text: the other text isn't normalized, so e.g.
a "fi" ligature (U+FB01)
stays a ligature. _ActualText(X)_ followed by U+FB01 gives _Xfi_ instead of
{_}Xfi{_}.
*Cause*
Since PDFBOX-6281, ActualText is used as is because it's already in logical
order, but the check is
{_}wordPositions.get(0).isFromActualText(){_}, so it only looks at the first
glyph.
*Fix*
_createWord()_ goes through the word's positions. The text of positions from an
ActualText is copied as
is, and only the text between them is normalized. A word without ActualText is
still normalized as a
whole, exactly as before, so most words are unaffected. The empty-word case (a
word separator at the start
of a line) needs no special check anymore.
*Test*
_TestTextStripper#testWordWithActualTextAndOtherText_ covers both cases above,
using a ToUnicode CMap
that maps a glyph to U+FB01, and expects {_}aאב\nXfi\n{_}. It fails without the
fix in both lines.
{_}TestTextStripper{_}, {_}BidiTest{_}, _PDFTextStripperByAreaTest_ and the
_GlyphLayout*Test_ tests in
_pdfbox-layout-awt_ and _pdfbox-layout-fop_ (which use the ActualText PDFs from
PDFBOX-6281) pass.
was:
*Problem*
_createWord()_ decides from the *first* glyph of a word whether the whole word
is normalized
(_normalizeWord()_: ligature decomposition, Arabic/Hebrew presentation forms
and visual-to-logical
reordering). A word that has both text from an `/ActualText` and other text is
handled wrongly:
1. Other text first, then an ActualText: the ActualText is normalized too, so
right-to-left ActualText is
reversed. _a_ followed by _ActualText(אב)_ gives _aבא_ instead of aאב.
2. ActualText first, then other text: the other text isn't normalized, so e.g.
a "fi" ligature (U+FB01)
stays a ligature. `ActualText(X)` followed by U+FB01 gives `Xfi` instead of
`Xfi`.
*Cause*
Since PDFBOX-6281, ActualText is used as is because it's already in logical
order, but the check is
`wordPositions.get(0).isFromActualText()`, so it only looks at the first glyph.
*Fix*
`createWord()` goes through the word's positions. The text of positions from an
ActualText is copied as
is, and only the text between them is normalized. A word without ActualText is
still normalized as a
whole, exactly as before, so most words are unaffected. The empty-word case (a
word separator at the start
of a line) needs no special check anymore.
*Test*
`TestTextStripper#testWordWithActualTextAndOtherText` covers both cases above,
using a ToUnicode CMap
that maps a glyph to U+FB01, and expects `aאב\nXfi\n`. It fails without the fix
in both lines.
`TestTextStripper`, `BidiTest`, `PDFTextStripperByAreaTest` and the
`GlyphLayout*Test` tests in
`pdfbox-layout-awt` and `pdfbox-layout-fop` (which use the ActualText PDFs from
PDFBOX-6281) pass.
> Fix words with actual text and other text
> -----------------------------------------
>
> Key: PDFBOX-6365
> URL: https://issues.apache.org/jira/browse/PDFBOX-6365
> 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
>
> *Problem*
> _createWord()_ decides from the *first* glyph of a word whether the whole
> word is normalized
> ({_}normalizeWord(){_}: ligature decomposition, Arabic/Hebrew presentation
> forms and visual-to-logical
> reordering). A word that has both text from an `/ActualText` and other text
> is handled wrongly:
> 1. Other text first, then an ActualText: the ActualText is normalized too, so
> right-to-left ActualText is
> reversed. _a_ followed by _ActualText(אב)_ gives _aבא_ instead of
> {_}aאב{_}.
> 2. ActualText first, then other text: the other text isn't normalized, so
> e.g. a "fi" ligature (U+FB01)
> stays a ligature. _ActualText(X)_ followed by U+FB01 gives _Xfi_ instead of
> {_}Xfi{_}.
> *Cause*
> Since PDFBOX-6281, ActualText is used as is because it's already in logical
> order, but the check is
> {_}wordPositions.get(0).isFromActualText(){_}, so it only looks at the first
> glyph.
> *Fix*
> _createWord()_ goes through the word's positions. The text of positions from
> an ActualText is copied as
> is, and only the text between them is normalized. A word without ActualText
> is still normalized as a
> whole, exactly as before, so most words are unaffected. The empty-word case
> (a word separator at the start
> of a line) needs no special check anymore.
> *Test*
> _TestTextStripper#testWordWithActualTextAndOtherText_ covers both cases
> above, using a ToUnicode CMap
> that maps a glyph to U+FB01, and expects {_}aאב\nXfi\n{_}. It fails without
> the fix in both lines.
> {_}TestTextStripper{_}, {_}BidiTest{_}, _PDFTextStripperByAreaTest_ and the
> _GlyphLayout*Test_ tests in
> _pdfbox-layout-awt_ and _pdfbox-layout-fop_ (which use the ActualText PDFs
> from PDFBOX-6281) 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]