Pajdeg  0.2.2
Pajdeg
PDXTable.h
Go to the documentation of this file.
1 //
2 // PDXTable.h
3 //
4 // Copyright (c) 2012 - 2015 Karl-Johan Alm (http://github.com/kallewoof)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 //
24 
40 #ifndef INCLUDED_PDXTable_h
41 #define INCLUDED_PDXTable_h
42 
43 #include <sys/types.h>
44 #include "PDDefines.h"
45 
58 typedef enum {
61 } PDXFormat;
62 
68 enum {
72 };
73 
74 typedef unsigned char PDXType;
75 //typedef u_int32_t PDXOffsetType; ///< The offset representation of an XREF entry.
76 //typedef unsigned char PDXGenType; ///< The generation / index representation of an XREF entry.
77 
78 //#define PDXTypeSize 1 ///< The size of the XREF type. Note: this must not be changed
79 //#define PDXOffsSize 4 ///< The size of the offset type. Note: changing this requires updating PDXGet/SetOffsetForID
80 //#define PDXGenSize 1 ///< The generation number / object index type size. Note: this must not be changed
81 
82 //#define PDXTypeAlign 0 ///< The alignment of the XREF type inside its XREF field
83 //#define PDXOffsAlign PDXTypeSize ///< The alignment of the offset type inside its XREF field
84 //#define PDXGenAlign (PDXOffsAlign + PDXOffsSize) ///< The alignment of the generation number inside its XREF field
85 //#define PDXWidth (PDXGenAlign + PDXGenSize) ///< The width of an XREF field
86 
87 // Why can't I make this use the quoted value of the #defines above...?
88 //#define PDXWEntry "[ 1 4 1 ]" ///< The PDF array expression for the sizes above (a [ followed by a the numbers in order followed by a ])
89 
93 struct PDXTable {
94  PDInteger allocx;
96  char *xrefs;
97 
103 
106 
108 
111 
112  unsigned char typeSize;
113  unsigned char offsSize;
114  unsigned char genSize;
115  unsigned char typeAlign;
116  unsigned char offsAlign;
117  unsigned char genAlign;
118  unsigned char width;
119 };
120 
128 
136 extern void PDXTableSetOffsetForID(PDXTableRef table, PDInteger obid, PDOffset offset);
137 
144 #define PDXTableGetTypeForID(table, id) (PDXType)((table->xrefs)[id*table->width])
145 //extern PDInteger PDXTableGetTypeForID(PDXTableRef table, PDInteger obid);
146 
154 #define PDXTableSetTypeForID(table, id, t) *(PDXType*)&((table->xrefs)[id*table->width]) = t
155 //extern void PDXTableSetTypeForID(PDXTableRef table, PDInteger obid, PDInteger type);
156 
164 //#define PDXGetGenForID(xrefs, id) (PDXGenType)((xrefs)[PDXGenAlign+id*PDXWidth])
165 
169 //static inline PDXGenType _PDXGetGenForID(char *xrefs, PDInteger obid)
170 //{
171 // return (PDXGenType)((xrefs)[PDXGenAlign+obid*PDXWidth]);
172 //}
173 
181 extern void PDXTableSetGenForID(PDXTableRef table, PDInteger obid, PDInteger gen);
182 //#define PDXSetGenForID(xrefs, id, gen) *(PDXGenType*)&((xrefs)[PDXGenAlign+id*PDXWidth]) = gen
183 
185 // Get the type for the given object in the table.
186 //
187 // @param xtable The PDXTableRef instance
188 // @param id The object ID.
189 // */
190 //#define PDXTableGetTypeForID(xtable, id) PDXGetTypeForID(xtable->xrefs, id)
191 //
193 // Set the type for the given object in the table.
194 //
195 // @param xtable The PDXTableRef instance
196 // @param id The object ID.
197 // @param t The new type.
198 // */
199 //#define PDXTableSetTypeForID(xtable, id, t) PDXSetTypeForID(xtable->xrefs, id, t)
200 //
202 // Get the offset for the given object in the table.
203 //
204 // @param xtable The PDXTableRef instance
205 // @param id The object ID.
206 // */
207 //#define PDXTableGetOffsetForID(xtable, id) PDXGetOffsetForID(xtable->xrefs, id)
208 //
210 // Get the generation number or object stream index for the given object in the table.
211 //
212 // @param xtable The PDXTableRef instance
213 // @param id The object ID.
214 // */
215 //#define PDXTableGetGenForID(xtable, id) PDXGetGenForID(xtable->xrefs, id)
216 
223 #define PDXTableIsIDFree(xtable, id) (PDXTypeFreed == PDXTableGetTypeForID(xtable, id))
224 
226 // Set the offset for the object with the given ID to the given offset in the XREF table.
227 //
228 // @param xtable The PDX table instance.
229 // @param id The object ID.
230 // @param offs The new offset.
231 // */
232 //#define PDXTableSetOffset(xtable, id, offs) PDXSetOffsetForID(xtable->xrefs, id, (PDXOffsetType)offs)
233 
244 extern PDBool PDXTableFetchXRefs(PDParserRef parser);
245 
255 extern PDBool PDXTablePassoverXRefEntry(PDParserRef parser, pd_stack stack, PDBool includeTrailer);
256 
265 extern PDBool PDXTableInsert(PDParserRef parser);
266 
271 
275 extern void PDXTableSetSizes(PDXTableRef table, unsigned char typeSize, unsigned char offsSize, unsigned char genSize);
276 
280 extern void PDXTableGrow(PDXTableRef table, PDSize cap);
281 
291 
292 #endif
293 
PDOffset offsCap
threshold for offsets using current offsSize
Definition: PDXTable.h:107
unsigned char offsSize
offset size
Definition: PDXTable.h:113
Compressed object (no text format equivalent)
Definition: PDXTable.h:71
Freed object ('f' for text format entries)
Definition: PDXTable.h:69
PDXFormat
Definition: PDXTable.h:58
long PDInteger
Definition: PDDefines.h:184
PDF-1.4 and below, using 20-byte leading zero space delimited entries.
Definition: PDXTable.h:59
long long PDOffset
Definition: PDDefines.h:223
unsigned char PDBool
Definition: PDDefines.h:207
void PDXTableSetGenForID(PDXTableRef table, PDInteger obid, PDInteger gen)
Definition: PDXTable.c:156
unsigned char typeSize
type size, current implementation requires this to be 1
Definition: PDXTable.h:112
PDBool linearized
If set, unexpected XREF entries in the PDF are silently ignored by the parser.
Definition: PDXTable.h:99
PDInteger * nextOb
Array of object id's succeeding the object for the given array index. I.e. if the file has 4 0 obj ...
Definition: PDXTable.h:110
void PDXTableGrow(PDXTableRef table, PDSize cap)
Definition: PDXTable.c:1203
PDBool PDXTableFetchXRefs(PDParserRef parser)
Definition: PDXTable.c:1070
unsigned char typeAlign
type align
Definition: PDXTable.h:115
unsigned char PDXType
The type representation of an XREF entry.
Definition: PDXTable.h:74
void PDXTableSetSizes(PDXTableRef table, unsigned char typeSize, unsigned char offsSize, unsigned char genSize)
Definition: PDXTable.c:1163
void PDXTableSetOffsetForID(PDXTableRef table, PDInteger obid, PDOffset offset)
Definition: PDXTable.c:111
PDSize pos
Byte-wise position in the PDF where the XRef (and subsequent trailer, if text format) begins; reachin...
Definition: PDXTable.h:102
PDBool PDXTableInsert(PDParserRef parser)
Definition: PDXTable.c:336
PDArrayRef w
The W entry, if set.
Definition: PDXTable.h:109
Definition: PDXTable.h:93
Used object ('n' for text format entries)
Definition: PDXTable.h:70
unsigned char genAlign
gen ID align
Definition: PDXTable.h:117
PDX-1.5 and forward, using variable width object stream format.
Definition: PDXTable.h:60
unsigned char width
width of table entry
Definition: PDXTable.h:118
size_t PDSize
Definition: PDDefines.h:213
PDSize PDXTableDetermineObjectSize(PDXTableRef table, PDInteger obid)
Definition: PDXTable.c:1257
PDXFormat format
Original format of this entry, which can be text (PDF 1.4-) or binary (PDF 1.5+). Internally...
Definition: PDXTable.h:98
unsigned char genSize
gen ID size
Definition: PDXTable.h:114
PDBool PDXTablePassoverXRefEntry(PDParserRef parser, pd_stack stack, PDBool includeTrailer)
Definition: PDXTable.c:347
PDArrayRef PDXTableWEntry(PDXTableRef table)
Definition: PDXTable.c:1151
Definition: pd_internal.h:544
Definition: pd_internal.h:611
Definition: pd_internal.h:408
Definitions for the Pajdeg interface.
PDOffset PDXTableGetOffsetForID(PDXTableRef table, PDInteger obid)
Definition: PDXTable.c:69
PDSize count
Number of objects held by the XRef.
Definition: PDXTable.h:101
PDInteger PDXTableGetGenForID(PDXTableRef table, PDInteger obid)
Definition: PDXTable.c:129
PDInteger obid
object containing this XRef, if binary (text XRefs are not proper objects)
Definition: PDXTable.h:95
PDSize cap
Capacity of the table's xrefs buffer, in entries.
Definition: PDXTable.h:100
char * xrefs
XRef entries stored as a chunk of memory.
Definition: PDXTable.h:96
PDXTableRef next
next (newer) table (mostly debug related)
Definition: PDXTable.h:105
PDXTableRef prev
previous (older) table (mostly debug related)
Definition: PDXTable.h:104
unsigned char offsAlign
offset align
Definition: PDXTable.h:116