Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / afmscanner.cc
blob83918b5e02eb97751407cdbf764a1e718ab26a50
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 "afmscanner.h"
20 #include "strrefdup.h"
21 #include "charconverters.h"
23 #include <sstream>
26 AfmScanner::AfmScanner( FontMetrics::BaseFont * fontMetricsDst, std::istream * yyin )
27 : yyFlexLexer( yyin, 0 ), fontMetricsDst_( fontMetricsDst ),
28 currentDirectionDst_( 0 ),
29 currentDirectionID_( -1 ),
30 activateDirectionID_( 0 ),
31 metricsSets_( 0 ),
32 tellQue_( false ),
33 encoding_( & Shapes::Helpers::requireMacRomanEncoding( ) )
34 { }
36 void
37 AfmScanner::throwError( const char * msg )
39 std::ostringstream oss;
40 oss << "In font metrics for " ;
41 if( fontMetricsDst_->fullName_ == NullPtr< const char >( ) )
43 oss << "???" ;
45 else
47 oss << fontMetricsDst_->fullName_;
49 oss << ": " << msg ;
50 throw strrefdup( oss );
53 void
54 AfmScanner::synchWritingDirection( )
56 if( currentDirectionID_ == activateDirectionID_ )
58 return;
61 typedef FontMetrics::WritingDirectionMetrics MetricsType;
63 switch( activateDirectionID_ )
65 case 0:
67 if( fontMetricsDst_->horizontalMetrics_ != NullPtr< MetricsType >( ) )
69 throwError( "Reactivating writing direction 0." );
71 fontMetricsDst_->horizontalMetrics_ = RefCountPtr< MetricsType >( new MetricsType );
72 currentDirectionDst_ = fontMetricsDst_->horizontalMetrics_.getPtr( );
74 break;
75 case 1:
77 if( fontMetricsDst_->verticalMetrics_ != NullPtr< MetricsType >( ) )
79 throwError( "Reactivating writing direction 1." );
81 fontMetricsDst_->verticalMetrics_ = RefCountPtr< MetricsType >( new MetricsType );
82 currentDirectionDst_ = fontMetricsDst_->verticalMetrics_.getPtr( );
84 break;
85 case 2:
87 if( fontMetricsDst_->horizontalMetrics_ != NullPtr< MetricsType >( ) )
89 throwError( "Reactivating writing direction 0." );
91 if( fontMetricsDst_->verticalMetrics_ != NullPtr< MetricsType >( ) )
93 throwError( "Reactivating writing direction 1." );
95 fontMetricsDst_->horizontalMetrics_ = RefCountPtr< MetricsType >( new MetricsType );
96 fontMetricsDst_->verticalMetrics_ = fontMetricsDst_->horizontalMetrics_;
97 currentDirectionDst_ = fontMetricsDst_->horizontalMetrics_.getPtr( );
99 break;
100 default:
101 throwError( "activateDirectionID_ out of range." );
104 currentDirectionID_ = activateDirectionID_;