1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/graphite2/src/SegCacheEntry.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 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 + 1.31 +#ifndef GRAPHITE2_NSEGCACHE 1.32 + 1.33 +#include "inc/Main.h" 1.34 +#include "inc/Slot.h" 1.35 +#include "inc/Segment.h" 1.36 +#include "inc/SegCache.h" 1.37 +#include "inc/SegCacheEntry.h" 1.38 + 1.39 + 1.40 +using namespace graphite2; 1.41 + 1.42 +SegCacheEntry::SegCacheEntry(const uint16* cmapGlyphs, size_t length, Segment * seg, size_t charOffset, long long cacheTime) 1.43 + : m_glyphLength(0), m_unicode(gralloc<uint16>(length)), m_glyph(NULL), 1.44 + m_attr(NULL), m_justs(NULL), 1.45 + m_accessCount(0), m_lastAccess(cacheTime) 1.46 +{ 1.47 + if (m_unicode) 1.48 + for (uint16 i = 0; i < length; i++) 1.49 + m_unicode[i] = cmapGlyphs[i]; 1.50 + 1.51 + const size_t glyphCount = seg->slotCount(), 1.52 + sizeof_sjust = SlotJustify::size_of(seg->silf()->numJustLevels()); 1.53 + if (!glyphCount) return; 1.54 + size_t num_justs = 0, 1.55 + justs_pos = 0; 1.56 + if (seg->hasJustification()) 1.57 + { 1.58 + for (const Slot * s = seg->first(); s; s = s->next()) 1.59 + { 1.60 + if (s->m_justs == 0) continue; 1.61 + ++num_justs; 1.62 + } 1.63 + m_justs = gralloc<byte>(sizeof_sjust * num_justs); 1.64 + } 1.65 + const Slot * slot = seg->first(); 1.66 + m_glyph = new Slot[glyphCount]; 1.67 + m_attr = gralloc<int16>(glyphCount * seg->numAttrs()); 1.68 + if (!m_glyph || (!m_attr && seg->numAttrs())) return; 1.69 + m_glyphLength = glyphCount; 1.70 + Slot * slotCopy = m_glyph; 1.71 + m_glyph->prev(NULL); 1.72 + 1.73 + uint16 pos = 0; 1.74 + while (slot) 1.75 + { 1.76 + slotCopy->userAttrs(m_attr + pos * seg->numAttrs()); 1.77 + slotCopy->m_justs = m_justs ? reinterpret_cast<SlotJustify *>(m_justs + justs_pos++ * sizeof_sjust) : 0; 1.78 + slotCopy->set(*slot, -static_cast<int32>(charOffset), seg->numAttrs(), seg->silf()->numJustLevels(), length); 1.79 + slotCopy->index(pos); 1.80 + if (slot->firstChild()) 1.81 + slotCopy->m_child = m_glyph + slot->firstChild()->index(); 1.82 + if (slot->attachedTo()) 1.83 + slotCopy->attachTo(m_glyph + slot->attachedTo()->index()); 1.84 + if (slot->nextSibling()) 1.85 + slotCopy->m_sibling = m_glyph + slot->nextSibling()->index(); 1.86 + slot = slot->next(); 1.87 + ++slotCopy; 1.88 + ++pos; 1.89 + if (slot) 1.90 + { 1.91 + slotCopy->prev(slotCopy-1); 1.92 + (slotCopy-1)->next(slotCopy); 1.93 + } 1.94 + } 1.95 +} 1.96 + 1.97 + 1.98 +void SegCacheEntry::clear() 1.99 +{ 1.100 + free(m_unicode); 1.101 + free(m_attr); 1.102 + free(m_justs); 1.103 + delete [] m_glyph; 1.104 + m_unicode = NULL; 1.105 + m_glyph = NULL; 1.106 + m_glyphLength = 0; 1.107 + m_attr = NULL; 1.108 +} 1.109 + 1.110 +#endif 1.111 +