gfx/graphite2/src/SegCacheEntry.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*  GRAPHITE2 LICENSING
     3     Copyright 2010, SIL International
     4     All rights reserved.
     6     This library is free software; you can redistribute it and/or modify
     7     it under the terms of the GNU Lesser General Public License as published
     8     by the Free Software Foundation; either version 2.1 of License, or
     9     (at your option) any later version.
    11     This program is distributed in the hope that it will be useful,
    12     but WITHOUT ANY WARRANTY; without even the implied warranty of
    13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    14     Lesser General Public License for more details.
    16     You should also have received a copy of the GNU Lesser General Public
    17     License along with this library in the file named "LICENSE".
    18     If not, write to the Free Software Foundation, 51 Franklin Street,
    19     Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
    20     internet at http://www.fsf.org/licenses/lgpl.html.
    22 Alternatively, the contents of this file may be used under the terms of the
    23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
    24 License, as published by the Free Software Foundation, either version 2
    25 of the License or (at your option) any later version.
    26 */
    28 #ifndef GRAPHITE2_NSEGCACHE
    30 #include "inc/Main.h"
    31 #include "inc/Slot.h"
    32 #include "inc/Segment.h"
    33 #include "inc/SegCache.h"
    34 #include "inc/SegCacheEntry.h"
    37 using namespace graphite2;
    39 SegCacheEntry::SegCacheEntry(const uint16* cmapGlyphs, size_t length, Segment * seg, size_t charOffset, long long cacheTime)
    40     : m_glyphLength(0), m_unicode(gralloc<uint16>(length)), m_glyph(NULL),
    41     m_attr(NULL), m_justs(NULL),
    42     m_accessCount(0), m_lastAccess(cacheTime)
    43 {
    44     if (m_unicode)
    45         for (uint16 i = 0; i < length; i++)
    46             m_unicode[i] = cmapGlyphs[i];
    48     const size_t    glyphCount = seg->slotCount(),
    49                     sizeof_sjust = SlotJustify::size_of(seg->silf()->numJustLevels());
    50     if (!glyphCount) return;
    51     size_t num_justs = 0,
    52            justs_pos = 0;
    53     if (seg->hasJustification())
    54     {
    55         for (const Slot * s = seg->first(); s; s = s->next())
    56         {
    57             if (s->m_justs == 0)    continue;
    58             ++num_justs;
    59         }
    60         m_justs = gralloc<byte>(sizeof_sjust * num_justs);
    61     }
    62     const Slot * slot = seg->first();
    63     m_glyph = new Slot[glyphCount];
    64     m_attr = gralloc<int16>(glyphCount * seg->numAttrs());
    65     if (!m_glyph || (!m_attr && seg->numAttrs())) return;
    66     m_glyphLength = glyphCount;
    67     Slot * slotCopy = m_glyph;
    68     m_glyph->prev(NULL);
    70     uint16 pos = 0;
    71     while (slot)
    72     {
    73         slotCopy->userAttrs(m_attr + pos * seg->numAttrs());
    74         slotCopy->m_justs = m_justs ? reinterpret_cast<SlotJustify *>(m_justs + justs_pos++ * sizeof_sjust) : 0;
    75         slotCopy->set(*slot, -static_cast<int32>(charOffset), seg->numAttrs(), seg->silf()->numJustLevels(), length);
    76         slotCopy->index(pos);
    77         if (slot->firstChild())
    78             slotCopy->m_child = m_glyph + slot->firstChild()->index();
    79         if (slot->attachedTo())
    80             slotCopy->attachTo(m_glyph + slot->attachedTo()->index());
    81         if (slot->nextSibling())
    82             slotCopy->m_sibling = m_glyph + slot->nextSibling()->index();
    83         slot = slot->next();
    84         ++slotCopy;
    85         ++pos;
    86         if (slot)
    87         {
    88             slotCopy->prev(slotCopy-1);
    89             (slotCopy-1)->next(slotCopy);
    90         }
    91     }
    92 }
    95 void SegCacheEntry::clear()
    96 {
    97     free(m_unicode);
    98     free(m_attr);
    99     free(m_justs);
   100     delete [] m_glyph;
   101     m_unicode = NULL;
   102     m_glyph = NULL;
   103     m_glyphLength = 0;
   104     m_attr = NULL;
   105 }
   107 #endif

mercurial