|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "FontsCache.h" |
|
17 |
|
18 NONSHARABLE_CLASS(CCachedFont) : public CFbsFont |
|
19 { |
|
20 public: |
|
21 CCachedFont(); |
|
22 ~CCachedFont(); |
|
23 |
|
24 TInt Duplicate(TInt aHandle); //lint !e1511 |
|
25 }; |
|
26 |
|
27 CCachedFont::CCachedFont() |
|
28 { |
|
29 } |
|
30 |
|
31 CCachedFont::~CCachedFont() |
|
32 { |
|
33 } |
|
34 |
|
35 TInt CCachedFont::Duplicate(TInt aHandle) |
|
36 { |
|
37 return CFbsFont::Duplicate(aHandle); |
|
38 } |
|
39 |
|
40 CFontsCache::CFontsCache() : CCacheBase() |
|
41 { |
|
42 } |
|
43 |
|
44 CFontsCache::~CFontsCache() |
|
45 { |
|
46 } |
|
47 |
|
48 /** |
|
49 Enables the use of a cached font with a specified handle. |
|
50 If no font with this handle is cached, the font is created and cached. |
|
51 |
|
52 @return KErrNone if no problem occured, otherwise a systemwide error. |
|
53 */ |
|
54 TInt CFontsCache::UseL(TInt aHandle) |
|
55 { |
|
56 TCacheEntry entry(aHandle); |
|
57 TInt index = iCachedItems.FindInUnsignedKeyOrder(entry); |
|
58 if(index != KErrNotFound) |
|
59 { |
|
60 iCachedItems[index].iIsUsed = ETrue; |
|
61 return KErrNone; |
|
62 } |
|
63 |
|
64 entry.iCachedItem = new (ELeave) CCachedFont; |
|
65 TInt err = static_cast<CCachedFont*>(entry.iCachedItem)->Duplicate(aHandle); |
|
66 if(err) |
|
67 { |
|
68 delete entry.iCachedItem; |
|
69 return err; |
|
70 } |
|
71 |
|
72 entry.iIsUsed = ETrue; |
|
73 CleanupStack::PushL(entry.iCachedItem); |
|
74 iCachedItems.InsertInUnsignedKeyOrderL(entry); |
|
75 CleanupStack::Pop(entry.iCachedItem); |
|
76 return KErrNone; |
|
77 } |
|
78 |
|
79 /** |
|
80 Returns a font from the cache corresponding to a specific handle. |
|
81 |
|
82 @param aHandle A handle to match against a font in the cache. |
|
83 @return The font that matches the handle provided as a parameter. |
|
84 */ |
|
85 const CFont* CFontsCache::Resolve(TInt aHandle) |
|
86 { |
|
87 const CBase* item = CCacheBase::Resolve(aHandle); |
|
88 if(item != NULL) |
|
89 return static_cast<const CCachedFont*>(item); |
|
90 else |
|
91 return NULL; |
|
92 } |
|
93 |