Valery Bokov created PDFBOX-6365:
------------------------------------

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


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

Reply via email to