fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / bencont.cxx
bloba09695184d90ed7e644819ee54c42b91ae5a68c9
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 ************************************************************************/
56 #include "first.hxx"
57 #include "assert.h"
58 #include <stdio.h>
59 #include <osl/diagnose.h>
60 #include <sot/storinfo.hxx>
61 namespace OpenStormBento
64 // String definitions
65 const char gsBenMagicBytes[] = BEN_MAGIC_BYTES;
67 /**
68 * New bento container from file stream
69 * @param pointer to length of bento file
70 * @param pointer to pointer of Bento Container object
71 * @return error code
73 sal_uLong BenOpenContainer(LwpSvStream * pStream, pLtcBenContainer * ppContainer)
75 BenError Err;
77 *ppContainer = NULL;
79 if (NULL == pStream)
81 return BenErr_ContainerWithNoObjects;
84 pLtcBenContainer pContainer = new LtcBenContainer(pStream);
85 if ((Err = pContainer->Open()) != BenErr_OK) // delete two inputs
87 delete pContainer;
88 return BenErr_InvalidTOC;
91 *ppContainer = pContainer;
92 return BenErr_OK;
95 LtcBenContainer::~LtcBenContainer()
99 BenError
100 LtcBenContainer::Open() // delete two inputs
102 BenError Err;
103 CBenTOCReader TOCReader(this);
104 if ((Err = TOCReader.ReadLabelAndTOC()) != BenErr_OK)
106 return Err;
108 return BenErr_OK;
111 BenError
112 LtcBenContainer::RegisterPropertyName(const char * sPropertyName,
113 pCBenPropertyName * ppPropertyName)
115 pCUtListElmt pPrevNamedObjectListElmt;
116 pCBenNamedObject pNamedObject = FindNamedObject(&cNamedObjects,
117 sPropertyName, &pPrevNamedObjectListElmt);
119 if (pNamedObject != NULL)
121 if (! pNamedObject->IsPropertyName())
122 return BenErr_NameConflict;
123 else *ppPropertyName = static_cast<pCBenPropertyName>(pNamedObject);
125 else
127 pCUtListElmt pPrevObject;
128 if (FindID(&cObjects, cNextAvailObjectID, &pPrevObject) != NULL)
129 return BenErr_DuplicateObjectID;
131 *ppPropertyName = new CBenPropertyName(this, cNextAvailObjectID,
132 static_cast<pCBenObject>(pPrevObject), sPropertyName, pPrevNamedObjectListElmt);
133 ++cNextAvailObjectID;
136 return BenErr_OK;
139 pCBenObject
140 LtcBenContainer::GetNextObject(pCBenObject pCurrObject)
142 return static_cast<pCBenObject>(cObjects.GetNextOrNULL(pCurrObject));
145 pCBenObject
146 LtcBenContainer::FindNextObjectWithProperty(pCBenObject pCurrObject,
147 BenObjectID PropertyID)
149 while ((pCurrObject = GetNextObject(pCurrObject)) != NULL)
150 if (pCurrObject->UseProperty(PropertyID) != NULL)
151 return pCurrObject;
153 return NULL;
157 * Construction
158 * @param Bento file stream pointer
159 * @return
161 LtcBenContainer::LtcBenContainer(LwpSvStream * pStream)
162 : cNextAvailObjectID(0)
164 cpStream = pStream;
165 pStream->Seek(STREAM_SEEK_TO_END);
166 m_ulLength = pStream->Tell();
167 pStream->Seek(STREAM_SEEK_TO_BEGIN);
171 * Read buffer fro bento file with specified buffer
172 * @date 07/05/2004
173 * @param buffer pointer
174 * @param buffer size
175 * @param number of bytes read
176 * @return BenError
178 BenError LtcBenContainer::Read(BenDataPtr pBuffer, unsigned long MaxSize,
179 unsigned long * pAmtRead)
181 *pAmtRead = cpStream->Read(pBuffer, MaxSize);
182 return BenErr_OK;
185 * Read buffer from bento file with specified size
186 * @date 07/05/2004
187 * @param buffer pointer
188 * @param number of bytes to be read
189 * @return BenError
191 BenError LtcBenContainer::ReadKnownSize(BenDataPtr pBuffer, unsigned long Amt)
193 sal_uLong ulLength;
194 ulLength = cpStream->Read(pBuffer, Amt);
195 if(ulLength == Amt)
197 return BenErr_OK;
199 return BenErr_ReadPastEndOfContainer;
202 * Seek to position from the beginning of the bento file
203 * @date 07/05/2004
204 * @param position in container file from beginning
205 * @return BenError
207 BenError LtcBenContainer::SeekToPosition(BenContainerPos Pos)
209 cpStream->Seek(Pos);
210 return BenErr_OK;
213 * Seek to position compare to end of bento file
214 * @date 07/05/2004
215 * @param position in container file from end
216 * @return BenError
218 BenError LtcBenContainer::SeekFromEnd(long Offset)
220 cpStream->Seek(STREAM_SEEK_TO_END);
221 cpStream->SeekRel(Offset);
223 return BenErr_OK;
226 * Find the next value stream with property name
227 * @date 07/05/2004
228 * @param string of property name
229 * @param current value stream pointer with the property name
230 * @return next value stream pointer with the property names
232 LtcUtBenValueStream * LtcBenContainer::FindNextValueStreamWithPropertyName(const char * sPropertyName, LtcUtBenValueStream * pCurrentValueStream)
234 CBenPropertyName * pPropertyName;
235 RegisterPropertyName(sPropertyName, &pPropertyName); // Get property name object
237 if (NULL == pPropertyName)
238 return NULL; // Property not exist
240 // Get current object
241 CBenObject * pObj = NULL;
242 if (pCurrentValueStream != NULL)
244 pObj = pCurrentValueStream->GetValue()->GetProperty()->GetBenObject();
247 pObj =FindNextObjectWithProperty(pObj, pPropertyName->GetID()); // Get next object with same property name
248 if (NULL == pObj)
249 return NULL;
251 CBenValue * pValue;
252 LtcUtBenValueStream * pValueStream;
254 pValue = pObj->UseValue(pPropertyName->GetID());
256 pValueStream = new LtcUtBenValueStream(pValue);
258 return pValueStream;
262 * Find the unique value stream with property name
263 * @date 07/05/2004
264 * @param string of property name
265 * @return the only value stream pointer with the property names
267 LtcUtBenValueStream * LtcBenContainer::FindValueStreamWithPropertyName(const char * sPropertyName)
269 return FindNextValueStreamWithPropertyName(sPropertyName, NULL);
272 * <description>
273 * @date 07/05/2004
274 * @param pointer to length of bento file
275 * @return BenError
277 BenError LtcBenContainer::GetSize(sal_uLong * pLength)
279 *pLength = m_ulLength;
280 return BenErr_OK;
283 sal_uInt32 GetSvStreamSize(SvStream * pStream)
285 sal_uInt32 nCurPos = pStream->Tell();
286 pStream->Seek(STREAM_SEEK_TO_END);
287 sal_uInt32 ulLength = pStream->Tell();
288 pStream->Seek(nCurPos);
290 return ulLength;
294 * Find hazily according to object ID
295 * @date 01/31/2005
296 * @param pObjectname - format as "GrXX,XXXXXXXX" wherein XX is high part of object ID, and XXXXXXXX is low part
297 * @return the value stream pointers with the property names
299 BenError LtcBenContainer::CreateGraphicStream(SvStream * &pStream, const char *pObjectName)
301 if (!pObjectName)
303 pStream = NULL;
304 return BenErr_NamedObjectError;
306 // construct the string of property name
307 char sSName[64]="";
308 char sDName[64]="";
310 sprintf(sSName, "%s-S", pObjectName);
311 sprintf(sDName, "%s-D", pObjectName);
313 /* traverse the found properties and construct the stream vectors */
314 SvMemoryStream * pMemStream = NULL;
315 // get S&D's stream and merge them together
316 SvStream *pD = NULL, *pS = NULL;
318 pS = FindValueStreamWithPropertyName(sSName);
319 pD = FindValueStreamWithPropertyName(sDName);
321 sal_uInt32 nDLen = 0;
322 if(pD)
324 nDLen = GetSvStreamSize(pD);
326 sal_uInt32 nLen = nDLen;
327 if(pS)
329 nLen += GetSvStreamSize(pS) ;
332 OSL_ENSURE(nLen > 0, "expected a non-0 length");
333 // the 'D' stream is NULL or it has invalid length
334 if (nLen <= 0)
336 pStream = NULL;
337 return BenErr_NamedObjectError;
340 char * pBuf = new char[nLen];
341 assert(pBuf != NULL);
342 char * pPointer = pBuf;
343 if(pD)
345 pD->Read(pPointer, nDLen);
346 delete pD;
348 pPointer += nDLen;
349 if(pS)
351 pS->Read(pPointer, nLen - nDLen);
352 delete pS;
355 pMemStream = new SvMemoryStream(pBuf, nLen, StreamMode::READ);
356 assert(pMemStream != NULL);
358 pStream = pMemStream;
359 return BenErr_OK;
362 }// end namespace OpenStormBento
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */