Pajdeg  0.2.2
Pajdeg
Files | Data Structures | Macros | Typedefs | Enumerations | Functions
PDXTable

PDF XRef (cross reference) table. More...

Files

file  PDXTable.h
 

Data Structures

struct  PDXTable
 

Macros

#define PDXTableGetTypeForID(table, id)   (PDXType)((table->xrefs)[id*table->width])
 
#define PDXTableSetTypeForID(table, id, t)   *(PDXType*)&((table->xrefs)[id*table->width]) = t
 
#define PDXTableIsIDFree(xtable, id)   (PDXTypeFreed == PDXTableGetTypeForID(xtable, id))
 

Typedefs

typedef unsigned char PDXType
 The type representation of an XREF entry.
 

Enumerations

enum  PDXFormat { PDXTableFormatText = 0, PDXTableFormatBinary = 1 }
 
enum  { PDXTypeFreed = 0, PDXTypeUsed = 1, PDXTypeComp = 2 }
 

Functions

PDOffset PDXTableGetOffsetForID (PDXTableRef table, PDInteger obid)
 
void PDXTableSetOffsetForID (PDXTableRef table, PDInteger obid, PDOffset offset)
 
PDInteger PDXTableGetGenForID (PDXTableRef table, PDInteger obid)
 
void PDXTableSetGenForID (PDXTableRef table, PDInteger obid, PDInteger gen)
 
PDBool PDXTableFetchXRefs (PDParserRef parser)
 
PDBool PDXTablePassoverXRefEntry (PDParserRef parser, pd_stack stack, PDBool includeTrailer)
 
PDBool PDXTableInsert (PDParserRef parser)
 
PDArrayRef PDXTableWEntry (PDXTableRef table)
 
void PDXTableSetSizes (PDXTableRef table, unsigned char typeSize, unsigned char offsSize, unsigned char genSize)
 
void PDXTableGrow (PDXTableRef table, PDSize cap)
 
PDSize PDXTableDetermineObjectSize (PDXTableRef table, PDInteger obid)
 

Parser

typedef struct PDXTablePDXTableRef
 

Detailed Description

PDF XRef (cross reference) table.


Data Structure Documentation

struct PDXTable

PDF XRef (cross reference) table

Data Fields

PDInteger allocx
 
PDInteger obid
 object containing this XRef, if binary (text XRefs are not proper objects)
 
char * xrefs
 XRef entries stored as a chunk of memory.
 
PDXFormat format
 Original format of this entry, which can be text (PDF 1.4-) or binary (PDF 1.5+). Internally, there is no difference to how the data is maintained, but Pajdeg will use the same format used in the original in its own output.
 
PDBool linearized
 If set, unexpected XREF entries in the PDF are silently ignored by the parser.
 
PDSize cap
 Capacity of the table's xrefs buffer, in entries.
 
PDSize count
 Number of objects held by the XRef.
 
PDSize pos
 Byte-wise position in the PDF where the XRef (and subsequent trailer, if text format) begins; reaching this point means the XRef ceases to apply.
 
PDXTableRef prev
 previous (older) table (mostly debug related)
 
PDXTableRef next
 next (newer) table (mostly debug related)
 
PDOffset offsCap
 threshold for offsets using current offsSize
 
PDArrayRef w
 The W entry, if set.
 
PDIntegernextOb
 Array of object id's succeeding the object for the given array index. I.e. if the file has 4 0 obj ... endobj 10 0 obj ... endobj, then next[4] == 10 because object 10 is directly below object 4. This array is NULL until the first call to PDXTableDetermineObjectSize is made.
 
unsigned char typeSize
 type size, current implementation requires this to be 1
 
unsigned char offsSize
 offset size
 
unsigned char genSize
 gen ID size
 
unsigned char typeAlign
 type align
 
unsigned char offsAlign
 offset align
 
unsigned char genAlign
 gen ID align
 
unsigned char width
 width of table entry
 

Macro Definition Documentation

#define PDXTableGetTypeForID (   table,
  id 
)    (PDXType)((table->xrefs)[id*table->width])

Get the type for the given object.

Parameters
xrefsThe XREF buffer
idThe object ID.
#define PDXTableIsIDFree (   xtable,
  id 
)    (PDXTypeFreed == PDXTableGetTypeForID(xtable, id))

Get the type for the given object in the table.

