3
Copyright (c) 2006-2007, BBR Inc. All rights reserved.
5
Permission is hereby granted, free of charge, to any person obtaining
6
a copy of this software and associated documentation files (the
7
"Software"), to deal in the Software without restriction, including
8
without limitation the rights to use, copy, modify, merge, publish,
9
distribute, sublicense, and/or sell copies of the Software, and to
10
permit persons to whom the Software is furnished to do so, subject to
11
the following conditions:
13
The above copyright notice and this permission notice shall be included
14
in all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
pdftopdf cross reference
34
#include "P2PObject.h"
37
/* increment size for object table */
40
P2PObject **P2PXRef::objects = 0;
41
int P2PXRef::objectsSize = 0;
42
int P2PXRef::currentNum = 1;
44
void P2PXRef::put(P2PObject *obj)
48
obj->getNum(&num,&gen);
49
if (num > 0) return; /* already registered */
50
if (objectsSize == 0) {
51
/* first time, alloc table */
52
objects = new P2PObject *[INCSIZE];
53
objectsSize = INCSIZE;
54
memset(objects,0,objectsSize*sizeof(P2PObject *));
55
} else if (++currentNum >= objectsSize) {
57
P2PObject **oldp = objects;
58
objectsSize += INCSIZE;
59
objects = new P2PObject *[objectsSize];
60
memcpy(objects,oldp,(objectsSize-INCSIZE)*sizeof(P2PObject *));
63
obj->setNum(currentNum,0);
64
objects[currentNum] = obj;
67
void P2PXRef::put(P2PObject *obj, P2POutputStream *str)
73
void P2PXRef::remove(P2PObject *obj)
77
obj->getNum(&num,&gen);
83
void P2PXRef::flush(P2POutputStream *str, XRef *xref)
93
for (i = 1;i < n;i++) {
94
if (objects[i] != 0 && objects[i]->getOffset() < 0
95
&& !objects[i]->isSecondPhase()) {
96
objects[i]->output(str,xref);
105
for (i = 1;i < n;i++) {
106
if (objects[i] != 0 && objects[i]->getOffset() < 0) {
107
objects[i]->output(str,xref);
114
int P2PXRef::output(P2POutputStream *str)
116
int xrefOffset = str->getPosition();
118
int n = getNObjects();
121
str->printf("0 %d\n", n);
122
str->puts("0000000000 65535 f \n");
123
for (i = 1;i < n;i++) {
127
if (objects[i] == 0) {
129
/* this situation is error. */
131
str->puts("0000000000 00000 f \n");
132
p2pError(-1,const_cast<char *>("freed object:%d found\n"),i);
134
objects[i]->getNum(&num,&gen);
135
offset = objects[i]->getOffset();
138
/* not output yet. error */
139
p2pError(-1,const_cast<char *>("not output object:%d found\n"),i);
141
str->printf("%010d %05d n \n",offset,gen);
148
void P2PXRef::clean()
151
int n = getNObjects();
153
for (i = 1;i < n;i++) {
154
if (objects[i] != 0) {