author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 11:34:25 +0300 | |
changeset 51 | a7c938434754 |
parent 44 | 601ab138ba0b |
child 57 | 01e38b33e72a |
permissions | -rw-r--r-- |
32 | 1 |
/* |
2 |
* Copyright (c) 2003-2010 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 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include <fntstore.h> |
|
20 |
#include <gdi.h> |
|
21 |
#include "FNTSTD.H" |
|
22 |
#include <graphics/shapeimpl.h> |
|
23 |
#include "ShaperCache.H" |
|
24 |
#include "openfontsprivate.h" |
|
25 |
#include <linkedfonts.h> |
|
26 |
#include "linkedfontsprivate.h" |
|
27 |
#include <graphics/openfontrasterizer.h> |
|
28 |
#include <graphics/gdi/glyphsample.h> |
|
29 |
||
44
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
30 |
#include "OstTraceDefinitions.h" |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
31 |
#ifdef OST_TRACE_COMPILER_IN_USE |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
32 |
#include "OPENFONTTraces.h" |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
33 |
#endif |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
34 |
|
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
35 |
|
32 | 36 |
const TInt KSessionCacheEntries = 512; |
37 |
const TInt KDefaultSlantFactor = 20480; |
|
38 |
const TInt KOneIn16Dot16FixedPointFormat = 65536; |
|
39 |
||
40 |
template<class T> |
|
41 |
ROffsetArray<T>::ROffsetArray() |
|
42 |
: iOffset(0), iCount(0) |
|
43 |
{} |
|
44 |
||
45 |
template<class T> |
|
46 |
TInt ROffsetArray<T>::Create(RHeap* aHeap, TInt aCount) |
|
47 |
{ |
|
48 |
if (iOffset != 0) |
|
49 |
{ |
|
50 |
return KErrAlreadyExists; |
|
51 |
} |
|
52 |
TAny* p = aHeap->AllocZ(aCount * sizeof(TInt)); |
|
53 |
if (p == NULL) |
|
54 |
{ |
|
55 |
return KErrNoMemory; |
|
56 |
} |
|
57 |
iOffset = (TInt)p - (TInt)this; |
|
58 |
iCount = aCount; |
|
59 |
return KErrNone; |
|
60 |
} |
|
61 |
||
62 |
template<class T> |
|
63 |
void ROffsetArray<T>::Close(RHeap* aHeap) |
|
64 |
{ |
|
65 |
if (iOffset != 0) |
|
66 |
{ |
|
67 |
aHeap->Free(PtrAdd(this, iOffset)); |
|
68 |
} |
|
69 |
iOffset = 0; |
|
70 |
iCount = 0; |
|
71 |
} |
|
72 |
||
73 |
template<class T> |
|
74 |
TInt ROffsetArray<T>::Count() const |
|
75 |
{ |
|
76 |
return iCount; |
|
77 |
} |
|
78 |
||
79 |
template<class T> |
|
80 |
T* ROffsetArray<T>::operator[](TInt aIndex) const |
|
81 |
{ |
|
82 |
TInt e = ((TInt*)PtrAdd(this, iOffset))[aIndex]; |
|
83 |
return e != 0 ? (T*)PtrAdd(this, e) : NULL; |
|
84 |
} |
|
85 |
||
86 |
template<class T> |
|
87 |
void ROffsetArray<T>::SetAt(TInt aIndex, T* aEntry) |
|
88 |
{ |
|
89 |
((TInt*)PtrAdd(this, iOffset))[aIndex] = aEntry ? (TInt)aEntry - (TInt)this : 0; |
|
90 |
} |
|
91 |
||
92 |
||
93 |
/*COpenFontGlyphCache*/ |
|
94 |
||
95 |
TShapeHeader* COpenFontGlyphCache::SearchShaperCache(TInt aSessionHandle, TFontShapeFunctionParameters*& aParams) |
|
96 |
{ |
|
97 |
if (iShaperCacheSentinel == NULL) |
|
98 |
return NULL; |
|
99 |
COpenFontShaperCacheEntry* searchNode = iShaperCacheSentinel->iNext; |
|
100 |
||
101 |
TInt start = aParams->iStart; |
|
102 |
TInt end = aParams->iEnd; |
|
103 |
TInt script = aParams->iScript; |
|
104 |
const TUint16* text = (TUint16*)aParams->iText->Ptr(); |
|
105 |
TUint16* cachedText; |
|
106 |
const TUint16* copyOfText; |
|
107 |
TInt noOfChars = end - start; |
|
108 |
TInt textIsSame = 1; |
|
109 |
while (searchNode != iShaperCacheSentinel) |
|
110 |
{ |
|
111 |
//Future work: add Script check for further script support |
|
112 |
//Future work: add Language check for further language support |
|
113 |
if ((searchNode->iEnd == end) && (searchNode->iStart == start) && (searchNode->iScript == script)) |
|
114 |
{ |
|
115 |
// Check for the entire text (within the context) coming in. |
|
116 |
TInt i = 0; |
|
117 |
copyOfText = text + start; |
|
118 |
cachedText = (TUint16*)searchNode->iText + searchNode->iStart; |
|
119 |
textIsSame = 1; |
|
120 |
while (i < noOfChars && textIsSame != 0) |
|
121 |
{ |
|
122 |
if (*cachedText != *copyOfText) |
|
123 |
textIsSame = 0; |
|
124 |
i++; |
|
125 |
copyOfText++; |
|
126 |
cachedText++; |
|
127 |
}; |
|
128 |
||
129 |
if (textIsSame) |
|
130 |
{ |
|
131 |
if (searchNode == iShaperCacheSentinel->iNext) |
|
132 |
{ |
|
133 |
// now we need to update the reference count here for that session |
|
134 |
if (searchNode->IncRefCount(aSessionHandle) != KErrNone) |
|
135 |
return NULL; |
|
136 |
return iShaperCacheSentinel->iNext->iShapeHeader; |
|
137 |
} |
|
138 |
// We have found a node, now put that node to the top of the list as the most recently used node |
|
139 |
searchNode->iPrevious->iNext = searchNode->iNext; |
|
140 |
searchNode->iNext->iPrevious = searchNode->iPrevious; |
|
141 |
||
142 |
searchNode->iNext = iShaperCacheSentinel->iNext; |
|
143 |
iShaperCacheSentinel->iNext->iPrevious = searchNode; |
|
144 |
iShaperCacheSentinel->iNext = searchNode; |
|
145 |
searchNode->iPrevious = iShaperCacheSentinel; |
|
146 |
if (searchNode->IncRefCount(aSessionHandle)!= KErrNone) |
|
147 |
return NULL; |
|
148 |
return searchNode->iShapeHeader; |
|
149 |
} |
|
150 |
} |
|
151 |
searchNode = searchNode->iNext; |
|
152 |
} |
|
153 |
return NULL; |
|
154 |
} |
|
155 |
||
156 |
TShapeHeader* COpenFontGlyphCache::Insert(TInt aSessionHandle, RHeap* aHeap, CShaper::TInput aInput, TShapeHeader* aShapeHeader, TInt& aAddedBytes) |
|
157 |
{ |
|
158 |
TInt heapSizeBefAloc = 0; |
|
159 |
aHeap->AllocSize(heapSizeBefAloc); |
|
160 |
||
161 |
COpenFontShaperCacheEntry* new_entry; |
|
162 |
new_entry = COpenFontShaperCacheEntry::New(aHeap, aInput, aShapeHeader); |
|
163 |
if (new_entry != NULL) |
|
164 |
{ |
|
165 |
// increase the reference count for this |
|
166 |
TInt ret=new_entry->IncRefCount(aSessionHandle); |
|
167 |
if (ret != KErrNone) |
|
168 |
{ |
|
169 |
//no memory here |
|
170 |
COpenFontShaperCacheEntry::Delete(aHeap, new_entry); |
|
171 |
return NULL; |
|
172 |
} |
|
173 |
new_entry->iNext = iShaperCacheSentinel->iNext; |
|
174 |
iShaperCacheSentinel->iNext->iPrevious = new_entry; |
|
175 |
iShaperCacheSentinel->iNext = new_entry; |
|
176 |
new_entry->iPrevious = iShaperCacheSentinel; |
|
177 |
||
178 |
iNumberOfShaperCacheEntries++; |
|
179 |
TInt heapSizeOnAloc = 0; |
|
180 |
aHeap->AllocSize(heapSizeOnAloc); |
|
181 |
aAddedBytes = heapSizeOnAloc - heapSizeBefAloc; |
|
182 |
||
183 |
// Update the amount of memory used in creation of a new entry |
|
184 |
iShapingInfoCacheMemory += heapSizeOnAloc - heapSizeBefAloc; |
|
185 |
||
186 |
return new_entry->iShapeHeader; |
|
187 |
} |
|
188 |
return NULL; |
|
189 |
} |
|
190 |
||
191 |
/** |
|
192 |
Searches from the least recently used towards the most recently used |
|
193 |
and try to free entry that is no longer referenced |
|
194 |
*/ |
|
195 |
TInt COpenFontGlyphCache::DeleteLeastRecentlyUsedEntry(RHeap* aHeap) |
|
196 |
{ |
|
197 |
// start from the least recently used |
|
198 |
COpenFontShaperCacheEntry* deleteNode = iShaperCacheSentinel->iPrevious; |
|
199 |
||
200 |
// if empty list there is nothing to delete |
|
201 |
if (deleteNode == iShaperCacheSentinel) |
|
202 |
return 0; |
|
203 |
// else navigating starting from the LRU entry |
|
204 |
while (deleteNode != iShaperCacheSentinel) |
|
205 |
{ |
|
206 |
// cannot delete if the iHandleRefCount is greater than zero |
|
207 |
if (deleteNode->iHandleRefCount>0) |
|
208 |
{ |
|
209 |
deleteNode = deleteNode->iPrevious; |
|
210 |
continue; |
|
211 |
} |
|
212 |
||
213 |
// otherwise we can delete the entry |
|
214 |
deleteNode->iPrevious->iNext = deleteNode->iNext; |
|
215 |
deleteNode->iNext->iPrevious = deleteNode->iPrevious; |
|
216 |
||
217 |
TInt heapSizeBeforeDel = 0; |
|
218 |
TInt heapSizeAfterDel = 0; |
|
219 |
aHeap->AllocSize(heapSizeBeforeDel); |
|
220 |
COpenFontShaperCacheEntry::Delete(aHeap, deleteNode); |
|
221 |
aHeap->AllocSize(heapSizeAfterDel); |
|
222 |
TInt deletedBytes = heapSizeBeforeDel - heapSizeAfterDel; |
|
223 |
||
224 |
iNumberOfShaperCacheEntries--; |
|
225 |
iShapingInfoCacheMemory -= deletedBytes; |
|
226 |
||
227 |
return deletedBytes; |
|
228 |
} |
|
229 |
// we have navigated through the whole list and cannot delete anything |
|
230 |
return 0; |
|
231 |
} |
|
232 |
||
233 |
TInt COpenFont::DecrementCachedRefCount(TInt aSessionHandle, TShapeHeader* aShapeHeader, TBool aResetAll) |
|
234 |
{ |
|
235 |
COpenFontShaperCacheEntry* ptr=NULL; |
|
236 |
COpenFontGlyphCache* glyphCache=GetGlyphCache(); |
|
237 |
if (glyphCache != NULL) |
|
238 |
ptr=glyphCache->iShaperCacheSentinel; |
|
239 |
if (ptr == NULL) |
|
240 |
return KErrNone; |
|
241 |
||
242 |
TInt ret = KErrNotFound; |
|
243 |
CFontStore* thisFontStore = File()->GetFontStore(); |
|
244 |
TInt allocBefDec = 0; |
|
245 |
TInt allocAfterDec = 0; |
|
246 |
TInt deletedBytes = 0; |
|
247 |
||
248 |
// loop through the cache entry to decrement the ref count for a particular session |
|
249 |
while (ptr->iNext != NULL) |
|
250 |
{ |
|
251 |
if (aResetAll) |
|
252 |
{ |
|
253 |
// we want to reset any cache that has a matching the session handle |
|
254 |
// i.e. here we dont care about which TShapeHeader and hence we can |
|
255 |
// ignore the error code here if not found |
|
256 |
||
257 |
// Always update the memory usage of the cache as decreasing the ref count |
|
258 |
// releases memory |
|
259 |
iHeap->AllocSize(allocBefDec); |
|
260 |
||
261 |
ptr->DecRefCount(aSessionHandle, ETrue); |
|
262 |
||
263 |
iHeap->AllocSize(allocAfterDec); |
|
264 |
deletedBytes = allocBefDec - allocAfterDec; |
|
265 |
glyphCache->iShapingInfoCacheMemory -= deletedBytes; |
|
266 |
thisFontStore->SetShaperCacheMemUsage(thisFontStore->GetShaperCacheMemUsage() - deletedBytes); |
|
267 |
||
268 |
ret=KErrNone; |
|
269 |
} |
|
270 |
else if (ptr->iShapeHeader != NULL && ptr->iShapeHeader==aShapeHeader) |
|
271 |
{ |
|
272 |
// Always update the memory usage of the cache as decreasing the ref count |
|
273 |
// releases memory |
|
274 |
iHeap->AllocSize(allocBefDec); |
|
275 |
||
276 |
ptr->DecRefCount(aSessionHandle); |
|
277 |
||
278 |
iHeap->AllocSize(allocAfterDec); |
|
279 |
deletedBytes = allocBefDec - allocAfterDec; |
|
280 |
glyphCache->iShapingInfoCacheMemory -= deletedBytes; |
|
281 |
thisFontStore->SetShaperCacheMemUsage(thisFontStore->GetShaperCacheMemUsage() - deletedBytes); |
|
282 |
||
283 |
return KErrNone; |
|
284 |
} |
|
285 |
ptr=ptr->iNext; |
|
286 |
if (ptr == glyphCache->iShaperCacheSentinel) |
|
287 |
{ |
|
288 |
break; |
|
289 |
} |
|
290 |
} |
|
291 |
return ret; |
|
292 |
} |
|
293 |
||
294 |
TInt COpenFont::FreeShaperCacheMemory(TInt aBytesNeeded) |
|
295 |
{ |
|
296 |
TInt totalDeletedBytes = 0; |
|
297 |
TInt tempDeletedBytes = 0; |
|
298 |
CFontStore* thisFontStore = File()->GetFontStore(); |
|
299 |
||
300 |
if (aBytesNeeded <= KMaxShaperSesssionCacheMemory) |
|
301 |
{ |
|
302 |
// delete LRU entries from all the caches except the one owned by this COpenFont |
|
303 |
// The 'if' condition here is to avoid looping through every font in the system |
|
304 |
// if only one of the them has a non-empty cache. In situations where only one |
|
305 |
// cache is left and it is full, this strategy makes freeing the memory faster. |
|
306 |
if (thisFontStore->GetNumShaperCaches() > 1) |
|
307 |
{ |
|
308 |
CArrayPtrFlat<COpenFont>* fontList; |
|
309 |
CArrayPtrFlat<COpenFontFile>* fontFileList = thisFontStore->GetOpenFontFileList(); |
|
310 |
TInt numberOfFontFiles = fontFileList->Count(); |
|
311 |
TInt i = 0; |
|
312 |
while ((totalDeletedBytes < aBytesNeeded) && (i < numberOfFontFiles)) |
|
313 |
{ |
|
314 |
fontList = (*fontFileList)[i]->GetOpenFontList(); |
|
315 |
TInt fontListCount=fontList->Count(); |
|
316 |
TInt j = 0; |
|
317 |
while ((totalDeletedBytes < aBytesNeeded) && (j < fontListCount)) |
|
318 |
{ |
|
319 |
COpenFont* open_font = (*fontList)[j]; |
|
320 |
COpenFontGlyphCache* glyphCache = open_font->GetGlyphCache(); |
|
321 |
if ((open_font != this) && (glyphCache != NULL)) |
|
322 |
{ |
|
323 |
while ((totalDeletedBytes < aBytesNeeded) && (!glyphCache->ShaperCacheIsEmpty())) |
|
324 |
{ |
|
325 |
totalDeletedBytes += glyphCache->DeleteLeastRecentlyUsedEntry(iHeap); |
|
326 |
if (glyphCache->ShaperCacheIsEmpty()) |
|
327 |
{ |
|
328 |
thisFontStore->DecNumShaperCaches(); |
|
329 |
} |
|
330 |
||
331 |
// If totalDeletedBytes is zero mean we cannot delete from this font |
|
332 |
if (totalDeletedBytes == 0) |
|
333 |
{ |
|
334 |
break; |
|
335 |
} |
|
336 |
} |
|
337 |
} |
|
338 |
j++; |
|
339 |
} |
|
340 |
i++; |
|
341 |
} |
|
342 |
} |
|
343 |
||
344 |
// If deleted bytes are still less than the required one delete from this font |
|
345 |
COpenFontGlyphCache* glyphCache = GetGlyphCache(); |
|
346 |
if (glyphCache != NULL) |
|
347 |
{ |
|
348 |
while (totalDeletedBytes < aBytesNeeded && !glyphCache->ShaperCacheIsEmpty()) |
|
349 |
{ |
|
350 |
tempDeletedBytes = glyphCache->DeleteLeastRecentlyUsedEntry(iHeap); |
|
351 |
if (tempDeletedBytes == 0) |
|
352 |
break; |
|
353 |
totalDeletedBytes += tempDeletedBytes; |
|
354 |
} |
|
355 |
} //if(glyphCache) |
|
356 |
} //if(aBytesNeeded <= KMaxShaperSesssionCacheMemory) |
|
357 |
||
358 |
// Update the global CFontStore cache memory count |
|
359 |
if (totalDeletedBytes > 0) |
|
360 |
{ |
|
361 |
thisFontStore->SetShaperCacheMemUsage(thisFontStore->GetShaperCacheMemUsage() - totalDeletedBytes); |
|
362 |
} |
|
363 |
||
364 |
return totalDeletedBytes; |
|
365 |
} |
|
366 |
||
367 |
TShapeHeader* COpenFont::InsertShapedDataIntoCache(TInt aSessionHandle,TFontShapeFunctionParameters* aParams, TShapeHeader* aShapeHeader) |
|
368 |
{ |
|
369 |
CShaper::TInput input; |
|
370 |
input.iEnd = aParams->iEnd; |
|
371 |
input.iStart = aParams->iStart; |
|
372 |
input.iScript = aParams->iScript; |
|
373 |
input.iLanguage = aParams->iLanguage; |
|
374 |
input.iText = aParams->iText; |
|
375 |
input.iMaximumAdvance = KMaxTInt; |
|
376 |
input.iFlags = 0; |
|
377 |
input.iSessionHandle = aSessionHandle; |
|
378 |
input.iReserved1 = 0; |
|
379 |
||
380 |
CFontStore* thisFontStore = File()->GetFontStore(); |
|
381 |
||
382 |
// Create the glyph cache if it doesn't already exist. |
|
383 |
// This call can only come from FBSERV |
|
384 |
COpenFontGlyphCache* glyphCache = GetGlyphCache(); |
|
385 |
if (glyphCache == NULL) |
|
386 |
{ |
|
387 |
glyphCache = (COpenFontGlyphCache*) iHeap->Alloc(sizeof(COpenFontGlyphCache)); |
|
388 |
if (glyphCache == NULL) // no memory |
|
389 |
{ |
|
390 |
return NULL; |
|
391 |
} |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
392 |
new (glyphCache) COpenFontGlyphCache(iHeap); |
32 | 393 |
SetGlyphCache(glyphCache); |
394 |
} |
|
395 |
// If there is no sentinel present, i.e. new cache |
|
396 |
if (glyphCache->iShaperCacheSentinel == NULL) |
|
397 |
{ |
|
398 |
// Create a sentinel |
|
399 |
glyphCache->iShaperCacheSentinel = COpenFontShaperCacheEntry::New(iHeap); |
|
400 |
if (glyphCache->iShaperCacheSentinel == NULL) |
|
401 |
{ |
|
402 |
// no memory |
|
403 |
return NULL; |
|
404 |
} |
|
405 |
glyphCache->iShaperCacheSentinel->iNext = glyphCache->iShaperCacheSentinel; |
|
406 |
glyphCache->iShaperCacheSentinel->iPrevious = glyphCache->iShaperCacheSentinel; |
|
407 |
glyphCache->iNumberOfShaperCacheEntries = 1; |
|
408 |
} |
|
409 |
||
410 |
// Before inserting into this cache, check if it was empty. |
|
411 |
// If empty, then increment the global cache count signifying one more cache is active |
|
412 |
if (glyphCache->ShaperCacheIsEmpty()) |
|
413 |
{ |
|
414 |
thisFontStore->IncNumShaperCaches(); |
|
415 |
} |
|
416 |
||
417 |
TInt addedBytes = 0; |
|
418 |
TShapeHeader* cached_header = NULL; |
|
419 |
||
420 |
// Insert a new entry and return the newly inserted TShapeHeader entry |
|
421 |
cached_header = glyphCache->Insert(aSessionHandle, iHeap, input, aShapeHeader, addedBytes); |
|
422 |
if (cached_header == NULL) |
|
423 |
return NULL; |
|
424 |
||
425 |
// If the memory used by all the caches is greater than KMaxShaperSesssionCacheMemory, then |
|
426 |
// free some memory by releasing the same amount of memory that was just added |
|
427 |
if (thisFontStore->GetShaperCacheMemUsage() + addedBytes > KMaxShaperSesssionCacheMemory) |
|
428 |
{ |
|
429 |
FreeShaperCacheMemory(addedBytes); |
|
430 |
} |
|
431 |
||
432 |
// Now update the memory count with the added memory for the new entry |
|
433 |
thisFontStore->SetShaperCacheMemUsage(thisFontStore->GetShaperCacheMemUsage() + addedBytes); |
|
434 |
return cached_header; |
|
435 |
} |
|
436 |
||
437 |
TShapeHeader* COpenFont::GetShapedData(TInt aSessionHandle, TFontShapeFunctionParameters* aParams) |
|
438 |
{ |
|
439 |
COpenFontGlyphCache* glyphCache = GetGlyphCache(); |
|
440 |
if (glyphCache == NULL) |
|
441 |
return NULL; |
|
442 |
||
443 |
TShapeHeader* cachedHeader = NULL; |
|
444 |
CFontStore* thisFontStore = File()->GetFontStore(); |
|
445 |
||
446 |
// Always update the memory usage of the cache as increasing the reference count of a found header uses up memory |
|
447 |
TInt allocBefInc = 0; |
|
448 |
TInt allocAfterInc = 0; |
|
449 |
iHeap->AllocSize(allocBefInc); |
|
450 |
||
451 |
cachedHeader = glyphCache->SearchShaperCache(aSessionHandle,aParams); |
|
452 |
||
453 |
iHeap->AllocSize(allocAfterInc); |
|
454 |
TInt addedBytes = allocAfterInc - allocBefInc; |
|
455 |
glyphCache->iShapingInfoCacheMemory += addedBytes; |
|
456 |
thisFontStore->SetShaperCacheMemUsage(thisFontStore->GetShaperCacheMemUsage() + addedBytes); |
|
457 |
||
458 |
return cachedHeader; |
|
459 |
} |
|
460 |
||
461 |
TBool COpenFontGlyphCache::ShaperCacheIsEmpty() |
|
462 |
{ |
|
463 |
if (iShaperCacheSentinel == NULL) |
|
464 |
return ETrue; |
|
465 |
||
466 |
if (iShaperCacheSentinel->iNext == iShaperCacheSentinel) |
|
467 |
return ETrue; |
|
468 |
else |
|
469 |
return EFalse; |
|
470 |
} |
|
471 |
||
472 |
/** |
|
473 |
C++ constructor taking shared heap, session cache list and font file as parameters. |
|
474 |
||
475 |
You must either use this, or the other constructor, when creating your derived |
|
476 |
object. This constructor might be used, in preference to the other, if there |
|
477 |
is only a single typeface in the font file. |
|
478 |
||
479 |
@param aHeap The shared heap. |
|
480 |
@param aSessionCacheList The session cache list. |
|
481 |
@param aFile A pointer to the COpenFontFile object creating this COpenFont. |
|
482 |
e.g. when creating a COpenFont the COpenFontFile derived object would pass |
|
483 |
it this. |
|
484 |
*/ |
|
485 |
EXPORT_C COpenFont::COpenFont(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList, |
|
486 |
COpenFontFile* aFile): |
|
487 |
iHeap(aHeap), |
|
488 |
iShaper(NULL), |
|
489 |
iFaceIndex(0) |
|
490 |
{ |
|
491 |
SetFile(aFile); |
|
492 |
SetSessionCacheList(aSessionCacheList); |
|
493 |
} |
|
494 |
||
495 |
/** |
|
496 |
C++ constructor taking shared heap, session cache list, font file and face |
|
497 |
index as parameters. |
|
498 |
||
499 |
You must either use this, or the other constructor, when creating your derived |
|
500 |
object. This constructor would be used if the font file contains more than |
|
501 |
one typeface. |
|
502 |
||
503 |
@param aHeap The shared heap. |
|
504 |
@param aSessionCacheList The session cache list. |
|
505 |
@param aFile A pointer to the COpenFontFile object creating this COpenFont. |
|
506 |
e.g. when creating a COpenFont the COpenFontFile derived object would pass |
|
507 |
it this. |
|
508 |
@param aFaceIndex The index of the typeface within the font file aFile. |
|
509 |
*/ |
|
510 |
EXPORT_C COpenFont::COpenFont(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList, COpenFontFile* aFile,TInt aFaceIndex) : |
|
511 |
iHeap(aHeap), |
|
512 |
iShaper(NULL), |
|
513 |
iFaceIndex(aFaceIndex) |
|
514 |
{ |
|
515 |
SetFile(aFile); |
|
516 |
SetSessionCacheList(aSessionCacheList); |
|
517 |
} |
|
518 |
||
519 |
/** |
|
520 |
Destructor |
|
521 |
||
522 |
This function frees all memory owned by the object, including the session |
|
523 |
cache list and the glyph list, prior to its destruction. |
|
524 |
*/ |
|
525 |
EXPORT_C COpenFont::~COpenFont() |
|
526 |
{ |
|
527 |
//Delete the shaper |
|
528 |
delete iShaper; |
|
529 |
||
530 |
File()->GetFontStore()->CleanupCacheOnOpenFontRemoval(this); |
|
531 |
||
532 |
COpenFontGlyphCache* glyphCache = GetGlyphCache(); |
|
533 |
if (glyphCache != NULL) |
|
534 |
{ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
535 |
glyphCache->iGlyphTreeById.ResetAndDestroy(); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
536 |
glyphCache->iGlyphTreeByUnicode.ResetAndDestroy(); |
32 | 537 |
|
538 |
// Delete the shaper cache as well |
|
539 |
if (glyphCache->iShaperCacheSentinel) |
|
540 |
{ |
|
541 |
COpenFontShaperCacheEntry* previous = NULL; |
|
542 |
COpenFontShaperCacheEntry* si = glyphCache->iShaperCacheSentinel->iPrevious; |
|
543 |
TInt heapBefore = 0; |
|
544 |
TInt heapAfter = 0; |
|
545 |
iHeap->AllocSize(heapBefore); |
|
546 |
while (glyphCache->iNumberOfShaperCacheEntries > 0) |
|
547 |
{ |
|
548 |
previous = si->iPrevious; |
|
549 |
COpenFontShaperCacheEntry::Delete(iHeap, si); |
|
550 |
si = previous; |
|
551 |
glyphCache->iNumberOfShaperCacheEntries--; |
|
552 |
} |
|
553 |
iHeap->AllocSize(heapAfter); |
|
554 |
File()->GetFontStore()->SetShaperCacheMemUsage(File()->GetFontStore()->GetShaperCacheMemUsage() - (heapBefore - heapAfter)); |
|
555 |
File()->GetFontStore()->DecNumShaperCaches(); |
|
556 |
} |
|
557 |
||
558 |
iHeap->Free(glyphCache); |
|
559 |
} |
|
560 |
COpenFontSessionCacheList* sessionCacheList = SessionCacheList(); |
|
561 |
if (sessionCacheList != NULL) |
|
562 |
{ |
|
563 |
sessionCacheList->DeleteFontGlyphs(iHeap, this); |
|
564 |
} |
|
565 |
COpenFontFile* file = File(); |
|
566 |
if (file != NULL) |
|
567 |
{ |
|
568 |
file->RemoveFontFromList(this); |
|
569 |
} |
|
570 |
} |
|
571 |
||
572 |
EXPORT_C void COpenFont::operator delete(TAny *aFont) |
|
573 |
{ |
|
574 |
if(aFont != NULL) |
|
575 |
{ |
|
576 |
COpenFont* f = (COpenFont*)aFont; |
|
577 |
if (f->iHeap) |
|
578 |
f->iHeap->Free(aFont); |
|
579 |
} |
|
580 |
} |
|
581 |
||
582 |
/** |
|
583 |
Rasterize a glyph |
|
584 |
||
585 |
This function may only be called via an FBSERV message. |
|
586 |
||
587 |
@param aSessionHandle Session handle of the calling session |
|
588 |
@param aCode Unicode value or glyph code if top bit is set |
|
589 |
@param aGlyphData |
|
590 |
Output data. May be null, in which case output may be |
|
591 |
obtained through a call to GetCharacterData. |
|
592 |
||
593 |
@return |
|
594 |
ETrue if aGlyphData contains valid data (that is, if aGlyphData->Bitmap() |
|
595 |
and aGlyphData->Metrics() are valid), EFalse otherwise. |
|
596 |
*/ |
|
597 |
TBool COpenFont::Rasterize(TInt aSessionHandle, TInt aCode, |
|
598 |
TOpenFontGlyphData* aGlyphData) |
|
599 |
{ |
|
600 |
// create the cache if it doesn't exisit. As this call can only come from |
|
601 |
// FBSERV if the chunk has to be resized then no panic will happen. |
|
602 |
COpenFontGlyphCache* glyphCache = GetGlyphCache(); |
|
603 |
if (glyphCache == NULL) |
|
604 |
{ |
|
605 |
glyphCache = (COpenFontGlyphCache*)iHeap->Alloc(sizeof(COpenFontGlyphCache)); |
|
606 |
if (glyphCache == NULL) // no memory |
|
607 |
{ |
|
608 |
return EFalse; |
|
609 |
} |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
610 |
new(glyphCache) COpenFontGlyphCache(iHeap); |
32 | 611 |
SetGlyphCache(glyphCache); |
612 |
} |
|
613 |
||
614 |
// Look in the Font Cache |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
615 |
const COpenFontGlyph* g = FontCacheGlyph(aCode); |
32 | 616 |
|
617 |
// If it has already been rasterized return it. |
|
618 |
if (g != NULL) |
|
619 |
{ |
|
620 |
if (aGlyphData != NULL) |
|
621 |
{ |
|
622 |
aGlyphData->SetMetricsPointer(&g->iMetrics); |
|
623 |
aGlyphData->SetBitmapPointer(g->Bitmap()); |
|
624 |
} |
|
625 |
||
626 |
return ETrue; |
|
627 |
} |
|
628 |
||
629 |
// Rasterize the glyph. |
|
630 |
TOpenFontGlyphData* temp_glyph_data = NULL; |
|
631 |
TInt error = KErrNone; |
|
632 |
TRAP(error, RasterizeHelperL(aCode, aGlyphData, temp_glyph_data)); |
|
633 |
if (error != KErrNone) |
|
634 |
{ |
|
635 |
iHeap->Free(temp_glyph_data); |
|
636 |
return EFalse; |
|
637 |
} |
|
638 |
||
639 |
TBool glyph_data_valid = ETrue; |
|
640 |
const TOpenFontGlyphData* cur_glyph_data = temp_glyph_data ? temp_glyph_data : aGlyphData; |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
641 |
COpenFontGlyph* new_glyph = NULL; |
32 | 642 |
|
643 |
// If the maximum per-font cache memory will not be exceeded, put the glyph into the font cache. |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
644 |
TInt bytes = sizeof(COpenFontGlyph) + cur_glyph_data->BytesNeeded(); |
32 | 645 |
if(glyphCache != NULL && bytes + glyphCache->iGlyphCacheMemory <= KMaxGlyphCacheMemory) |
646 |
{ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
647 |
new_glyph = COpenFontGlyph::New(iHeap, aCode, cur_glyph_data->GlyphIndex(), *cur_glyph_data->Metrics(), cur_glyph_data->Bitmap()); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
648 |
if (new_glyph != NULL) |
32 | 649 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
650 |
if ((aCode & 0x80000000) != 0) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
651 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
652 |
error = glyphCache->iGlyphTreeById.SetAt(aCode & 0x7FFFFFFF, new_glyph); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
653 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
654 |
else |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
655 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
656 |
error = glyphCache->iGlyphTreeByUnicode.SetAt(aCode, new_glyph); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
657 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
658 |
if (error == KErrNone) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
659 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
660 |
glyphCache->iGlyphCacheMemory += bytes; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
661 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
662 |
else |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
663 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
664 |
iHeap->Free(new_glyph); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
665 |
new_glyph = NULL; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
666 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
667 |
} |
32 | 668 |
} |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
669 |
// Otherwise put the glyph into the per-session cache. |
32 | 670 |
else |
671 |
{ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
672 |
// Look in the session cache. Do not expect to find the glyph here |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
673 |
// since the session cache has already been searched client-side. |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
674 |
// However, SessionCacheGlyph() is called so that the session cache is |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
675 |
// created if needed and an index is found where the new glyph will be |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
676 |
// placed when added to the session cache. |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
677 |
COpenFontSessionCache* cache = NULL; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
678 |
TInt index = 0; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
679 |
(void)SessionCacheGlyph(iHeap, aSessionHandle, aCode, cache, index, ETrue); |
32 | 680 |
if (cache == NULL) |
681 |
{ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
682 |
iHeap->Free(temp_glyph_data); |
32 | 683 |
return EFalse; |
684 |
} |
|
685 |
||
686 |
COpenFontSessionCacheEntry* new_entry = |
|
687 |
COpenFontSessionCacheEntry::New(iHeap, this, aCode, cur_glyph_data->GlyphIndex(), *cur_glyph_data->Metrics(), cur_glyph_data->Bitmap()); |
|
688 |
new_glyph = new_entry; |
|
689 |
if (new_entry != NULL) |
|
690 |
{ |
|
691 |
cache->Insert(iHeap, new_entry, index); |
|
692 |
} |
|
693 |
} |
|
694 |
||
695 |
if (temp_glyph_data != NULL) |
|
696 |
{ |
|
697 |
iHeap->Free(temp_glyph_data); |
|
698 |
} |
|
699 |
||
700 |
// Fix up the returned glyph data pointers to point to the actual data. |
|
701 |
if (new_glyph == NULL) |
|
702 |
glyph_data_valid = EFalse; |
|
703 |
else if (aGlyphData != NULL) |
|
704 |
{ |
|
705 |
aGlyphData->SetMetricsPointer(&new_glyph->iMetrics); |
|
706 |
aGlyphData->SetBitmapPointer(new_glyph->Bitmap()); |
|
707 |
} |
|
708 |
||
709 |
return glyph_data_valid; |
|
710 |
} |
|
711 |
||
712 |
void COpenFont::RasterizeHelperL(TInt aCode, TOpenFontGlyphData* aGlyphData, TOpenFontGlyphData*& aTempGlyphData) |
|
713 |
{ |
|
714 |
aTempGlyphData = 0; |
|
715 |
MOpenFontShapingExtension* extensionInterface = 0; |
|
716 |
||
717 |
// if the MSB is set this is a request to rasterize a glyph code |
|
718 |
// rather than a unicode value. This can only be done if the rasterizer |
|
719 |
// supports the extended API. |
|
720 |
if ( aCode & 0x80000000 ) |
|
721 |
{ |
|
722 |
aCode = GLYPH_CODE(aCode); |
|
723 |
// get the extension API for RasterizeGlyphL() if available |
|
724 |
TAny* ext = NULL; |
|
725 |
ExtendedInterface(KUidOpenFontShapingExtension, ext); |
|
726 |
extensionInterface = reinterpret_cast<MOpenFontShapingExtension*>(ext); |
|
727 |
||
728 |
if (extensionInterface == NULL) |
|
729 |
// an attempt to rasterize a glyph when the rasterizer does not |
|
730 |
// support it; best to do nothing |
|
731 |
return; |
|
732 |
} |
|
733 |
TOpenFontGlyphData* currGlyphData = aGlyphData; |
|
734 |
||
735 |
if (currGlyphData == NULL) |
|
736 |
{ |
|
737 |
aTempGlyphData = TOpenFontGlyphData::New(iHeap, 0); |
|
738 |
if (!aTempGlyphData) |
|
739 |
User::Leave(KErrNoMemory); |
|
740 |
currGlyphData = aTempGlyphData; |
|
741 |
} |
|
742 |
||
743 |
if (extensionInterface != NULL) |
|
744 |
extensionInterface->RasterizeGlyphL(aCode, currGlyphData); |
|
745 |
else |
|
746 |
RasterizeL(aCode, currGlyphData); |
|
747 |
||
748 |
// If the GlyphData object was not large enough, create a temporary one |
|
749 |
// that can then be deleted by the caller. |
|
750 |
if (currGlyphData->Overflow()) |
|
751 |
{ |
|
752 |
TInt bytesNeeded = currGlyphData->BytesNeeded(); |
|
753 |
if (aTempGlyphData) |
|
754 |
iHeap->Free(aTempGlyphData); |
|
755 |
aTempGlyphData = TOpenFontGlyphData::New(iHeap, bytesNeeded); |
|
756 |
if (aTempGlyphData == NULL) |
|
757 |
User::Leave(KErrNoMemory); |
|
758 |
||
759 |
currGlyphData = aTempGlyphData; |
|
760 |
||
761 |
// If the extension interface was used above, then use again here |
|
762 |
if (extensionInterface != NULL) |
|
763 |
extensionInterface->RasterizeGlyphL(aCode, currGlyphData); |
|
764 |
else |
|
765 |
RasterizeL(aCode, currGlyphData); |
|
766 |
} |
|
767 |
||
768 |
if (currGlyphData->Metrics() == NULL) |
|
769 |
{ |
|
770 |
User::Leave(KErrArgument); |
|
771 |
} |
|
772 |
} |
|
773 |
||
774 |
/** @internalComponent */ |
|
775 |
void COpenFont::SetShaper(CShaper* aShaper) |
|
776 |
{ |
|
777 |
iShaper = aShaper; |
|
778 |
} |
|
779 |
||
780 |
/** @internalComponent */ |
|
781 |
CShaper* COpenFont::GetShaper() |
|
782 |
{ |
|
783 |
return iShaper; |
|
784 |
} |
|
785 |
||
786 |
/** @internalComponent */ |
|
787 |
TBool COpenFont::HasShaper() const |
|
788 |
{ |
|
789 |
return iShaper != NULL; |
|
790 |
} |
|
791 |
||
792 |
void COpenFont::DeleteShaper() const |
|
793 |
{ |
|
794 |
delete iShaper; |
|
795 |
} |
|
796 |
||
797 |
TInt COpenFont::GetFontTable(TUint32 aTag, TAny*& aTableContent, TInt& aLength) |
|
798 |
{ |
|
799 |
// get the extension API for GetTrueTypeTable() if available |
|
800 |
TAny* ext = NULL; |
|
801 |
ExtendedInterface(KUidOpenFontTrueTypeExtension, ext); |
|
802 |
MOpenFontTrueTypeExtension* extensionInterface = |
|
803 |
reinterpret_cast<MOpenFontTrueTypeExtension*>(ext); |
|
804 |
||
805 |
TInt ret = KErrNone; |
|
806 |
if (extensionInterface == NULL) |
|
807 |
{ |
|
808 |
ret = KErrNotSupported; |
|
809 |
} |
|
810 |
else |
|
811 |
{ |
|
812 |
TUint32 tag = aTag; |
|
813 |
TInt len = 0; |
|
814 |
aTableContent = extensionInterface->GetTrueTypeTable(ret, tag, &len); |
|
815 |
if (KErrNone == ret) |
|
816 |
{ |
|
817 |
aLength = len; |
|
818 |
} |
|
819 |
} |
|
820 |
return ret; |
|
821 |
} |
|
822 |
||
823 |
TInt COpenFont::GetGlyphOutline(TUint aCode, |
|
824 |
TBool aHinted, TAny*& aOutline, TInt &aLength) |
|
825 |
{ |
|
826 |
// get the extension API for GetTrueTypeTable() if available |
|
827 |
TAny* ext = NULL; |
|
828 |
ExtendedInterface(KUidOpenFontGlyphOutlineExtension, ext); |
|
829 |
MOpenFontGlyphOutlineExtension *extensionInterface = |
|
830 |
reinterpret_cast<MOpenFontGlyphOutlineExtension*>(ext); |
|
831 |
||
832 |
TInt ret = KErrNone; |
|
833 |
if (extensionInterface == NULL) |
|
834 |
{ |
|
835 |
ret = KErrNotSupported; |
|
836 |
} |
|
837 |
else |
|
838 |
{ |
|
839 |
ret = extensionInterface->GetGlyphOutline(aCode, ETrue, |
|
840 |
aHinted, aOutline, aLength); |
|
841 |
} |
|
842 |
return ret; |
|
843 |
} |
|
844 |
||
845 |
||
846 |
/** |
|
847 |
A constructor initialised with a TCharacterMetrics object. |
|
848 |
||
849 |
This is the old-style character metrics object. As for other T classes, there |
|
850 |
is no need to explicitly cleanup TOpenFontCharMetrics objects. |
|
851 |
||
852 |
@param aMetrics The old-style metrics object. |
|
853 |
*/ |
|
854 |
EXPORT_C TOpenFontCharMetrics::TOpenFontCharMetrics(const TCharacterMetrics& aMetrics) |
|
855 |
{ |
|
856 |
iWidth = (TInt16)(aMetrics.iMoveInPixels - aMetrics.iLeftAdjustInPixels - aMetrics.iRightAdjustInPixels); |
|
857 |
iHeight = aMetrics.iHeightInPixels; |
|
858 |
iHorizBearingX = aMetrics.iLeftAdjustInPixels; |
|
859 |
iHorizBearingY = aMetrics.iAscentInPixels; |
|
860 |
iHorizAdvance = aMetrics.iMoveInPixels; |
|
861 |
iVertBearingX = 0; |
|
862 |
iVertBearingY = 0; |
|
863 |
iVertAdvance = aMetrics.iHeightInPixels; |
|
864 |
iGlyphBitmapType = 0; |
|
865 |
} |
|
866 |
||
867 |
/** |
|
868 |
Converts a TOpenFontCharacterMetrics object to a TCharacterMetrics. |
|
869 |
||
870 |
@param aMetrics On return, contains the character's old-style metrics. |
|
871 |
@return ETrue if it was possible to get the metrics, otherwise EFalse. |
|
872 |
*/ |
|
873 |
EXPORT_C TBool TOpenFontCharMetrics::GetTCharacterMetrics(TCharacterMetrics& aMetrics) const |
|
874 |
{ |
|
875 |
aMetrics.iAscentInPixels = iHorizBearingY; |
|
876 |
aMetrics.iHeightInPixels = iHeight; |
|
877 |
aMetrics.iLeftAdjustInPixels = iHorizBearingX; |
|
878 |
aMetrics.iMoveInPixels = iHorizAdvance; |
|
879 |
aMetrics.iRightAdjustInPixels = (TInt16)(iHorizAdvance - iHorizBearingX - iWidth); |
|
880 |
return ETrue; |
|
881 |
} |
|
882 |
||
883 |
TBool COpenFont::GetCharacterData(TInt aSessionHandle, TInt aCode, const TOpenFontCharMetrics*& aMetrics, const TUint8*& aBitmap) const |
|
884 |
{ |
|
885 |
const COpenFontGlyph* g = Glyph(aSessionHandle, aCode); |
|
886 |
if (g != NULL) |
|
887 |
{ |
|
888 |
aMetrics = &g->iMetrics; |
|
889 |
aBitmap = g->Bitmap(); |
|
890 |
return ETrue; |
|
891 |
} |
|
892 |
else |
|
893 |
{ |
|
894 |
aMetrics = NULL; |
|
895 |
aBitmap = NULL; |
|
896 |
return EFalse; |
|
897 |
} |
|
898 |
} |
|
899 |
||
900 |
||
901 |
||
902 |
void COpenFont::OnFileDeleted() |
|
903 |
{ |
|
904 |
iFileOffset = 0; |
|
905 |
} |
|
906 |
||
907 |
COpenFontGlyphCache* COpenFont::GetGlyphCache() |
|
908 |
{ |
|
909 |
if (iGlyphCacheOffset == 0) |
|
910 |
{ |
|
911 |
return NULL; |
|
912 |
} |
|
913 |
return reinterpret_cast<COpenFontGlyphCache*>(PtrAdd(this, iGlyphCacheOffset)); |
|
914 |
} |
|
915 |
||
916 |
const COpenFontGlyph* COpenFont::Glyph(TInt aSessionHandle, TInt aCode) const |
|
917 |
{ |
|
918 |
const COpenFontGlyph* glyph = const_cast<COpenFont*>(this)->FontCacheGlyph(aCode); |
|
919 |
if (glyph == NULL) |
|
920 |
{ |
|
921 |
COpenFontSessionCache* cache; |
|
922 |
TInt index; |
|
923 |
glyph = SessionCacheGlyph(iHeap, aSessionHandle, aCode, cache, index, EFalse); |
|
924 |
} |
|
925 |
||
926 |
return glyph; |
|
927 |
} |
|
928 |
||
929 |
/** |
|
930 |
Is the specified character present in the font? |
|
931 |
*/ |
|
932 |
TBool COpenFont::HasCharacterL(TInt aCode) const |
|
933 |
{ |
|
934 |
COpenFontFile* file = File(); |
|
935 |
if (file != NULL) |
|
936 |
return file->HasUnicodeCharacterL(iFaceIndex, aCode); |
|
937 |
else |
|
938 |
return EFalse; |
|
939 |
} |
|
940 |
||
941 |
/** |
|
942 |
Retrieve glyph data from the per-font glyph cache. |
|
943 |
If it is not found return NULL. |
|
944 |
If the cache hasn't been created, then return NULL. |
|
945 |
Previous versions of this function created the cache, but as this function can potentially |
|
946 |
run in the context of threads other than FBSERV the alloc could panic if iHeap's chunk had to |
|
947 |
be resized - this is not allowed by the kernel. |
|
948 |
The cache is now created in COpenFont::Rasterize which can only be called within the context of FBSERV |
|
949 |
@param aCode The code for the glpyh to look for in the cache |
|
950 |
@return A pointer to the requested glyph if it was found in the glyph cache, NULL if it was not found. |
|
951 |
*/ |
|
952 |
const COpenFontGlyph* COpenFont::FontCacheGlyph(TInt aCode) |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
953 |
{ |
32 | 954 |
if (COpenFontGlyphCache* glyphCache = GetGlyphCache()) |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
955 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
956 |
if ((aCode & 0x80000000) != 0) |
32 | 957 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
958 |
return glyphCache->iGlyphTreeById.At(aCode & 0x7FFFFFFF); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
959 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
960 |
else |
32 | 961 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
962 |
return glyphCache->iGlyphTreeByUnicode.At(aCode); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
963 |
} |
32 | 964 |
} |
965 |
||
966 |
// No glyph found |
|
967 |
return NULL; |
|
968 |
} |
|
969 |
||
970 |
/** Retrieve glyph data from the session cache. If the glyph is not in the |
|
971 |
cache, return the cache and glyph index where the glyph data should be put. If |
|
972 |
there is no session cache, optionally create it. |
|
973 |
||
974 |
@param aHeap |
|
975 |
The heap on which to create the new cache, if appropriate. Not used if |
|
976 |
either the appropriate session cache already exists, or if aCreate is |
|
977 |
passed as false |
|
978 |
@param aSessionHandle The session handle |
|
979 |
@param aCode |
|
980 |
The code of the glyph to look up (Unicode or glyph code if the top bit is |
|
981 |
set) |
|
982 |
@param aCache |
|
983 |
Returns the appropriate session cache, or NULL if an attempt to create it |
|
984 |
has failed. |
|
985 |
@param aIndex |
|
986 |
Returns where the glyph is, or should be put |
|
987 |
@param aCreate |
|
988 |
If False, creation of a new cache is inhibited |
|
989 |
@return The glyph data, or null if the glyph is not in the cache |
|
990 |
@internalComponent |
|
991 |
*/ |
|
992 |
const COpenFontGlyph* COpenFont::SessionCacheGlyph(RHeap* aHeap, |
|
993 |
TInt aSessionHandle, TInt aCode, COpenFontSessionCache*& aCache, |
|
994 |
TInt& aIndex, TBool aCreate) const |
|
995 |
{ |
|
996 |
aIndex = 0; |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
997 |
COpenFontSessionCacheList* cacheList = SessionCacheList(); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
998 |
aCache = cacheList->FindCache(aSessionHandle); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
999 |
if (aCache != NULL) |
32 | 1000 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1001 |
return aCache->Glyph(this, aCode, aIndex); |
32 | 1002 |
} |
1003 |
||
1004 |
if (aCreate) |
|
1005 |
{ |
|
1006 |
COpenFontSessionCache* new_cache = NULL; |
|
1007 |
TRAPD(error, new_cache = COpenFontSessionCache::NewL(aHeap, aSessionHandle, KSessionCacheEntries)); |
|
1008 |
||
1009 |
if ((!error) && new_cache != NULL) |
|
1010 |
{ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1011 |
if (cacheList->AddCache(new_cache) != KErrNone) |
32 | 1012 |
{ |
1013 |
new_cache->Delete(aHeap); |
|
1014 |
aHeap->Free(new_cache); |
|
1015 |
return NULL; |
|
1016 |
} |
|
1017 |
||
1018 |
aCache = new_cache; |
|
1019 |
aIndex = GLYPH_CODE(aCode) % KSessionCacheEntries; |
|
1020 |
} |
|
1021 |
} |
|
1022 |
return NULL; |
|
1023 |
} |
|
1024 |
||
1025 |
COpenFontSessionCacheList* COpenFont::SessionCacheList()const |
|
1026 |
{ |
|
1027 |
if (iSessionCacheListOffset == 0) |
|
1028 |
{ |
|
1029 |
return NULL; |
|
1030 |
} |
|
1031 |
return reinterpret_cast<COpenFontSessionCacheList*>(reinterpret_cast<TInt>(this) + iSessionCacheListOffset); |
|
1032 |
} |
|
1033 |
||
1034 |
void COpenFont::SetSessionCacheList(COpenFontSessionCacheList* aSessionCacheList) |
|
1035 |
{ |
|
1036 |
iSessionCacheListOffset = aSessionCacheList ? reinterpret_cast<TInt>(aSessionCacheList) - reinterpret_cast<TInt>(this) : NULL; |
|
1037 |
} |
|
1038 |
||
1039 |
void COpenFont::SetFile(COpenFontFile* aFile) |
|
1040 |
{ |
|
1041 |
iFileOffset = aFile ? reinterpret_cast<TInt>(aFile) - reinterpret_cast<TInt>(this) : NULL; |
|
1042 |
} |
|
1043 |
||
1044 |
void COpenFont::SetGlyphCache(COpenFontGlyphCache* aGlyphCache) |
|
1045 |
{ |
|
1046 |
iGlyphCacheOffset = aGlyphCache ? reinterpret_cast<TInt>(aGlyphCache) - reinterpret_cast<TInt>(this) : NULL; |
|
1047 |
} |
|
1048 |
||
1049 |
||
1050 |
/** |
|
1051 |
Create a glyph data object on the shared heap, given the code, metrics and the data bytes. |
|
1052 |
The data is copied; ownership remains with the caller. |
|
1053 |
*/ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1054 |
COpenFontGlyph* COpenFontGlyph::New(RHeap* aHeap, TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap) |
32 | 1055 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1056 |
COpenFontGlyph* glyph = (COpenFontGlyph*)aHeap->Alloc(sizeof(COpenFontGlyph) + aBitmap.Size()); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1057 |
if (glyph == NULL) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1058 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1059 |
return NULL; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1060 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1061 |
new(glyph) COpenFontGlyph(aCode, aGlyphIndex, aMetrics); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1062 |
glyph->SetBitmap(glyph + 1); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1063 |
Mem::Copy(glyph + 1, aBitmap.Ptr(), aBitmap.Size()); |
32 | 1064 |
return glyph; |
1065 |
} |
|
1066 |
||
1067 |
COpenFontSessionCacheEntry* COpenFontSessionCacheEntry::New(RHeap* aHeap, const COpenFont* aFont, TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap) |
|
1068 |
{ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1069 |
COpenFontSessionCacheEntry* entry = (COpenFontSessionCacheEntry*)aHeap->Alloc(sizeof(COpenFontSessionCacheEntry) + aBitmap.Size()); |
32 | 1070 |
if (entry == NULL) |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1071 |
{ |
32 | 1072 |
return NULL; |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1073 |
} |
32 | 1074 |
new(entry) COpenFontSessionCacheEntry(aFont, aCode, aGlyphIndex, aMetrics); |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1075 |
entry->SetBitmap(entry + 1); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1076 |
Mem::Copy(entry + 1, aBitmap.Ptr(), aBitmap.Size()); |
32 | 1077 |
return entry; |
1078 |
} |
|
1079 |
||
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1080 |
void COpenFontGlyph::SetBitmap(const TAny* aBitmap) |
32 | 1081 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1082 |
iBitmapOffset = reinterpret_cast<TInt>(aBitmap) - reinterpret_cast<TInt>(this); |
32 | 1083 |
} |
1084 |
||
1085 |
COpenFontSessionCache* COpenFontSessionCache::NewL(RHeap* aHeap, TInt aSessionHandle, TInt aEntries) |
|
1086 |
{ |
|
1087 |
COpenFontSessionCache* c = (COpenFontSessionCache*)aHeap->AllocL(sizeof(COpenFontSessionCache)); |
|
1088 |
new(c) COpenFontSessionCache(aSessionHandle); |
|
1089 |
if (c->iEntryArray.Create(aHeap, aEntries) != KErrNone) |
|
1090 |
{ |
|
1091 |
aHeap->Free(c); |
|
1092 |
User::Leave(KErrNoMemory); |
|
1093 |
} |
|
1094 |
return c; |
|
1095 |
} |
|
1096 |
||
1097 |
||
1098 |
void COpenFontSessionCache::Delete(RHeap* aHeap) |
|
1099 |
{ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1100 |
TInt numEntries = iEntryArray.Count(); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1101 |
for (TInt i = 0; i < numEntries; ++i) |
32 | 1102 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1103 |
COpenFontSessionCacheEntry* entry = iEntryArray[i]; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1104 |
if (entry != NULL) |
32 | 1105 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1106 |
COpenFont* font=const_cast<COpenFont*>(entry->Font()); |
32 | 1107 |
if (font != NULL) |
1108 |
font->DecrementCachedRefCount(iSessionHandle,NULL,ETrue); |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1109 |
COpenFontSessionCacheEntry::Delete(aHeap, entry); |
32 | 1110 |
} |
1111 |
} |
|
1112 |
iEntryArray.Close(aHeap); |
|
1113 |
} |
|
1114 |
||
1115 |
const COpenFontGlyph* COpenFontSessionCache::Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex) |
|
1116 |
{ |
|
1117 |
aIndex = -1; |
|
1118 |
TInt oldest = KMaxTInt; |
|
1119 |
TInt oldest_index = 0; |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1120 |
TInt numEntries = iEntryArray.Count(); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1121 |
TInt index = GLYPH_CODE(aCode) % numEntries; // simple hash function to shorten searches |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1122 |
for (TInt i = 0; i < numEntries; ++i, ++index) |
32 | 1123 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1124 |
if (index >= numEntries) |
32 | 1125 |
index = 0; |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1126 |
COpenFontSessionCacheEntry* entry = iEntryArray[index]; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1127 |
if (entry == NULL) |
32 | 1128 |
{ |
1129 |
if (aIndex == -1) |
|
1130 |
aIndex = index; |
|
1131 |
} |
|
1132 |
else |
|
1133 |
{ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1134 |
if (entry->Font() == aFont && entry->iCode == aCode) |
32 | 1135 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1136 |
entry->iLastAccess = iLastAccess++; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1137 |
return entry; |
32 | 1138 |
} |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1139 |
if (entry->iLastAccess < oldest) |
32 | 1140 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1141 |
oldest = entry->iLastAccess; |
32 | 1142 |
oldest_index = index; |
1143 |
} |
|
1144 |
} |
|
1145 |
} |
|
1146 |
if (aIndex == -1) |
|
1147 |
aIndex = oldest_index; |
|
1148 |
return NULL; |
|
1149 |
} |
|
1150 |
||
1151 |
||
1152 |
void COpenFontSessionCache::Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex) |
|
1153 |
{ |
|
1154 |
if (aIndex < 0 || aIndex >= iEntryArray.Count()) |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1155 |
{ |
32 | 1156 |
Panic(EFntSessionCacheIndexOutOfRange); |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1157 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1158 |
COpenFontSessionCacheEntry::Delete(aHeap, iEntryArray[aIndex]); |
32 | 1159 |
iEntryArray.SetAt(aIndex, aEntry); |
1160 |
aEntry->iLastAccess = iLastAccess++; |
|
1161 |
} |
|
1162 |
||
1163 |
COpenFontSessionCache::COpenFontSessionCache(TInt aSessionHandle): |
|
1164 |
iSessionHandle(aSessionHandle), |
|
1165 |
iLastAccess(0) |
|
1166 |
{ |
|
1167 |
} |
|
1168 |
||
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1169 |
TInt COpenFontSessionCacheList::AddCache(COpenFontSessionCache* aCache) |
32 | 1170 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1171 |
for (TInt index = 0; index < EMaxNumCaches; ++index) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1172 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1173 |
if (iSessionHandleArray[index] == 0) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1174 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1175 |
iSessionHandleArray[index] = aCache->SessionHandle(); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1176 |
iCacheOffsetArray[index] = reinterpret_cast<TInt>(aCache) - reinterpret_cast<TInt>(this); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1177 |
return KErrNone; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1178 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1179 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1180 |
return KErrNoMemory; |
32 | 1181 |
} |
1182 |
||
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1183 |
COpenFontSessionCache* COpenFontSessionCacheList::FindCache(TInt aSessionHandle) const |
32 | 1184 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1185 |
if (aSessionHandle == 0) |
32 | 1186 |
{ |
1187 |
return NULL; |
|
1188 |
} |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1189 |
for (TInt index = 0; index < EMaxNumCaches; ++index) |
32 | 1190 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1191 |
if (iSessionHandleArray[index] == aSessionHandle) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1192 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1193 |
return reinterpret_cast<COpenFontSessionCache*>(reinterpret_cast<TInt>(this) + iCacheOffsetArray[index]); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1194 |
} |
32 | 1195 |
} |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1196 |
return NULL; |
32 | 1197 |
} |
1198 |
||
1199 |
/** Delete all the items in the session cache if the current cache session handle |
|
1200 |
matches the passed session handle. |
|
1201 |
||
1202 |
@param aHeap The heap base of the current process. |
|
1203 |
@param aSessionHandle The session handle of the cache to be deleted. |
|
1204 |
*/ |
|
1205 |
void COpenFontSessionCacheList::DeleteCache(RHeap* aHeap, TInt aSessionHandle) |
|
1206 |
{ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1207 |
if (aSessionHandle == 0) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1208 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1209 |
return; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1210 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1211 |
for (TInt index = 0; index < EMaxNumCaches; ++index) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1212 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1213 |
if (iSessionHandleArray[index] == aSessionHandle) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1214 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1215 |
COpenFontSessionCache* cache = reinterpret_cast<COpenFontSessionCache*>(PtrAdd(this, iCacheOffsetArray[index])); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1216 |
cache->Delete(aHeap); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1217 |
aHeap->Free(cache); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1218 |
iSessionHandleArray[index] = 0; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1219 |
iCacheOffsetArray[index] = 0; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1220 |
return; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1221 |
} |
32 | 1222 |
} |
1223 |
} |
|
1224 |
||
1225 |
/** Delete all the items in the current session cache. |
|
1226 |
||
1227 |
@param aHeap The heap base of the current process. |
|
1228 |
*/ |
|
1229 |
void COpenFontSessionCacheList::Delete(RHeap* aHeap) |
|
1230 |
{ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1231 |
for (TInt index = 0; index < EMaxNumCaches; ++index) |
32 | 1232 |
{ |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1233 |
if (iCacheOffsetArray[index] != 0) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1234 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1235 |
COpenFontSessionCache* cache = reinterpret_cast<COpenFontSessionCache*>(PtrAdd(this, iCacheOffsetArray[index])); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1236 |
cache->Delete(aHeap); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1237 |
aHeap->Free(cache); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1238 |
} |
32 | 1239 |
} |
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1240 |
Mem::FillZ(this, sizeof(COpenFontSessionCacheList)); |
32 | 1241 |
} |
1242 |
||
1243 |
/** |
|
1244 |
Delete all glyphs belonging to a particular font. |
|
1245 |
*/ |
|
1246 |
void COpenFontSessionCacheList::DeleteFontGlyphs(RHeap* aHeap, const COpenFont* aFont) |
|
1247 |
{ |
|
51
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1248 |
for (TInt index = 0; index < EMaxNumCaches; ++index) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1249 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1250 |
if (iCacheOffsetArray[index] != 0) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1251 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1252 |
COpenFontSessionCache* cache = reinterpret_cast<COpenFontSessionCache*>(PtrAdd(this, iCacheOffsetArray[index])); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1253 |
TInt numEntries = cache->iEntryArray.Count(); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1254 |
for (TInt i = 0; i < numEntries; ++i) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1255 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1256 |
COpenFontSessionCacheEntry* entry = cache->iEntryArray[i]; |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1257 |
if (entry != NULL && entry->Font() == aFont) |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1258 |
{ |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1259 |
COpenFontSessionCacheEntry::Delete(aHeap, entry); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1260 |
cache->iEntryArray.SetAt(i, NULL); |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1261 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1262 |
} |
a7c938434754
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1263 |
} |
32 | 1264 |
} |
1265 |
} |
|
1266 |
||
1267 |
/** |
|
1268 |
C++ constructor with a CFont parameter. |
|
1269 |
||
1270 |
This creates a TOpenFontMetrics and initialises it with size, ascent, maximum |
|
1271 |
height, descent, maximum depth and maximum character width information from |
|
1272 |
the CFont that was passed as a parameter. |
|
1273 |
||
1274 |
@param aFont The font from which to initialise the metrics object. |
|
1275 |
*/ |
|
1276 |
EXPORT_C TOpenFontMetrics::TOpenFontMetrics(const CFont* aFont) |
|
1277 |
{ |
|
1278 |
iDesignHeight = (TInt16) aFont->HeightInPixels(); |
|
1279 |
iAscent = iMaxHeight = (TInt16) aFont->AscentInPixels(); |
|
1280 |
iDescent = iMaxDepth = (TInt16)(iDesignHeight - iAscent); |
|
1281 |
iMaxWidth = (TInt16)aFont->MaxCharWidthInPixels(); |
|
1282 |
iBaselineCorrection = 0; |
|
1283 |
} |
|
1284 |
||
1285 |
/** |
|
1286 |
@publishedPartner |
|
1287 |
@prototype |
|
1288 |
||
1289 |
@param aBaselineCorrection The baseline correction to be associated with this font |
|
1290 |
||
1291 |
Sets the baseline correction applied to this font; this value is used to offset |
|
1292 |
the underlinke and strikethrough positions and is used by linked fonts only. |
|
1293 |
*/ |
|
1294 |
const TUint16 KBitsForUnderline = 10; |
|
1295 |
const TUint16 KMaskUnderline = (1<<KBitsForUnderline)-1; //bottom bits which are set |
|
1296 |
const TUint16 KMaskBitmapType = ~KMaskUnderline; //top bits which are set |
|
1297 |
const TUint16 KSignBit = 1<<(KBitsForUnderline-1); //sign bit for the lower number, which can be signed |
|
1298 |
const TUint32 KTop16Of32Bits = 0xffff0000; |
|
1299 |
||
1300 |
EXPORT_C void TOpenFontMetrics::SetBaselineCorrection(TInt aBaselineCorrection) |
|
1301 |
{ |
|
44
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1302 |
if (aBaselineCorrection >= (1<<(KBitsForUnderline-1))) |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1303 |
{ |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1304 |
OstTrace1( TRACE_FATAL, TOPENFONTMETRICS_SETBASELINECORRECTION, "aBaselineCorrection=%d, Panic(EFntOverFlow)", aBaselineCorrection ); |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1305 |
__ASSERT_DEBUG(0, Panic(EFntOverFlow)); |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1306 |
} |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1307 |
if (aBaselineCorrection <= (0-(1<<(KBitsForUnderline-1)))) |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1308 |
{ |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1309 |
OstTrace1( TRACE_FATAL, DUP1_TOPENFONTMETRICS_SETBASELINECORRECTION, "aBaselineCorrection=%d, Panic(EFntOverFlow)", aBaselineCorrection ); |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1310 |
__ASSERT_DEBUG(0, Panic(EFntOverFlow)); |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1311 |
} |
32 | 1312 |
|
1313 |
TUint16 value = iBaselineCorrection; |
|
1314 |
value &=~KMaskUnderline; //zero all the underline position bits |
|
1315 |
if (aBaselineCorrection<0) |
|
1316 |
{ |
|
1317 |
//need to mask out extra sign bits for negative value |
|
1318 |
iBaselineCorrection = value | (static_cast<TUint16>(aBaselineCorrection)&~KMaskBitmapType); |
|
1319 |
} |
|
1320 |
else |
|
1321 |
{ |
|
1322 |
iBaselineCorrection = value | static_cast<TUint16>(aBaselineCorrection); |
|
1323 |
} |
|
1324 |
} |
|
1325 |
||
1326 |
/** |
|
1327 |
@publishedPartner |
|
1328 |
@prototype |
|
1329 |
||
1330 |
Gets the baseline correction applied to this font; this value is used to offset |
|
1331 |
the underlinke and strikethrough positions and is used by linked fonts only. |
|
1332 |
||
1333 |
@return The baseline correction associated with this font |
|
1334 |
*/ |
|
1335 |
||
1336 |
EXPORT_C TInt TOpenFontMetrics::BaselineCorrection() |
|
1337 |
{ |
|
1338 |
TUint16 value = iBaselineCorrection; //read once for improved multi threading |
|
1339 |
if (!(value & KSignBit)) |
|
1340 |
{ |
|
1341 |
//value is positive, no need to sign extend |
|
1342 |
return value & KMaskUnderline; |
|
1343 |
} |
|
1344 |
else |
|
1345 |
{ |
|
1346 |
//value is negative, need to stuff ones into the high bits |
|
1347 |
//could shift up and shift down |
|
1348 |
return static_cast<TInt>(static_cast<TUint>(value) | KMaskBitmapType | KTop16Of32Bits); |
|
1349 |
} |
|
1350 |
} |
|
1351 |
||
1352 |
/** |
|
1353 |
C++ constructor with UID and filename. |
|
1354 |
||
1355 |
Call this constructor in the constructor for your derived object, passing |
|
1356 |
it aUid and aFileName arguments. |
|
1357 |
||
1358 |
Non Symbian-platform-native font files are allocated IDs by the font store. |
|
1359 |
These are passed in by the rasteriser class. UIDs are required by the |
|
1360 |
font framework. However you should not use the ID to access the file, since |
|
1361 |
a new UID will need to be allocated when the file is next loaded, e.g. after |
|
1362 |
a device reboot. Instead use the font file name. |
|
1363 |
||
1364 |
@param aUid The UID of the font file. |
|
1365 |
@param aFileName The full filename, including the path, of the font file. |
|
1366 |
*/ |
|
1367 |
EXPORT_C COpenFontFile::COpenFontFile(TInt aUid, const TDesC& aFileName) |
|
1368 |
: iFaceAttrib(1), |
|
1369 |
iUid(TUid::Uid(aUid)), |
|
1370 |
iFileName(aFileName), |
|
1371 |
iFontList(8) |
|
1372 |
{ |
|
1373 |
} |
|
1374 |
||
1375 |
/** |
|
1376 |
Destructor. |
|
1377 |
||
1378 |
It is not allowed that file is deleted before its fonts |
|
1379 |
and the logic is handled in CFontStore::RemoveFile(). |
|
1380 |
*/ |
|
1381 |
EXPORT_C COpenFontFile::~COpenFontFile() |
|
1382 |
{ |
|
1383 |
CFontStore *fs = GetFontStore(); |
|
1384 |
if (fs != NULL) |
|
1385 |
{ |
|
1386 |
fs->CleanupCacheOnOpenFontFileRemoval(this); |
|
1387 |
} |
|
1388 |
delete iData; |
|
1389 |
} |
|
1390 |
||
1391 |
/** |
|
1392 |
Gets the nearest font in pixels. |
|
1393 |
||
1394 |
Implementations of this pure virtual function should create the COpenFont |
|
1395 |
derived object that most closely matches aFontSpec, and place a pointer to |
|
1396 |
it in aFont. If this cannot be done, e.g. if the font name doesn't match, |
|
1397 |
aFont should be set to NULL. |
|
1398 |
||
1399 |
The other two arguments, aHeap and aSessionCacheList, should be passed to |
|
1400 |
the COpenFont constructor. |
|
1401 |
||
1402 |
Implementations may use the utilitity function GetNearestFontHelper() to get |
|
1403 |
the attributes of the closest matching font. |
|
1404 |
||
1405 |
@param aHeap Shared heap. This value should be passed to the COpenFont derived |
|
1406 |
classes' constructor. |
|
1407 |
@param aSessionCacheList The session cache list. This value should be passed |
|
1408 |
to the COpenFont derived classes' constructor. |
|
1409 |
@param aDesiredFontSpec The desired font specification. |
|
1410 |
@param aPixelWidth The width of a pixel. Used with aPixelHeight for calculating |
|
1411 |
the algorithmic slant of the typeface. |
|
1412 |
@param aPixelHeight The height of a pixel. Used with aPixelWidth for calculating |
|
1413 |
the algorithmic slant of the typeface. |
|
1414 |
@param aFont On return, contains a pointer to the newly created COpenFont |
|
1415 |
derived object, or NULL if no font matching aDesiredFontSpec exists. |
|
1416 |
@param aActualFontSpec The actual font specification of the font retrieved |
|
1417 |
into aFont. |
|
1418 |
@see GetNearestFontHelper() |
|
1419 |
@deprecated Use GetNearestFontToDesignHeightInPixels |
|
1420 |
*/ |
|
1421 |
TInt COpenFontFile::GetNearestFontInPixels( |
|
1422 |
RHeap* aHeap, |
|
1423 |
COpenFontSessionCacheList* aSessionCacheList, |
|
1424 |
const TOpenFontSpec& aDesiredFontSpec, |
|
1425 |
TInt aPixelWidth, |
|
1426 |
TInt aPixelHeight, |
|
1427 |
COpenFont*& aFont, |
|
1428 |
TOpenFontSpec& aActualFontSpec) |
|
1429 |
{ |
|
1430 |
return GetNearestFontToDesignHeightInPixels(aHeap, aSessionCacheList, aDesiredFontSpec, aPixelWidth, aPixelHeight, aFont, aActualFontSpec); |
|
1431 |
} |
|
1432 |
||
1433 |
/** |
|
1434 |
Gets the nearest font in pixels. |
|
1435 |
||
1436 |
Implementations of this pure virtual function should create the COpenFont |
|
1437 |
derived object that most closely matches aFontSpec, and place a pointer to |
|
1438 |
it in aFont. If this cannot be done, e.g. if the font name doesn't match, |
|
1439 |
aFont should be set to NULL. |
|
1440 |
||
1441 |
The other two arguments, aHeap and aSessionCacheList, should be passed to |
|
1442 |
the COpenFont constructor. |
|
1443 |
||
1444 |
Implementations may use the utilitity function GetNearestFontHelper() to get |
|
1445 |
the attributes of the closest matching font. |
|
1446 |
||
1447 |
@param aHeap Shared heap. This value should be passed to the COpenFont derived |
|
1448 |
classes' constructor. |
|
1449 |
@param aSessionCacheList The session cache list. This value should be passed |
|
1450 |
to the COpenFont derived classes' constructor. |
|
1451 |
@param aDesiredFontSpec The desired font specification. |
|
1452 |
@param aPixelWidth The width of a pixel. Used with aPixelHeight for calculating |
|
1453 |
the algorithmic slant of the typeface. |
|
1454 |
@param aPixelHeight The height of a pixel. Used with aPixelWidth for calculating |
|
1455 |
the algorithmic slant of the typeface. |
|
1456 |
@param aFont On return, contains a pointer to the newly created COpenFont |
|
1457 |
derived object, or NULL if no font matching aDesiredFontSpec exists. |
|
1458 |
@param aActualFontSpec The actual font specification of the font retrieved |
|
1459 |
into aFont. |
|
1460 |
@see GetNearestFontHelper() |
|
1461 |
*/ |
|
1462 |
TInt COpenFontFile::GetNearestFontToDesignHeightInPixels( |
|
1463 |
RHeap* aHeap, |
|
1464 |
COpenFontSessionCacheList* aSessionCacheList, |
|
1465 |
const TOpenFontSpec& aDesiredFontSpec, |
|
1466 |
TInt aPixelWidth, |
|
1467 |
TInt aPixelHeight, |
|
1468 |
COpenFont*& aFont, |
|
1469 |
TOpenFontSpec& aActualFontSpec) |
|
1470 |
{ |
|
1471 |
aFont = NULL; |
|
1472 |
TRAPD(error, GetNearestFontToDesignHeightInPixelsAndAddToListL(aHeap, aSessionCacheList, aDesiredFontSpec, aPixelWidth, aPixelHeight, aFont, aActualFontSpec)); |
|
1473 |
return error; |
|
1474 |
} |
|
1475 |
||
1476 |
||
1477 |
void COpenFontFile::GetNearestFontToDesignHeightInPixelsAndAddToListL( |
|
1478 |
RHeap* aHeap, |
|
1479 |
COpenFontSessionCacheList* aSessionCacheList, |
|
1480 |
const TOpenFontSpec& aDesiredFontSpec, |
|
1481 |
TInt aPixelWidth, |
|
1482 |
TInt aPixelHeight, |
|
1483 |
COpenFont*& aFont, |
|
1484 |
TOpenFontSpec& aActualFontSpec) |
|
1485 |
{ |
|
1486 |
COpenFont* fontPtr = NULL; |
|
1487 |
GetNearestFontToDesignHeightInPixelsL(aHeap, aSessionCacheList, aDesiredFontSpec, aPixelWidth, aPixelHeight, fontPtr, aActualFontSpec); |
|
1488 |
if (fontPtr != NULL) |
|
1489 |
{ // found a matching font |
|
1490 |
CleanupStack::PushL(fontPtr); |
|
1491 |
iFontList.AppendL(fontPtr); |
|
1492 |
// transfer ownership |
|
1493 |
aFont = fontPtr; |
|
1494 |
CleanupStack::Pop(fontPtr); |
|
1495 |
} |
|
1496 |
} |
|
1497 |
||
1498 |
||
1499 |
/** |
|
1500 |
Gets the nearest font in pixels that fits inside specified max height. |
|
1501 |
||
1502 |
Implementations of this pure virtual function should create the COpenFont |
|
1503 |
derived object that most closely matches aFontSpec, while fitting within |
|
1504 |
aMaxHeight, and place a pointer to it in aFont. If this cannot be done, |
|
1505 |
e.g. if the font name doesn't match, aFont should be set to NULL. |
|
1506 |
||
1507 |
The other two arguments, aHeap and aSessionCacheList, should be passed to |
|
1508 |
the COpenFont constructor. |
|
1509 |
||
1510 |
Implementations may use the utilitity function GetNearestFontHelper() |
|
1511 |
to get the attributes of the closest matching font. |
|
1512 |
||
1513 |
@param aHeap Shared heap. This value should be passed to the COpenFont derived |
|
1514 |
classes' constructor. |
|
1515 |
@param aSessionCacheList The session cache list. This value should be passed |
|
1516 |
to the COpenFont derived classes' constructor. |
|
1517 |
@param aDesiredFontSpec The desired font specification. |
|
1518 |
@param aPixelWidth The width of a pixel. Used with aPixelHeight for calculating |
|
1519 |
the algorithmic slant of the typeface. |
|
1520 |
@param aPixelHeight The height of a pixel. Used with aPixelWidth for calculating |
|
1521 |
the algorithmic slant of the typeface. |
|
1522 |
@param aFont On return, contains a pointer to the newly created COpenFont |
|
1523 |
derived object, or NULL if no font matching aDesiredFontSpec exists. |
|
1524 |
@param aActualFontSpec The actual font specification of the font retrieved |
|
1525 |
into aFont. |
|
1526 |
@param aMaxHeight The maximum height within which the font must fit. |
|
1527 |
@see GetNearestFontHelper() |
|
1528 |
*/ |
|
1529 |
TInt COpenFontFile::GetNearestFontToMaxHeightInPixels( |
|
1530 |
RHeap* aHeap, |
|
1531 |
COpenFontSessionCacheList* aSessionCacheList, |
|
1532 |
const TOpenFontSpec& aDesiredFontSpec, |
|
1533 |
TInt aPixelWidth, |
|
1534 |
TInt aPixelHeight, |
|
1535 |
COpenFont*& aFont, |
|
1536 |
TOpenFontSpec& aActualFontSpec, |
|
1537 |
TInt aMaxHeight) |
|
1538 |
{ |
|
1539 |
aFont = NULL; |
|
1540 |
TRAPD(error, GetNearestFontToMaxHeightInPixelsAndAddToListL(aHeap, aSessionCacheList, aDesiredFontSpec, aPixelWidth, aPixelHeight, aFont, aActualFontSpec, aMaxHeight)); |
|
1541 |
return error; |
|
1542 |
} |
|
1543 |
||
1544 |
||
1545 |
void COpenFontFile::GetNearestFontToMaxHeightInPixelsAndAddToListL( |
|
1546 |
RHeap* aHeap, |
|
1547 |
COpenFontSessionCacheList* aSessionCacheList, |
|
1548 |
const TOpenFontSpec& aDesiredFontSpec, |
|
1549 |
TInt aPixelWidth, |
|
1550 |
TInt aPixelHeight, |
|
1551 |
COpenFont*& aFont, |
|
1552 |
TOpenFontSpec& aActualFontSpec, |
|
1553 |
TInt aMaxHeight) |
|
1554 |
{ |
|
1555 |
COpenFont* fontPtr = NULL; |
|
1556 |
GetNearestFontToMaxHeightInPixelsL(aHeap, aSessionCacheList, aDesiredFontSpec, aPixelWidth, aPixelHeight, fontPtr, aActualFontSpec, aMaxHeight); |
|
1557 |
if (fontPtr != NULL) |
|
1558 |
{ // found a matching font |
|
1559 |
CleanupStack::PushL(fontPtr); |
|
1560 |
iFontList.AppendL(fontPtr); |
|
1561 |
// transfer ownership |
|
1562 |
aFont = fontPtr; |
|
1563 |
CleanupStack::Pop(fontPtr); |
|
1564 |
} |
|
1565 |
} |
|
1566 |
||
1567 |
||
1568 |
/** |
|
1569 |
Gets the nearest font helper function. |
|
1570 |
||
1571 |
This function may be used by derived classes in their GetNearestFontInPixelsL() |
|
1572 |
implementations. It finds the nearest font in the typeface attribute array, |
|
1573 |
if any, to the provided font specification. If there is a possible match it |
|
1574 |
places the face index in aFaceIndex and the actual specification (including |
|
1575 |
algorithmic effects) in aActualFontSpec. |
|
1576 |
||
1577 |
@param aDesiredFontSpec The desired font specification. |
|
1578 |
@param aPixelWidth The width of a pixel. Used with aPixelHeight for calculating |
|
1579 |
the algorithmic slant of the typeface. |
|
1580 |
@param aPixelHeight The height of a pixel. Used with aPixelWidth for calculating |
|
1581 |
the algorithmic slant of the typeface. |
|
1582 |
@param aFaceIndex The index of the typeface which contains the closest match |
|
1583 |
to aDesiredFontSpec. |
|
1584 |
@param aActualFontSpec The actual font specification of the font with attributes |
|
1585 |
closest to aDesiredFontSpec. |
|
1586 |
@return ETrue if there is a possible font match, otherwise EFalse. |
|
1587 |
*/ |
|
1588 |
EXPORT_C TBool COpenFontFile::GetNearestFontHelper( |
|
1589 |
const TOpenFontSpec& aDesiredFontSpec, |
|
1590 |
TInt aPixelWidth, |
|
1591 |
TInt aPixelHeight, |
|
1592 |
TInt& aFaceIndex, |
|
1593 |
TOpenFontSpec& aActualFontSpec) const |
|
1594 |
{ |
|
1595 |
const TInt faces = FaceCount(); |
|
1596 |
TInt best_points = 0; |
|
1597 |
TInt best_index = -1; |
|
1598 |
||
1599 |
for (TInt i = 0; i < faces; i++) |
|
1600 |
{ |
|
1601 |
TInt cur_points = 0; |
|
1602 |
||
1603 |
if (0 < aDesiredFontSpec.Name().Length()) |
|
1604 |
{ |
|
1605 |
cur_points = ScoreByName(aDesiredFontSpec, iFaceAttrib[i]); |
|
1606 |
} |
|
1607 |
else |
|
1608 |
{ |
|
1609 |
cur_points = ScoreByStyle(aDesiredFontSpec, iFaceAttrib[i]); |
|
1610 |
} |
|
1611 |
||
1612 |
if (cur_points) |
|
1613 |
{ |
|
1614 |
if (aDesiredFontSpec.IsItalic() == iFaceAttrib[i].IsItalic()) |
|
1615 |
cur_points++; |
|
1616 |
if (aDesiredFontSpec.IsBold() == iFaceAttrib[i].IsBold()) |
|
1617 |
cur_points++; |
|
1618 |
} |
|
1619 |
||
1620 |
if (cur_points > best_points) |
|
1621 |
{ |
|
1622 |
best_points = cur_points; |
|
1623 |
best_index = i; |
|
1624 |
} |
|
1625 |
} |
|
1626 |
||
1627 |
if (best_index != -1) |
|
1628 |
{ |
|
1629 |
aActualFontSpec = aDesiredFontSpec; |
|
1630 |
// copy attributes & name |
|
1631 |
aActualFontSpec.SetAttrib(iFaceAttrib[best_index]); |
|
1632 |
aActualFontSpec.SetName(iFaceAttrib[best_index].FamilyName()); |
|
1633 |
// Set an algorithmic slant and adjust it for the pixel aspect ratio. |
|
1634 |
if ((aDesiredFontSpec.IsItalic()) && (!iFaceAttrib[best_index].IsItalic()) && (0 == aDesiredFontSpec.SlantFactor())) |
|
1635 |
{ |
|
1636 |
TInt factor = KDefaultSlantFactor; |
|
1637 |
if (TOpenFontSpec::IsCompensationForAspectRatioNeeded(aPixelWidth, aPixelHeight)) |
|
1638 |
{ |
|
1639 |
TOpenFontSpec::ApplyRatio(factor, aPixelWidth, aPixelHeight); |
|
1640 |
} |
|
1641 |
aActualFontSpec.SetSlantFactor(factor); |
|
1642 |
} |
|
1643 |
} |
|
1644 |
||
1645 |
aFaceIndex = best_index; |
|
1646 |
return best_index != -1; |
|
1647 |
} |
|
1648 |
||
1649 |
TInt COpenFontFile::ScoreByName(const TOpenFontSpec& aDesiredFontSpec, const TAttrib& aAttrib) |
|
1650 |
{ |
|
1651 |
if (!aDesiredFontSpec.Name().CompareF(aAttrib.FullName()) || !aDesiredFontSpec.Name().CompareF(aAttrib.LocalFullName())) |
|
1652 |
{ |
|
1653 |
return 4; |
|
1654 |
} |
|
1655 |
else if (!aDesiredFontSpec.Name().CompareF(aAttrib.ShortFullName()) || !aDesiredFontSpec.Name().CompareF(aAttrib.ShortLocalFullName())) |
|
1656 |
{ |
|
1657 |
return 3; |
|
1658 |
} |
|
1659 |
else if (!aDesiredFontSpec.Name().CompareF(aAttrib.FamilyName()) || !aDesiredFontSpec.Name().CompareF(aAttrib.LocalFamilyName())) |
|
1660 |
{ |
|
1661 |
return 2; |
|
1662 |
} |
|
1663 |
else if (!aDesiredFontSpec.Name().CompareF(aAttrib.ShortFamilyName()) || !aDesiredFontSpec.Name().CompareF(aAttrib.ShortLocalFamilyName())) |
|
1664 |
{ |
|
1665 |
return 1; |
|
1666 |
} |
|
1667 |
return 0; |
|
1668 |
} |
|
1669 |
||
1670 |
TInt COpenFontFile::ScoreByStyle(const TOpenFontSpec& aDesiredFontSpec, const TAttrib& aAttrib) |
|
1671 |
{ |
|
1672 |
if (aDesiredFontSpec.IsSymbol() == aAttrib.IsSymbol()) |
|
1673 |
{ |
|
1674 |
return 4; |
|
1675 |
} |
|
1676 |
else if(aDesiredFontSpec.IsMonoWidth() == aAttrib.IsMonoWidth()) |
|
1677 |
{ |
|
1678 |
return 3; |
|
1679 |
} |
|
1680 |
else if(aDesiredFontSpec.IsSerif() == aAttrib.IsSerif()) |
|
1681 |
{ |
|
1682 |
return 2; |
|
1683 |
} |
|
1684 |
||
1685 |
return 0; |
|
1686 |
} |
|
1687 |
||
1688 |
#ifdef _DEBUG |
|
1689 |
/** @internalComponent */ |
|
1690 |
EXPORT_C TBool COpenFontFile::GetNearestFontHelperOld(const TOpenFontSpec& aDesiredFontSpec, TInt aPixelWidth,TInt aPixelHeight,TInt& aFaceIndex, TOpenFontSpec& aActualFontSpec) const |
|
1691 |
{ |
|
1692 |
TInt faces = FaceCount(); |
|
1693 |
TInt best_points = 0; |
|
1694 |
TInt best_index = -1; |
|
1695 |
TBool slant = FALSE; |
|
1696 |
for (TInt i = 0; i < faces; i++) |
|
1697 |
{ |
|
1698 |
TPtrC family_name = iFaceAttrib[i].FamilyName(); |
|
1699 |
TPtrC full_name = iFaceAttrib[i].FullName(); |
|
1700 |
TPtrC local_family_name = iFaceAttrib[i].LocalFamilyName(); |
|
1701 |
TPtrC local_full_name = iFaceAttrib[i].LocalFullName(); |
|
1702 |
TPtrC desired_name = aDesiredFontSpec.Name(); |
|
1703 |
||
1704 |
TInt cur_points = 0; |
|
1705 |
if (desired_name.Length() > 0) |
|
1706 |
{ |
|
1707 |
if ((full_name.CompareF(desired_name) == 0) || (local_full_name.CompareF(desired_name) == 0)) |
|
1708 |
cur_points = 4; |
|
1709 |
else if ((family_name.CompareF(desired_name) == 0) || (local_family_name.CompareF(desired_name) == 0)) |
|
1710 |
cur_points = 2; |
|
1711 |
} |
|
1712 |
else |
|
1713 |
{ |
|
1714 |
if ((aDesiredFontSpec.IsSerif() == iFaceAttrib[i].IsSerif()) && (aDesiredFontSpec.IsMonoWidth() == iFaceAttrib[i].IsMonoWidth()) && (aDesiredFontSpec.IsSymbol() == iFaceAttrib[i].IsSymbol())) |
|
1715 |
cur_points = 2; |
|
1716 |
} |
|
1717 |
if (cur_points) |
|
1718 |
{ |
|
1719 |
if (aDesiredFontSpec.IsItalic() == iFaceAttrib[i].IsItalic()) |
|
1720 |
cur_points++; |
|
1721 |
if (aDesiredFontSpec.IsBold() == iFaceAttrib[i].IsBold()) |
|
1722 |
cur_points++; |
|
1723 |
if (cur_points > best_points) |
|
1724 |
{ |
|
1725 |
best_points = cur_points; |
|
1726 |
best_index = i; |
|
1727 |
slant = (aDesiredFontSpec.IsItalic()) && (!iFaceAttrib[i].IsItalic()); |
|
1728 |
} |
|
1729 |
} |
|
1730 |
} |
|
1731 |
||
1732 |
if (best_index != -1) |
|
1733 |
{ |
|
1734 |
TInt32 slant_factor = aDesiredFontSpec.SlantFactor(); |
|
1735 |
||
1736 |
// Set an algorithmic slant and adjust it for the pixel aspect ratio. |
|
1737 |
if (slant && slant_factor == 0) |
|
1738 |
{ |
|
1739 |
slant_factor = KDefaultSlantFactor; |
|
1740 |
if (aPixelWidth>0 && aPixelHeight>0 && TOpenFontSpec::IsCompensationForAspectRatioNeeded(aPixelWidth,aPixelHeight)) |
|
1741 |
{ |
|
1742 |
TOpenFontSpec::ApplyRatio(slant_factor,aPixelWidth,aPixelHeight); |
|
1743 |
} |
|
1744 |
} |
|
1745 |
||
1746 |
aActualFontSpec = aDesiredFontSpec; |
|
1747 |
// copy attributes & name |
|
1748 |
aActualFontSpec.SetAttrib(iFaceAttrib[best_index]); |
|
1749 |
aActualFontSpec.SetName(iFaceAttrib[best_index].FamilyName()); |
|
1750 |
aActualFontSpec.SetSlantFactor(slant_factor); |
|
1751 |
aActualFontSpec.SetEffects(0); |
|
1752 |
} |
|
1753 |
||
1754 |
aFaceIndex = best_index; |
|
1755 |
return best_index != -1; |
|
1756 |
} |
|
1757 |
#else //_DEBUG |
|
1758 |
/** |
|
1759 |
@internalComponent |
|
1760 |
*/ |
|
1761 |
EXPORT_C TBool COpenFontFile::GetNearestFontHelperOld(const TOpenFontSpec&, TInt, TInt, TInt&, TOpenFontSpec&) const |
|
1762 |
{ |
|
1763 |
return EFalse; |
|
1764 |
} |
|
1765 |
#endif //_DEBUG |
|
1766 |
||
1767 |
/** This function is called (via iFile) by a COpenFont when it is destroyed. */ |
|
1768 |
void COpenFontFile::RemoveFontFromList(const COpenFont* aFont) |
|
1769 |
{ |
|
1770 |
TInt fonts = iFontList.Count(); |
|
1771 |
for (TInt i = 0; i < fonts; i++) |
|
1772 |
if (iFontList[i] == aFont) |
|
1773 |
{ |
|
1774 |
iFontList.Delete(i); |
|
1775 |
break; |
|
1776 |
} |
|
1777 |
} |
|
1778 |
||
1779 |
/** |
|
1780 |
Adds a typeface to this object's typeface array. |
|
1781 |
||
1782 |
This function should be called during construction to add the attributes for |
|
1783 |
each typeface in the font file to the typeface attribute array. |
|
1784 |
||
1785 |
Note: |
|
1786 |
||
1787 |
The typeface array is what is searched for the closest match to a specified |
|
1788 |
font by GetNearestFontHelper(). |
|
1789 |
||
1790 |
@param aAttrib The attributes for a typeface to be added to the typeface attribute |
|
1791 |
array. |
|
1792 |
@see FaceAttrib() |
|
1793 |
@see FaceCount() |
|
1794 |
*/ |
|
1795 |
EXPORT_C void COpenFontFile::AddFaceL(const TOpenFontFaceAttrib& aAttrib) |
|
1796 |
{ |
|
1797 |
TAttrib& a = iFaceAttrib.ExtendL(); |
|
1798 |
(TOpenFontFaceAttrib&)a = aAttrib; |
|
1799 |
} |
|
1800 |
||
1801 |
void COpenFontFile::SetFontStoreL(CFontStore* aFontStore) |
|
1802 |
{ |
|
1803 |
if (iData == NULL) |
|
1804 |
{ |
|
1805 |
iData = new (ELeave) TOpenFontFileData; |
|
1806 |
} |
|
1807 |
iData->iFontStore = aFontStore; |
|
1808 |
} |
|
1809 |
||
1810 |
CFontStore* COpenFontFile::GetFontStore() |
|
1811 |
{ |
|
1812 |
return iData ? iData->iFontStore : NULL; |
|
1813 |
} |
|
1814 |
||
1815 |
CArrayPtrFlat<COpenFont>* COpenFontFile::GetOpenFontList() |
|
1816 |
{ |
|
1817 |
return &iFontList; |
|
1818 |
} |
|
1819 |
||
1820 |
||
1821 |
static const TInt KTOpenFontSpecBitsNumSymbol = 1; |
|
1822 |
static const TInt KTOpenFontSpecBitsNumScript = 4; |
|
1823 |
static const TInt KTOpenFontSpecMaskSymbol = (1 << KTOpenFontSpecBitsNumSymbol) - 1; |
|
1824 |
static const TInt KTOpenFontSpecMaskScript = ((1 << KTOpenFontSpecBitsNumScript) - 1) << KTOpenFontSpecBitsNumSymbol; |
|
1825 |
static const TInt KTOpenFontSpecSymbolFlag = 0x1; |
|
1826 |
||
1827 |
/** |
|
1828 |
Default C++ constructor setting |
|
1829 |
height to 16 pixels or twips, |
|
1830 |
width factor to 1 (65536 in 16.16 format), |
|
1831 |
slant factor to 0 (no slant), |
|
1832 |
effects to ENone, |
|
1833 |
symbol to 0 (assuming EScriptNone = 0), |
|
1834 |
print position to EPrintPosNormal. |
|
1835 |
*/ |
|
1836 |
EXPORT_C TOpenFontSpec::TOpenFontSpec() |
|
1837 |
: iHeight(16), |
|
1838 |
iWidthFactor(KOneIn16Dot16FixedPointFormat), |
|
1839 |
iSlantFactor(0), |
|
1840 |
iBitmapType(0), |
|
1841 |
iEffects(FontEffect::ENone), |
|
1842 |
iSymbol(0), |
|
1843 |
iPrintPosition(EPrintPosNormal), |
|
1844 |
iReserved2(0) |
|
1845 |
{ |
|
1846 |
} |
|
1847 |
||
1848 |
/** |
|
1849 |
C++ constructor taking a reference to a TFontSpec. |
|
1850 |
||
1851 |
This object's members are initialised from the values of the aFontSpec parameter. |
|
1852 |
||
1853 |
@param aFontSpec The font specification used to initialise this font specification. |
|
1854 |
*/ |
|
1855 |
EXPORT_C TOpenFontSpec::TOpenFontSpec(const TFontSpec& aFontSpec) |
|
1856 |
{ |
|
1857 |
*this = aFontSpec; |
|
1858 |
} |
|
1859 |
||
1860 |
/** |
|
1861 |
Assignment operator. |
|
1862 |
||
1863 |
@param aFontSpec The old-style font specification to copy into this font specification. |
|
1864 |
*/ |
|
1865 |
EXPORT_C void TOpenFontSpec::operator=(const TFontSpec& aFontSpec) |
|
1866 |
{ |
|
1867 |
iSlantFactor = 0; |
|
1868 |
iWidthFactor = KOneIn16Dot16FixedPointFormat; |
|
1869 |
iHeight = aFontSpec.iHeight; // in twips |
|
1870 |
iBitmapType = aFontSpec.iFontStyle.BitmapType(); |
|
1871 |
iEffects = aFontSpec.iFontStyle.Effects(); |
|
1872 |
iPrintPosition = aFontSpec.iFontStyle.PrintPosition(); |
|
1873 |
iName = aFontSpec.iTypeface.iName; |
|
1874 |
SetScriptTypeForMetrics(aFontSpec.iTypeface.ScriptTypeForMetrics()); |
|
1875 |
const TBool symbol = aFontSpec.iTypeface.IsSymbol(); |
|
1876 |
SetSymbol(symbol); |
|
1877 |
if (symbol) |
|
1878 |
SetCoverage(0); // no appropriate coverage value for the symbol set |
|
1879 |
else |
|
1880 |
SetCoverage(3); // Latin and Latin-1 supplement |
|
1881 |
iStyle = 0; |
|
1882 |
if (!aFontSpec.iTypeface.IsProportional()) |
|
1883 |
iStyle |= TOpenFontFaceAttrib::EMonoWidth; |
|
1884 |
if (aFontSpec.iTypeface.IsSerif()) |
|
1885 |
iStyle |= TOpenFontFaceAttrib::ESerif; |
|
1886 |
if (aFontSpec.iFontStyle.Posture() == EPostureItalic) |
|
1887 |
iStyle |= TOpenFontFaceAttrib::EItalic; |
|
1888 |
if (aFontSpec.iFontStyle.StrokeWeight() == EStrokeWeightBold) |
|
1889 |
iStyle |= TOpenFontFaceAttrib::EBold; |
|
1890 |
} |
|
1891 |
||
1892 |
||
1893 |
/** |
|
1894 |
Adjust the width factor and slant factor to suit a pixel aspect ratio. |
|
1895 |
@publishedAll |
|
1896 |
@released |
|
1897 |
@param aPixelWidth The pixel width, in the same units as aPixelHeight. |
|
1898 |
@param aPixelHeight The pixel height, in the same units as aPixelWidth. |
|
1899 |
*/ |
|
1900 |
EXPORT_C void TOpenFontSpec::CompensateForAspectRatio(TInt aPixelWidth, TInt aPixelHeight) |
|
1901 |
{ |
|
1902 |
if (IsCompensationForAspectRatioNeeded(aPixelWidth, aPixelHeight)) |
|
1903 |
{ |
|
1904 |
ApplyRatio(iWidthFactor, aPixelHeight, aPixelWidth); |
|
1905 |
ApplyRatio(iSlantFactor, aPixelWidth, aPixelHeight); |
|
1906 |
} |
|
1907 |
} |
|
1908 |
||
1909 |
/** |
|
1910 |
Adjust the width factor and slant factor to suit a pixel aspect ratio stored |
|
1911 |
in a MGraphicsDeviceMap derived object. |
|
1912 |
@publishedAll |
|
1913 |
@released |
|
1914 |
@param aMap The MGraphicsDeviceMap defining the pixel aspect ratio. |
|
1915 |
*/ |
|
1916 |
EXPORT_C void TOpenFontSpec::CompensateForAspectRatio(const MGraphicsDeviceMap& aMap) |
|
1917 |
{ |
|
1918 |
CompensateForAspectRatio(aMap.HorizontalPixelsToTwips(1000), aMap.VerticalPixelsToTwips(1000)); |
|
1919 |
} |
|
1920 |
||
1921 |
/** |
|
1922 |
The pixel width and height are used to derive a ratio, and so can be |
|
1923 |
in any units. Aspect ratios differing by less than 1/1000 are treated as 1:1. |
|
1924 |
@internalTechnology |
|
1925 |
*/ |
|
1926 |
TBool TOpenFontSpec::IsCompensationForAspectRatioNeeded(TInt aPixelWidth,TInt aPixelHeight) |
|
1927 |
{ |
|
1928 |
if ((aPixelWidth != aPixelHeight) && (0 < aPixelWidth) && (0 < aPixelHeight)) |
|
1929 |
{ |
|
1930 |
//If nearly square don't transform (0.999 < aPixelHeight/aPixelWidth < 1.001) |
|
1931 |
TInt64 width = aPixelWidth; |
|
1932 |
TInt64 height = aPixelHeight; |
|
1933 |
width *= 999; // Cannot do multiplication on declaration lines above as risk of TInt32 overflow |
|
1934 |
height *= 1000; |
|
1935 |
if (width <= height) // 999 * aPixelWidth <= 1000 * aPixelHeight |
|
1936 |
return ETrue; |
|
1937 |
width += aPixelWidth; |
|
1938 |
width += aPixelWidth; // Cannot do with previous line as small risk of TInt32 overflow |
|
1939 |
if (width >= height) // 1001 * aPixelWidth >= 1000 * aPixelHeight |
|
1940 |
return ETrue; |
|
1941 |
} |
|
1942 |
return EFalse; |
|
1943 |
} |
|
1944 |
||
1945 |
/** |
|
1946 |
Multiplies aValue by aNumerator/aDenominator but using TInt64's to avoid any overflows. |
|
1947 |
Returns ETrue if the final result has an overflow. |
|
1948 |
@internalTechnology |
|
1949 |
*/ |
|
1950 |
TBool TOpenFontSpec::ApplyRatio(TInt& aValue, TInt aNumerator, TInt aDenominator) |
|
1951 |
{ |
|
1952 |
TInt64 value(aValue); |
|
1953 |
value = (value * aNumerator) / aDenominator; |
|
1954 |
aValue = I64LOW(value); |
|
44
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1955 |
if (I64HIGH(value) != 0) |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1956 |
{ |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1957 |
OstTrace1( TRACE_FATAL, TOPENFONTSPEC_APPLYRATIO, "value=%ld, Panic(EFntOverFlow)", value ); |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1958 |
__ASSERT_DEBUG(0, Panic(EFntOverFlow)); |
601ab138ba0b
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
1959 |
} |
32 | 1960 |
return I64HIGH(value) != 0; |
1961 |
} |
|
1962 |
||
1963 |
/** |
|
1964 |
Same as above function but this takes a TInt32 not a TInt |
|
1965 |
*/ |
|
1966 |
TBool TOpenFontSpec::ApplyRatio(TInt32& aValue, TInt aNumerator, TInt aDenominator) |
|
1967 |
{ |
|
1968 |
TInt value = aValue; |
|
1969 |
TBool ret = ApplyRatio(value, aNumerator, aDenominator); |
|
1970 |
aValue = value; |
|
1971 |
return ret; |
|
1972 |
} |
|
1973 |
||
1974 |
EXPORT_C void TOpenFontSpec::SetAttrib(const TOpenFontFaceAttribBase& aAttrib) |
|
1975 |
/** |
|
1976 |
Sets the font attributes. |
|
1977 |
||
1978 |
@param aAttrib The font attributes. |
|
1979 |
*/ |
|
1980 |
{ |
|
1981 |
TOpenFontFaceAttribBase* self = this; |
|
1982 |
*self = aAttrib; |
|
1983 |
} |
|
1984 |
||
1985 |
/** |
|
1986 |
Gets the TFontSpec corresponding to this Open Font System font specification. |
|
1987 |
@publishedAll |
|
1988 |
@released |
|
1989 |
@param aFontSpec On return, contains the TFontSpec corresponding to this font |
|
1990 |
specification. |
|
1991 |
*/ |
|
1992 |
EXPORT_C void TOpenFontSpec::GetTFontSpec(TFontSpec& aFontSpec) const |
|
1993 |
{ |
|
1994 |
aFontSpec = TFontSpec(); |
|
1995 |
TPtrC short_name(iName.Ptr(), Min(iName.Length(), KMaxTypefaceNameLength)); |
|
1996 |
aFontSpec.iTypeface.iName = short_name; |
|
1997 |
aFontSpec.iTypeface.SetIsProportional(!IsMonoWidth()); |
|
1998 |
aFontSpec.iTypeface.SetIsSerif(IsSerif()); |
|
1999 |
aFontSpec.iTypeface.SetIsSymbol(Symbol()); |
|
2000 |
aFontSpec.iTypeface.SetScriptTypeForMetrics(ScriptTypeForMetrics()); |
|
2001 |
aFontSpec.iHeight = iHeight; // as twips |
|
2002 |
if (IsItalic() || (iSlantFactor > 0)) |
|
2003 |
aFontSpec.iFontStyle.SetPosture(EPostureItalic); |
|
2004 |
if (IsBold() || IsEffectOn(FontEffect::EAlgorithmicBold)) |
|
2005 |
aFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); |
|
2006 |
aFontSpec.iFontStyle.SetPrintPosition(iPrintPosition); |
|
2007 |
aFontSpec.iFontStyle.SetBitmapType(BitmapType()); |
|
2008 |
aFontSpec.iFontStyle.SetEffects(iEffects); |
|
2009 |
} |
|
2010 |
||
2011 |
/** |
|
2012 |
Sets a font effect to the given state. |
|
2013 |
@publishedAll |
|
2014 |
@released |
|
2015 |
@param aEffect The font effect to be set. |
|
2016 |
@param aOn True represents on, otherwise off. |
|
2017 |
@see TOpenFontSpec::IsEffectOn() |
|
2018 |
*/ |
|
2019 |
EXPORT_C void TOpenFontSpec::SetEffects(FontEffect::TEffect aEffect, TBool aOn) |
|
2020 |
{ |
|
2021 |
FontEffect::SetEffect(aEffect, aOn, iEffects); |
|
2022 |
} |
|
2023 |
||
2024 |
/** Checks if a font effect is on. |
|
2025 |
@publishedAll |
|
2026 |
@released |
|
2027 |
@return True represents the specified font effect is on, otherwise off. |
|
2028 |
@param aEffect The font effect to be checked. |
|
2029 |
@see TOpenFontSpec::SetEffects() |
|
2030 |
*/ |
|
2031 |
EXPORT_C TBool TOpenFontSpec::IsEffectOn(FontEffect::TEffect aEffect) const |
|
2032 |
{ |
|
2033 |
return FontEffect::IsEffectOn(aEffect, iEffects); |
|
2034 |
} |
|
2035 |
||
2036 |
/** |
|
2037 |
@deprecated This needs to be maintained to just call the inline methods. |
|
2038 |
*/ |
|
2039 |
EXPORT_C void TOpenFontSpec::DoSetEffects(TUint32 aEffects) |
|
2040 |
{ |
|
2041 |
SetEffects(aEffects); |
|
2042 |
} |
|
2043 |
||
2044 |
/** |
|
2045 |
@deprecated This needs to be maintained to just call the inline methods. |
|
2046 |
*/ |
|
2047 |
EXPORT_C TUint32 TOpenFontSpec::DoEffects() const |
|
2048 |
{ |
|
2049 |
return Effects(); |
|
2050 |
} |
|
2051 |
||
2052 |
/** |
|
2053 |
Specifies the script which font metrics calculation will be based on. |
|
2054 |
@publishedAll |
|
2055 |
@released |
|
2056 |
@param aLanguage The language used to derive the required script. |
|
2057 |
*/ |
|
2058 |
EXPORT_C void TOpenFontSpec::SetScriptTypeForMetrics(TLanguage aLanguage) |
|
2059 |
{ |
|
2060 |
SetScriptTypeForMetrics(GlyphSample::TLanguage2TScript(aLanguage)); |
|
2061 |
} |
|
2062 |
||
2063 |
/** |
|
2064 |
@internalTechnology |
|
2065 |
*/ |
|
2066 |
void TOpenFontSpec::SetScriptTypeForMetrics(TInt aScript) |
|
2067 |
{ |
|
2068 |
iSymbol &= ~KTOpenFontSpecMaskScript; |
|
2069 |
iSymbol |= (KTOpenFontSpecMaskScript & (aScript << KTOpenFontSpecBitsNumSymbol)); |
|
2070 |
} |
|
2071 |
||
2072 |
/** |
|
2073 |
Gets the script which the font metrics calculation will be based on. |
|
2074 |
@internalTechnology |
|
2075 |
@return The script. |
|
2076 |
*/ |
|
2077 |
EXPORT_C TInt TOpenFontSpec::ScriptTypeForMetrics() const |
|
2078 |
{ |
|
2079 |
return (KTOpenFontSpecMaskScript & iSymbol) >> KTOpenFontSpecBitsNumSymbol; |
|
2080 |
} |
|
2081 |
||
2082 |
/** |
|
2083 |
@internalTechnology |
|
2084 |
*/ |
|
2085 |
void TOpenFontSpec::SetSymbol(TBool aSymbol) |
|
2086 |
{ |
|
2087 |
iSymbol &= ~KTOpenFontSpecMaskSymbol; |
|
2088 |
iSymbol |= (aSymbol ? KTOpenFontSpecSymbolFlag : 0); |
|
2089 |
} |
|
2090 |
||
2091 |
/** |
|
2092 |
@internalTechnology |
|
2093 |
*/ |
|
2094 |
TBool TOpenFontSpec::Symbol() const |
|
2095 |
{ |
|
2096 |
return (KTOpenFontSpecSymbolFlag & iSymbol) > 0; |
|
2097 |
} |
|
2098 |
||
2099 |
/** |
|
2100 |
@deprecated This needs to be maintained to just call the inline methods. |
|
2101 |
*/ |
|
2102 |
EXPORT_C TBool TOpenFontSpec::OperatorEquality(const TOpenFontSpec& aOpenFontSpec) const |
|
2103 |
{ |
|
2104 |
return this->operator == (aOpenFontSpec); |
|
2105 |
} |
|
2106 |
||
2107 |
/** |
|
2108 |
@internalTechnology |
|
2109 |
*/ |
|
2110 |
TBool TOpenFontSpec::operator!=(const TOpenFontSpec& aOpenFontSpec) const |
|
2111 |
{ |
|
2112 |
return !(this->operator == (aOpenFontSpec)); |
|
2113 |
} |
|
2114 |
||
2115 |
/** |
|
2116 |
Static constructor for a TOpenFontGlyphData. |
|
2117 |
||
2118 |
This constructor creates the object on a specified heap. It must be deleted |
|
2119 |
using RHeap::Free(). |
|
2120 |
||
2121 |
@param aHeap The shared heap on which the object is constructed. |
|
2122 |
@param aBufferSize The amount of memory allocated for the glyph data. |
|
2123 |
@return A pointer to the newly created object. |
|
2124 |
*/ |
|
2125 |
EXPORT_C TOpenFontGlyphData* TOpenFontGlyphData::New(RHeap* aHeap, TInt aBufferSize) |
|
2126 |
{ |
|
2127 |
if (aBufferSize < 1) |
|
2128 |
aBufferSize = 1; |
|
2129 |
TInt bytes = sizeof(TOpenFontGlyphData) + aBufferSize - 1; |
|
2130 |
TOpenFontGlyphData* g = (TOpenFontGlyphData*)aHeap->Alloc(bytes); |
|
2131 |
if (g != NULL) |
|
2132 |
{ |
|
2133 |
Mem::FillZ(g, bytes); |
|
2134 |
g->iBitmapBufferSize = aBufferSize; |
|
2135 |
} |
|
2136 |
return g; |
|
2137 |
} |
|
2138 |
||
2139 |
// Virtual functions reserved for future expansion. |
|
2140 |
/** |
|
2141 |
@publishedPartner |
|
2142 |
@prototype |
|
2143 |
*/ |
|
2144 |
EXPORT_C void COpenFontRasterizer::ExtendedInterface(TUid, TAny*&) |
|
2145 |
{ |
|
2146 |
} |
|
2147 |
||
2148 |
/** @internalComponent */ |
|
2149 |
EXPORT_C void COpenFontFile::ExtendedInterface(TUid, TAny*&) |
|
2150 |
{ |
|
2151 |
} |
|
2152 |
||
2153 |
EXPORT_C void COpenFont::ExtendedInterface(TUid, TAny*&) |
|
2154 |
{ |
|
2155 |
} |
|
2156 |
||
2157 |
EXPORT_C CShaper::CShaper() |
|
2158 |
{ |
|
2159 |
||
2160 |
} |
|
2161 |
||
2162 |
EXPORT_C CShaper::~CShaper() |
|
2163 |
{ |
|
2164 |
||
2165 |
} |
|
2166 |
/** @internalComponent */ |
|
2167 |
EXPORT_C void* CShaper::ExtendedInterface(TUid) |
|
2168 |
{ |
|
2169 |
return 0; |
|
2170 |
} |
|
2171 |
||
2172 |
/** |
|
2173 |
Sets the glyph bitmap type. |
|
2174 |
||
2175 |
Normally the bitmap type belongs to the font, but for linked fonts this can |
|
2176 |
be different between different font elements making up the linked font. |
|
2177 |
||
2178 |
Note: This is only of use in conjunction with rasterizer based linked fonts. |
|
2179 |
||
2180 |
@publishedPartner |
|
2181 |
@prototype |
|
2182 |
*/ |
|
2183 |
EXPORT_C void TOpenFontCharMetrics::SetGlyphType(TGlyphBitmapType aGlyphBitmapType) |
|
2184 |
{ |
|
2185 |
iGlyphBitmapType = aGlyphBitmapType; |
|
2186 |
} |
|
2187 |
||
2188 |
/** |
|
2189 |
Gets the glyph bitmap type. |
|
2190 |
||
2191 |
@publishedPartner |
|
2192 |
@prototype |
|
2193 |
*/ |
|
2194 |
EXPORT_C TGlyphBitmapType TOpenFontCharMetrics::GlyphType() const |
|
2195 |
{ |
|
2196 |
if (iGlyphBitmapType == 0) |
|
2197 |
return EGlyphBitmapTypeNotDefined; |
|
2198 |
else |
|
2199 |
return static_cast<TGlyphBitmapType>(iGlyphBitmapType); |
|
2200 |
} |