gfx/graphite2/src/inc/SegCacheStore.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/graphite2/src/inc/SegCacheStore.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,127 @@
     1.4 +/*  GRAPHITE2 LICENSING
     1.5 +
     1.6 +    Copyright 2010, SIL International
     1.7 +    All rights reserved.
     1.8 +
     1.9 +    This library is free software; you can redistribute it and/or modify
    1.10 +    it under the terms of the GNU Lesser General Public License as published
    1.11 +    by the Free Software Foundation; either version 2.1 of License, or
    1.12 +    (at your option) any later version.
    1.13 +
    1.14 +    This program is distributed in the hope that it will be useful,
    1.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.17 +    Lesser General Public License for more details.
    1.18 +
    1.19 +    You should also have received a copy of the GNU Lesser General Public
    1.20 +    License along with this library in the file named "LICENSE".
    1.21 +    If not, write to the Free Software Foundation, 51 Franklin Street,
    1.22 +    Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
    1.23 +    internet at http://www.fsf.org/licenses/lgpl.html.
    1.24 +
    1.25 +Alternatively, the contents of this file may be used under the terms of the
    1.26 +Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
    1.27 +License, as published by the Free Software Foundation, either version 2
    1.28 +of the License or (at your option) any later version.
    1.29 +*/
    1.30 +#pragma once
    1.31 +
    1.32 +#ifndef GRAPHITE2_NSEGCACHE
    1.33 +
    1.34 +#include "inc/Main.h"
    1.35 +#include "inc/CmapCache.h"
    1.36 +#include "inc/SegCache.h"
    1.37 +
    1.38 +namespace graphite2 {
    1.39 +
    1.40 +class SegCache;
    1.41 +class Face;
    1.42 +
    1.43 +class SilfSegCache
    1.44 +{
    1.45 +    SilfSegCache(const SilfSegCache &);
    1.46 +    SilfSegCache & operator = (const SilfSegCache &);
    1.47 +
    1.48 +public:
    1.49 +    SilfSegCache() : m_caches(NULL), m_cacheCount(0) {};
    1.50 +    ~SilfSegCache()
    1.51 +    {
    1.52 +        assert(m_caches == NULL);
    1.53 +    }
    1.54 +    void clear(SegCacheStore * cacheStore)
    1.55 +    {
    1.56 +        for (size_t i = 0; i < m_cacheCount; i++)
    1.57 +        {
    1.58 +            m_caches[i]->clear(cacheStore);
    1.59 +            delete m_caches[i];
    1.60 +        }
    1.61 +        free(m_caches);
    1.62 +        m_caches = NULL;
    1.63 +        m_cacheCount = 0;
    1.64 +    }
    1.65 +    SegCache * getOrCreate(SegCacheStore * cacheStore, const Features & features)
    1.66 +    {
    1.67 +        for (size_t i = 0; i < m_cacheCount; i++)
    1.68 +        {
    1.69 +            if (m_caches[i]->features() == features)
    1.70 +                return m_caches[i];
    1.71 +        }
    1.72 +        SegCache ** newData = gralloc<SegCache*>(m_cacheCount+1);
    1.73 +        if (newData)
    1.74 +        {
    1.75 +            if (m_cacheCount > 0)
    1.76 +            {
    1.77 +                memcpy(newData, m_caches, sizeof(SegCache*) * m_cacheCount);
    1.78 +                free(m_caches);
    1.79 +            }
    1.80 +            m_caches = newData;
    1.81 +            m_caches[m_cacheCount] = new SegCache(cacheStore, features);
    1.82 +            m_cacheCount++;
    1.83 +            return m_caches[m_cacheCount - 1];
    1.84 +        }
    1.85 +        return NULL;
    1.86 +    }
    1.87 +    CLASS_NEW_DELETE
    1.88 +private:
    1.89 +    SegCache ** m_caches;
    1.90 +    size_t m_cacheCount;
    1.91 +};
    1.92 +
    1.93 +class SegCacheStore
    1.94 +{
    1.95 +    SegCacheStore(const SegCacheStore &);
    1.96 +    SegCacheStore & operator = (const SegCacheStore &);
    1.97 +
    1.98 +public:
    1.99 +    SegCacheStore(const Face & face, unsigned int numSilf, size_t maxSegments);
   1.100 +    ~SegCacheStore()
   1.101 +    {
   1.102 +        for (size_t i = 0; i < m_numSilf; i++)
   1.103 +        {
   1.104 +            m_caches[i].clear(this);
   1.105 +        }
   1.106 +        delete [] m_caches;
   1.107 +        m_caches = NULL;
   1.108 +    }
   1.109 +    SegCache * getOrCreate(unsigned int i, const Features & features)
   1.110 +    {
   1.111 +        return m_caches[i].getOrCreate(this, features);
   1.112 +    }
   1.113 +    bool isSpaceGlyph(uint16 gid) const { return (gid == m_spaceGid) || (gid == m_zwspGid); }
   1.114 +    uint16 maxCmapGid() const { return m_maxCmapGid; }
   1.115 +    uint32 maxSegmentCount() const { return m_maxSegments; };
   1.116 +
   1.117 +    CLASS_NEW_DELETE
   1.118 +private:
   1.119 +    SilfSegCache * m_caches;
   1.120 +    uint8 m_numSilf;
   1.121 +    uint32 m_maxSegments;
   1.122 +    uint16 m_maxCmapGid;
   1.123 +    uint16 m_spaceGid;
   1.124 +    uint16 m_zwspGid;
   1.125 +};
   1.126 +
   1.127 +} // namespace graphite2
   1.128 +
   1.129 +#endif
   1.130 +

mercurial