Commit 685250d7d6cc285be86e2c9e628449b51e08d489
1 parent
48b7de2c
Correct reversed Rectangle coordinates (fixes #363)
Showing
3 changed files
with
18 additions
and
6 deletions
ChangeLog
| 1 | 2019-09-19 Jay Berkenbilt <ejb@ql.org> | 1 | 2019-09-19 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | ||
| 3 | + * When converting an array to a Rectangle, ensure that llx <= urx | ||
| 4 | + and lly <= ury. This prevents flatten-annotations from flipping | ||
| 5 | + fields whose coordinates are messed up in the input. Fixes #363. | ||
| 6 | + | ||
| 3 | * Warn when duplicated dictionary keys are found during parsing. | 7 | * Warn when duplicated dictionary keys are found during parsing. |
| 4 | The behavior remains as before: later keys override earlier ones. | 8 | The behavior remains as before: later keys override earlier ones. |
| 5 | However, this generates a warning now rather than being silently | 9 | However, this generates a warning now rather than being silently |
libqpdf/QPDFObjectHandle.cc
| @@ -30,6 +30,7 @@ | @@ -30,6 +30,7 @@ | ||
| 30 | #include <ctype.h> | 30 | #include <ctype.h> |
| 31 | #include <limits.h> | 31 | #include <limits.h> |
| 32 | #include <cstring> | 32 | #include <cstring> |
| 33 | +#include <algorithm> | ||
| 33 | 34 | ||
| 34 | class TerminateParsing | 35 | class TerminateParsing |
| 35 | { | 36 | { |
| @@ -717,10 +718,17 @@ QPDFObjectHandle::getArrayAsRectangle() | @@ -717,10 +718,17 @@ QPDFObjectHandle::getArrayAsRectangle() | ||
| 717 | Rectangle result; | 718 | Rectangle result; |
| 718 | if (isRectangle()) | 719 | if (isRectangle()) |
| 719 | { | 720 | { |
| 720 | - result = Rectangle(getArrayItem(0).getNumericValue(), | ||
| 721 | - getArrayItem(1).getNumericValue(), | ||
| 722 | - getArrayItem(2).getNumericValue(), | ||
| 723 | - getArrayItem(3).getNumericValue()); | 721 | + // Rectangle coordinates are always supposed to be llx, lly, |
| 722 | + // urx, ury, but files have been found in the wild where | ||
| 723 | + // llx > urx or lly > ury. | ||
| 724 | + double i0 = getArrayItem(0).getNumericValue(); | ||
| 725 | + double i1 = getArrayItem(1).getNumericValue(); | ||
| 726 | + double i2 = getArrayItem(2).getNumericValue(); | ||
| 727 | + double i3 = getArrayItem(3).getNumericValue(); | ||
| 728 | + result = Rectangle(std::min(i0, i2), | ||
| 729 | + std::min(i1, i3), | ||
| 730 | + std::max(i0, i2), | ||
| 731 | + std::max(i1, i3)); | ||
| 724 | } | 732 | } |
| 725 | return result; | 733 | return result; |
| 726 | } | 734 | } |
qpdf/qtest/qpdf/manual-appearances.pdf
| @@ -819,10 +819,10 @@ endobj | @@ -819,10 +819,10 @@ endobj | ||
| 819 | /Ff 4096 | 819 | /Ff 4096 |
| 820 | /P 100 0 R | 820 | /P 100 0 R |
| 821 | /Rect [ | 821 | /Rect [ |
| 822 | - 294.149 | ||
| 823 | - 430.251 | ||
| 824 | 366.951 | 822 | 366.951 |
| 825 | 528.249 | 823 | 528.249 |
| 824 | + 294.149 | ||
| 825 | + 430.251 | ||
| 826 | ] | 826 | ] |
| 827 | /Subtype /Widget | 827 | /Subtype /Widget |
| 828 | /T (Text Box 3) | 828 | /T (Text Box 3) |