Update procedures
[shapes.git] / source / pdfversion.cc
blobf5ad8c682c76f85919aa55716c017c88ec5ce3e7
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, 2010 Henrik Tidefelt
19 #include "pdfversion.h"
20 #include "shapesexceptions.h"
21 #include "warn.h"
23 #include <algorithm>
25 using namespace SimplePDF;
27 SimplePDF::PDF_Version::PDF_Version( )
28 : version_( SimplePDF::PDF_Version::PDF_1_4 ),
29 maxRequestVersion_( SimplePDF::PDF_Version::PDF_1_1 ),
30 versionAction_( SimplePDF::PDF_Version::WARN )
31 { }
33 void
34 SimplePDF::PDF_Version::setVersion( Version version )
36 version_ = version;
39 void
40 SimplePDF::PDF_Version::setAction( Action action )
42 versionAction_ = action;
45 bool
46 SimplePDF::PDF_Version::greaterOrEqual( Version required, bool justCurious )
48 if( ! justCurious )
50 maxRequestVersion_ = std::max( maxRequestVersion_, required );
52 return version_ >= required;
55 bool
56 SimplePDF::PDF_Version::greaterOrEqualOrX( Version required, bool justCurious )
58 if( ! justCurious )
60 maxRequestVersion_ = std::max( maxRequestVersion_, required );
62 return version_ >= required || version_ == PDF_X;
65 const char *
66 SimplePDF::PDF_Version::maxRequestVersionString( ) const
68 if( version_ == PDF_X )
70 return toString( PDF_X );
72 return toString( maxRequestVersion_ );
75 void
76 SimplePDF::PDF_Version::message( Version required, const char * message ) const
78 using namespace Shapes;
80 switch( versionAction_ )
82 case ERROR:
83 throw Exceptions::PDFVersionError( version_, required, message );
84 break;
85 case WARN:
86 WARN_OR_THROW( Exceptions::PDFVersionError( version_, required, message, true ) );
87 break;
88 case SILENT:
89 // Just be quiet.
90 break;
91 default:
92 throw Exceptions::InternalError( "PDF_out versionAction_ out of range." );
96 const char *
97 SimplePDF::PDF_Version::toString( SimplePDF::PDF_Version::Version version )
99 switch( version )
101 case PDF_X:
102 return "PDF-X" ;
103 case PDF_1_1:
104 return "PDF-1.1" ;
105 case PDF_1_2:
106 return "PDF-1.2" ;
107 case PDF_1_3:
108 return "PDF-1.3" ;
109 case PDF_1_4:
110 return "PDF-1.4" ;
111 case PDF_1_5:
112 return "PDF-1.5" ;
113 case PDF_1_6:
114 return "PDF-1.6" ;
115 default:
116 throw Shapes::Exceptions::InternalError( "PDF version out of range." );