gfx/graphite2/src/CachedFace.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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
michael@0 28 #ifndef GRAPHITE2_NSEGCACHE
michael@0 29
michael@0 30 #include <graphite2/Segment.h>
michael@0 31 #include "inc/CachedFace.h"
michael@0 32 #include "inc/SegCacheStore.h"
michael@0 33
michael@0 34
michael@0 35 using namespace graphite2;
michael@0 36
michael@0 37 CachedFace::CachedFace(const void* appFaceHandle/*non-NULL*/, const gr_face_ops & ops)
michael@0 38 : Face(appFaceHandle, ops), m_cacheStore(0)
michael@0 39 {
michael@0 40 }
michael@0 41
michael@0 42 CachedFace::~CachedFace()
michael@0 43 {
michael@0 44 delete m_cacheStore;
michael@0 45 }
michael@0 46
michael@0 47 bool CachedFace::setupCache(unsigned int cacheSize)
michael@0 48 {
michael@0 49 m_cacheStore = new SegCacheStore(*this, m_numSilf, cacheSize);
michael@0 50 return bool(m_cacheStore);
michael@0 51 }
michael@0 52
michael@0 53
michael@0 54 bool CachedFace::runGraphite(Segment *seg, const Silf *pSilf) const
michael@0 55 {
michael@0 56 assert(pSilf);
michael@0 57 pSilf->runGraphite(seg, 0, pSilf->substitutionPass());
michael@0 58
michael@0 59 unsigned int silfIndex = 0;
michael@0 60 for (; silfIndex < m_numSilf && &(m_silfs[silfIndex]) != pSilf; ++silfIndex);
michael@0 61 if (silfIndex == m_numSilf) return false;
michael@0 62 SegCache * const segCache = m_cacheStore->getOrCreate(silfIndex, seg->getFeatures(0));
michael@0 63 if (!segCache)
michael@0 64 return false;
michael@0 65
michael@0 66 assert(m_cacheStore);
michael@0 67 // find where the segment can be broken
michael@0 68 Slot * subSegStartSlot = seg->first();
michael@0 69 Slot * subSegEndSlot = subSegStartSlot;
michael@0 70 uint16 cmapGlyphs[eMaxSpliceSize];
michael@0 71 int subSegStart = 0;
michael@0 72 for (unsigned int i = 0; i < seg->charInfoCount(); ++i)
michael@0 73 {
michael@0 74 const unsigned int length = i - subSegStart + 1;
michael@0 75 if (length < eMaxSpliceSize)
michael@0 76 cmapGlyphs[length-1] = subSegEndSlot->gid();
michael@0 77 else return false;
michael@0 78 const bool spaceOnly = m_cacheStore->isSpaceGlyph(subSegEndSlot->gid());
michael@0 79 // at this stage the character to slot mapping is still 1 to 1
michael@0 80 const int breakWeight = seg->charinfo(i)->breakWeight(),
michael@0 81 nextBreakWeight = (i + 1 < seg->charInfoCount())?
michael@0 82 seg->charinfo(i+1)->breakWeight() : 0;
michael@0 83 const uint8 f = seg->charinfo(i)->flags();
michael@0 84 if (((spaceOnly
michael@0 85 || (breakWeight > 0 && breakWeight <= gr_breakWord)
michael@0 86 || i + 1 == seg->charInfoCount()
michael@0 87 || ((nextBreakWeight < 0 && nextBreakWeight >= gr_breakBeforeWord)
michael@0 88 || (subSegEndSlot->next() && m_cacheStore->isSpaceGlyph(subSegEndSlot->next()->gid()))))
michael@0 89 && f != 1)
michael@0 90 || f == 2)
michael@0 91 {
michael@0 92 // record the next slot before any splicing
michael@0 93 Slot * nextSlot = subSegEndSlot->next();
michael@0 94 // spaces should be left untouched by graphite rules in any sane font
michael@0 95 if (!spaceOnly)
michael@0 96 {
michael@0 97 // found a break position, check for a cache of the sub sequence
michael@0 98 const SegCacheEntry * entry = segCache->find(cmapGlyphs, length);
michael@0 99 // TODO disable cache for words at start/end of line with contextuals
michael@0 100 if (!entry)
michael@0 101 {
michael@0 102 SegmentScopeState scopeState = seg->setScope(subSegStartSlot, subSegEndSlot, length);
michael@0 103 pSilf->runGraphite(seg, pSilf->substitutionPass(), pSilf->numPasses());
michael@0 104 if (length < eMaxSpliceSize)
michael@0 105 {
michael@0 106 seg->associateChars(subSegStart, length);
michael@0 107 segCache->cache(m_cacheStore, cmapGlyphs, length, seg, subSegStart);
michael@0 108 }
michael@0 109 seg->removeScope(scopeState);
michael@0 110 }
michael@0 111 else
michael@0 112 seg->splice(subSegStart, length, subSegStartSlot, subSegEndSlot,
michael@0 113 entry->first(), entry->glyphLength());
michael@0 114 }
michael@0 115 subSegStartSlot = subSegEndSlot = nextSlot;
michael@0 116 subSegStart = i + 1;
michael@0 117 }
michael@0 118 else
michael@0 119 {
michael@0 120 subSegEndSlot = subSegEndSlot->next();
michael@0 121 }
michael@0 122 }
michael@0 123 return true;
michael@0 124 }
michael@0 125
michael@0 126 #endif
michael@0 127

mercurial