Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* GRAPHITE2 LICENSING |
michael@0 | 2 | |
michael@0 | 3 | Copyright 2010, SIL International |
michael@0 | 4 | All rights reserved. |
michael@0 | 5 | |
michael@0 | 6 | This library is free software; you can redistribute it and/or modify |
michael@0 | 7 | it under the terms of the GNU Lesser General Public License as published |
michael@0 | 8 | by the Free Software Foundation; either version 2.1 of License, or |
michael@0 | 9 | (at your option) any later version. |
michael@0 | 10 | |
michael@0 | 11 | This program is distributed in the hope that it will be useful, |
michael@0 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
michael@0 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
michael@0 | 14 | Lesser General Public License for more details. |
michael@0 | 15 | |
michael@0 | 16 | You should also have received a copy of the GNU Lesser General Public |
michael@0 | 17 | License along with this library in the file named "LICENSE". |
michael@0 | 18 | If not, write to the Free Software Foundation, 51 Franklin Street, |
michael@0 | 19 | Suite 500, Boston, MA 02110-1335, USA or visit their web page on the |
michael@0 | 20 | internet at http://www.fsf.org/licenses/lgpl.html. |
michael@0 | 21 | |
michael@0 | 22 | Alternatively, the contents of this file may be used under the terms of the |
michael@0 | 23 | Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public |
michael@0 | 24 | License, as published by the Free Software Foundation, either version 2 |
michael@0 | 25 | of the License or (at your option) any later version. |
michael@0 | 26 | */ |
michael@0 | 27 | #pragma once |
michael@0 | 28 | |
michael@0 | 29 | #ifndef GRAPHITE2_NSEGCACHE |
michael@0 | 30 | |
michael@0 | 31 | #include "inc/Main.h" |
michael@0 | 32 | #include "inc/CmapCache.h" |
michael@0 | 33 | #include "inc/SegCache.h" |
michael@0 | 34 | |
michael@0 | 35 | namespace graphite2 { |
michael@0 | 36 | |
michael@0 | 37 | class SegCache; |
michael@0 | 38 | class Face; |
michael@0 | 39 | |
michael@0 | 40 | class SilfSegCache |
michael@0 | 41 | { |
michael@0 | 42 | SilfSegCache(const SilfSegCache &); |
michael@0 | 43 | SilfSegCache & operator = (const SilfSegCache &); |
michael@0 | 44 | |
michael@0 | 45 | public: |
michael@0 | 46 | SilfSegCache() : m_caches(NULL), m_cacheCount(0) {}; |
michael@0 | 47 | ~SilfSegCache() |
michael@0 | 48 | { |
michael@0 | 49 | assert(m_caches == NULL); |
michael@0 | 50 | } |
michael@0 | 51 | void clear(SegCacheStore * cacheStore) |
michael@0 | 52 | { |
michael@0 | 53 | for (size_t i = 0; i < m_cacheCount; i++) |
michael@0 | 54 | { |
michael@0 | 55 | m_caches[i]->clear(cacheStore); |
michael@0 | 56 | delete m_caches[i]; |
michael@0 | 57 | } |
michael@0 | 58 | free(m_caches); |
michael@0 | 59 | m_caches = NULL; |
michael@0 | 60 | m_cacheCount = 0; |
michael@0 | 61 | } |
michael@0 | 62 | SegCache * getOrCreate(SegCacheStore * cacheStore, const Features & features) |
michael@0 | 63 | { |
michael@0 | 64 | for (size_t i = 0; i < m_cacheCount; i++) |
michael@0 | 65 | { |
michael@0 | 66 | if (m_caches[i]->features() == features) |
michael@0 | 67 | return m_caches[i]; |
michael@0 | 68 | } |
michael@0 | 69 | SegCache ** newData = gralloc<SegCache*>(m_cacheCount+1); |
michael@0 | 70 | if (newData) |
michael@0 | 71 | { |
michael@0 | 72 | if (m_cacheCount > 0) |
michael@0 | 73 | { |
michael@0 | 74 | memcpy(newData, m_caches, sizeof(SegCache*) * m_cacheCount); |
michael@0 | 75 | free(m_caches); |
michael@0 | 76 | } |
michael@0 | 77 | m_caches = newData; |
michael@0 | 78 | m_caches[m_cacheCount] = new SegCache(cacheStore, features); |
michael@0 | 79 | m_cacheCount++; |
michael@0 | 80 | return m_caches[m_cacheCount - 1]; |
michael@0 | 81 | } |
michael@0 | 82 | return NULL; |
michael@0 | 83 | } |
michael@0 | 84 | CLASS_NEW_DELETE |
michael@0 | 85 | private: |
michael@0 | 86 | SegCache ** m_caches; |
michael@0 | 87 | size_t m_cacheCount; |
michael@0 | 88 | }; |
michael@0 | 89 | |
michael@0 | 90 | class SegCacheStore |
michael@0 | 91 | { |
michael@0 | 92 | SegCacheStore(const SegCacheStore &); |
michael@0 | 93 | SegCacheStore & operator = (const SegCacheStore &); |
michael@0 | 94 | |
michael@0 | 95 | public: |
michael@0 | 96 | SegCacheStore(const Face & face, unsigned int numSilf, size_t maxSegments); |
michael@0 | 97 | ~SegCacheStore() |
michael@0 | 98 | { |
michael@0 | 99 | for (size_t i = 0; i < m_numSilf; i++) |
michael@0 | 100 | { |
michael@0 | 101 | m_caches[i].clear(this); |
michael@0 | 102 | } |
michael@0 | 103 | delete [] m_caches; |
michael@0 | 104 | m_caches = NULL; |
michael@0 | 105 | } |
michael@0 | 106 | SegCache * getOrCreate(unsigned int i, const Features & features) |
michael@0 | 107 | { |
michael@0 | 108 | return m_caches[i].getOrCreate(this, features); |
michael@0 | 109 | } |
michael@0 | 110 | bool isSpaceGlyph(uint16 gid) const { return (gid == m_spaceGid) || (gid == m_zwspGid); } |
michael@0 | 111 | uint16 maxCmapGid() const { return m_maxCmapGid; } |
michael@0 | 112 | uint32 maxSegmentCount() const { return m_maxSegments; }; |
michael@0 | 113 | |
michael@0 | 114 | CLASS_NEW_DELETE |
michael@0 | 115 | private: |
michael@0 | 116 | SilfSegCache * m_caches; |
michael@0 | 117 | uint8 m_numSilf; |
michael@0 | 118 | uint32 m_maxSegments; |
michael@0 | 119 | uint16 m_maxCmapGid; |
michael@0 | 120 | uint16 m_spaceGid; |
michael@0 | 121 | uint16 m_zwspGid; |
michael@0 | 122 | }; |
michael@0 | 123 | |
michael@0 | 124 | } // namespace graphite2 |
michael@0 | 125 | |
michael@0 | 126 | #endif |
michael@0 | 127 |