1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008 Henrik Tidefelt
21 #include "SimplePDF_decls.h"
35 typedef std::map
< class PDF_Indirect
, RefCountPtr
< class PDF_Indirect_out
> > IndirectRemapType
;
42 virtual ~PDF_Object( );
43 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const; // Not pure virtual only to make it possible to use ths class as base in std::map etc
44 virtual RefCountPtr
< PDF_Object
> deepCopy( RefCountPtr
< PDF_Object
> self
, size_t * indirectObjectCounter
, IndirectRemapType
* remap
);
48 RefCountPtr
< S
> down_cast_follow( RefCountPtr
< PDF_Object
> maybeIndirect
);
50 class PDF_Null
: public PDF_Object
55 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
58 class PDF_Boolean
: public PDF_Object
61 typedef bool ValueType
;
65 PDF_Boolean( ValueType _value
);
66 virtual ~PDF_Boolean( );
67 ValueType
value( ) const;
68 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
71 class PDF_Int
: public PDF_Object
74 typedef int ValueType
;
78 PDF_Int( ValueType _value
);
79 PDF_Int( const char * strvalue
);
81 ValueType
value( ) const;
82 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
85 class PDF_Float
: public PDF_Object
88 typedef double ValueType
;
92 PDF_Float( ValueType _value
);
93 PDF_Float( const char * strvalue
);
94 virtual ~PDF_Float( );
95 ValueType
value( ) const;
96 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
99 class PDF_String
: public PDF_Object
103 virtual ~PDF_String( );
106 class PDF_LiteralString
: public PDF_String
110 PDF_LiteralString( const std::string
& _str
);
111 PDF_LiteralString( const char * _str
);
112 PDF_LiteralString( const std::list
< RefCountPtr
< char > > & strs
);
113 virtual ~PDF_LiteralString( );
114 const std::string
& str( ) const;
115 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
118 class PDF_HexString
: public PDF_String
120 std::string my_hexstr
;
122 PDF_HexString( const std::string
& _hexstr
);
123 PDF_HexString( const char * _hexstr
);
124 virtual ~PDF_HexString( );
125 const std::string
& hexstr( ) const;
126 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
129 class PDF_Name
: public PDF_Object
133 PDF_Name( const std::string
& _name
);
134 virtual ~PDF_Name( );
135 const std::string
& name( ) const;
136 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
137 friend std::ostream
& operator << ( std::ostream
& os
, const PDF_Name
& self
);
140 std::ostream
& operator << ( std::ostream
& os
, const PDF_Name
& self
);
142 class PDF_Vector
: public PDF_Object
146 PDF_Vector( PDF_Float::ValueType c
);
147 PDF_Vector( PDF_Float::ValueType c1
, PDF_Float::ValueType c2
);
148 PDF_Vector( PDF_Float::ValueType c1
, PDF_Float::ValueType c2
, PDF_Float::ValueType c3
);;
149 PDF_Vector( PDF_Float::ValueType x1
, PDF_Float::ValueType y1
,
150 PDF_Float::ValueType x2
, PDF_Float::ValueType y2
);
151 PDF_Vector( PDF_Float::ValueType a
, PDF_Float::ValueType b
,
152 PDF_Float::ValueType c
, PDF_Float::ValueType d
,
153 PDF_Float::ValueType e
, PDF_Float::ValueType f
);
154 PDF_Vector( PDF_Int::ValueType x1
, PDF_Int::ValueType y1
,
155 PDF_Int::ValueType x2
, PDF_Int::ValueType y2
);
156 virtual ~PDF_Vector( );
157 typedef std::vector
< RefCountPtr
<PDF_Object
> > VecType
;
159 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
160 virtual RefCountPtr
< PDF_Object
> deepCopy( RefCountPtr
< PDF_Object
> self
, size_t * indirectObjectCounter
, IndirectRemapType
* remap
);
161 RefCountPtr
< PDF_Vector
> rectangleIntersection( const RefCountPtr
< PDF_Vector
> & other
) const;
164 class PDF_Dictionary
: public PDF_Object
168 PDF_Dictionary( const PDF_Dictionary
& orig
);
169 virtual ~PDF_Dictionary( );
171 typedef std::map
< std::string
, RefCountPtr
<PDF_Object
> > DicType
;
173 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
174 virtual void writeToWithLength( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, size_t len
) const;
176 PDF_Int::ValueType
getLength( ) const;
177 PDF_Int::ValueType
getCount( ) const;
178 bool isPages( ) const;
179 RefCountPtr
< PDF_Object
> getInheritable( const char * name
) const;
181 RefCountPtr
< PDF_Object
> & operator [] ( const char * key
);
182 bool hasKey( const char * key
) const;
183 virtual RefCountPtr
< PDF_Object
> deepCopy( RefCountPtr
< PDF_Object
> self
, size_t * indirectObjectCounter
, IndirectRemapType
* remap
);
186 class PDF_Stream
: public PDF_Dictionary
190 PDF_Stream( const PDF_Dictionary
& dic
);
191 virtual ~PDF_Stream( );
193 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
194 virtual RefCountPtr
< PDF_Object
> deepCopy( RefCountPtr
< PDF_Object
> self
, size_t * indirectObjectCounter
, IndirectRemapType
* remap
);
195 PDF_Int::ValueType
getPredictor( ) const;
198 class PDF_Stream_out
: public PDF_Stream
202 virtual ~PDF_Stream_out( );
204 std::ostringstream data
;
205 bool invertFilterOnWrite
;
206 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
208 void writeStream_NoFilter( std::ostream
& stream
) const;
209 void writeStream_FlateDecode( std::ostream
& stream
) const;
212 class PDF_Stream_in
: public PDF_Stream
216 std::streamoff dataStart
;
218 PDF_Stream_in( PDF_Dictionary
* dic
, std::istream
* _is
, std::streamoff _dataStart
);
219 PDF_Stream_in( std::istream
* _is
, std::streamoff _dataStart
);
220 virtual ~PDF_Stream_in( );
222 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
223 void writeDataTo( std::ostream
& os
) const;
224 void writeDataDefilteredTo( std::ostream
& os
) const;
225 virtual RefCountPtr
< PDF_Object
> deepCopy( RefCountPtr
< PDF_Object
> self
, size_t * indirectObjectCounter
, IndirectRemapType
* remap
);
228 class PDF_Indirect
: public PDF_Object
233 PDF_Indirect( size_t _i
, size_t _v
= 0 );
234 virtual ~PDF_Indirect( );
235 virtual RefCountPtr
< PDF_Object
> deepCopy( RefCountPtr
< PDF_Object
> self
, size_t * indirectObjectCounter
, IndirectRemapType
* remap
);
238 bool operator < ( const PDF_Indirect
& o1
, const PDF_Indirect
& o2
);
240 class PDF_Indirect_out
: public PDF_Indirect
244 RefCountPtr
< PDF_Object
> obj
;
245 PDF_Indirect_out( RefCountPtr
< PDF_Object
> _obj
, size_t _i
, size_t _v
= 0 );
246 virtual ~PDF_Indirect_out( );
247 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
248 void writeObject( std::ostream
& os
, SimplePDF::PDF_xref
* xref
) const;
251 class PDF_Indirect_in
: public PDF_Indirect
255 PDF_Indirect_in( size_t _i
, size_t _v
= 0 );
256 virtual ~PDF_Indirect_in( );
257 virtual void writeTo( std::ostream
& os
, SimplePDF::PDF_xref
* xref
, const RefCountPtr
< const PDF_Object
> & self
) const;
258 RefCountPtr
< PDF_Object
> deref( );
259 virtual RefCountPtr
< PDF_Object
> deepCopy( RefCountPtr
< PDF_Object
> self
, size_t * indirectObjectCounter
, IndirectRemapType
* remap
);
265 mutable size_t size_
;
266 std::list
< RefCountPtr
< const PDF_Indirect_out
> > indirectQueue_
;
267 std::list
< size_t > localOrder_
; /* This list gives the order in which local numbers were assigned. */
268 std::deque
< size_t > localNumbers_
;
269 std::deque
< size_t > byteOffsets_
;
270 std::deque
< size_t > generations_
;
273 void enqueue( const RefCountPtr
< const PDF_Indirect_out
> & obj
);
274 void writeRecursive( std::ostream
& os
);
275 size_t local( size_t i
) const; /* Return local object number for the global object number i. Allows the xref table to be compact. */
277 void writeTable( std::ostream
& os
) const;
278 size_t size( ) const;
281 RefCountPtr
< PDF_Indirect_out
> indirect( RefCountPtr
< PDF_Object
> obj
, size_t * i
, size_t v
= 0 );
283 RefCountPtr
< PDF_Object
> deepCopy( RefCountPtr
< PDF_Object
> obj
, size_t * indirectObjectCounter
, IndirectRemapType
* remap
);