Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / fontmetrics.h
blobb6daa00251f1b13d643bf11d6df0baaec7ac128a
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 #pragma once
21 #include "FontMetrics_decls.h"
23 #include "charptrless.h"
24 #include "ptrowner.h"
26 #include <vector>
27 #include <map>
28 #include <list>
30 namespace FontMetrics
32 class CharacterMetrics
34 public:
35 size_t internalPosition_; // this is the position of this character in the containing charData_ vector of a WritingDirectionMetrics object.
36 int characterCode_;
37 double horizontalCharWidthX_;
38 double horizontalCharWidthY_;
39 double verticalCharWidthX_;
40 double verticalCharWidthY_;
41 double xmin_;
42 double ymin_;
43 double xmax_;
44 double ymax_;
45 double vX_;
46 double vY_;
48 private:
49 // The following fields are mutable since they cannot be synchronized at an early stage, yet the object is not really
50 // ready for access until synchronized. Hence, it should be safe to store const pointers to objects of this type
51 // in WritingDirectionMetrics, which are then synchronized once all characters are known by name.
52 mutable std::map< size_t, size_t > ligatures_;
53 mutable std::map< RefCountPtr< const char >, RefCountPtr< const char >, charRefPtrLess > * ligatureSetupMap_;
55 public:
56 CharacterMetrics( size_t internalPosition )
57 : internalPosition_( internalPosition ),
58 characterCode_( -1 ),
59 horizontalCharWidthX_( 0 ),
60 horizontalCharWidthY_( 0 ),
61 verticalCharWidthX_( 0 ),
62 verticalCharWidthY_( 0 ),
63 xmin_( 0 ),
64 ymin_( 0 ),
65 xmax_( 0 ),
66 ymax_( 0 ),
67 vX_( 0 ),
68 vY_( 0 ),
69 ligatureSetupMap_( 0 )
70 { }
71 ~CharacterMetrics( );
72 bool isEmpty( ) const;
73 bool hasLigature( size_t otherInternalPosition, size_t * ligatureInternalPosition ) const;
74 void addLigature( RefCountPtr< const char > otherName, RefCountPtr< const char > ligatureName );
75 void setupLigatures( const std::map< RefCountPtr< const char >, size_t, charRefPtrLess > & nameMap ) const;
77 void display( std::ostream & os ) const;
80 class WritingDirectionMetrics
82 public:
83 double underlinePosition_;
84 double underlineThickness_;
85 double italicAngleRadians_;
86 double charWidthX_;
87 double charWidthY_;
88 bool isFixedPitch_;
90 PtrOwner_back_Access< std::vector< const CharacterMetrics * > > charData_;
92 // The size_t is an index into charData_;
93 std::map< RefCountPtr< const char >, size_t, charRefPtrLess > nameMap_;
94 std::vector< size_t > codeMap_;
96 WritingDirectionMetrics( );
97 ~WritingDirectionMetrics( );
99 void setupLigatures( );
100 const CharacterMetrics * charByName( const char * name ) const;
101 const CharacterMetrics * charByCode( unsigned char code ) const;
102 const CharacterMetrics * charByCode( char code ) const; // shall not be used; generates an error
104 void display( std::ostream & os ) const;
107 class TrackKerning
109 double sizeLow_;
110 double trackLow_;
111 double sizeHigh_;
112 double trackHigh_;
113 public:
114 TrackKerning( double sizeLow, double trackLow, double sizeHigh, double trackHigh );
115 double operator () ( double sz ) const;
118 class AFM
120 public:
121 RefCountPtr< const char > fontName_;
122 RefCountPtr< const char > fullName_;
123 RefCountPtr< const char > familyName_;
124 RefCountPtr< const char > weight_;
125 size_t weightNumber_;
126 double fontBBoxXMin_;
127 double fontBBoxYMin_;
128 double fontBBoxXMax_;
129 double fontBBoxYMax_;
130 RefCountPtr< const char > version_;
131 RefCountPtr< const char > notice_;
132 RefCountPtr< const char > encodingScheme_;
133 RefCountPtr< const char > characterSet_;
134 size_t charCount_;
135 bool isCIDFont_;
136 double capHeight_;
137 double xHeight_;
138 double ascender_;
139 double descender_;
140 double leading_;
141 double stdHW_;
142 double stdVW_;
144 double vVectorX_;
145 double vVectorY_;
146 bool isFixedV_;
147 // Either of these may be null.
148 RefCountPtr< WritingDirectionMetrics > horizontalMetrics_;
149 RefCountPtr< WritingDirectionMetrics > verticalMetrics_;
151 std::map< int, RefCountPtr< TrackKerning > > trackKernings_;
152 typedef std::map< std::pair< size_t, size_t >, double > KernPairMap;
153 KernPairMap horizontalKernPairsX_;
154 KernPairMap horizontalKernPairsY_;
155 KernPairMap verticalKernPairsX_;
156 KernPairMap verticalKernPairsY_;
158 typedef std::pair< RefCountPtr< const char >, RefCountPtr< const char > > AssortedInfo;
159 std::list< AssortedInfo > assortedGlobalInfo_;
160 std::list< AssortedInfo > comments_;
162 AFM( )
163 : fontName_( NullPtr< const char >( ) ),
164 fullName_( NullPtr< const char >( ) ),
165 familyName_( NullPtr< const char >( ) ),
166 weight_( NullPtr< const char >( ) ),
167 weightNumber_( 0 ),
168 version_( NullPtr< const char >( ) ),
169 notice_( NullPtr< const char >( ) ),
170 encodingScheme_( NullPtr< const char >( ) ),
171 characterSet_( NullPtr< const char >( ) ),
172 leading_( 0 ),
173 isFixedV_( false ),
174 horizontalMetrics_( NullPtr< WritingDirectionMetrics >( ) ),
175 verticalMetrics_( NullPtr< WritingDirectionMetrics >( ) )
177 virtual ~AFM( );
179 virtual bool isBaseFont( ) const = 0;
181 double getHorizontalKernPairXByCode( unsigned char code1, unsigned char code2 ) const;
182 double getHorizontalKernPairXByCode( char code1, char code2 ) const; // generates error
185 class BaseFont : public AFM
187 public:
188 BaseFont( )
190 ~BaseFont( );
192 virtual bool isBaseFont( ) const { return true; }