Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / pdfversion.cc
blobb00bb07157d574f4b191cd974b008bc74a76f91e
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 #include "pdfversion.h"
20 #include "shapesexceptions.h"
22 #include <algorithm>
24 using namespace SimplePDF;
26 SimplePDF::PDF_Version::PDF_Version( )
27 : version_( SimplePDF::PDF_Version::PDF_1_4 ),
28 maxRequestVersion_( SimplePDF::PDF_Version::PDF_1_1 ),
29 versionAction_( SimplePDF::PDF_Version::WARN )
30 { }
32 void
33 SimplePDF::PDF_Version::setVersion( Version version )
35 version_ = version;
38 void
39 SimplePDF::PDF_Version::setAction( Action action )
41 versionAction_ = action;
44 bool
45 SimplePDF::PDF_Version::greaterOrEqual( Version required, bool justCurious )
47 if( ! justCurious )
49 maxRequestVersion_ = std::max( maxRequestVersion_, required );
51 return version_ >= required;
54 bool
55 SimplePDF::PDF_Version::greaterOrEqualOrX( Version required, bool justCurious )
57 if( ! justCurious )
59 maxRequestVersion_ = std::max( maxRequestVersion_, required );
61 return version_ >= required || version_ == PDF_X;
64 const char *
65 SimplePDF::PDF_Version::maxRequestVersionString( ) const
67 if( version_ == PDF_X )
69 return toString( PDF_X );
71 return toString( maxRequestVersion_ );
74 void
75 SimplePDF::PDF_Version::message( Version required, const char * message ) const
77 using namespace Shapes;
79 switch( versionAction_ )
81 case ERROR:
82 throw Exceptions::PDFVersionError( version_, required, message );
83 break;
84 case WARN:
85 std::cerr << toString( version_ ) << " warning: " << message << std::endl ;
86 break;
87 case SILENT:
88 // Just be quiet.
89 break;
90 default:
91 throw Exceptions::InternalError( "PDF_out versionAction_ out of range." );
95 const char *
96 SimplePDF::PDF_Version::toString( SimplePDF::PDF_Version::Version version )
98 switch( version )
100 case PDF_X:
101 return "PDF-X" ;
102 case PDF_1_1:
103 return "PDF-1.1" ;
104 case PDF_1_2:
105 return "PDF-1.2" ;
106 case PDF_1_3:
107 return "PDF-1.3" ;
108 case PDF_1_4:
109 return "PDF-1.4" ;
110 case PDF_1_5:
111 return "PDF-1.5" ;
112 case PDF_1_6:
113 return "PDF-1.6" ;
114 default:
115 throw Shapes::Exceptions::InternalError( "PDF version out of range." );