void AnnotWriter::UpdateBePDFAcroForm() { if (mWrittenFonts.empty()) return; Object acroForm; Object oldDR; acroForm.initDict(mXRef); oldDR.initNull(); if (is_empty_ref(mBePDFAcroForm->GetRef())) { Ref fieldsRef = mXRefTable.GetNewRef(xrefEntryUncompressed); // create empty array for fields Object fields; fields.initArray(mXRef); WriteObject(fieldsRef, &fields); fields.free(); // create new BePDFAcroForm mBePDFAcroFormRef = mXRefTable.GetNewRef(xrefEntryUncompressed); AddName(&acroForm, "Type", "BePDFAcroForm"); AddRef(&acroForm, "Fields", fieldsRef); } else { // copy existing BePDFAcroForm except DR mBePDFAcroFormRef = mBePDFAcroForm->GetRef(); Object ref; Object oldForm; ref.initRef(mBePDFAcroFormRef.num, mBePDFAcroFormRef.gen); ref.fetch(mXRef, &oldForm); CopyDict(&oldForm, &acroForm, acroFormExcludeKeys); oldForm.dictLookup("DR", &oldDR); oldForm.free(); ref.free(); } // Add DR to BePDFAcroForm Object dr; dr.initDict(mXRef); if (oldDR.isDict()) { CopyDict(&oldDR, &dr, drExcludeKeys); oldDR.free(); } // Add font dict Object font; font.initDict(mXRef); // add old fonts AddFonts(&font, mBePDFAcroForm->GetFonts()); // add new fonts AddFonts(&font, &mWrittenFonts); AddDict(&dr, "Font", &font); AddDict(&acroForm, "DR", &dr); WriteObject(mBePDFAcroFormRef, &acroForm); acroForm.free(); }
void AnnotWriter::DoAnnotation(Annotation* a) { AddRect(&mAnnot, "Rect", a->GetRect()); if (a->HasColor()) { AddColor(&mAnnot, "C", a->GetColor()); } if (a->GetDate()[0] != 0) { AddString(&mAnnot, "M", (char*)a->GetDate()); } AddInteger(&mAnnot, "F", a->GetFlags()->Flags()); if (a->GetTitle() != NULL) { AddString(&mAnnot, "T", a->GetTitle()); } if (a->GetOpacity() != 1.0) { AddReal(&mAnnot, "CA", a->GetOpacity()); } PopupAnnot* popup = a->GetPopup(); if (popup != NULL) { popup->SetParentRef(a->GetRef()); if (is_empty_ref(popup->GetRef())) { popup->SetRef(mXRefTable.GetNewRef(xrefEntryUncompressed)); } AddRef(&mAnnot, "Popup", popup->GetRef()); } if (HasAppearanceStream(a)) { mASRef = mXRefTable.GetNewRef(xrefEntryUncompressed); Object ap; ap.initDict(mXRef); AddRef(&ap, "N", mASRef); AddDict(&mAnnot, "AP", &ap); } if (dynamic_cast<PopupAnnot*>(a) == NULL) { AddRef(&mAnnot, "P", mPageRef); } }
void AnnotWriter::DoStyledAnnot(StyledAnnot* s) { AddAnnotContents(s); // border style char* style = NULL; Object bs; bs.initDict(mXRef); AddName(&bs, "Type", "Border"); AddInteger(&bs, "W", (float)s->GetBorderStyle()->GetWidth()); // width switch (s->GetBorderStyle()->GetStyle()) { case BorderStyle::solid_style: style = "S"; case BorderStyle::dashed_style: style = "D"; case BorderStyle::beveled_style: style = "B"; case BorderStyle::inset_style: style = "I"; case BorderStyle::underline_style: style = "U"; } if (style != NULL) { AddName(&bs, "S", style); // border style } AddDict(&mAnnot, "BS", &bs); }
//--------// main() function //---------------------------------------------// int main(int argc, char* argv[]){ /* general variables */ int retrieve_buffer = 0; unsigned char data; /* retrieve data from stdin */ int byte_counter = 0; /* counts bytes received from stdin */ unsigned int index_counter = 0; /* counts factors created */ node_t trie = RootNode(); node_t *parent_node = ≜ node_t *temp_node = ≜ dict_t dict = EmptyDict(); dict_t *dict_ptr = &dict; unsigned char* output; size_t t_memblock = 0; /* last-factor variables */ unsigned char data_buffer; /* retains data when EOF is reached */ int is_added = FALSE; /* indicates if data_buffer is added */ while((retrieve_buffer = fgetc(stdin)) != EOF){ //fprintf(stderr, "%02x ", retrieve_buffer); data = (unsigned char) retrieve_buffer; byte_counter++; /* update current parent_node */ parent_node = temp_node; /* if data is a member of current parent_node: * set the node that representing data as next parent_node */ if((temp_node = SearchNode(parent_node, data)) != NULL){ /* set data to data_buffer */ is_added = FALSE; data_buffer = data; continue; } /* if data is not a member of current parent_node: * create a child node to represent data, * and create the associated dictionary element */ index_counter++; temp_node = AddNode(parent_node, data, index_counter); dict_ptr = AddDict(dict_ptr, temp_node, parent_node->index); is_added = TRUE; /* reset parent_node */ temp_node = ≜ } /* create factor for data_buffer if required */ if(is_added == FALSE){ /* temp_node is NULL if data_buffer is not member of parent_node, * indicating parent_node needs to be reset */ if(temp_node == NULL){ parent_node = ≜ } index_counter++; temp_node = AddNode(parent_node, data_buffer, index_counter); dict_ptr = AddDict(dict_ptr, temp_node, parent_node->index); } /* skip the first element of the dictionary */ output = PrintDict(dict.next, index_counter); t_memblock = (index_counter * 4) + WIDTH_HEADER + 1; fwrite(output, sizeof(char), t_memblock, stdout); #if DEBUG { char temp_char; int k = 0; while(k < t_memblock){ temp_char = output[k]; fprintf(stderr, "output = %02x\n", temp_char); k++; } } #endif #if SUMMARY { /* SUMMARY INFO */ fprintf(stderr, "encode: %6d bytes input\n", byte_counter); fprintf(stderr, "encode: %6d factors generated\n", index_counter); fprintf(stderr, "encode: %6zu bytes output\n", t_memblock); } #endif free(output); output = NULL; return 0; }