aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFFormFieldObjectHelper.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-01-21 04:48:24 +0100
committerJay Berkenbilt <ejb@ql.org>2019-01-21 13:38:21 +0100
commit2d32f4db8fd125f2481ecf767d9f6506e80481f6 (patch)
treead13a821c881c2b498119c1591aeaf1451503691 /libqpdf/QPDFFormFieldObjectHelper.cc
parent9cb599875bbd1aaf1d2e91d44201ee0fcb79418f (diff)
downloadqpdf-2d32f4db8fd125f2481ecf767d9f6506e80481f6.tar.zst
Handle fallback font size in text appearances
If we end up using our fallback font size when generating appearances for text fields, reflect that in the Tf operator used in the appearance stream.
Diffstat (limited to 'libqpdf/QPDFFormFieldObjectHelper.cc')
-rw-r--r--libqpdf/QPDFFormFieldObjectHelper.cc36
1 files changed, 35 insertions, 1 deletions
diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc
index da49505a..38755388 100644
--- a/libqpdf/QPDFFormFieldObjectHelper.cc
+++ b/libqpdf/QPDFFormFieldObjectHelper.cc
@@ -715,17 +715,23 @@ class TfFinder: public QPDFObjectHandle::TokenFilter
virtual void handleToken(QPDFTokenizer::Token const&);
double getTf();
std::string getFontName();
+ std::string getDA();
private:
double tf;
+ size_t tf_idx;
std::string font_name;
double last_num;
+ size_t last_num_idx;
std::string last_name;
+ std::vector<std::string> DA;
};
TfFinder::TfFinder() :
tf(11.0),
- last_num(0.0)
+ tf_idx(0),
+ last_num(0.0),
+ last_num_idx(0)
{
}
@@ -734,11 +740,13 @@ TfFinder::handleToken(QPDFTokenizer::Token const& token)
{
QPDFTokenizer::token_type_e ttype = token.getType();
std::string value = token.getValue();
+ DA.push_back(token.getRawValue());
switch (ttype)
{
case QPDFTokenizer::tt_integer:
case QPDFTokenizer::tt_real:
last_num = strtod(value.c_str(), 0);
+ last_num_idx = DA.size() - 1;
break;
case QPDFTokenizer::tt_name:
@@ -754,6 +762,7 @@ TfFinder::handleToken(QPDFTokenizer::Token const& token)
// insane things or suffering from over/underflow
tf = last_num;
}
+ tf_idx = last_num_idx;
font_name = last_name;
break;
@@ -769,6 +778,30 @@ TfFinder::getTf()
}
std::string
+TfFinder::getDA()
+{
+ std::string result;
+ size_t n = this->DA.size();
+ for (size_t i = 0; i < n; ++i)
+ {
+ std::string cur = this->DA.at(i);
+ if (i == tf_idx)
+ {
+ double delta = strtod(cur.c_str(), 0) - this->tf;
+ if ((delta > 0.001) || (delta < -0.001))
+ {
+ // tf doesn't match the font size passed to Tf, so
+ // substitute.
+ QTC::TC("qpdf", "QPDFFormFieldObjectHelper fallback Tf");
+ cur = QUtil::double_to_string(tf);
+ }
+ }
+ result += cur;
+ }
+ return result;
+}
+
+std::string
TfFinder::getFontName()
{
return this->font_name;
@@ -843,6 +876,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(
tok.write(QUtil::unsigned_char_pointer(DA.c_str()), DA.length());
tok.finish();
double tf = tff.getTf();
+ DA = tff.getDA();
std::string (*encoder)(std::string const&, char) = &QUtil::utf8_to_ascii;
std::string font_name = tff.getFontName();