|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Implementation of access to Series 60 font system for 3rd parties. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 #include "AknFontAccess.h" |
|
21 |
|
22 #include "avkon.hrh" |
|
23 #include <aknenv.h> |
|
24 |
|
25 #include <AknTextDecorationMetrics.h> |
|
26 #include <AknFontSpecification.h> |
|
27 #include <AknFontId.h> |
|
28 #include <AknFontProvider.h> |
|
29 #include "AknFontSpecificationLayoutFont.h" |
|
30 #include "AknUtils.h" |
|
31 #include "AknLayoutFont.h" |
|
32 #include <AknFontProviderSuppliedMetrics.h> |
|
33 |
|
34 #include <e32std.h> |
|
35 #include <eikenv.h> |
|
36 #include <gulicon.h> |
|
37 #include <gulfont.h> |
|
38 |
|
39 /** |
|
40 * Generic font family name descriptors. These act as aliases to the real typefaces or typeface |
|
41 * families, if supported on the product. |
|
42 * Note: A 0-length descriptor can be used to obtain a default product font family. |
|
43 */ |
|
44 _LIT(KAknFontFamilySansSerif,"SansSerif"); |
|
45 _LIT(KAknFontFamilySerif,"Serif"); |
|
46 _LIT(KAknFontFamilyMonospace,"Monospace"); |
|
47 |
|
48 LOCAL_C void MapFontFamilyToGenericAlias( AknFontAccess::TAknFontFamily aFontFamily, TTypeface& aTypeface) |
|
49 { |
|
50 |
|
51 // State a bias toward proportional. (Default value of TTypeface currently has slight bias toward Monospace) |
|
52 aTypeface.SetIsProportional(ETrue); |
|
53 |
|
54 switch( aFontFamily) |
|
55 { |
|
56 case AknFontAccess::EAknFontFamilySansSerif: |
|
57 aTypeface.iName = KAknFontFamilySansSerif; |
|
58 aTypeface.SetIsSerif(EFalse); |
|
59 break; |
|
60 |
|
61 case AknFontAccess::EAknFontFamilySerif: |
|
62 aTypeface.iName = KAknFontFamilySerif; |
|
63 aTypeface.SetIsSerif(ETrue); |
|
64 break; |
|
65 |
|
66 case AknFontAccess::EAknFontFamilyMonospace: |
|
67 aTypeface.iName = KAknFontFamilyMonospace; |
|
68 aTypeface.SetIsProportional(EFalse); |
|
69 break; |
|
70 |
|
71 case AknFontAccess::EAknFontFamilyNotSpecified: // fallthrough to default |
|
72 default: |
|
73 // Wipe name, but still with proportional attribute |
|
74 aTypeface.iName = KNullDesC; |
|
75 } |
|
76 } |
|
77 |
|
78 EXPORT_C CFbsFont* AknFontAccess::GetFont( |
|
79 CBitmapDevice& aBitmapDevice, |
|
80 const TFontStyle aFontStyle, |
|
81 TInt aFontSizeInTwips, |
|
82 TAknFontFamily aFontFamily) |
|
83 { |
|
84 TTypeface typeface; // Buffer is just used for the typeface alias. |
|
85 MapFontFamilyToGenericAlias(aFontFamily, typeface); |
|
86 return DoGetFont( aBitmapDevice, aFontStyle, aFontSizeInTwips, typeface, ETrue); |
|
87 } |
|
88 |
|
89 EXPORT_C CFbsFont* AknFontAccess::GetFont( |
|
90 CBitmapDevice& aBitmapDevice, |
|
91 const TFontStyle aFontStyle, |
|
92 TInt aFontSizeInTwips, |
|
93 const TDesC& aFontFamilyName) |
|
94 { |
|
95 TTypeface typeface; |
|
96 typeface.iName = aFontFamilyName.Left(KMaxTypefaceNameLength); |
|
97 typeface.SetIsProportional(ETrue); |
|
98 return DoGetFont(aBitmapDevice, aFontStyle, aFontSizeInTwips, typeface, ETrue ); |
|
99 } |
|
100 |
|
101 |
|
102 EXPORT_C CFbsFont* AknFontAccess::GetClosestFont( |
|
103 CBitmapDevice& aBitmapDevice, |
|
104 const TFontStyle aFontStyle, |
|
105 TInt aFontSizeInTwips, |
|
106 TAknFontFamily aFontFamily) |
|
107 { |
|
108 TTypeface typeface; // Buffer is just used for the typeface alias. |
|
109 MapFontFamilyToGenericAlias(aFontFamily, typeface); |
|
110 return DoGetFont(aBitmapDevice, aFontStyle, aFontSizeInTwips, typeface, EFalse); |
|
111 } |
|
112 |
|
113 EXPORT_C CFbsFont* AknFontAccess::GetClosestFont( |
|
114 CBitmapDevice& aBitmapDevice, |
|
115 const TFontStyle aFontStyle, |
|
116 TInt aFontSizeInTwips, |
|
117 const TDesC& aFontFamilyName) |
|
118 { |
|
119 TTypeface typeface; |
|
120 typeface.iName = aFontFamilyName.Left(KMaxTypefaceNameLength); |
|
121 typeface.SetIsProportional(ETrue); |
|
122 return DoGetFont(aBitmapDevice, aFontStyle, aFontSizeInTwips, typeface, EFalse ); |
|
123 } |
|
124 |
|
125 CFbsFont* AknFontAccess::DoGetFont( |
|
126 CBitmapDevice& aBitmapDevice, |
|
127 const TFontStyle aFontStyle, |
|
128 TInt aFontSizeInTwips, |
|
129 const TTypeface& aTypeface, |
|
130 TBool aExactMatchRequired) |
|
131 { |
|
132 TAknFontSpecification spec(KAknFontCategoryUndefined); |
|
133 spec.SetUnits(TAknFontSpecification::ETwips); // Causes implicit SetScalesInTwips(ETrue); |
|
134 spec.SetTextPaneHeightIsDesignHeight(ETrue); // Suppresses "font size downscaling" |
|
135 spec.SetExactMatchRequired( aExactMatchRequired ); // Supresses fallbacks in FontProvider |
|
136 |
|
137 spec.SetTextPaneHeight(aFontSizeInTwips); |
|
138 spec.SetWeight( aFontStyle.StrokeWeight()); |
|
139 spec.SetPosture( aFontStyle.Posture()); |
|
140 |
|
141 // Unused interfaces: |
|
142 TAknFontProviderSuppliedMetrics suppliedMetrics; |
|
143 TInt fontProviderIndex; |
|
144 |
|
145 return AknFontProvider::CreateFontFromTypefaceAndMetrics ( |
|
146 aBitmapDevice, aTypeface, spec, suppliedMetrics, fontProviderIndex ); |
|
147 } |
|
148 |
|
149 EXPORT_C CAknLayoutFont* AknFontAccess::CreateLayoutFontFromSpecificationL( |
|
150 CBitmapDevice& aBitmapDevice, |
|
151 const TAknFontSpecification& aSpec ) |
|
152 { |
|
153 return CAknFontSpecificationLayoutFont::NewL( aBitmapDevice, aSpec ); |
|
154 } |
|
155 |
|
156 EXPORT_C CAknLayoutFont* AknFontAccess::CreateLayoutFontFromSpecificationL( |
|
157 CBitmapDevice& aBitmapDevice, |
|
158 const TTypeface& aTypeface, |
|
159 const TAknFontSpecification& aSpec ) |
|
160 { |
|
161 return CAknFontSpecificationLayoutFont::NewL( aBitmapDevice, aTypeface, aSpec ); |
|
162 } |
|
163 |
|
164 // End of file |
|
165 |