1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8FKPImpl.cxx,v $
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
{
38 sal_uInt32
WW8FKPImpl::getIndex(const Fc
& rFc
) const
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
))
61 sal_uInt32
WW8FKPImpl::getIndex(const Fc
& rFc
) const
63 sal_uInt32 nResult
= getEntryCount();
65 while (rFc
< getFc(nResult
))
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
));
94 clog
<< "outsider!!!" << endl
;
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
)
110 snprintf(sBuffer
, sizeof(sBuffer
),
111 "<fkpentry fc='%" SAL_PRIxUINT32
"' offsetInFkp='%x'/>",
112 getFc(n
).get(), 2 * getU8(getRgb() + n
));
117 WW8StructBase::dump(o
);
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);
132 if (nOffset
> getRgb() + getEntryCount() * 13)
134 sal_uInt32 nOffsetIStd
= nOffset
+ 1;
135 sal_uInt16 nCbPapx
= getU8(nOffset
) * 2;
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
,
157 clog
<< "outsider!!!" << endl
;
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
)
174 snprintf(sBuffer
, sizeof(sBuffer
),
175 "<fkpentry fc='%" SAL_PRIxUINT32
"' offsetInFKP='%x'/>",
176 getFc(n
).get(), 2 * getU8(getRgb() + n
* 13));
181 WW8StructBase::dump(o
);
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
,
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();
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
);
230 WW8FKP::Pointer_t
WW8CHPFKPCacheImpl::createFKP(sal_uInt32 nPageNumber
,
233 return WW8FKP::Pointer_t(new WW8CHPFKPImpl
234 (*mpStream
, nPageNumber
, bComplex
));
237 WW8FKP::Pointer_t
WW8PAPFKPCacheImpl::createFKP(sal_uInt32 nPageNumber
,
240 return WW8FKP::Pointer_t(new WW8PAPFKPImpl
241 (*mpStream
, nPageNumber
, bComplex
));