Skip to content

Commit

Permalink
Merge pull request #39 from sensiblecodeio/render-form-fields
Browse files Browse the repository at this point in the history
Render filled form fields into Glyphs
  • Loading branch information
StevenMaude authored Jan 17, 2019
2 parents ea414b4 + 27ca8cd commit 0b1a861
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,17 @@ void dump_document_meta(const std::string filename, PDFDoc *doc,

void TextPageDecRef(TextPage *text_page) { text_page->decRefCnt(); }

void render_annotations(std::unique_ptr<Gfx> &gfx, Annots *annots) {
gfx->saveState();

for (auto i = 0; i < annots->getNumAnnots(); i++) {
auto *annot = annots->getAnnot(i);
annot->draw(gfx.get(), false);
}

gfx->restoreState();
}

typedef std::unique_ptr<TextPage, decltype(&TextPageDecRef)> TextPagePtr;

TextPagePtr page_to_text_page(Page *page) {
Expand All @@ -319,7 +330,14 @@ TextPagePtr page_to_text_page(Page *page) {
-1, -1, -1, -1, false, /* printing */
NULL, NULL));

gfx->saveState();
page->display(gfx.get());
gfx->restoreState();

// Note: page->getAnnots() contains form fields, so this has the effect of
// rendering form fields.
render_annotations(gfx, page->getAnnots());

dev->endPage();

return TextPagePtr(dev->takeText(), TextPageDecRef);
Expand Down

0 comments on commit 0b1a861

Please sign in to comment.