1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
119 TTypefaceSupport info; |
119 TTypefaceSupport info; |
120 _LIT(KIgnoreFont1, "Test2"); |
120 _LIT(KIgnoreFont1, "Test2"); |
121 _LIT(KIgnoreFont2, "LinkedFont3TT"); //LinkedFont3/4TT both cause test failure on Freetype |
121 _LIT(KIgnoreFont2, "LinkedFont3TT"); //LinkedFont3/4TT both cause test failure on Freetype |
122 _LIT(KIgnoreFont3, "LinkedFont4TT"); //They are test files with incorrect metrics |
122 _LIT(KIgnoreFont3, "LinkedFont4TT"); //They are test files with incorrect metrics |
123 |
123 |
124 // Maximum height of font allowed by iType rasteriser |
|
125 const TInt KMaxITypeHeightInPixels = 256; |
|
126 _LIT(KErrorMessageWithFontName, "Font: %S, pixel height requested: %d, pixel height of font: %d"); |
|
127 _LIT(KErrorMessage, "Pixel height requested: %d, pixel height of font: %d"); |
|
128 |
|
129 for (TInt count = 0; count < typefaces; count++) |
124 for (TInt count = 0; count < typefaces; count++) |
130 { |
125 { |
131 iDevice->TypefaceSupport( info, count ); |
126 iDevice->TypefaceSupport( info, count ); |
132 |
127 |
133 for (TInt index = 0; index < info.iNumHeights; index++) |
128 for (TInt index = 0; index < info.iNumHeights; index++) |
134 { |
129 { |
135 TInt height = iDevice->FontHeightInPixels( count, index ); |
130 TInt height = iDevice->FontHeightInPixels( count, index ); |
136 if (height > KMaxITypeHeightInPixels) |
|
137 { |
|
138 continue; |
|
139 } |
|
140 fs.iTypeface = info.iTypeface; |
131 fs.iTypeface = info.iTypeface; |
141 fs.iHeight = height; |
132 fs.iHeight = height; |
142 |
133 |
143 INFO_PRINTF1(_L("Test GetNearestFontInPixels")); |
134 INFO_PRINTF1(_L("Test GetNearestFontInPixels")); |
144 User::LeaveIfError( iDevice->GetNearestFontInPixels( (CFont*&)iFont1 ,fs ) ); |
135 User::LeaveIfError( iDevice->GetNearestFontInPixels( (CFont*&)iFont1 ,fs ) ); |
145 TInt heightInPixels = iFont1->HeightInPixels(); |
136 TEST(iFont1->HeightInPixels() == height); |
146 if ( heightInPixels == height ) |
|
147 { |
|
148 TEST( ETrue ); |
|
149 } |
|
150 else |
|
151 { |
|
152 TOpenFontFaceAttrib attrib; |
|
153 if( iFont1->GetFaceAttrib( attrib ) ) |
|
154 { |
|
155 INFO_PRINTF4(KErrorMessageWithFontName, &attrib.FullName(), height, heightInPixels); |
|
156 } |
|
157 else |
|
158 { |
|
159 INFO_PRINTF3(KErrorMessage, height, heightInPixels); |
|
160 } |
|
161 TEST( EFalse ); |
|
162 } |
|
163 |
137 |
164 INFO_PRINTF1(_L("Test GetNearestFontToDesignHeightInPixels")); |
138 INFO_PRINTF1(_L("Test GetNearestFontToDesignHeightInPixels")); |
165 User::LeaveIfError( iDevice->GetNearestFontToDesignHeightInPixels( (CFont*&)iFont2, fs ) ); |
139 User::LeaveIfError( iDevice->GetNearestFontToDesignHeightInPixels( (CFont*&)iFont2, fs ) ); |
166 heightInPixels = iFont2->HeightInPixels(); |
140 TEST(iFont2->HeightInPixels() == height); |
167 if ( heightInPixels == height ) |
|
168 { |
|
169 TEST( ETrue ); |
|
170 } |
|
171 else |
|
172 { |
|
173 TOpenFontFaceAttrib attrib; |
|
174 if( iFont2->GetFaceAttrib( attrib ) ) |
|
175 { |
|
176 INFO_PRINTF4(KErrorMessageWithFontName, &attrib.FullName(), height, heightInPixels); |
|
177 } |
|
178 else |
|
179 { |
|
180 INFO_PRINTF3(KErrorMessage, height, heightInPixels); |
|
181 } |
|
182 TEST( EFalse ); |
|
183 } |
|
184 iDevice->ReleaseFont( iFont2 ); |
141 iDevice->ReleaseFont( iFont2 ); |
185 iDevice->ReleaseFont( iFont1 ); |
142 iDevice->ReleaseFont(iFont1); |
186 } |
143 } |
187 |
144 |
188 INFO_PRINTF1(_L("Test GetNearestFontToMaxHeightInPixels")); |
145 INFO_PRINTF1(_L("Test GetNearestFontToMaxHeightInPixels")); |
189 for (TInt maxHeight = 20; maxHeight <= 50; maxHeight += 10) |
146 for (TInt maxHeight = 20; maxHeight <= 50; maxHeight += 10) |
190 { |
147 { |
220 { // got a scalable (TrueType) font - can't guarantee will fit for bitmap font |
177 { // got a scalable (TrueType) font - can't guarantee will fit for bitmap font |
221 // N.B. If this ever fails then try replacing maxHeight with maxHeight + 1 in the test |
178 // N.B. If this ever fails then try replacing maxHeight with maxHeight + 1 in the test |
222 // as it could be down to the hinting rounding error that can very occasionally occur |
179 // as it could be down to the hinting rounding error that can very occasionally occur |
223 // We can't make this test reliably with bitmap fonts |
180 // We can't make this test reliably with bitmap fonts |
224 INFO_PRINTF1(_L("Font is scalable")); |
181 INFO_PRINTF1(_L("Font is scalable")); |
225 TEST(iFont3->FontMaxHeight() <= maxHeight+1); |
182 TEST(iFont3->FontMaxHeight() <= maxHeight); |
226 } |
183 } |
227 |
184 |
228 INFO_PRINTF1(_L("Test font level metrics")); |
185 INFO_PRINTF1(_L("Test font level metrics")); |
229 INFO_PRINTF3(_L("Requested max height %d, returned max height %d"), maxHeight, iFont3->FontMaxHeight()); |
186 INFO_PRINTF3(_L("Requested max height %d, returned max height %d"), maxHeight, iFont3->FontMaxHeight()); |
230 INFO_PRINTF4(_L("MaxAscent %d, MaxDescent %d, HeightInPixels %d"), iFont3->FontMaxAscent(), iFont3->FontMaxDescent(), iFont3->HeightInPixels()); |
187 INFO_PRINTF4(_L("MaxAscent %d, MaxDescent %d, HeightInPixels %d"), iFont3->FontMaxAscent(), iFont3->FontMaxDescent(), iFont3->HeightInPixels()); |