~ubuntu-branches/ubuntu/raring/cups-filters/raring-proposed

« back to all changes in this revision

Viewing changes to filter/pdftopdf/P2PObject.h

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2012-08-20 14:53:42 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20120820145342-bddzpwqv0klmt84d
* New upstream release
   - pdftopdf filter replaced by new QPDF-based filter from Tobias
     Hoffmann's Google Summer of Code project. The former Poppler-based
     pdftopdf duplicated a lot of Poppler's code. The old filter is
     still in the package as pdftopdf.old with source code in
     filter/pdftopdf.old. It will be removed in a later release.
   - bannertopdf: Page duplication routine fixed.
   - bannertopdf: Fixed invalid output of a direct stream object.
   - Added most recent contributors to AUTHORS and COPYING files.
* debian/control: Added build dependency on libqpdf-dev.
* debian/copyright: Updated for the addition of the new pdftopdf filter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
Copyright (c) 2006-2007, BBR Inc.  All rights reserved.
4
 
 
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:
12
 
 
13
 
The above copyright notice and this permission notice shall be included
14
 
in all copies or substantial portions of the Software.
15
 
 
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.
23
 
 
24
 
*/
25
 
/*
26
 
 P2PObject.h
27
 
 pdftopdf object
28
 
*/
29
 
#ifndef _P2POBJECT_H_
30
 
#define _P2POBJECT_H_
31
 
 
32
 
#include "P2POutputStream.h"
33
 
#include "P2PXRef.h"
34
 
#include "Object.h"
35
 
#include "P2POutput.h"
36
 
#include "P2PError.h"
37
 
#include "XRef.h"
38
 
 
39
 
class P2PObject {
40
 
public:
41
 
  /* find object with original object number and generation */
42
 
  static P2PObject *find(int orgNumA, int orgGenA);
43
 
 
44
 
  P2PObject() {
45
 
    next = 0;
46
 
    offset = -1;
47
 
    orgNum = -1;
48
 
    orgGen = -1;
49
 
    num = -1;
50
 
    gen = -1;
51
 
    secondPhase = gFalse;
52
 
    put();
53
 
  }
54
 
  P2PObject(int orgNumA, int orgGenA) {
55
 
    next = 0;
56
 
    offset = -1;
57
 
    orgNum = orgNumA;
58
 
    orgGen = orgGenA;
59
 
    num = -1;
60
 
    gen = -1;
61
 
    secondPhase = gFalse;
62
 
    put();
63
 
  }
64
 
 
65
 
  virtual ~P2PObject() {
66
 
    remove();
67
 
    P2PXRef::remove(this);
68
 
  }
69
 
  void setOffset(int offsetA) {
70
 
    offset = offsetA;
71
 
  }
72
 
  void setOffset(P2POutputStream *str) {
73
 
    offset = str->getPosition();
74
 
  }
75
 
  int getOffset() { return offset; }
76
 
 
77
 
  void setNum(int numA, int genA) {
78
 
    num = numA;
79
 
    gen = genA;
80
 
  }
81
 
 
82
 
  void getNum(int *numA, int *genA) {
83
 
    *numA = num;
84
 
    *genA = gen;
85
 
  }
86
 
 
87
 
  /* output begin object */
88
 
  void outputBegin(P2POutputStream *str);
89
 
  /* output end object */
90
 
  void outputEnd(P2POutputStream *str);
91
 
  /* output reference */
92
 
  void outputRef(P2POutputStream *str);
93
 
 
94
 
  /* output as an object */
95
 
  virtual void output(P2POutputStream *str, XRef *xref) {
96
 
    p2pError(-1,const_cast<char *>("Illegal output call of P2PObject:%d"),num);
97
 
  }
98
 
 
99
 
  GBool isSecondPhase() { return secondPhase; }
100
 
  void setSecondPhase(GBool v) { secondPhase = v; }
101
 
 
102
 
private:
103
 
  /* original object number hash table */
104
 
  static P2PObject **orgTable;
105
 
  /* hash function */
106
 
  static int hash(int num, int gen);
107
 
 
108
 
  /* put this into original object number table */
109
 
  void put();
110
 
  /* remove this from original object number able */
111
 
  void remove();
112
 
 
113
 
  /* original object number */
114
 
  int orgNum;
115
 
  /* original object generation */
116
 
  int orgGen;
117
 
 
118
 
  /* object number */
119
 
  int num;
120
 
  /* object generation */
121
 
  int gen;
122
 
  /* offset in output file */
123
 
  /* when minus value, not output this yet. */
124
 
  int offset;
125
 
  /* next object pointer for list */
126
 
  P2PObject *next;
127
 
  /* flag indicating that should be output in second phase */
128
 
  GBool secondPhase;
129
 
};
130
 
 
131
 
class P2PObj : public P2PObject {
132
 
public:
133
 
  P2PObj() {}
134
 
  P2PObj(Object *objA, int orgNumA = -1, int orgGenA = -1) 
135
 
     : P2PObject(orgNumA, orgGenA) {
136
 
    objA->copy(&obj);
137
 
  }
138
 
 
139
 
  virtual ~P2PObj() {
140
 
    obj.free();
141
 
  }
142
 
 
143
 
  virtual void output(P2POutputStream *str, XRef *xref) {
144
 
    if (getOffset() < 0) {
145
 
      int num, gen;
146
 
 
147
 
      getNum(&num,&gen);
148
 
      if (num > 0) outputBegin(str);
149
 
      if (obj.isRef()) {
150
 
        Object fobj;
151
 
        Ref ref;
152
 
 
153
 
        ref = obj.getRef();
154
 
        xref->fetch(ref.num,ref.gen,&fobj);
155
 
        P2POutput::outputObject(&fobj,str,xref);
156
 
        fobj.free();
157
 
      } else {
158
 
        P2POutput::outputObject(&obj,str,xref);
159
 
      }
160
 
      str->putchar('\n');
161
 
      if (num > 0) outputEnd(str);
162
 
    }
163
 
  }
164
 
  void setObj(Object *objA) {
165
 
    obj.free();
166
 
    objA->copy(&obj);
167
 
  }
168
 
  Object *getObj() {
169
 
    return &obj;
170
 
  }
171
 
 
172
 
private:
173
 
  Object obj;
174
 
};
175
 
 
176
 
#endif