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
21 #include "FontMetrics_decls.h"
23 #include "charptrless.h"
32 class CharacterMetrics
35 size_t internalPosition_
; // this is the position of this character in the containing charData_ vector of a WritingDirectionMetrics object.
37 double horizontalCharWidthX_
;
38 double horizontalCharWidthY_
;
39 double verticalCharWidthX_
;
40 double verticalCharWidthY_
;
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_
;
56 CharacterMetrics( size_t internalPosition
)
57 : internalPosition_( internalPosition
),
59 horizontalCharWidthX_( 0 ),
60 horizontalCharWidthY_( 0 ),
61 verticalCharWidthX_( 0 ),
62 verticalCharWidthY_( 0 ),
69 ligatureSetupMap_( 0 )
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
83 double underlinePosition_
;
84 double underlineThickness_
;
85 double italicAngleRadians_
;
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;
114 TrackKerning( double sizeLow
, double trackLow
, double sizeHigh
, double trackHigh
);
115 double operator () ( double sz
) const;
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_
;
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_
;
163 : fontName_( NullPtr
< const char >( ) ),
164 fullName_( NullPtr
< const char >( ) ),
165 familyName_( NullPtr
< const char >( ) ),
166 weight_( NullPtr
< const char >( ) ),
168 version_( NullPtr
< const char >( ) ),
169 notice_( NullPtr
< const char >( ) ),
170 encodingScheme_( NullPtr
< const char >( ) ),
171 characterSet_( NullPtr
< const char >( ) ),
174 horizontalMetrics_( NullPtr
< WritingDirectionMetrics
>( ) ),
175 verticalMetrics_( NullPtr
< WritingDirectionMetrics
>( ) )
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
192 virtual bool isBaseFont( ) const { return true; }