1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_WW8_FKP_IMPL_HXX
25 #define INCLUDED_WW8_FKP_IMPL_HXX
26 
27 #include <set>
28 #include <deque>
29 #include <WW8FKP.hxx>
30 
31 #ifndef INCLUDED_OUTPUT_WITH_DEPTH_HXX
32 #include <resourcemodel/OutputWithDepth.hxx>
33 #endif
34 
35 namespace writerfilter {
36 namespace doctok
37 {
38 /**
39    Implementation class for formatted disk pages.
40  */
41 class WW8FKPImpl : public WW8FKP
42 {
43     sal_uInt32 mnPageNumber;
44     bool mbComplex;
45 
46 public:
WW8FKPImpl(WW8Stream & rStream,sal_uInt32 nPageNumber,bool bComplex)47     WW8FKPImpl(WW8Stream & rStream, sal_uInt32 nPageNumber, bool bComplex)
48     : WW8FKP(rStream, nPageNumber * 512), mnPageNumber(nPageNumber),
49       mbComplex(bComplex)
50     {
51     }
52 
getPageNumber() const53     virtual sal_uInt32 getPageNumber() const { return mnPageNumber; }
54 
getEntryCount() const55     virtual sal_uInt32 getEntryCount() const { return getU8(511); }
getRgb() const56     virtual sal_uInt32 getRgb() const { return 4 * (getEntryCount() + 1); }
getFc(sal_uInt32 nIndex) const57     virtual Fc getFc(sal_uInt32 nIndex) const
58     { return Fc(getU32(nIndex * 4), mbComplex); }
getFirstFc() const59     virtual Fc getFirstFc() const { return getFc(0); }
getLastFc() const60     virtual Fc getLastFc() const { return getFc(getEntryCount()); }
61 
contains(const Fc & rFc) const62     virtual bool contains(const Fc & rFc) const
63     { return getFirstFc() <= rFc && rFc < getLastFc(); }
64 
65     virtual sal_uInt32 getIndex(const Fc & rFc) const;
66 
67     friend bool operator < (const WW8FKPImpl & rA,
68                             const WW8FKPImpl & rB);
69 };
70 
71 /**
72    Implementation class for formatted disk pages containing character
73    properties.
74  */
75 class WW8CHPFKPImpl : public WW8FKPImpl
76 {
77 public:
WW8CHPFKPImpl(WW8Stream & rStream,sal_uInt32 nPageNumber,bool bComplex)78     WW8CHPFKPImpl(WW8Stream & rStream, sal_uInt32 nPageNumber,
79                   bool bComplex)
80     : WW8FKPImpl(rStream, nPageNumber, bComplex)
81     {
82     }
83 
84     virtual writerfilter::Reference<Properties>::Pointer_t
85     getProperties(const Fc & rFc) const;
86 
87     virtual void dump(OutputWithDepth<string> & o) const;
88 };
89 
90 /**
91    Implementation class for formatted disk pages containing paragraph
92    properties.
93  */
94 class WW8PAPFKPImpl : public WW8FKPImpl
95 {
96 public:
WW8PAPFKPImpl(WW8Stream & rStream,sal_uInt32 nPageNumber,bool bComplex)97     WW8PAPFKPImpl(WW8Stream & rStream, sal_uInt32 nPageNumber,
98                   bool bComplex)
99     : WW8FKPImpl(rStream, nPageNumber, bComplex)
100     {
101     }
102 
103     virtual writerfilter::Reference<Properties>::Pointer_t
104     getProperties(const Fc & rFc) const;
105 
106     virtual void dump(OutputWithDepth<string> & o) const;
107 };
108 
109 /**
110    Tuple of page number and formattet disk page.
111  */
112 class PageNumberAndFKP
113 {
114     /// page number
115     sal_uInt32 mnPageNumber;
116 
117     /// pointer to formatted disk page
118     WW8FKP::Pointer_t mpFKP;
119 
120 public:
PageNumberAndFKP(sal_uInt32 nPageNumber,WW8FKP::Pointer_t pFKP)121     PageNumberAndFKP(sal_uInt32 nPageNumber, WW8FKP::Pointer_t pFKP)
122     : mnPageNumber(nPageNumber), mpFKP(pFKP)
123     {
124     }
125 
126     /**
127        Return page number.
128      */
getPageNumber() const129     sal_uInt32 getPageNumber() const { return mnPageNumber; }
130 
131     /**
132        Return formatted disk page.
133      */
getFKP() const134     const WW8FKP::Pointer_t getFKP() const { return mpFKP; }
135 
136     friend bool operator < (const PageNumberAndFKP & rA,
137                             const PageNumberAndFKP & rB);
138 };
139 
140 /**
141    Cache for formatted disk pages.
142  */
143 class WW8FKPCacheImpl : public WW8FKPCache
144 {
145     /// size of the cache
146     sal_uInt32 mnCacheSize;
147 
148     /// set of tuples of page number and FKP
149     typedef set<PageNumberAndFKP> PageNumbersAndFKPs;
150 
151     ///
152     typedef deque<sal_uInt32> PageNumbers;
153 
154     PageNumbers mPageNumbers;
155     PageNumbersAndFKPs mPageNumbersAndFKPs;
156 
157 protected:
158     WW8Stream::Pointer_t mpStream;
159     virtual WW8FKP::Pointer_t createFKP(sal_uInt32 nPageNumber,
160                                         bool bComplex) = 0;
161 
162 public:
WW8FKPCacheImpl(WW8Stream::Pointer_t rpStream,sal_uInt32 nCacheSize)163     WW8FKPCacheImpl(WW8Stream::Pointer_t rpStream, sal_uInt32 nCacheSize)
164     : mnCacheSize(nCacheSize), mpStream(rpStream)
165     {
166     }
167 
~WW8FKPCacheImpl()168     virtual ~WW8FKPCacheImpl()
169     {
170     }
171 
172     WW8FKP::Pointer_t get(sal_uInt32 nPageNumber, bool bComplex);
173 };
174 
175 class WW8CHPFKPCacheImpl : public WW8FKPCacheImpl
176 {
177     virtual WW8FKP::Pointer_t createFKP(sal_uInt32 nPageNumber,
178                                         bool bComplex);
179 
180 public:
WW8CHPFKPCacheImpl(WW8Stream::Pointer_t rpStream,sal_uInt32 nCacheSize)181     WW8CHPFKPCacheImpl(WW8Stream::Pointer_t rpStream,
182                        sal_uInt32 nCacheSize)
183     : WW8FKPCacheImpl(rpStream, nCacheSize)
184     {
185     }
186 
~WW8CHPFKPCacheImpl()187     virtual ~WW8CHPFKPCacheImpl()
188     {
189     }
190 };
191 
192 class WW8PAPFKPCacheImpl : public WW8FKPCacheImpl
193 {
194     virtual WW8FKP::Pointer_t createFKP(sal_uInt32 nPageNumber,
195                                         bool bComplex);
196 
197 public:
WW8PAPFKPCacheImpl(WW8Stream::Pointer_t rpStream,sal_uInt32 nCacheSize)198     WW8PAPFKPCacheImpl(WW8Stream::Pointer_t rpStream,
199                        sal_uInt32 nCacheSize)
200     : WW8FKPCacheImpl(rpStream, nCacheSize)
201     {
202     }
203 
~WW8PAPFKPCacheImpl()204     virtual ~WW8PAPFKPCacheImpl()
205     {
206     }
207 };
208 }}
209 
210 #endif // INCLUDED_WW8_FKP_IMPL_HXX
211