1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
{
26 sal_uInt32
WW8FKPImpl::getIndex(const Fc
& rFc
) const
28 sal_uInt32 nResult
= getEntryCount();
30 while (rFc
< getFc(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
));
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
)
68 snprintf(sBuffer
, sizeof(sBuffer
),
69 "<fkpentry fc='%" SAL_PRIxUINT32
"' offsetInFkp='%x'/>",
70 getFc(n
).get(), 2 * getU8(getRgb() + n
));
75 WW8StructBase::dump(o
);
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);
90 if (nOffset
> getRgb() + getEntryCount() * 13)
92 sal_uInt32 nOffsetIStd
= nOffset
+ 1;
93 sal_uInt16 nCbPapx
= getU8(nOffset
) * 2;
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
,
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
)
125 snprintf(sBuffer
, sizeof(sBuffer
),
126 "<fkpentry fc='%" SAL_PRIxUINT32
"' offsetInFKP='%x'/>",
127 getFc(n
).get(), 2 * getU8(getRgb() + n
* 13));
132 WW8StructBase::dump(o
);
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
,
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();
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
);
181 WW8FKP::Pointer_t
WW8CHPFKPCacheImpl::createFKP(sal_uInt32 nPageNumber
,
184 return WW8FKP::Pointer_t(new WW8CHPFKPImpl
185 (*mpStream
, nPageNumber
, bComplex
));
188 WW8FKP::Pointer_t
WW8PAPFKPCacheImpl::createFKP(sal_uInt32 nPageNumber
,
191 return WW8FKP::Pointer_t(new WW8PAPFKPImpl
192 (*mpStream
, nPageNumber
, bComplex
));
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */