Update ooo320-m1
[ooovba.git] / writerfilter / source / doctok / WW8FKPImpl.cxx
blob6b80ddd139d611dfd2a64e55b8fb8ca96be1d47c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8FKPImpl.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "WW8FKPImpl.hxx"
32 #include "WW8PropertySetImpl.hxx"
34 namespace writerfilter {
35 namespace doctok
37 #if 0
38 sal_uInt32 WW8FKPImpl::getIndex(const Fc & rFc) const
40 sal_uInt32 nLeft = 0;
41 sal_uInt32 nRight = getEntryCount();
43 while (nRight - nLeft > 1)
45 sal_uInt32 nMiddle = (nLeft + nRight) / 2;
46 Fc aFcMiddle = getFc(nMiddle);
48 if (! (rFc < aFcMiddle))
50 nLeft = nMiddle;
52 else
54 nRight = nMiddle;
58 return nLeft;
60 #else
61 sal_uInt32 WW8FKPImpl::getIndex(const Fc & rFc) const
63 sal_uInt32 nResult = getEntryCount();
65 while (rFc < getFc(nResult))
66 nResult--;
68 return nResult;
70 #endif
73 writerfilter::Reference<Properties>::Pointer_t WW8CHPFKPImpl::getProperties(const Fc & rFc) const
75 writerfilter::Reference<Properties>::Pointer_t pResult;
77 sal_uInt32 n = getIndex(rFc);
79 sal_uInt16 nOffset = 2 * getU8(getRgb() + n);
81 if (nOffset > getRgb() + getEntryCount())
83 sal_uInt16 nCbChpx = getU8(nOffset);
85 if (nCbChpx > 1 && nOffset + nCbChpx + 1 <= 511)
87 pResult = writerfilter::Reference<Properties>::Pointer_t
88 (new WW8PropertySetImpl(*this, nOffset + 1, nCbChpx));
91 #if 0
92 else
94 clog << "outsider!!!" << endl;
96 #endif
98 return pResult;
101 void WW8CHPFKPImpl::dump(OutputWithDepth<string> & o) const
103 o.addItem("<fkp type='CHP'>");
105 sal_uInt32 nCount = getEntryCount();
106 for (sal_uInt32 n = 0; n < nCount; ++n)
108 char sBuffer[256];
110 snprintf(sBuffer, sizeof(sBuffer),
111 "<fkpentry fc='%" SAL_PRIxUINT32 "' offsetInFkp='%x'/>",
112 getFc(n).get(), 2 * getU8(getRgb() + n));
114 o.addItem(sBuffer);
117 WW8StructBase::dump(o);
118 o.addItem("</fkp>");
121 writerfilter::Reference<Properties>::Pointer_t
122 WW8PAPFKPImpl::getProperties(const Fc & rFc) const
124 writerfilter::Reference<Properties>::Pointer_t pResult;
126 sal_uInt32 n = getIndex(rFc);
128 sal_uInt16 nOffset = 2 * getU8(getRgb() + n * 13);
130 if (nOffset != 0)
132 if (nOffset > getRgb() + getEntryCount() * 13)
134 sal_uInt32 nOffsetIStd = nOffset + 1;
135 sal_uInt16 nCbPapx = getU8(nOffset) * 2;
137 if (nCbPapx == 0)
139 nOffsetIStd = nOffset + 2;
140 nCbPapx = getU8(nOffset + 1) * 2 + 2;
143 sal_uInt32 nOffsetEnd = nOffset + nCbPapx;
144 //sal_uInt32 nOffsetSprms = nOffsetIStd + 2;
146 if (nCbPapx > 1 && nOffset + nCbPapx <= 511)
148 pResult = writerfilter::Reference<Properties>::Pointer_t
149 (new WW8PropertySetImpl(*this, nOffsetIStd,
150 nOffsetEnd - nOffsetIStd,
151 true));
154 #if 0
155 else
157 clog << "outsider!!!" << endl;
159 #endif
162 return pResult;
165 void WW8PAPFKPImpl::dump(OutputWithDepth<string> & o) const
167 o.addItem("<fkp type='PAP'>");
169 sal_uInt32 nCount = getEntryCount();
170 for (sal_uInt32 n = 0; n < nCount; ++n)
172 char sBuffer[256];
174 snprintf(sBuffer, sizeof(sBuffer),
175 "<fkpentry fc='%" SAL_PRIxUINT32 "' offsetInFKP='%x'/>",
176 getFc(n).get(), 2 * getU8(getRgb() + n * 13));
178 o.addItem(sBuffer);
181 WW8StructBase::dump(o);
183 o.addItem("</fkp>");
186 bool operator < (const PageNumberAndFKP & rA,
187 const PageNumberAndFKP & rB)
189 return rA.mnPageNumber < rB.mnPageNumber;
192 WW8FKPCache::~WW8FKPCache()
196 WW8FKP::Pointer_t WW8FKPCacheImpl::get(sal_uInt32 nPageNumber,
197 bool bComplex)
199 WW8FKP::Pointer_t pResult;
201 PageNumbersAndFKPs::iterator aIt;
202 aIt = mPageNumbersAndFKPs.find
203 (PageNumberAndFKP(nPageNumber, WW8FKP::Pointer_t()));
205 if (aIt != mPageNumbersAndFKPs.end())
206 pResult = aIt->getFKP();
207 else
209 if (mPageNumbersAndFKPs.size() > mnCacheSize)
211 PageNumbersAndFKPs::iterator aItDel =
212 mPageNumbersAndFKPs.find
213 (PageNumberAndFKP(mPageNumbers.front(),
214 WW8FKP::Pointer_t()));
216 mPageNumbersAndFKPs.erase(aItDel);
217 mPageNumbers.pop_front();
220 pResult = createFKP(nPageNumber, bComplex);
222 PageNumberAndFKP aPageNumberAndFKP(nPageNumber, pResult);
223 mPageNumbersAndFKPs.insert(aPageNumberAndFKP);
224 mPageNumbers.push_back(nPageNumber);
227 return pResult;
230 WW8FKP::Pointer_t WW8CHPFKPCacheImpl::createFKP(sal_uInt32 nPageNumber,
231 bool bComplex)
233 return WW8FKP::Pointer_t(new WW8CHPFKPImpl
234 (*mpStream, nPageNumber, bComplex));
237 WW8FKP::Pointer_t WW8PAPFKPCacheImpl::createFKP(sal_uInt32 nPageNumber,
238 bool bComplex)
240 return WW8FKP::Pointer_t(new WW8PAPFKPImpl
241 (*mpStream, nPageNumber, bComplex));