Commit 31b45b0fd4196c809357236a6fbf5b5a0a4123e4
1 parent
3e2109ab
Fix logic error with Tf when generating appearances (fixes #655)
Showing
5 changed files
with
7043 additions
and
16 deletions
ChangeLog
| 1 | +2022-02-18 Jay Berkenbilt <ejb@ql.org> | |
| 2 | + | |
| 3 | + * Bug fix: when generating appearance streams, the font size was | |
| 4 | + substituted incorrectly from /DA if Tf was absent or the number | |
| 5 | + preceding Tf was out of range. Fixes #655. | |
| 6 | + | |
| 1 | 7 | 2022-02-16 Jay Berkenbilt <ejb@ql.org> |
| 2 | 8 | |
| 3 | 9 | * 10.6.2: release | ... | ... |
libqpdf/QPDFFormFieldObjectHelper.cc
| ... | ... | @@ -798,19 +798,19 @@ class TfFinder: public QPDFObjectHandle::TokenFilter |
| 798 | 798 | |
| 799 | 799 | private: |
| 800 | 800 | double tf; |
| 801 | - size_t tf_idx; | |
| 801 | + int tf_idx; | |
| 802 | 802 | std::string font_name; |
| 803 | 803 | double last_num; |
| 804 | - size_t last_num_idx; | |
| 804 | + int last_num_idx; | |
| 805 | 805 | std::string last_name; |
| 806 | 806 | std::vector<std::string> DA; |
| 807 | 807 | }; |
| 808 | 808 | |
| 809 | 809 | TfFinder::TfFinder() : |
| 810 | 810 | tf(11.0), |
| 811 | - tf_idx(0), | |
| 811 | + tf_idx(-1), | |
| 812 | 812 | last_num(0.0), |
| 813 | - last_num_idx(0) | |
| 813 | + last_num_idx(-1) | |
| 814 | 814 | { |
| 815 | 815 | } |
| 816 | 816 | |
| ... | ... | @@ -825,7 +825,7 @@ TfFinder::handleToken(QPDFTokenizer::Token const& token) |
| 825 | 825 | case QPDFTokenizer::tt_integer: |
| 826 | 826 | case QPDFTokenizer::tt_real: |
| 827 | 827 | last_num = strtod(value.c_str(), 0); |
| 828 | - last_num_idx = DA.size() - 1; | |
| 828 | + last_num_idx = QIntC::to_int(DA.size() - 1); | |
| 829 | 829 | break; |
| 830 | 830 | |
| 831 | 831 | case QPDFTokenizer::tt_name: |
| ... | ... | @@ -833,16 +833,17 @@ TfFinder::handleToken(QPDFTokenizer::Token const& token) |
| 833 | 833 | break; |
| 834 | 834 | |
| 835 | 835 | case QPDFTokenizer::tt_word: |
| 836 | - if ((value == "Tf") && | |
| 837 | - (last_num > 1.0) && | |
| 838 | - (last_num < 1000.0)) | |
| 836 | + if (value == "Tf") | |
| 839 | 837 | { |
| 840 | - // These ranges are arbitrary but keep us from doing | |
| 841 | - // insane things or suffering from over/underflow | |
| 842 | - tf = last_num; | |
| 838 | + if ((last_num > 1.0) && (last_num < 1000.0)) | |
| 839 | + { | |
| 840 | + // These ranges are arbitrary but keep us from doing | |
| 841 | + // insane things or suffering from over/underflow | |
| 842 | + tf = last_num; | |
| 843 | + } | |
| 844 | + tf_idx = last_num_idx; | |
| 845 | + font_name = last_name; | |
| 843 | 846 | } |
| 844 | - tf_idx = last_num_idx; | |
| 845 | - font_name = last_name; | |
| 846 | 847 | break; |
| 847 | 848 | |
| 848 | 849 | default: |
| ... | ... | @@ -864,7 +865,7 @@ TfFinder::getDA() |
| 864 | 865 | for (size_t i = 0; i < n; ++i) |
| 865 | 866 | { |
| 866 | 867 | std::string cur = this->DA.at(i); |
| 867 | - if (i == tf_idx) | |
| 868 | + if (QIntC::to_int(i) == tf_idx) | |
| 868 | 869 | { |
| 869 | 870 | double delta = strtod(cur.c_str(), 0) - this->tf; |
| 870 | 871 | if ((delta > 0.001) || (delta < -0.001)) | ... | ... |
qpdf/qtest/qpdf.test
| ... | ... | @@ -563,11 +563,12 @@ $td->runtest("compare files", |
| 563 | 563 | show_ntests(); |
| 564 | 564 | # ---------- |
| 565 | 565 | $td->notify("--- Appearance Streams ---"); |
| 566 | -$n_tests += 10; | |
| 566 | +$n_tests += 12; | |
| 567 | 567 | |
| 568 | 568 | foreach my $f ('need-appearances', |
| 569 | 569 | 'need-appearances-more', |
| 570 | - 'need-appearances-more2') | |
| 570 | + 'need-appearances-more2', | |
| 571 | + 'need-appearances-more3') | |
| 571 | 572 | { |
| 572 | 573 | $td->runtest("generate appearances and flatten ($f)", |
| 573 | 574 | {$td->COMMAND => | ... | ... |
qpdf/qtest/qpdf/appearances-a-more3.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/need-appearances-more3.pdf
0 → 100644
No preview for this file type