[PATCH] Adds addIndirectObject method to XRef. This method allow the creation of new indirect objects.
Julien Rebetez
julien at fhtagn.net
Wed Oct 24 09:23:52 PDT 2007
Modify the writeToFile method of XRef so it uses OutStream instead of a C file descriptor.
---
poppler/XRef.cc | 45 ++++++++++++++++++++++++++++++++++++++++-----
poppler/XRef.h | 3 ++-
2 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index b84e198..8561712 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -1023,14 +1023,49 @@ void XRef::setModifiedObject (Object* o, Ref r) {
o->copy(&entries[r.num].obj);
}
+Ref XRef::addIndirectObject (Object* o) {
+ //Found the next free entry
+ int lastEntry = 0;
+ int newEntry;
+
+ do {
+ newEntry = entries[lastEntry].offset;
+ //we shouldn't reuse entry with a gen number of 65535
+ } while (entries[newEntry].gen == 65535 &&
+ (lastEntry = newEntry));
+
+ //the linked list of free entry is empty => create a new one
+ if (newEntry == 0) {
+ newEntry = size;
+ size++;
+ entries = (XRefEntry *)greallocn(entries, size, sizeof(XRefEntry));
+ entries[newEntry].gen = 0;
+ entries[newEntry].num = newEntry;
+ } else { //reuse a free entry
+ //restore the free entry linked list
+ entries[lastEntry].offset = entries[newEntry].offset;
+ entries[newEntry].num = newEntry;
+ //Don't touch gen number, it should have been incremented when the object was deleted
+ }
+
+ entries[newEntry].type = xrefEntryUncompressed;
+ o->copy(&entries[newEntry].obj);
+
+ Ref r;
+ r.num = entries[newEntry].num;
+ r.gen = entries[newEntry].gen;
+ return r;
+}
+
//used to sort the entries
int compare (const void* a, const void* b)
{
return (((XRefEntry*)a)->num - ((XRefEntry*)b)->num);
}
-void XRef::writeToFile(FILE* file) {
+void XRef::writeToFile(OutStream* outStr) {
qsort(entries, size, sizeof(XRefEntry), compare);
+
//create free entries linked-list
if (entries[0].gen != 65535) {
error(-1, "XRef::writeToFile, entry 0 of the XRef is invalid (gen != 65535)\n");
@@ -1044,16 +1079,16 @@ void XRef::writeToFile(FILE* file) {
}
//write the new xref
int j;
- fprintf(file,"xref\r\n");
+ outStr->printf("xref\r\n");
for (int i=0; i<size; i++) {
- for(j=i; j<size; j++) { //look for consecutive entry
+ for(j=i; j<size; j++) { //look for consecutive entries
if (j!=i && entries[j].num != entries[j-1].num+1)
break;
}
- fprintf(file,"%i %i\r\n", entries[i].num, j-i);
+ outStr->printf("%i %i\r\n", entries[i].num, j-i);
for (int k=i; k<j; k++) {
if(entries[k].gen > 65535) entries[k].gen = 65535; //cap generation number to 65535 (required by PDFReference)
- fprintf(file,"%010i %05i %c\r\n", entries[k].offset, entries[k].gen, (entries[k].type==xrefEntryFree)?'f':'n');
+ outStr->printf("%010i %05i %c\r\n", entries[k].offset, entries[k].gen, (entries[k].type==xrefEntryFree)?'f':'n');
}
i = j-1;
}
diff --git a/poppler/XRef.h b/poppler/XRef.h
index 05699c4..d5a395b 100644
--- a/poppler/XRef.h
+++ b/poppler/XRef.h
@@ -109,8 +109,9 @@ public:
// Write access
void setModifiedObject(Object* o, Ref r);
+ Ref addIndirectObject (Object* o);
void add(int num, int gen, Guint offs, GBool used);
- void writeToFile(FILE* f);
+ void writeToFile(OutStream* outStr);
private:
--
1.5.2.5
--------------030500050101040903030608
Content-Type: text/x-patch;
name="0002-Make-the-md5-method-of-Decrypt-public-so-it-can-be-u.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename*0="0002-Make-the-md5-method-of-Decrypt-public-so-it-can-be-u.pa";
filename*1="tch"
More information about the poppler
mailing list