]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/letest/FontTableCache.cpp
2 **********************************************************************
3 * Copyright (C) 2003-2013, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
8 #include "layout/LETypes.h"
11 #include "FontTableCache.h"
13 #define TABLE_CACHE_INIT 5
14 #define TABLE_CACHE_GROW 5
16 struct FontTableCacheEntry
23 FontTableCache::FontTableCache()
24 : fTableCacheCurr(0), fTableCacheSize(TABLE_CACHE_INIT
)
26 fTableCache
= LE_NEW_ARRAY(FontTableCacheEntry
, fTableCacheSize
);
28 if (fTableCache
== NULL
) {
33 for (int i
= 0; i
< fTableCacheSize
; i
+= 1) {
34 fTableCache
[i
].tag
= 0;
35 fTableCache
[i
].table
= NULL
;
36 fTableCache
[i
].length
= 0;
40 FontTableCache::~FontTableCache()
42 for (int i
= fTableCacheCurr
- 1; i
>= 0; i
-= 1) {
43 LE_DELETE_ARRAY(fTableCache
[i
].table
);
45 fTableCache
[i
].tag
= 0;
46 fTableCache
[i
].table
= NULL
;
47 fTableCache
[i
].length
= 0;
52 LE_DELETE_ARRAY(fTableCache
);
55 void FontTableCache::freeFontTable(const void *table
) const
57 LE_DELETE_ARRAY(table
);
60 const void *FontTableCache::find(LETag tableTag
, size_t &length
) const
62 for (int i
= 0; i
< fTableCacheCurr
; i
+= 1) {
63 if (fTableCache
[i
].tag
== tableTag
) {
64 length
= fTableCache
[i
].length
;
65 return fTableCache
[i
].table
;
69 const void *table
= readFontTable(tableTag
, length
);
71 ((FontTableCache
*) this)->add(tableTag
, table
, length
);
76 void FontTableCache::add(LETag tableTag
, const void *table
, size_t length
)
78 if (fTableCacheCurr
>= fTableCacheSize
) {
79 le_int32 newSize
= fTableCacheSize
+ TABLE_CACHE_GROW
;
81 fTableCache
= (FontTableCacheEntry
*) LE_GROW_ARRAY(fTableCache
, newSize
);
83 for (le_int32 i
= fTableCacheSize
; i
< newSize
; i
+= 1) {
84 fTableCache
[i
].tag
= 0;
85 fTableCache
[i
].table
= NULL
;
86 fTableCache
[i
].length
= 0;
89 fTableCacheSize
= newSize
;
92 fTableCache
[fTableCacheCurr
].tag
= tableTag
;
93 fTableCache
[fTableCacheCurr
].table
= table
;
94 fTableCache
[fTableCacheCurr
].length
= length
;