Coordinate calculation errors in getDataTm()
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.7k
- Forks
- 579
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
- PHP Version: 8.1.11
- PDFParser Version: 2.2.1
First of all, I am new to the PDF-specification and just read the text section (9.). So in case I understood someting wrong, feel free to edit this issue.
Description:
Some positions are calculated incorrectly in diffenrent situations
The text showing operators Tj and TJ do not adjust the x position:
- Wrong x-coordinate when multiple Tj operators are used in same line: The x-coordinate should be moved to the ending of the last printed glyph.
- Wrong x-coordinate when multiple TJ operators are used in same line: Same as above, in addition the TJ operator allows individual glyph positioning of the given strings (see pdf reference 9.4.3). These are not taken into account.
These two issues lead to the following situation: If there are multiple Tj/TJ operators in the same line, getDataTm() will return the same x-coordinate for all strings.
As a result of adapting this, all the operators that move the origin of the text space to the next line (like T*, ' and ") should reset the x-coordinate. I think that has to be done with the Tlm (Text line matrix).
- Text-positioning operators Td and TD don't reflect scaling of text:
The text can be scaled either with the Tf, Tfs or Tm operators. When the text-positioning operators Td or TD are used the coordinates are updated without taking in account the current scaling set by Tf or Tm, thus resulting in an incorrect translation of the current position. Correcting this will also solve #532.
Consideration of other text space paramenters: The following text space parameters are also not being considered during the calculation of the x,y-coordinates:
- For the x-coordinate: Tc (character spacing), Tw (word spacing), Th (horizontal scaling)
- For the y-coordinate: Trise (text rise)
The PDF-specification contains a formula for adapting the x,y-coordinates during horizontal or vertical writing under 9.4.4 (Text space details)
There is a description of all text operands in the PDF-specification under 9.: https://opensource.adobe.com/dc-acrobat-sdk-docs/standards/pdfstandards/pdf/PDF32000_2008.pdf
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at getDataTm() and trace how Tj, TJ, Td, TD, T*, ', and " update text coordinates. Read PDF specification sections 9.4.3 and 9.4.4, then verify handling of text scaling, spacing, rise, and line resets. Done means coordinates reflect the listed text-space parameters and operators, including the case described in #532.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100