Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / pdfstructure.h
blobec85a2aff45af3c0b6241353406d3a670b06f70f
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
6 * any later version.
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
19 #pragma once
21 #include "SimplePDF_decls.h"
23 #include "refcount.h"
25 #include <iostream>
26 #include <list>
27 #include <map>
28 #include <vector>
29 #include <deque>
30 #include <sstream>
32 namespace SimplePDF
35 typedef std::map< class PDF_Indirect, RefCountPtr< class PDF_Indirect_out > > IndirectRemapType;
37 class PDF_Object
39 public:
40 bool complete;
41 PDF_Object( );
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 );
47 template< class S >
48 RefCountPtr< S > down_cast_follow( RefCountPtr< PDF_Object > maybeIndirect );
50 class PDF_Null : public PDF_Object
52 public:
53 PDF_Null( );
54 virtual ~PDF_Null( );
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
60 public:
61 typedef bool ValueType;
62 private:
63 ValueType my_value;
64 public:
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
73 public:
74 typedef int ValueType;
75 private:
76 ValueType my_value;
77 public:
78 PDF_Int( ValueType _value );
79 PDF_Int( const char * strvalue );
80 virtual ~PDF_Int( );
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
87 public:
88 typedef double ValueType;
89 private:
90 ValueType my_value;
91 public:
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
101 public:
102 PDF_String( );
103 virtual ~PDF_String( );
106 class PDF_LiteralString : public PDF_String
108 std::string my_str;
109 public:
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;
121 public:
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
131 std::string my_name;
132 public:
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
144 public:
145 PDF_Vector( );
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;
158 VecType vec;
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
166 public:
167 PDF_Dictionary( );
168 PDF_Dictionary( const PDF_Dictionary & orig );
169 virtual ~PDF_Dictionary( );
171 typedef std::map< std::string, RefCountPtr<PDF_Object> > DicType;
172 DicType dic;
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
188 public:
189 PDF_Stream( );
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 );
197 class PDF_Stream_out : public PDF_Stream
199 public:
200 PDF_Stream_out( );
201 virtual ~PDF_Stream_out( );
203 std::ostringstream data;
204 virtual void writeTo( std::ostream & os, SimplePDF::PDF_xref * xref, const RefCountPtr< const PDF_Object > & self ) const;
207 class PDF_Stream_in : public PDF_Stream
209 public:
210 std::istream * is;
211 std::streamoff dataStart;
213 PDF_Stream_in( PDF_Dictionary * dic, std::istream * _is, std::streamoff _dataStart );
214 PDF_Stream_in( std::istream * _is, std::streamoff _dataStart );
215 virtual ~PDF_Stream_in( );
217 virtual void writeTo( std::ostream & os, SimplePDF::PDF_xref * xref, const RefCountPtr< const PDF_Object > & self ) const;
218 void writeDataTo( std::ostream & os ) const;
219 void writeDataDefilteredTo( std::ostream & os ) const;
220 virtual RefCountPtr< PDF_Object > deepCopy( RefCountPtr< PDF_Object > self, size_t * indirectObjectCounter, IndirectRemapType * remap );
223 class PDF_Indirect : public PDF_Object
225 public:
226 size_t i;
227 size_t v;
228 PDF_Indirect( size_t _i, size_t _v = 0 );
229 virtual ~PDF_Indirect( );
230 virtual RefCountPtr< PDF_Object > deepCopy( RefCountPtr< PDF_Object > self, size_t * indirectObjectCounter, IndirectRemapType * remap );
233 bool operator < ( const PDF_Indirect & o1, const PDF_Indirect & o2 );
235 class PDF_Indirect_out : public PDF_Indirect
237 public:
238 bool inUse;
239 RefCountPtr< PDF_Object > obj;
240 PDF_Indirect_out( RefCountPtr< PDF_Object > _obj, size_t _i, size_t _v = 0 );
241 virtual ~PDF_Indirect_out( );
242 virtual void writeTo( std::ostream & os, SimplePDF::PDF_xref * xref, const RefCountPtr< const PDF_Object > & self ) const;
243 void writeObject( std::ostream & os, SimplePDF::PDF_xref * xref ) const;
246 class PDF_Indirect_in : public PDF_Indirect
248 public:
249 PDF_in * PDFin;
250 PDF_Indirect_in( size_t _i, size_t _v = 0 );
251 virtual ~PDF_Indirect_in( );
252 virtual void writeTo( std::ostream & os, SimplePDF::PDF_xref * xref, const RefCountPtr< const PDF_Object > & self ) const;
253 RefCountPtr< PDF_Object > deref( );
254 virtual RefCountPtr< PDF_Object > deepCopy( RefCountPtr< PDF_Object > self, size_t * indirectObjectCounter, IndirectRemapType * remap );
257 class PDF_xref
259 private:
260 mutable size_t size_;
261 std::list< RefCountPtr< const PDF_Indirect_out > > indirectQueue_;
262 std::list< size_t > localOrder_; /* This list gives the order in which local numbers were assigned. */
263 std::deque< size_t > localNumbers_;
264 std::deque< size_t > byteOffsets_;
265 std::deque< size_t > generations_;
266 public:
267 PDF_xref( );
268 void enqueue( const RefCountPtr< const PDF_Indirect_out > & obj );
269 void writeRecursive( std::ostream & os );
270 size_t local( size_t i ) const; /* Return local object number for the global object number i. Allows the xref table to be compact. */
272 void writeTable( std::ostream & os ) const;
273 size_t size( ) const;
276 RefCountPtr< PDF_Indirect_out > indirect( RefCountPtr< PDF_Object > obj, size_t * i, size_t v = 0 );
278 RefCountPtr< PDF_Object > deepCopy( RefCountPtr< PDF_Object > obj, size_t * indirectObjectCounter, IndirectRemapType * remap );