Commit 9cb599875bbd1aaf1d2e91d44201ee0fcb79418f

Authored by Jay Berkenbilt
1 parent 930eade6

Improve text objects used in text appearance streams

libqpdf/QPDFFormFieldObjectHelper.cc
@@ -673,7 +673,6 @@ ValueSetter::writeAppearance() @@ -673,7 +673,6 @@ ValueSetter::writeAppearance()
673 // Write the lines centered vertically, highlighting if needed 673 // Write the lines centered vertically, highlighting if needed
674 size_t nlines = lines.size(); 674 size_t nlines = lines.size();
675 double dy = bbox.ury - ((bbox.ury - bbox.lly - (nlines * tfh)) / 2.0); 675 double dy = bbox.ury - ((bbox.ury - bbox.lly - (nlines * tfh)) / 2.0);
676 - write(DA + "\nq\n");  
677 if (highlight) 676 if (highlight)
678 { 677 {
679 write("q\n0.85 0.85 0.85 rg\n" + 678 write("q\n0.85 0.85 0.85 rg\n" +
@@ -684,17 +683,26 @@ ValueSetter::writeAppearance() @@ -684,17 +683,26 @@ ValueSetter::writeAppearance()
684 QUtil::double_to_string(tfh) + 683 QUtil::double_to_string(tfh) +
685 " re f\nQ\n"); 684 " re f\nQ\n");
686 } 685 }
687 - dy += 0.2 * tf; 686 + dy -= tf;
  687 + write("q\nBT\n" + DA + "\n");
688 for (size_t i = 0; i < nlines; ++i) 688 for (size_t i = 0; i < nlines; ++i)
689 { 689 {
690 - dy -= tfh;  
691 - write("BT\n" +  
692 - QUtil::int_to_string(bbox.llx + dx) + " " +  
693 - QUtil::double_to_string(bbox.lly + dy) + " Td\n" +  
694 - QPDFObjectHandle::newString(lines.at(i)).unparse() +  
695 - " Tj\nET\n"); 690 + // We could adjust Tm to translate to the beginning the first
  691 + // line, set TL to tfh, and use T* for each subsequent line,
  692 + // but doing this would require extracting any Tm from DA,
  693 + // which doesn't seem really worth the effort.
  694 + if (i == 0)
  695 + {
  696 + write(QUtil::int_to_string(bbox.llx + dx) + " " +
  697 + QUtil::double_to_string(bbox.lly + dy) + " Td\n");
  698 + }
  699 + else
  700 + {
  701 + write("0 " + QUtil::double_to_string(-tfh) + " Td\n");
  702 + }
  703 + write(QPDFObjectHandle::newString(lines.at(i)).unparse() + " Tj\n");
696 } 704 }
697 - write("Q\nEMC"); 705 + write("ET\nQ\nEMC");
698 } 706 }
699 707
700 class TfFinder: public QPDFObjectHandle::TokenFilter 708 class TfFinder: public QPDFObjectHandle::TokenFilter
qpdf/qtest/qpdf/appearances-1.pdf
No preview for this file type
qpdf/qtest/qpdf/appearances-11.pdf
No preview for this file type
qpdf/qtest/qpdf/appearances-12.pdf
No preview for this file type
qpdf/qtest/qpdf/appearances-2.pdf
No preview for this file type
qpdf/qtest/qpdf/appearances-a-more.pdf
No preview for this file type
qpdf/qtest/qpdf/appearances-a-more2.pdf
No preview for this file type
qpdf/qtest/qpdf/appearances-a.pdf
No preview for this file type
qpdf/qtest/qpdf/appearances-b.pdf
No preview for this file type
qpdf/qtest/qpdf/appearances-quack.pdf
No preview for this file type