Update procedures
[shapes.git] / source / afmscanner.cc
bloba6678c39ae5e3e64d63033eb8ea3c959f177f073
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::AFM * 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 horizontalMetrics_typed_ = new FontMetrics::SingleByte_WritingDirectionMetrics;
72 currentDirectionDst_ = horizontalMetrics_typed_;
73 fontMetricsDst_->horizontalMetrics_ = RefCountPtr< MetricsType >( currentDirectionDst_ );
75 break;
76 case 1:
78 if( fontMetricsDst_->verticalMetrics_ != NullPtr< MetricsType >( ) )
80 throwError( "Reactivating writing direction 1." );
82 verticalMetrics_typed_ = new FontMetrics::SingleByte_WritingDirectionMetrics;
83 currentDirectionDst_ = verticalMetrics_typed_;
84 fontMetricsDst_->verticalMetrics_ = RefCountPtr< MetricsType >( currentDirectionDst_ );
86 break;
87 case 2:
89 if( fontMetricsDst_->horizontalMetrics_ != NullPtr< MetricsType >( ) )
91 throwError( "Reactivating writing direction 0." );
93 if( fontMetricsDst_->verticalMetrics_ != NullPtr< MetricsType >( ) )
95 throwError( "Reactivating writing direction 1." );
97 horizontalMetrics_typed_ = new FontMetrics::SingleByte_WritingDirectionMetrics;
98 currentDirectionDst_ = horizontalMetrics_typed_;
99 fontMetricsDst_->horizontalMetrics_ = RefCountPtr< MetricsType >( currentDirectionDst_ );
100 fontMetricsDst_->verticalMetrics_ = fontMetricsDst_->horizontalMetrics_;
102 break;
103 default:
104 throwError( "activateDirectionID_ out of range." );
107 currentDirectionID_ = activateDirectionID_;