michael@0: /* GRAPHITE2 LICENSING michael@0: michael@0: Copyright 2010, SIL International michael@0: All rights reserved. michael@0: michael@0: This library is free software; you can redistribute it and/or modify michael@0: it under the terms of the GNU Lesser General Public License as published michael@0: by the Free Software Foundation; either version 2.1 of License, or michael@0: (at your option) any later version. michael@0: michael@0: This program is distributed in the hope that it will be useful, michael@0: but WITHOUT ANY WARRANTY; without even the implied warranty of michael@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU michael@0: Lesser General Public License for more details. michael@0: michael@0: You should also have received a copy of the GNU Lesser General Public michael@0: License along with this library in the file named "LICENSE". michael@0: If not, write to the Free Software Foundation, 51 Franklin Street, michael@0: Suite 500, Boston, MA 02110-1335, USA or visit their web page on the michael@0: internet at http://www.fsf.org/licenses/lgpl.html. michael@0: michael@0: Alternatively, the contents of this file may be used under the terms of the michael@0: Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public michael@0: License, as published by the Free Software Foundation, either version 2 michael@0: of the License or (at your option) any later version. michael@0: */ michael@0: michael@0: #ifndef GRAPHITE2_NSEGCACHE michael@0: michael@0: #include "inc/Main.h" michael@0: #include "inc/Slot.h" michael@0: #include "inc/Segment.h" michael@0: #include "inc/SegCache.h" michael@0: #include "inc/SegCacheEntry.h" michael@0: michael@0: michael@0: using namespace graphite2; michael@0: michael@0: SegCacheEntry::SegCacheEntry(const uint16* cmapGlyphs, size_t length, Segment * seg, size_t charOffset, long long cacheTime) michael@0: : m_glyphLength(0), m_unicode(gralloc(length)), m_glyph(NULL), michael@0: m_attr(NULL), m_justs(NULL), michael@0: m_accessCount(0), m_lastAccess(cacheTime) michael@0: { michael@0: if (m_unicode) michael@0: for (uint16 i = 0; i < length; i++) michael@0: m_unicode[i] = cmapGlyphs[i]; michael@0: michael@0: const size_t glyphCount = seg->slotCount(), michael@0: sizeof_sjust = SlotJustify::size_of(seg->silf()->numJustLevels()); michael@0: if (!glyphCount) return; michael@0: size_t num_justs = 0, michael@0: justs_pos = 0; michael@0: if (seg->hasJustification()) michael@0: { michael@0: for (const Slot * s = seg->first(); s; s = s->next()) michael@0: { michael@0: if (s->m_justs == 0) continue; michael@0: ++num_justs; michael@0: } michael@0: m_justs = gralloc(sizeof_sjust * num_justs); michael@0: } michael@0: const Slot * slot = seg->first(); michael@0: m_glyph = new Slot[glyphCount]; michael@0: m_attr = gralloc(glyphCount * seg->numAttrs()); michael@0: if (!m_glyph || (!m_attr && seg->numAttrs())) return; michael@0: m_glyphLength = glyphCount; michael@0: Slot * slotCopy = m_glyph; michael@0: m_glyph->prev(NULL); michael@0: michael@0: uint16 pos = 0; michael@0: while (slot) michael@0: { michael@0: slotCopy->userAttrs(m_attr + pos * seg->numAttrs()); michael@0: slotCopy->m_justs = m_justs ? reinterpret_cast(m_justs + justs_pos++ * sizeof_sjust) : 0; michael@0: slotCopy->set(*slot, -static_cast(charOffset), seg->numAttrs(), seg->silf()->numJustLevels(), length); michael@0: slotCopy->index(pos); michael@0: if (slot->firstChild()) michael@0: slotCopy->m_child = m_glyph + slot->firstChild()->index(); michael@0: if (slot->attachedTo()) michael@0: slotCopy->attachTo(m_glyph + slot->attachedTo()->index()); michael@0: if (slot->nextSibling()) michael@0: slotCopy->m_sibling = m_glyph + slot->nextSibling()->index(); michael@0: slot = slot->next(); michael@0: ++slotCopy; michael@0: ++pos; michael@0: if (slot) michael@0: { michael@0: slotCopy->prev(slotCopy-1); michael@0: (slotCopy-1)->next(slotCopy); michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: void SegCacheEntry::clear() michael@0: { michael@0: free(m_unicode); michael@0: free(m_attr); michael@0: free(m_justs); michael@0: delete [] m_glyph; michael@0: m_unicode = NULL; michael@0: m_glyph = NULL; michael@0: m_glyphLength = 0; michael@0: m_attr = NULL; michael@0: } michael@0: michael@0: #endif michael@0: