]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
b75a7d8f A |
3 | /* |
4 | ********************************************************************** | |
57a6839d | 5 | * Copyright (C) 2003-2013, International Business Machines |
b75a7d8f A |
6 | * Corporation and others. All Rights Reserved. |
7 | ********************************************************************** | |
8 | */ | |
9 | ||
10 | #include "layout/LETypes.h" | |
11 | ||
57a6839d | 12 | //#include "letest.h" |
b75a7d8f A |
13 | #include "FontTableCache.h" |
14 | ||
15 | #define TABLE_CACHE_INIT 5 | |
16 | #define TABLE_CACHE_GROW 5 | |
17 | ||
18 | struct FontTableCacheEntry | |
19 | { | |
57a6839d A |
20 | LETag tag; |
21 | const void *table; | |
22 | size_t length; | |
b75a7d8f A |
23 | }; |
24 | ||
25 | FontTableCache::FontTableCache() | |
26 | : fTableCacheCurr(0), fTableCacheSize(TABLE_CACHE_INIT) | |
27 | { | |
57a6839d | 28 | fTableCache = LE_NEW_ARRAY(FontTableCacheEntry, fTableCacheSize); |
b75a7d8f A |
29 | |
30 | if (fTableCache == NULL) { | |
31 | fTableCacheSize = 0; | |
32 | return; | |
33 | } | |
34 | ||
35 | for (int i = 0; i < fTableCacheSize; i += 1) { | |
36 | fTableCache[i].tag = 0; | |
37 | fTableCache[i].table = NULL; | |
57a6839d | 38 | fTableCache[i].length = 0; |
b75a7d8f A |
39 | } |
40 | } | |
41 | ||
42 | FontTableCache::~FontTableCache() | |
43 | { | |
44 | for (int i = fTableCacheCurr - 1; i >= 0; i -= 1) { | |
57a6839d | 45 | LE_DELETE_ARRAY(fTableCache[i].table); |
b75a7d8f A |
46 | |
47 | fTableCache[i].tag = 0; | |
48 | fTableCache[i].table = NULL; | |
57a6839d | 49 | fTableCache[i].length = 0; |
b75a7d8f A |
50 | } |
51 | ||
52 | fTableCacheCurr = 0; | |
73c04bcf | 53 | |
57a6839d | 54 | LE_DELETE_ARRAY(fTableCache); |
b75a7d8f A |
55 | } |
56 | ||
46f4442e A |
57 | void FontTableCache::freeFontTable(const void *table) const |
58 | { | |
57a6839d | 59 | LE_DELETE_ARRAY(table); |
46f4442e A |
60 | } |
61 | ||
57a6839d | 62 | const void *FontTableCache::find(LETag tableTag, size_t &length) const |
b75a7d8f A |
63 | { |
64 | for (int i = 0; i < fTableCacheCurr; i += 1) { | |
65 | if (fTableCache[i].tag == tableTag) { | |
57a6839d A |
66 | length = fTableCache[i].length; |
67 | return fTableCache[i].table; | |
b75a7d8f A |
68 | } |
69 | } | |
70 | ||
57a6839d | 71 | const void *table = readFontTable(tableTag, length); |
b75a7d8f | 72 | |
57a6839d | 73 | ((FontTableCache *) this)->add(tableTag, table, length); |
b75a7d8f A |
74 | |
75 | return table; | |
76 | } | |
77 | ||
57a6839d | 78 | void FontTableCache::add(LETag tableTag, const void *table, size_t length) |
b75a7d8f A |
79 | { |
80 | if (fTableCacheCurr >= fTableCacheSize) { | |
81 | le_int32 newSize = fTableCacheSize + TABLE_CACHE_GROW; | |
82 | ||
57a6839d | 83 | fTableCache = (FontTableCacheEntry *) LE_GROW_ARRAY(fTableCache, newSize); |
b75a7d8f A |
84 | |
85 | for (le_int32 i = fTableCacheSize; i < newSize; i += 1) { | |
86 | fTableCache[i].tag = 0; | |
87 | fTableCache[i].table = NULL; | |
57a6839d | 88 | fTableCache[i].length = 0; |
b75a7d8f A |
89 | } |
90 | ||
91 | fTableCacheSize = newSize; | |
92 | } | |
93 | ||
94 | fTableCache[fTableCacheCurr].tag = tableTag; | |
95 | fTableCache[fTableCacheCurr].table = table; | |
57a6839d | 96 | fTableCache[fTableCacheCurr].length = length; |
b75a7d8f A |
97 | |
98 | fTableCacheCurr += 1; | |
99 | } |