Parameters
xtableThe PDXTableRef instance
idThe object ID. Set the type for the given object in the table.
xtableThe PDXTableRef instance
idThe object ID.
tThe new type. Get the offset for the given object in the table.
xtableThe PDXTableRef instance
idThe object ID. Get the generation number or object stream index for the given object in the table.
xtableThe PDXTableRef instance
idThe object ID. Determine if the object with given ID is free.
xtableThe PDXTableRef instance
idThe object ID.
#define PDXTableSetTypeForID (   table,
  id,
 
)    *(PDXType*)&((table->xrefs)[id*table->width]) = t

Set the type for the given object.

Parameters
xrefsThe XREF buffer
idThe object ID.
tThe new type.

Typedef Documentation

typedef struct PDXTable* PDXTableRef

Enumeration Type Documentation

anonymous enum

An XREF entry's type, which is one of freed (unused), used, or compressed.

Compressed objects are located inside of an object stream.

Enumerator
PDXTypeFreed 

Freed object ('f' for text format entries)

PDXTypeUsed 

Used object ('n' for text format entries)

PDXTypeComp 

Compressed object (no text format equivalent)

enum PDXFormat

The XREF format, which can be one of text or binary.

Text XREFs have the appearance

1 xref 3 0
2 000000029 00000 n
3 000000142 00000 n
4 000013023 65535 f

while binary XREFs are binary values stored in an object with /Type /XRefStm.

Enumerator
PDXTableFormatText 

PDF-1.4 and below, using 20-byte leading zero space delimited entries.

PDXTableFormatBinary 

PDX-1.5 and forward, using variable width object stream format.

Function Documentation

PDSize PDXTableDetermineObjectSize ( PDXTableRef  table,
PDInteger  obid 
)

Determine the number of bytes between the first character in "<num> <num> obj" of the given object until the first character in the "<num> <num> obj" of the succeeding object in the file.

Parameters
tablePDX table
obidObject whose size should be determined
Returns
Size of object in bytes
PDBool PDXTableFetchXRefs ( PDParserRef  parser)

Set the offset for the object with the given ID to the given offset in the XREF table.

Parameters
xtableThe PDX table instance.
idThe object ID.
offsThe new offset. Read a PDFs XREF data by jumping to the end of the file, reading in the startxref value and jumping to every XREF defined via e.g. /Prev, reading the XREFs in as a series with defined domains (by byte).
Note
The master XREF (the one pointed to by the startxref offset) defines whether the output PDF uses text or binary format, regardless of what other entries happen to be formatted as.

Takes into account linearized PDFs.

Parameters
parserThe parser.
PDInteger PDXTableGetGenForID ( PDXTableRef  table,
PDInteger  obid 
)

Get the generation number or object stream index for the given object.

Parameters
xrefsThe XREF buffer
idThe object ID.
PDOffset PDXTableGetOffsetForID ( PDXTableRef  table,
PDInteger  obid 
)

Get the offset for the object with the given ID in the XREF table.

Parameters
tableThe PDXTable instance.
obidThe object ID.
void PDXTableGrow ( PDXTableRef  table,
PDSize  cap 
)

Grow the xref table to accomodate the given cap.

PDBool PDXTableInsert ( PDParserRef  parser)

Insert the one and only XREF table.

Note
Pajdeg does not support multiple XREF tables in a single PDF. The only downside to this is that linearized PDFs are delinearized in Pajdeg. Support for linearized PDFs is planned.
Parameters
parserThe parser.
Returns
true if the insertion was successful.
PDBool PDXTablePassoverXRefEntry ( PDParserRef  parser,
pd_stack  stack,
PDBool  includeTrailer 
)

Pass over an XREF entry in the input PDF.

Note
This is only called for text formatted XREF tables; binary XREF tables appear as regular objects with streams
Parameters
parserThe parser.
stackThe XREF header stack scanned in from the PDScanner.
includeTrailerWhether the trailer should also be consumed, or whether scanning should end after the XREF offsets.
void PDXTableSetGenForID ( PDXTableRef  table,
PDInteger  obid,
PDInteger  gen 
)

Debug Set the generation number / object stream index for the given object.

Parameters
xrefsThe XREF buffer
idThe object ID.
genThe new value.
void PDXTableSetOffsetForID ( PDXTableRef  table,
PDInteger  obid,
PDOffset  offset 
)

Set the offset for the object with the given ID to the given offset in the XREF table.

Parameters
tableThe PDXTable instance.
obidThe object ID.
offsetThe new offset.
void PDXTableSetSizes ( PDXTableRef  table,
unsigned char  typeSize,
unsigned char  offsSize,
unsigned char  genSize 
)

Set the type, offset, and gen sizes for the table.

PDArrayRef PDXTableWEntry ( PDXTableRef  table)

Get the W entry for the table.