Fix logic error with Tf when generating appearances (fixes #655)

This commit is contained in:
Jay Berkenbilt 2022-02-18 13:43:26 -05:00
parent 3e2109ab37
commit 31b45b0fd4
5 changed files with 7043 additions and 16 deletions

View File

@ -1,3 +1,9 @@
2022-02-18 Jay Berkenbilt <ejb@ql.org>
* Bug fix: when generating appearance streams, the font size was
substituted incorrectly from /DA if Tf was absent or the number
preceding Tf was out of range. Fixes #655.
2022-02-16 Jay Berkenbilt <ejb@ql.org>
* 10.6.2: release

View File

@ -798,19 +798,19 @@ class TfFinder: public QPDFObjectHandle::TokenFilter
private:
double tf;
size_t tf_idx;
int tf_idx;
std::string font_name;
double last_num;
size_t last_num_idx;
int last_num_idx;
std::string last_name;
std::vector<std::string> DA;
};
TfFinder::TfFinder() :
tf(11.0),
tf_idx(0),
tf_idx(-1),
last_num(0.0),
last_num_idx(0)
last_num_idx(-1)
{
}
@ -825,7 +825,7 @@ TfFinder::handleToken(QPDFTokenizer::Token const& token)
case QPDFTokenizer::tt_integer:
case QPDFTokenizer::tt_real:
last_num = strtod(value.c_str(), 0);
last_num_idx = DA.size() - 1;
last_num_idx = QIntC::to_int(DA.size() - 1);
break;
case QPDFTokenizer::tt_name:
@ -833,16 +833,17 @@ TfFinder::handleToken(QPDFTokenizer::Token const& token)
break;
case QPDFTokenizer::tt_word:
if ((value == "Tf") &&
(last_num > 1.0) &&
(last_num < 1000.0))
if (value == "Tf")
{
// These ranges are arbitrary but keep us from doing
// insane things or suffering from over/underflow
tf = last_num;
if ((last_num > 1.0) && (last_num < 1000.0))
{
// These ranges are arbitrary but keep us from doing
// insane things or suffering from over/underflow
tf = last_num;
}
tf_idx = last_num_idx;
font_name = last_name;
}
tf_idx = last_num_idx;
font_name = last_name;
break;
default:
@ -864,7 +865,7 @@ TfFinder::getDA()
for (size_t i = 0; i < n; ++i)
{
std::string cur = this->DA.at(i);
if (i == tf_idx)
if (QIntC::to_int(i) == tf_idx)
{
double delta = strtod(cur.c_str(), 0) - this->tf;
if ((delta > 0.001) || (delta < -0.001))

View File

@ -563,11 +563,12 @@ $td->runtest("compare files",
show_ntests();
# ----------
$td->notify("--- Appearance Streams ---");
$n_tests += 10;
$n_tests += 12;
foreach my $f ('need-appearances',
'need-appearances-more',
'need-appearances-more2')
'need-appearances-more2',
'need-appearances-more3')
{
$td->runtest("generate appearances and flatten ($f)",
{$td->COMMAND =>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff