Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "WW8FKPImpl.hxx"
21 : #include "WW8PropertySetImpl.hxx"
22 :
23 : namespace writerfilter {
24 : namespace doctok
25 : {
26 0 : sal_uInt32 WW8FKPImpl::getIndex(const Fc & rFc) const
27 : {
28 0 : sal_uInt32 nResult = getEntryCount();
29 :
30 0 : while (rFc < getFc(nResult))
31 0 : nResult--;
32 :
33 0 : return nResult;
34 : }
35 :
36 :
37 0 : writerfilter::Reference<Properties>::Pointer_t WW8CHPFKPImpl::getProperties(const Fc & rFc) const
38 : {
39 0 : writerfilter::Reference<Properties>::Pointer_t pResult;
40 :
41 0 : sal_uInt32 n = getIndex(rFc);
42 :
43 0 : sal_uInt16 nOffset = 2 * getU8(getRgb() + n);
44 :
45 0 : if (nOffset > getRgb() + getEntryCount())
46 : {
47 0 : sal_uInt16 nCbChpx = getU8(nOffset);
48 :
49 0 : if (nCbChpx > 1 && nOffset + nCbChpx + 1 <= 511)
50 : {
51 : pResult = writerfilter::Reference<Properties>::Pointer_t
52 0 : (new WW8PropertySetImpl(*this, nOffset + 1, nCbChpx));
53 : }
54 : }
55 :
56 0 : return pResult;
57 : }
58 :
59 0 : void WW8CHPFKPImpl::dump(OutputWithDepth<string> & o) const
60 : {
61 0 : o.addItem("<fkp type='CHP'>");
62 :
63 0 : sal_uInt32 nCount = getEntryCount();
64 0 : for (sal_uInt32 n = 0; n < nCount; ++n)
65 : {
66 : char sBuffer[256];
67 :
68 : snprintf(sBuffer, sizeof(sBuffer),
69 : "<fkpentry fc='%" SAL_PRIxUINT32 "' offsetInFkp='%x'/>",
70 0 : getFc(n).get(), 2 * getU8(getRgb() + n));
71 :
72 0 : o.addItem(sBuffer);
73 : }
74 :
75 0 : WW8StructBase::dump(o);
76 0 : o.addItem("</fkp>");
77 0 : }
78 :
79 : writerfilter::Reference<Properties>::Pointer_t
80 0 : WW8PAPFKPImpl::getProperties(const Fc & rFc) const
81 : {
82 0 : writerfilter::Reference<Properties>::Pointer_t pResult;
83 :
84 0 : sal_uInt32 n = getIndex(rFc);
85 :
86 0 : sal_uInt16 nOffset = 2 * getU8(getRgb() + n * 13);
87 :
88 0 : if (nOffset != 0)
89 : {
90 0 : if (nOffset > getRgb() + getEntryCount() * 13)
91 : {
92 0 : sal_uInt32 nOffsetIStd = nOffset + 1;
93 0 : sal_uInt16 nCbPapx = getU8(nOffset) * 2;
94 :
95 0 : if (nCbPapx == 0)
96 : {
97 0 : nOffsetIStd = nOffset + 2;
98 0 : nCbPapx = getU8(nOffset + 1) * 2 + 2;
99 : }
100 :
101 0 : sal_uInt32 nOffsetEnd = nOffset + nCbPapx;
102 :
103 0 : if (nCbPapx > 1 && nOffset + nCbPapx <= 511)
104 : {
105 : pResult = writerfilter::Reference<Properties>::Pointer_t
106 : (new WW8PropertySetImpl(*this, nOffsetIStd,
107 : nOffsetEnd - nOffsetIStd,
108 0 : true));
109 : }
110 : }
111 : }
112 :
113 0 : return pResult;
114 : }
115 :
116 0 : void WW8PAPFKPImpl::dump(OutputWithDepth<string> & o) const
117 : {
118 0 : o.addItem("<fkp type='PAP'>");
119 :
120 0 : sal_uInt32 nCount = getEntryCount();
121 0 : for (sal_uInt32 n = 0; n < nCount; ++n)
122 : {
123 : char sBuffer[256];
124 :
125 : snprintf(sBuffer, sizeof(sBuffer),
126 : "<fkpentry fc='%" SAL_PRIxUINT32 "' offsetInFKP='%x'/>",
127 0 : getFc(n).get(), 2 * getU8(getRgb() + n * 13));
128 :
129 0 : o.addItem(sBuffer);
130 : }
131 :
132 0 : WW8StructBase::dump(o);
133 :
134 0 : o.addItem("</fkp>");
135 0 : }
136 :
137 0 : bool operator < (const PageNumberAndFKP & rA,
138 : const PageNumberAndFKP & rB)
139 : {
140 0 : return rA.mnPageNumber < rB.mnPageNumber;
141 : }
142 :
143 0 : WW8FKPCache::~WW8FKPCache()
144 : {
145 0 : }
146 :
147 0 : WW8FKP::Pointer_t WW8FKPCacheImpl::get(sal_uInt32 nPageNumber,
148 : bool bComplex)
149 : {
150 0 : WW8FKP::Pointer_t pResult;
151 :
152 0 : PageNumbersAndFKPs::iterator aIt;
153 : aIt = mPageNumbersAndFKPs.find
154 0 : (PageNumberAndFKP(nPageNumber, WW8FKP::Pointer_t()));
155 :
156 0 : if (aIt != mPageNumbersAndFKPs.end())
157 0 : pResult = aIt->getFKP();
158 : else
159 : {
160 0 : if (mPageNumbersAndFKPs.size() > mnCacheSize)
161 : {
162 : PageNumbersAndFKPs::iterator aItDel =
163 : mPageNumbersAndFKPs.find
164 0 : (PageNumberAndFKP(mPageNumbers.front(),
165 0 : WW8FKP::Pointer_t()));
166 :
167 0 : mPageNumbersAndFKPs.erase(aItDel);
168 0 : mPageNumbers.pop_front();
169 : }
170 :
171 0 : pResult = createFKP(nPageNumber, bComplex);
172 :
173 0 : PageNumberAndFKP aPageNumberAndFKP(nPageNumber, pResult);
174 0 : mPageNumbersAndFKPs.insert(aPageNumberAndFKP);
175 0 : mPageNumbers.push_back(nPageNumber);
176 : }
177 :
178 0 : return pResult;
179 : }
180 :
181 0 : WW8FKP::Pointer_t WW8CHPFKPCacheImpl::createFKP(sal_uInt32 nPageNumber,
182 : bool bComplex)
183 : {
184 : return WW8FKP::Pointer_t(new WW8CHPFKPImpl
185 0 : (*mpStream, nPageNumber, bComplex));
186 : }
187 :
188 0 : WW8FKP::Pointer_t WW8PAPFKPCacheImpl::createFKP(sal_uInt32 nPageNumber,
189 : bool bComplex)
190 : {
191 : return WW8FKP::Pointer_t(new WW8PAPFKPImpl
192 0 : (*mpStream, nPageNumber, bComplex));
193 : }
194 15 : }}
195 :
196 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|