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