Commit cf0e34222bdd84e417880f7f70f6a173d005d526

Authored by m-holger
1 parent 361b387b

Refactor `FormNode::generateTextAppearance`: instead of attaching a stream filte…

…r replace the appearance stream content with the generated appearance.
libqpdf/QPDFFormFieldObjectHelper.cc
... ... @@ -2,6 +2,7 @@
2 2  
3 3 #include <qpdf/AcroForm.hh>
4 4  
  5 +#include <qpdf/Pipeline_private.hh>
5 6 #include <qpdf/Pl_QPDFTokenizer.hh>
6 7 #include <qpdf/QIntC.hh>
7 8 #include <qpdf/QPDFAcroFormDocumentHelper.hh>
... ... @@ -912,13 +913,6 @@ FormNode::generateTextAppearance(QPDFAnnotationObjectHelper&amp; aoh)
912 913 aoh.replace("/AP", Dictionary({{"/N", AS}}));
913 914 }
914 915 }
915   - if (!AS) {
916   - // This could only have happened if aoh.getAppearanceStream("/N") did not return a stream.
917   - // The only way creation of a new AS could have failed is if getOwningQPDF returned a
918   - // nullptr, but this would throw a runtime error in newStream. So this should be impossible
919   - aoh.warn("unable to get normal appearance stream for update");
920   - return;
921   - }
922 916  
923 917 if (AS.obj_sp().use_count() > 3) {
924 918 // The following check ensures that we only update the appearance stream if it is not
... ... @@ -988,6 +982,12 @@ FormNode::generateTextAppearance(QPDFAnnotationObjectHelper&amp; aoh)
988 982 for (size_t i = 0; i < opt.size(); ++i) {
989 983 opt.at(i) = (*encoder)(opt.at(i), '?');
990 984 }
991   - AS.addTokenFilter(
992   - std::shared_ptr<QPDFObjectHandle::TokenFilter>(new ValueSetter(DA, V, opt, tf, bbox)));
  985 +
  986 + std::string result;
  987 + pl::String pl(result);
  988 + ValueSetter vs(DA, V, opt, tf, bbox);
  989 + Pl_QPDFTokenizer vs_tok("", &vs, &pl);
  990 + vs_tok.writeString(AS.getStreamData(qpdf_dl_all));
  991 + vs_tok.finish();
  992 + AS.replaceStreamData(std::move(result), Null::temp(), Null::temp());
993 993 }
... ...