Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / simplepdfi.h
blob060ac3158e798bcc20120c232491801c7f7eadb9
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 <vector>
23 #include "SimplePDF_decls.h"
25 #include "refcount.h"
26 #include "pdfstructure.h"
28 namespace SimplePDF
31 class PDF_in
33 std::streamoff xref;
34 size_t xrefSize;
36 RefCountPtr< std::istream > is;
37 std::istream * isPtr;
39 RefCountPtr< PDF_Dictionary > resources;
40 RefCountPtr< PDF_Vector > pages;
42 RefCountPtr< PDF_Object > readObjectAt( std::streamoff pos );
43 std::streamoff xreflookup( size_t i, size_t v );
44 RefCountPtr< PDF_Object > parse( );
45 public:
46 class PageIterator
48 int pageNo;
49 SimplePDF::PDF_in & in;
50 public:
51 PageIterator( SimplePDF::PDF_in & _in, int _pageNo );
52 PageIterator( const PageIterator & orig );
53 PageIterator & operator = ( const PageIterator & orig );
54 bool operator == ( const PageIterator & i2 ) const;
55 bool operator != ( const PageIterator & i2 ) const;
56 RefCountPtr< PDF_Dictionary > operator * ( );
57 PageIterator operator ++ ();
58 PageIterator operator -- ();
59 PageIterator operator ++ ( int );
60 PageIterator operator -- ( int );
61 PageIterator & operator += ( int diff );
62 PageIterator & operator -= ( int diff );
65 PDF_in( RefCountPtr< std::istream > _is );
66 ~PDF_in( );
68 RefCountPtr< PDF_Object > readObjectNumbered( size_t i, size_t v );
69 template< class S >
70 RefCountPtr< S > follow( RefCountPtr< PDF_Object > maybeIndirect );
71 RefCountPtr< PDF_Object > follow( RefCountPtr< PDF_Object > maybeIndirect );
72 size_t getPageCount( );
73 PageIterator beginPages( );
74 PageIterator endPages( );
75 RefCountPtr< PDF_Dictionary > getPage( size_t pageNo );
78 template< class S >
79 RefCountPtr< S > PDF_in::follow( RefCountPtr< PDF_Object > maybeIndirect )
81 PDF_Indirect * tmp( dynamic_cast< PDF_Indirect * >( maybeIndirect.getPtr( ) ) );
82 if( tmp == 0 )
84 RefCountPtr< S > res( maybeIndirect.down_cast< S >( ) );
85 if( res == NullPtr< S >( ) )
87 throw( "Downcast in PDF_in::follow failed" );
89 return res;
91 return follow< S >( readObjectNumbered( tmp->i, tmp->v ) );