]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/layout/FontTableCache.cpp
2 **********************************************************************
3 * Copyright (C) 2003 - 2008, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
8 #include "layout/LETypes.h"
10 #include "FontTableCache.h"
12 #define TABLE_CACHE_INIT 5
13 #define TABLE_CACHE_GROW 5
15 struct FontTableCacheEntry
21 FontTableCache::FontTableCache()
22 : fTableCacheCurr(0), fTableCacheSize(TABLE_CACHE_INIT
)
24 fTableCache
= LE_NEW_ARRAY(FontTableCacheEntry
, fTableCacheSize
);
26 if (fTableCache
== NULL
) {
31 for (int i
= 0; i
< fTableCacheSize
; i
+= 1) {
32 fTableCache
[i
].tag
= 0;
33 fTableCache
[i
].table
= NULL
;
37 FontTableCache::~FontTableCache()
39 for (int i
= fTableCacheCurr
- 1; i
>= 0; i
-= 1) {
40 freeFontTable(fTableCache
[i
].table
);
42 fTableCache
[i
].tag
= 0;
43 fTableCache
[i
].table
= NULL
;
48 LE_DELETE_ARRAY(fTableCache
);
52 void FontTableCache::freeFontTable(const void *table
) const
54 LE_DELETE_ARRAY(table
);
57 const void *FontTableCache::find(LETag tableTag
) const
59 for (int i
= 0; i
< fTableCacheCurr
; i
+= 1) {
60 if (fTableCache
[i
].tag
== tableTag
) {
61 return fTableCache
[i
].table
;
65 const void *table
= readFontTable(tableTag
);
67 ((FontTableCache
*) this)->add(tableTag
, table
);
72 void FontTableCache::add(LETag tableTag
, const void *table
)
74 if (fTableCacheCurr
>= fTableCacheSize
) {
75 le_int32 newSize
= fTableCacheSize
+ TABLE_CACHE_GROW
;
77 fTableCache
= (FontTableCacheEntry
*) LE_GROW_ARRAY(fTableCache
, newSize
);
79 for (le_int32 i
= fTableCacheSize
; i
< newSize
; i
+= 1) {
80 fTableCache
[i
].tag
= 0;
81 fTableCache
[i
].table
= NULL
;
84 fTableCacheSize
= newSize
;
87 fTableCache
[fTableCacheCurr
].tag
= tableTag
;
88 fTableCache
[fTableCacheCurr
].table
= table
;