1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef INCLUDED_WW8_FKP_IMPL_HXX 29 #define INCLUDED_WW8_FKP_IMPL_HXX 30 31 #include <set> 32 #include <deque> 33 #include <WW8FKP.hxx> 34 35 #ifndef INCLUDED_OUTPUT_WITH_DEPTH_HXX 36 #include <resourcemodel/OutputWithDepth.hxx> 37 #endif 38 39 namespace writerfilter { 40 namespace doctok 41 { 42 /** 43 Implementation class for formatted disk pages. 44 */ 45 class WW8FKPImpl : public WW8FKP 46 { 47 sal_uInt32 mnPageNumber; 48 bool mbComplex; 49 50 public: 51 WW8FKPImpl(WW8Stream & rStream, sal_uInt32 nPageNumber, bool bComplex) 52 : WW8FKP(rStream, nPageNumber * 512), mnPageNumber(nPageNumber), 53 mbComplex(bComplex) 54 { 55 } 56 57 virtual sal_uInt32 getPageNumber() const { return mnPageNumber; } 58 59 virtual sal_uInt32 getEntryCount() const { return getU8(511); } 60 virtual sal_uInt32 getRgb() const { return 4 * (getEntryCount() + 1); } 61 virtual Fc getFc(sal_uInt32 nIndex) const 62 { return Fc(getU32(nIndex * 4), mbComplex); } 63 virtual Fc getFirstFc() const { return getFc(0); } 64 virtual Fc getLastFc() const { return getFc(getEntryCount()); } 65 66 virtual bool contains(const Fc & rFc) const 67 { return getFirstFc() <= rFc && rFc < getLastFc(); } 68 69 virtual sal_uInt32 getIndex(const Fc & rFc) const; 70 71 friend bool operator < (const WW8FKPImpl & rA, 72 const WW8FKPImpl & rB); 73 }; 74 75 /** 76 Implementation class for formatted disk pages containing character 77 properties. 78 */ 79 class WW8CHPFKPImpl : public WW8FKPImpl 80 { 81 public: 82 WW8CHPFKPImpl(WW8Stream & rStream, sal_uInt32 nPageNumber, 83 bool bComplex) 84 : WW8FKPImpl(rStream, nPageNumber, bComplex) 85 { 86 } 87 88 virtual writerfilter::Reference<Properties>::Pointer_t 89 getProperties(const Fc & rFc) const; 90 91 virtual void dump(OutputWithDepth<string> & o) const; 92 }; 93 94 /** 95 Implementation class for formatted disk pages containing paragraph 96 properties. 97 */ 98 class WW8PAPFKPImpl : public WW8FKPImpl 99 { 100 public: 101 WW8PAPFKPImpl(WW8Stream & rStream, sal_uInt32 nPageNumber, 102 bool bComplex) 103 : WW8FKPImpl(rStream, nPageNumber, bComplex) 104 { 105 } 106 107 virtual writerfilter::Reference<Properties>::Pointer_t 108 getProperties(const Fc & rFc) const; 109 110 virtual void dump(OutputWithDepth<string> & o) const; 111 }; 112 113 /** 114 Tuple of page number and formattet disk page. 115 */ 116 class PageNumberAndFKP 117 { 118 /// page number 119 sal_uInt32 mnPageNumber; 120 121 /// pointer to formatted disk page 122 WW8FKP::Pointer_t mpFKP; 123 124 public: 125 PageNumberAndFKP(sal_uInt32 nPageNumber, WW8FKP::Pointer_t pFKP) 126 : mnPageNumber(nPageNumber), mpFKP(pFKP) 127 { 128 } 129 130 /** 131 Return page number. 132 */ 133 sal_uInt32 getPageNumber() const { return mnPageNumber; } 134 135 /** 136 Return formatted disk page. 137 */ 138 const WW8FKP::Pointer_t getFKP() const { return mpFKP; } 139 140 friend bool operator < (const PageNumberAndFKP & rA, 141 const PageNumberAndFKP & rB); 142 }; 143 144 /** 145 Cache for formatted disk pages. 146 */ 147 class WW8FKPCacheImpl : public WW8FKPCache 148 { 149 /// size of the cache 150 sal_uInt32 mnCacheSize; 151 152 /// set of tuples of page number and FKP 153 typedef set<PageNumberAndFKP> PageNumbersAndFKPs; 154 155 /// 156 typedef deque<sal_uInt32> PageNumbers; 157 158 PageNumbers mPageNumbers; 159 PageNumbersAndFKPs mPageNumbersAndFKPs; 160 161 protected: 162 WW8Stream::Pointer_t mpStream; 163 virtual WW8FKP::Pointer_t createFKP(sal_uInt32 nPageNumber, 164 bool bComplex) = 0; 165 166 public: 167 WW8FKPCacheImpl(WW8Stream::Pointer_t rpStream, sal_uInt32 nCacheSize) 168 : mnCacheSize(nCacheSize), mpStream(rpStream) 169 { 170 } 171 172 virtual ~WW8FKPCacheImpl() 173 { 174 } 175 176 WW8FKP::Pointer_t get(sal_uInt32 nPageNumber, bool bComplex); 177 }; 178 179 class WW8CHPFKPCacheImpl : public WW8FKPCacheImpl 180 { 181 virtual WW8FKP::Pointer_t createFKP(sal_uInt32 nPageNumber, 182 bool bComplex); 183 184 public: 185 WW8CHPFKPCacheImpl(WW8Stream::Pointer_t rpStream, 186 sal_uInt32 nCacheSize) 187 : WW8FKPCacheImpl(rpStream, nCacheSize) 188 { 189 } 190 191 virtual ~WW8CHPFKPCacheImpl() 192 { 193 } 194 }; 195 196 class WW8PAPFKPCacheImpl : public WW8FKPCacheImpl 197 { 198 virtual WW8FKP::Pointer_t createFKP(sal_uInt32 nPageNumber, 199 bool bComplex); 200 201 public: 202 WW8PAPFKPCacheImpl(WW8Stream::Pointer_t rpStream, 203 sal_uInt32 nCacheSize) 204 : WW8FKPCacheImpl(rpStream, nCacheSize) 205 { 206 } 207 208 virtual ~WW8PAPFKPCacheImpl() 209 { 210 } 211 }; 212 }} 213 214 #endif // INCLUDED_WW8_FKP_IMPL_HXX 215