tdf#131098 docx export: write fill property of graphic
[LibreOffice.git] / lotuswordpro / source / filter / lwpidxmgr.cxx
blobe9f34bf956d1d068a16384559411274d1bde9ca0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
57 /**********************************************************************************************************************
58 * @file
59 * index manager implementation
60 * Three record types are related with index information, and two ways are used.
61 * 1. VO_ROOTOBJINDEX works with one or more VO_LEAFOBJINDEX records to
62 * provide the map of all object ids and their offsets.
63 * VO_ROOTOBJINDEX includes k (object id, offset) and timetable which is used to map index to actual low id
64 * 2. VO_ROOTLEAFOBJINDEX is used when the file is so small that the number of objects is less than 256(?)
65 * VO_ROOTLEAFOBJINDEX contains directly the (object id, offset) map and time table.
67 **********************************************************************************************************************/
69 #include <lwpidxmgr.hxx>
70 #include <lwpobjhdr.hxx>
71 #include <lwptools.hxx>
72 #include <memory>
74 const sal_uInt8 LwpIndexManager::MAXOBJECTIDS = 255;
76 LwpIndexManager::LwpIndexManager()
77 : m_nKeyCount(0)
78 , m_nLeafCount(0)
80 m_TempVec.resize( LwpIndexManager::MAXOBJECTIDS );
84 /**
85 * @descr Read all index records, VO_ROOTLEAFOBJINDEX, VO_ROOTOBJINDEX, VO_LEAFOBJINDEX
87 void LwpIndexManager::Read(LwpSvStream* pStrm)
89 //Read index obj
90 LwpObjectHeader ObjHdr;
91 if (!ObjHdr.Read(*pStrm))
92 throw BadRead();
93 std::unique_ptr<LwpObjectStream> xObjStrm(new LwpObjectStream(pStrm, ObjHdr.IsCompressed(),
94 static_cast<sal_uInt16>(ObjHdr.GetSize())));
96 if( ObjHdr.GetTag() == VO_ROOTLEAFOBJINDEX )
98 ReadLeafData(xObjStrm.get());
99 ReadTimeTable(xObjStrm.get());
100 xObjStrm.reset();
102 else
104 ReadRootData(xObjStrm.get());
105 xObjStrm.reset();
107 for (sal_uInt16 k = 0; k < m_nLeafCount; k++)
109 //Read leaf
110 sal_Int64 nPos = m_ChildIndex[k]+LwpSvStream::LWP_STREAM_BASE;
111 if (!pStrm->CheckSeek(nPos))
112 throw BadSeek();
114 //Old Code
115 //ReadLeafIndex(pStrm);
116 //New Code
117 ReadObjIndex( pStrm );
119 //Read object in root, these objects are between the leaf objects
120 if(k!=m_nLeafCount-1)
122 m_ObjectKeys.push_back(m_RootObjs[k]);
123 m_nKeyCount ++;
126 m_RootObjs.clear();
131 * @descr Read data in VO_ROOTOBJINDEX
133 void LwpIndexManager::ReadRootData(LwpObjectStream* pObjStrm)
136 sal_uInt16 KeyCount = pObjStrm->QuickReaduInt16();
137 m_nLeafCount = KeyCount ? KeyCount + 1 : 0;
139 if (m_nLeafCount > SAL_N_ELEMENTS(m_ChildIndex))
140 throw std::range_error("corrupt RootData");
142 if (KeyCount)
144 //read object keys
145 LwpKey akey;
146 akey.id.Read(pObjStrm);
147 m_RootObjs.push_back(akey);
149 sal_uInt16 k = 0;
151 for (k = 1; k < KeyCount; k++)
153 akey.id.ReadCompressed(pObjStrm, m_RootObjs[k-1].id);
154 m_RootObjs.push_back(akey);
157 for (k = 0; k < KeyCount; k++)
158 m_RootObjs[k].offset = pObjStrm->QuickReaduInt32();
160 //read leaf index offset
161 for (k = 0; k < m_nLeafCount; k++)
162 m_ChildIndex[k] = pObjStrm->QuickReaduInt32();
165 ReadTimeTable(pObjStrm);
169 //Add new method to handle ObjIndex data
171 * @descr Read data in VO_OBJINDEX
173 void LwpIndexManager::ReadObjIndexData(LwpObjectStream* pObjStrm)
175 sal_uInt16 KeyCount = pObjStrm->QuickReaduInt16();
176 sal_uInt16 LeafCount = KeyCount + 1;
178 std::vector<LwpKey> vObjIndexs;
180 if (KeyCount)
182 LwpKey akey;
183 akey.id.Read(pObjStrm);
184 vObjIndexs.push_back(akey);
186 sal_uInt16 k = 0;
188 for (k = 1; k < KeyCount; k++)
190 akey.id.ReadCompressed(pObjStrm, vObjIndexs[k-1].id);
191 vObjIndexs.push_back(akey);
194 for (k = 0; k < KeyCount; k++)
195 vObjIndexs[k].offset = pObjStrm->QuickReaduInt32();
197 for (k = 0; k < LeafCount; k++)
198 m_TempVec.at(k) = pObjStrm->QuickReaduInt32();
201 for( sal_uInt16 j=0; j<LeafCount; j++ )
203 sal_Int64 nPos = m_TempVec.at(j) + LwpSvStream::LWP_STREAM_BASE;
204 sal_Int64 nActualPos = pObjStrm->GetStream()->Seek(nPos);
206 if (nPos != nActualPos)
207 throw BadSeek();
209 ReadLeafIndex(pObjStrm->GetStream());
211 if(j!=LeafCount-1)
213 m_ObjectKeys.push_back(vObjIndexs[j]);
215 m_nKeyCount ++;
219 vObjIndexs.clear();
220 m_TempVec.clear();
224 * @descr Read VO_OBJINDEX
226 void LwpIndexManager::ReadObjIndex( LwpSvStream *pStrm )
228 LwpObjectHeader ObjHdr;
229 if (!ObjHdr.Read(*pStrm))
230 throw BadRead();
231 LwpObjectStream aObjStrm(pStrm, ObjHdr.IsCompressed(),
232 static_cast<sal_uInt16>(ObjHdr.GetSize()) );
234 if( sal_uInt32(VO_OBJINDEX) == ObjHdr.GetTag() )
236 ReadObjIndexData( &aObjStrm );
238 else if( sal_uInt32(VO_LEAFOBJINDEX) == ObjHdr.GetTag() )
240 ReadLeafData( &aObjStrm );
245 * @descr Read VO_LEAFOBJINDEX
247 void LwpIndexManager::ReadLeafIndex( LwpSvStream *pStrm )
249 LwpObjectHeader ObjHdr;
250 if (!ObjHdr.Read(*pStrm))
251 throw BadRead();
252 LwpObjectStream aObjStrm( pStrm, ObjHdr.IsCompressed(),
253 static_cast<sal_uInt16>(ObjHdr.GetSize()) );
255 ReadLeafData(&aObjStrm);
258 * @descr Read data in VO_LEAFOBJINDEX
260 void LwpIndexManager::ReadLeafData( LwpObjectStream *pObjStrm )
262 sal_uInt16 KeyCount = pObjStrm->QuickReaduInt16();
264 if(KeyCount)
266 LwpKey akey;
267 //read object keys: id & offset
268 akey.id.Read(pObjStrm);
269 m_ObjectKeys.push_back(akey);
271 for (sal_uInt16 k = 1; k < KeyCount; k++)
273 akey.id.ReadCompressed(pObjStrm, m_ObjectKeys.at(m_nKeyCount+k-1).id);
274 m_ObjectKeys.push_back(akey);
277 for (sal_uInt16 j = 0; j < KeyCount; j++)
278 m_ObjectKeys.at(m_nKeyCount+j).offset = pObjStrm->QuickReaduInt32();
280 m_nKeyCount += KeyCount;
283 * @descr Read time table in VO_ROOTLEAFOBJINDEX and VO_ROOTOBJINDEX
285 void LwpIndexManager::ReadTimeTable(LwpObjectStream *pObjStrm)
287 sal_uInt16 nTimeCount = pObjStrm->QuickReaduInt16();
289 for(sal_uInt16 i=0; i<nTimeCount; ++i)
291 sal_uInt32 atime = pObjStrm->QuickReaduInt32();
292 m_TimeTable.push_back(atime);
296 * @descr get object offset per the object id
298 sal_uInt32 LwpIndexManager::GetObjOffset( LwpObjectID objid )
301 //sal_uInt16 L, U, M;
302 sal_uInt32 L, U, M;
304 L = 0;
305 U = m_nKeyCount;
306 while (L != U)
308 M = (L + U) >> 1;
310 if (objid.GetLow() > m_ObjectKeys[M].id.GetLow())
311 L = M + 1;
312 else if (objid.GetLow() < m_ObjectKeys[M].id.GetLow())
313 U = M;
314 else if (objid.GetHigh() > m_ObjectKeys[M].id.GetHigh())
315 L = M + 1;
316 else if (objid.GetHigh() < m_ObjectKeys[M].id.GetHigh())
317 U = M;
318 else
320 return(m_ObjectKeys[M].offset);
323 return BAD_OFFSET;
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */