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
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"
26 AfmScanner::AfmScanner( FontMetrics::AFM
* fontMetricsDst
, std::istream
* yyin
)
27 : yyFlexLexer( yyin
, 0 ), fontMetricsDst_( fontMetricsDst
),
28 currentDirectionDst_( 0 ),
29 currentDirectionID_( -1 ),
30 activateDirectionID_( 0 ),
33 encoding_( & Shapes::Helpers::requireMacRomanEncoding( ) )
37 AfmScanner::throwError( const char * msg
)
39 std::ostringstream oss
;
40 oss
<< "In font metrics for " ;
41 if( fontMetricsDst_
->fullName_
== NullPtr
< const char >( ) )
47 oss
<< fontMetricsDst_
->fullName_
;
50 throw strrefdup( oss
);
54 AfmScanner::synchWritingDirection( )
56 if( currentDirectionID_
== activateDirectionID_
)
61 typedef FontMetrics::WritingDirectionMetrics MetricsType
;
63 switch( activateDirectionID_
)
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_
);
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_
);
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_
;
104 throwError( "activateDirectionID_ out of range." );
107 currentDirectionID_
= activateDirectionID_
;