#include <pdfwriter.h>
Public Member Functions | |
| OldStylePdfWriter () | |
| virtual void | writeContent (const ObjectList &objectList, StreamWriter &stream, size_t off=0) |
| virtual size_t | writeTrailer (const Object &trailer, const PrevSecInfo &prevSection, StreamWriter &stream, size_t off=0) |
| virtual void | reset () |
Static Public Attributes | |
| static const std::string | CONTENT = "Content phase" |
| static const std::string | TRAILER = "XREF/TRAILER phase" |
Private Types | |
| typedef std::map< const ::Ref, size_t, xpdf::RefComparator > | OffsetTab |
Private Attributes | |
| OffsetTab | offTable |
| int | maxObjNum |
Implementator of old style cross reference table pdf writer.
Writes content with old style cross reference table and trailer.
typedef std::map<const ::Ref, size_t, xpdf::RefComparator> pdfobjects::utils::OldStylePdfWriter::OffsetTab [private] |
Type for offset table. Mapping from reference to file offset of indirect object.
| pdfobjects::utils::OldStylePdfWriter::OldStylePdfWriter | ( | ) | [inline] |
Initialize constructor.
Initializes CONTENT and TRAILER fields to default values.
| void pdfobjects::utils::OldStylePdfWriter::reset | ( | ) | [virtual] |
Resets all collected data.
Clears offTable field and so this instance can be used for another revision.
Implements pdfobjects::utils::IPdfWriter.
References maxObjNum, and offTable.
Referenced by writeTrailer().
| void pdfobjects::utils::OldStylePdfWriter::writeContent | ( | const ObjectList & | objectList, | |
| StreamWriter & | stream, | |||
| size_t | off = 0 | |||
| ) | [virtual] |
Writes given objects.
| objectList | List of objects to write. | |
| stream | Stream writer where to write. | |
| off | Stream offset where to start writing (if 0, uses current position). |
Sets new position in the stream, if off parameter is non 0 and iterate through all objects from given list and writes each to the stream (uses helper writeIndirectObject function) and stores stream offset to the offTable mapping.
Notifies all observers immediately after object has been written to the stream. newValue parameter is number of written objects until now and context (typed as ChangeContext with OperationScope typed scope) contains total number of objects which should be written by this call. Context task field contains CONTENT string.
Implements pdfobjects::utils::IPdfWriter.
References CONTENT, debug::DBG_DBG, debug::DBG_WARN, maxObjNum, observer::ObserverHandler< OperationStep >::notifyObservers(), offTable, utilsPrintDbg, and pdfobjects::utils::writeObject().
| size_t pdfobjects::utils::OldStylePdfWriter::writeTrailer | ( | const Object & | trailer, | |
| const PrevSecInfo & | prevSection, | |||
| StreamWriter & | stream, | |||
| size_t | off = 0 | |||
| ) | [virtual] |
Writes cross reference table and trailer.
| trailer | Trailer object. | |
| prevSection | Context for previous section. | |
| off | Stream offset where to start writing (if 0, uses current position). | |
| stream | Stream writer where to write. |
Constructs (old style) cross reference table from internal reference to file offset mapping to the given stream according PDF specification.
In first step offTable is used for cross reference table builing. When cross reference table is ready, xref keyword is written to the stream followed by built cross reference table. Then checks given prevSection (context for previous section) structures and if xrefPos is not zero, sets Prev trailer field to given value. Finally calculates trailer's Size field as result of
Size = max { prevSection.objNum, (maxObjNum + 1)}
When all trailer information is ready, writes its dictionary to the stream followed by lastxref key word with position of this cross reference section start (file offset of xref key word). EOFMARKER is written immediately after.
PDF specification notes:
Old style cross reference section is set of cross reference subsections. Each subsection is preceeded by object number and size values. This is followed by size number of lines. Each line represents object with (number+line#-1) object number. Line format is as follows:
nnnnnnnnnn ggggg n \n
where n* stands for file offset of object (padded by leading 0) g* is generation number (padded by leading 0) n is literal keyword identifying in-use object
One subsection represents continuous sequence of indirect object numbers.
Cross reference subsections should also mark deleted objects, those which are not accessible anymore and so can be reused with higher generation number. This implementation doesn't write such entries.
Notifies observers immediately after one subsection is written. newValue parameter contains number of already written subsections and context (same asin writeContent method) contains total number of subsections and task field contains TRAILER string.
Implements pdfobjects::utils::IPdfWriter.
References debug::DBG_DBG, debug::DBG_WARN, pdfobjects::utils::IPdfWriter::PrevSecInfo::entriesNum, EOFMARKER, xpdf::freeXpdfObject(), kernelPrintDbg, _JM_NAMESPACE::max(), maxObjNum, observer::ObserverHandler< OperationStep >::notifyObservers(), offTable, StreamWriter::putLine(), reset(), STARTXREF_KEYWORD, pdfobjects::utils::stripXRefStreamFields(), TRAILER, TRAILER_KEYWORD, StreamWriter::trim(), utilsPrintDbg, pdfobjects::utils::writeObject(), XREF_KEYWORD, XREFFILLING, pdfobjects::utils::IPdfWriter::PrevSecInfo::xrefPos, and XREFROWLENGHT.
const std::string pdfobjects::utils::OldStylePdfWriter::CONTENT = "Content phase" [static] |
String for context task in writeContent. This value is used in ScopedChangeContext's task field in writeContent method. User of the instance can change this value directly.
Referenced by writeContent().
int pdfobjects::utils::OldStylePdfWriter::maxObjNum [private] |
Maximum object number written.
This value is set in writeContent method, used in writeTrailer and cleared by reset.
Motivation:
Each trailer contains Size field which contains total number of objects in document. This implies that also objects from previous sections are involved. Total count can't be determined from written objects, because we don't have any kind of guarantee, that all objects or even new objects were written.
This implementation handles this situation following way:
writeContent sets this field as maximum object number ever written from last reset (so for current section) and writeTrailer consumes parameter with previous trailer Size value. Result size is max{given, maxObjNum+1}. This is perfectly clean according PDF specification (see 3.4.4 Trailer chapter for more information).
Referenced by reset(), writeContent(), and writeTrailer().
Offset table.
Keeps mapping from objects referencies to their position in the stream (where they were written).
Referenced by reset(), writeContent(), and writeTrailer().
const std::string pdfobjects::utils::OldStylePdfWriter::TRAILER = "XREF/TRAILER phase" [static] |
String for context task in writeTrailer. This value is used in ScopedChangeContext's task field in writeTrailer method. User of the instance can change this value directly.
Referenced by writeTrailer().