Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / multipage.h
bloba00a6c2bdce6551c6f89163988ee9ec39941f5d9
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 "Shapes_Ast_decls.h"
22 #include "Shapes_Kernel_decls.h"
23 #include "Shapes_Lang_decls.h"
24 #include "FontMetrics_decls.h"
25 #include "SimplePDF_decls.h"
27 #include "hottypes.h"
28 #include "tagtypes.h"
29 #include "pdfstructure.h"
31 namespace Shapes
33 namespace Lang
36 class DocumentDestination : public Lang::NoOperatorOverloadGeometric2D
38 public:
39 enum Sides{ PAGE, TOPLEFT, TOP, LEFT, RECTANGLE };
40 private:
41 bool remote_;
42 /* Strings are used instead of symbols for destination names, since they are often composd from parts,
43 * like [sprintf `chap.%d.sec.%d´ chapNo secNo].
45 RefCountPtr< const char > name_; // Null if not a named destination. Must be present if remote_.
46 int outlineLevel_; // Negative if not to appear in the document outline.
48 RefCountPtr< const char > outlineText_;
49 bool outlineOpen_; // Only applies if to appear in the document outline.
50 bool outlineFontBold_;
51 bool outlineFontItalic_;
52 Concrete::RGB outlineColor_;
54 /* The following members shall not be used for remote_ destinations.
56 Sides sidesMode_;
57 RefCountPtr< const Lang::Drawable2D > target_; // Not used if sidesMode_ is <page>.
58 bool fittobbox_; // If true, the content's bounding box is used instead of the mediabox for zooming purposes.
59 double zoom_; // If not strictly positive, zoom is unspecified. Can only be specified in mode <topleft>.
60 public:
61 DocumentDestination( bool remote, RefCountPtr< const char > name, int outlineLevel,
62 RefCountPtr< const char > outlineText, bool outlineOpen, bool outlineFontBold, bool outlineFontItalic, const Concrete::RGB & outlineColor ); // remote must be true!.
63 DocumentDestination( RefCountPtr< const char > name, int outlineLevel,
64 RefCountPtr< const char > outlineText, bool outlineOpen, bool outlineFontBold, bool outlineFontItalic, const Concrete::RGB & outlineColor,
65 Sides sidesMode, RefCountPtr< const Lang::Drawable2D > target, bool fittobbox, double zoom );
66 virtual ~DocumentDestination( );
67 virtual RefCountPtr< const Lang::Geometric2D > transformed( const Lang::Transform2D & transform, const RefCountPtr< const Lang::Geometric2D > & self ) const;
68 virtual RefCountPtr< const Lang::Geometric3D > to3D( const RefCountPtr< const Lang::Geometric2D > & self ) const;
70 virtual void gcMark( Kernel::GCMarkedSet & marked );
72 bool definesNamed( ) const;
73 RefCountPtr< const char > name( ) const;
74 bool isOutlineEntry( ) const;
75 size_t outlineLevel( ) const;
76 RefCountPtr< SimplePDF::PDF_Object > getDestination( const RefCountPtr< SimplePDF::PDF_Indirect_out > & i_page ) const;
77 RefCountPtr< SimplePDF::PDF_Vector > getDirectDestination( const RefCountPtr< SimplePDF::PDF_Indirect_out > & i_page ) const;
78 RefCountPtr< SimplePDF::OutlineItem > getOutlineItem( const RefCountPtr< SimplePDF::PDF_Indirect_out > & i_page, RefCountPtr< const char > otherText = RefCountPtr< const char >( NullPtr< const char >( ) ) ) const;
80 TYPEINFODECL;
85 namespace Kernel
88 class WarmCatalog : public Kernel::State
90 public:
91 class BoundingRectangle
93 Concrete::Length xmin_;
94 Concrete::Length ymin_;
95 Concrete::Length xmax_;
96 Concrete::Length ymax_;
97 mutable bool modified_;
98 mutable RefCountPtr< SimplePDF::PDF_Vector > pdfVec_;
99 public:
100 BoundingRectangle( );
101 void growToContain( const Concrete::Coords2D & ll, const Concrete::Coords2D & ur );
102 RefCountPtr< SimplePDF::PDF_Vector > pdfVector( ) const;
104 class Page
106 public:
107 size_t index_;
108 RefCountPtr< SimplePDF::PDF_Resources > resources_;
109 RefCountPtr< SimplePDF::PDF_Stream_out > contents_;
110 RefCountPtr< BoundingRectangle > mediabox_;
111 std::vector< RefCountPtr< const Lang::DocumentDestination > > destinations_;
112 std::vector< RefCountPtr< const Lang::AnnotationBase > > annotations_;
114 Page( size_t index, const RefCountPtr< SimplePDF::PDF_Resources > & resources, const RefCountPtr< SimplePDF::PDF_Stream_out > & contents, const RefCountPtr< Kernel::WarmCatalog::BoundingRectangle > & mediabox );
115 ~Page( );
117 class PageLabelEntry
119 public:
120 enum Style{ NONE, DECIMAL, ROMAN, rOMAN, ALPHABET, aLPHABET };
121 size_t pageIndex_;
122 RefCountPtr< const char > prefix_;
123 Style style_;
124 size_t startNumber_;
126 PageLabelEntry( size_t pageIndex, const RefCountPtr< const char > & prefix, Style style, size_t startNumber );
127 ~PageLabelEntry( );
129 typedef std::vector< SimplePDF::PDF_out > ShipoutList;
130 private:
131 PtrOwner_back_Access< std::list< const Page * > > pages_;
132 PtrOwner_back_Access< std::list< const PageLabelEntry * > > labelEntries_;
133 bool pageLabelsActivated_;
134 std::map< Lang::Symbol::KeyType, RefCountPtr< BoundingRectangle > > mediaBoxes_;
135 RefCountPtr< const Lang::Symbol > bboxGroup_;
136 public:
137 WarmCatalog( );
138 virtual ~WarmCatalog( );
139 virtual void tackOnImpl( Kernel::EvalState * evalState, const RefCountPtr< const Lang::Value > & piece, const Ast::SourceLocation & callLoc );
140 virtual void peekImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
141 virtual void freezeImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
142 virtual void gcMark( Kernel::GCMarkedSet & marked );
144 void setLabel( RefCountPtr< const char > prefix, PageLabelEntry::Style style, size_t start );
145 size_t getNextPageNumber( ) const;
146 PageLabelEntry::Style getNextPageStyle( ) const;
147 RefCountPtr< const char > getNextPagePrefix( ) const;
148 RefCountPtr< const char > getNextPageLabel( ) const;
149 RefCountPtr< const char > getPageLabel( size_t index ) const;
151 void setBBoxGroup( const RefCountPtr< const Lang::Symbol > & group );
153 bool isEmpty( ) const;
154 void tackOnPage( const Kernel::PassedDyn & dyn, const RefCountPtr< const Lang::Drawable2D > & pageContents, const Ast::SourceLocation & callLoc );
155 void shipout( bool split, ShipoutList * docs );
157 TYPEINFODECL;
159 private:
160 RefCountPtr< const char > getPageLabel( const Kernel::WarmCatalog::PageLabelEntry * entry, size_t index ) const;
161 SimplePDF::PDF_out shipoutOne( RefCountPtr< SimplePDF::PDF_Indirect_out > i_info, int pageNo = 0 ); /* Use pageNo == -1 for all pages. */