Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / doctok / WW8FKPImpl.cxx
blobcc58d9416d77c2dc3cc0c0cec4b86c7e495a29cf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "WW8FKPImpl.hxx"
21 #include "WW8PropertySetImpl.hxx"
23 namespace writerfilter {
24 namespace doctok
26 sal_uInt32 WW8FKPImpl::getIndex(const Fc & rFc) const
28 sal_uInt32 nResult = getEntryCount();
30 while (rFc < getFc(nResult))
31 nResult--;
33 return nResult;
37 writerfilter::Reference<Properties>::Pointer_t WW8CHPFKPImpl::getProperties(const Fc & rFc) const
39 writerfilter::Reference<Properties>::Pointer_t pResult;
41 sal_uInt32 n = getIndex(rFc);
43 sal_uInt16 nOffset = 2 * getU8(getRgb() + n);
45 if (nOffset > getRgb() + getEntryCount())
47 sal_uInt16 nCbChpx = getU8(nOffset);
49 if (nCbChpx > 1 && nOffset + nCbChpx + 1 <= 511)
51 pResult = writerfilter::Reference<Properties>::Pointer_t
52 (new WW8PropertySetImpl(*this, nOffset + 1, nCbChpx));
56 return pResult;
59 void WW8CHPFKPImpl::dump(OutputWithDepth<string> & o) const
61 o.addItem("<fkp type='CHP'>");
63 sal_uInt32 nCount = getEntryCount();
64 for (sal_uInt32 n = 0; n < nCount; ++n)
66 char sBuffer[256];
68 snprintf(sBuffer, sizeof(sBuffer),
69 "<fkpentry fc='%" SAL_PRIxUINT32 "' offsetInFkp='%x'/>",
70 getFc(n).get(), 2 * getU8(getRgb() + n));
72 o.addItem(sBuffer);
75 WW8StructBase::dump(o);
76 o.addItem("</fkp>");
79 writerfilter::Reference<Properties>::Pointer_t
80 WW8PAPFKPImpl::getProperties(const Fc & rFc) const
82 writerfilter::Reference<Properties>::Pointer_t pResult;
84 sal_uInt32 n = getIndex(rFc);
86 sal_uInt16 nOffset = 2 * getU8(getRgb() + n * 13);
88 if (nOffset != 0)
90 if (nOffset > getRgb() + getEntryCount() * 13)
92 sal_uInt32 nOffsetIStd = nOffset + 1;
93 sal_uInt16 nCbPapx = getU8(nOffset) * 2;
95 if (nCbPapx == 0)
97 nOffsetIStd = nOffset + 2;
98 nCbPapx = getU8(nOffset + 1) * 2 + 2;
101 sal_uInt32 nOffsetEnd = nOffset + nCbPapx;
103 if (nCbPapx > 1 && nOffset + nCbPapx <= 511)
105 pResult = writerfilter::Reference<Properties>::Pointer_t
106 (new WW8PropertySetImpl(*this, nOffsetIStd,
107 nOffsetEnd - nOffsetIStd,
108 true));
113 return pResult;
116 void WW8PAPFKPImpl::dump(OutputWithDepth<string> & o) const
118 o.addItem("<fkp type='PAP'>");
120 sal_uInt32 nCount = getEntryCount();
121 for (sal_uInt32 n = 0; n < nCount; ++n)
123 char sBuffer[256];
125 snprintf(sBuffer, sizeof(sBuffer),
126 "<fkpentry fc='%" SAL_PRIxUINT32 "' offsetInFKP='%x'/>",
127 getFc(n).get(), 2 * getU8(getRgb() + n * 13));
129 o.addItem(sBuffer);
132 WW8StructBase::dump(o);
134 o.addItem("</fkp>");
137 bool operator < (const PageNumberAndFKP & rA,
138 const PageNumberAndFKP & rB)
140 return rA.mnPageNumber < rB.mnPageNumber;
143 WW8FKPCache::~WW8FKPCache()
147 WW8FKP::Pointer_t WW8FKPCacheImpl::get(sal_uInt32 nPageNumber,
148 bool bComplex)
150 WW8FKP::Pointer_t pResult;
152 PageNumbersAndFKPs::iterator aIt;
153 aIt = mPageNumbersAndFKPs.find
154 (PageNumberAndFKP(nPageNumber, WW8FKP::Pointer_t()));
156 if (aIt != mPageNumbersAndFKPs.end())
157 pResult = aIt->getFKP();
158 else
160 if (mPageNumbersAndFKPs.size() > mnCacheSize)
162 PageNumbersAndFKPs::iterator aItDel =
163 mPageNumbersAndFKPs.find
164 (PageNumberAndFKP(mPageNumbers.front(),
165 WW8FKP::Pointer_t()));
167 mPageNumbersAndFKPs.erase(aItDel);
168 mPageNumbers.pop_front();
171 pResult = createFKP(nPageNumber, bComplex);
173 PageNumberAndFKP aPageNumberAndFKP(nPageNumber, pResult);
174 mPageNumbersAndFKPs.insert(aPageNumberAndFKP);
175 mPageNumbers.push_back(nPageNumber);
178 return pResult;
181 WW8FKP::Pointer_t WW8CHPFKPCacheImpl::createFKP(sal_uInt32 nPageNumber,
182 bool bComplex)
184 return WW8FKP::Pointer_t(new WW8CHPFKPImpl
185 (*mpStream, nPageNumber, bComplex));
188 WW8FKP::Pointer_t WW8PAPFKPCacheImpl::createFKP(sal_uInt32 nPageNumber,
189 bool bComplex)
191 return WW8FKP::Pointer_t(new WW8PAPFKPImpl
192 (*mpStream, nPageNumber, bComplex));
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */