1efeef26fSAndrew Rist /**************************************************************
2efeef26fSAndrew Rist  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "rtfsdrexport.hxx"
25cdf0e10cSrcweir #include "rtfexport.hxx"
26cdf0e10cSrcweir #include "writerhelper.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hdl>
29cdf0e10cSrcweir #include <osl/diagnose.h>
30cdf0e10cSrcweir #include <rtl/strbuf.hxx>
31cdf0e10cSrcweir #include <rtl/ustring.hxx>
32cdf0e10cSrcweir #include <svl/itemiter.hxx>
33cdf0e10cSrcweir #include <svtools/rtfkeywd.hxx>
34cdf0e10cSrcweir #include <editeng/editdata.hxx>
35cdf0e10cSrcweir #include <editeng/editobj.hxx>
36cdf0e10cSrcweir #include <editeng/flditem.hxx>
37cdf0e10cSrcweir #include <editeng/fontitem.hxx>
38cdf0e10cSrcweir #include <svx/svdotext.hxx>
39cdf0e10cSrcweir #include <tools/stream.hxx>
40cdf0e10cSrcweir #include <breakit.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using rtl::OString;
43cdf0e10cSrcweir using rtl::OStringBuffer;
44cdf0e10cSrcweir using rtl::OUString;
45cdf0e10cSrcweir using rtl::OUStringBuffer;
46cdf0e10cSrcweir using namespace sw::util;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir /// Implementation of an empty stream that silently succeeds, but does nothing.
49cdf0e10cSrcweir ///
50cdf0e10cSrcweir /// In fact, this is a hack.  The right solution is to abstract EscherEx to be
51cdf0e10cSrcweir /// able to work without SvStream; but at the moment it is better to live with
52cdf0e10cSrcweir /// this I guess.
53cdf0e10cSrcweir class SvNullStream : public SvStream
54cdf0e10cSrcweir {
55cdf0e10cSrcweir protected:
GetData(void * pData,sal_Size nSize)56cdf0e10cSrcweir     virtual sal_Size GetData( void* pData, sal_Size nSize ) { memset( pData, 0, nSize ); return nSize; }
PutData(const void *,sal_Size nSize)57cdf0e10cSrcweir     virtual sal_Size PutData( const void*, sal_Size nSize ) { return nSize; }
SeekPos(sal_Size nPos)58cdf0e10cSrcweir     virtual sal_Size SeekPos( sal_Size nPos ) { return nPos; }
SetSize(sal_Size)59cdf0e10cSrcweir     virtual void SetSize( sal_Size ) {}
FlushData()60cdf0e10cSrcweir     virtual void FlushData() {}
61cdf0e10cSrcweir 
62cdf0e10cSrcweir public:
SvNullStream()63cdf0e10cSrcweir     SvNullStream() : SvStream() {}
~SvNullStream()64cdf0e10cSrcweir     virtual ~SvNullStream() {}
65cdf0e10cSrcweir };
66cdf0e10cSrcweir 
RtfSdrExport(RtfExport & rExport)67cdf0e10cSrcweir RtfSdrExport::RtfSdrExport( RtfExport &rExport )
68cdf0e10cSrcweir     : EscherEx( EscherExGlobalRef( new EscherExGlobal ), *( new SvNullStream )),
69cdf0e10cSrcweir       m_rExport( rExport ),
70cdf0e10cSrcweir       m_rAttrOutput( (RtfAttributeOutput&)m_rExport.AttrOutput() ),
71cdf0e10cSrcweir       m_nShapeType( ESCHER_ShpInst_Nil ),
72cdf0e10cSrcweir       m_pShapeStyle( new OStringBuffer( 200 ) ),
73cdf0e10cSrcweir       m_pShapeTypeWritten( new bool[ ESCHER_ShpInst_COUNT ] )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     mnGroupLevel = 1;
76cdf0e10cSrcweir     memset( m_pShapeTypeWritten, 0, ESCHER_ShpInst_COUNT * sizeof( bool ) );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
~RtfSdrExport()79cdf0e10cSrcweir RtfSdrExport::~RtfSdrExport()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     delete mpOutStrm, mpOutStrm = NULL;
82cdf0e10cSrcweir     delete m_pShapeStyle, m_pShapeStyle = NULL;
83cdf0e10cSrcweir     delete[] m_pShapeTypeWritten, m_pShapeTypeWritten = NULL;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
OpenContainer(sal_uInt16 nEscherContainer,int nRecInstance)86cdf0e10cSrcweir void RtfSdrExport::OpenContainer( sal_uInt16 nEscherContainer, int nRecInstance )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     OSL_TRACE("%s", OSL_THIS_FUNC);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     EscherEx::OpenContainer( nEscherContainer, nRecInstance );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     if ( nEscherContainer == ESCHER_SpContainer )
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         m_nShapeType = ESCHER_ShpInst_Nil;
95cdf0e10cSrcweir         if ( m_pShapeStyle->getLength() )
96cdf0e10cSrcweir             m_pShapeStyle->makeStringAndClear();
97cdf0e10cSrcweir         m_pShapeStyle->ensureCapacity( 200 );
98cdf0e10cSrcweir         m_aShapeProps.clear();
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
CloseContainer()102cdf0e10cSrcweir void RtfSdrExport::CloseContainer()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     OSL_TRACE("%s", OSL_THIS_FUNC);
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     if ( mRecTypes.back() == ESCHER_SpContainer )
107cdf0e10cSrcweir     {
108cdf0e10cSrcweir         // write the shape now when we have all the info
109cdf0e10cSrcweir         sal_Int32 nShapeElement = StartShape();
110cdf0e10cSrcweir         EndShape( nShapeElement );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         // cleanup
113cdf0e10cSrcweir         m_nShapeType = ESCHER_ShpInst_Nil;
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     EscherEx::CloseContainer();
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
EnterGroup(const String &,const Rectangle *)119cdf0e10cSrcweir sal_uInt32 RtfSdrExport::EnterGroup( const String& /*rShapeName*/, const Rectangle* /*pRect*/ )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     OSL_TRACE("%s", OSL_THIS_FUNC);
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     return GenerateShapeId();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
LeaveGroup()126cdf0e10cSrcweir void RtfSdrExport::LeaveGroup()
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     OSL_TRACE("%s", OSL_THIS_FUNC);
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     /* noop */
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
AddShape(sal_uInt32 nShapeType,sal_uInt32 nShapeFlags,sal_uInt32)133cdf0e10cSrcweir void RtfSdrExport::AddShape( sal_uInt32 nShapeType, sal_uInt32 nShapeFlags, sal_uInt32 /*nShapeId*/ )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     OSL_TRACE("%s", OSL_THIS_FUNC);
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     m_nShapeType = nShapeType;
138cdf0e10cSrcweir     m_nShapeFlags = nShapeFlags;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
impl_GetUInt16(const sal_uInt8 * & pVal)141cdf0e10cSrcweir inline sal_uInt16 impl_GetUInt16( const sal_uInt8* &pVal )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     sal_uInt16 nRet = *pVal++;
144cdf0e10cSrcweir     nRet += ( *pVal++ ) << 8;
145cdf0e10cSrcweir     return nRet;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
impl_GetPointComponent(const sal_uInt8 * & pVal,sal_uInt16 nPointSize)148cdf0e10cSrcweir inline sal_Int32 impl_GetPointComponent( const sal_uInt8* &pVal, sal_uInt16 nPointSize )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     sal_Int32 nRet = 0;
151cdf0e10cSrcweir     if ( ( nPointSize == 0xfff0 ) || ( nPointSize == 4 ) )
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         sal_uInt16 nUnsigned = *pVal++;
154cdf0e10cSrcweir         nUnsigned += ( *pVal++ ) << 8;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         nRet = sal_Int16( nUnsigned );
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir     else if ( nPointSize == 8 )
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir         sal_uInt32 nUnsigned = *pVal++;
161cdf0e10cSrcweir         nUnsigned += ( *pVal++ ) << 8;
162cdf0e10cSrcweir         nUnsigned += ( *pVal++ ) << 16;
163cdf0e10cSrcweir         nUnsigned += ( *pVal++ ) << 24;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         nRet = nUnsigned;
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     return nRet;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
Commit(EscherPropertyContainer & rProps,const Rectangle & rRect)171cdf0e10cSrcweir void RtfSdrExport::Commit( EscherPropertyContainer& rProps, const Rectangle& rRect )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     OSL_TRACE("%s", OSL_THIS_FUNC);
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     if ( m_nShapeType == ESCHER_ShpInst_Nil )
176cdf0e10cSrcweir         return;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     if ( m_nShapeType == ESCHER_ShpInst_Line )
179cdf0e10cSrcweir         AddLineDimensions( rRect );
180cdf0e10cSrcweir     else
181cdf0e10cSrcweir         AddRectangleDimensions( *m_pShapeStyle, rRect );
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     // properties
184cdf0e10cSrcweir     const EscherProperties &rOpts = rProps.GetOpts();
185cdf0e10cSrcweir     for ( EscherProperties::const_iterator it = rOpts.begin(); it != rOpts.end(); ++it )
186cdf0e10cSrcweir     {
187cdf0e10cSrcweir         sal_uInt16 nId = ( it->nPropId & 0x0FFF );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         switch ( nId )
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir             case ESCHER_Prop_WrapText:
192cdf0e10cSrcweir                 {
193cdf0e10cSrcweir                     int nWrapType = 0;
194cdf0e10cSrcweir                     switch ( it->nPropValue )
195cdf0e10cSrcweir                     {
196cdf0e10cSrcweir                         case ESCHER_WrapSquare:    nWrapType = 2; break;
197cdf0e10cSrcweir                         case ESCHER_WrapByPoints:  nWrapType = 4; break;
198cdf0e10cSrcweir                         case ESCHER_WrapNone:      nWrapType = 3; break;
199cdf0e10cSrcweir                         case ESCHER_WrapTopBottom: nWrapType = 1; break;
200cdf0e10cSrcweir                         case ESCHER_WrapThrough:   nWrapType = 5; break;
201cdf0e10cSrcweir                     }
202cdf0e10cSrcweir                     if ( nWrapType )
203cdf0e10cSrcweir                         m_pShapeStyle->append(OOO_STRING_SVTOOLS_RTF_SHPWR).append((sal_Int32)nWrapType);
204cdf0e10cSrcweir                 }
205cdf0e10cSrcweir                 break;
206cdf0e10cSrcweir             case ESCHER_Prop_fillColor:
207cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("fillColor"), OString::valueOf(sal_Int32(it->nPropValue))));
208cdf0e10cSrcweir                 break;
209cdf0e10cSrcweir             case ESCHER_Prop_fillBackColor:
210cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("fillBackColor"), OString::valueOf(sal_Int32(it->nPropValue))));
211cdf0e10cSrcweir                 break;
212cdf0e10cSrcweir             case ESCHER_Prop_AnchorText:
213cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("anchorText"), OString::valueOf(sal_Int32(it->nPropValue))));
214cdf0e10cSrcweir                 break;
215cdf0e10cSrcweir             case ESCHER_Prop_fNoFillHitTest:
216cdf0e10cSrcweir                 if (it->nPropValue)
217cdf0e10cSrcweir                     m_aShapeProps.insert(std::pair<OString,OString>(OString("fNoFillHitTest"), OString::valueOf(sal_Int32(1))));
218cdf0e10cSrcweir                 break;
219cdf0e10cSrcweir             case ESCHER_Prop_fNoLineDrawDash:
220cdf0e10cSrcweir                 // for some reason the value is set to 0x90000 if lines are switched off
221cdf0e10cSrcweir                 if( it->nPropValue == 0x90000 )
222cdf0e10cSrcweir                     m_aShapeProps.insert(std::pair<OString,OString>(OString("fLine"), OString::valueOf(sal_Int32(0))));
223cdf0e10cSrcweir                 break;
224cdf0e10cSrcweir             case ESCHER_Prop_lineColor:
225cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("lineColor"), OString::valueOf(sal_Int32(it->nPropValue))));
226cdf0e10cSrcweir                 break;
227cdf0e10cSrcweir             case ESCHER_Prop_lineBackColor:
228cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("lineBackColor"), OString::valueOf(sal_Int32(it->nPropValue))));
229cdf0e10cSrcweir                 break;
230cdf0e10cSrcweir             case ESCHER_Prop_lineJoinStyle:
231cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("lineJoinStyle"), OString::valueOf(sal_Int32(it->nPropValue))));
232cdf0e10cSrcweir                 break;
233cdf0e10cSrcweir             case ESCHER_Prop_fshadowObscured:
234cdf0e10cSrcweir                 if (it->nPropValue)
235cdf0e10cSrcweir                     m_aShapeProps.insert(std::pair<OString,OString>(OString("fshadowObscured"), OString::valueOf(sal_Int32(1))));
236cdf0e10cSrcweir                 break;
237cdf0e10cSrcweir             case ESCHER_Prop_geoLeft:
238cdf0e10cSrcweir             case ESCHER_Prop_geoTop:
239cdf0e10cSrcweir                 {
240cdf0e10cSrcweir                     sal_uInt32 nLeft = 0, nTop = 0;
241cdf0e10cSrcweir 
242cdf0e10cSrcweir                     if ( nId == ESCHER_Prop_geoLeft )
243cdf0e10cSrcweir                     {
244cdf0e10cSrcweir                         nLeft = it->nPropValue;
245cdf0e10cSrcweir                         rProps.GetOpt( ESCHER_Prop_geoTop, nTop );
246cdf0e10cSrcweir                     }
247cdf0e10cSrcweir                     else
248cdf0e10cSrcweir                     {
249cdf0e10cSrcweir                         nTop = it->nPropValue;
250cdf0e10cSrcweir                         rProps.GetOpt( ESCHER_Prop_geoLeft, nLeft );
251cdf0e10cSrcweir                     }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir                     m_aShapeProps.insert(std::pair<OString,OString>(OString("geoLeft"),
254cdf0e10cSrcweir                                 OString::valueOf(sal_Int32(sal_Int32( nLeft )))));
255cdf0e10cSrcweir                     m_aShapeProps.insert(std::pair<OString,OString>(OString("geoTop"),
256cdf0e10cSrcweir                                 OString::valueOf(sal_Int32(sal_Int32( nTop )))));
257cdf0e10cSrcweir                 }
258cdf0e10cSrcweir                 break;
259cdf0e10cSrcweir 
260cdf0e10cSrcweir             case ESCHER_Prop_geoRight:
261cdf0e10cSrcweir             case ESCHER_Prop_geoBottom:
262cdf0e10cSrcweir                 {
263cdf0e10cSrcweir                     sal_uInt32 nLeft = 0, nRight = 0, nTop = 0, nBottom = 0;
264cdf0e10cSrcweir                     rProps.GetOpt( ESCHER_Prop_geoLeft, nLeft );
265cdf0e10cSrcweir                     rProps.GetOpt( ESCHER_Prop_geoTop, nTop );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir                     if ( nId == ESCHER_Prop_geoRight )
268cdf0e10cSrcweir                     {
269cdf0e10cSrcweir                         nRight = it->nPropValue;
270cdf0e10cSrcweir                         rProps.GetOpt( ESCHER_Prop_geoBottom, nBottom );
271cdf0e10cSrcweir                     }
272cdf0e10cSrcweir                     else
273cdf0e10cSrcweir                     {
274cdf0e10cSrcweir                         nBottom = it->nPropValue;
275cdf0e10cSrcweir                         rProps.GetOpt( ESCHER_Prop_geoRight, nRight );
276cdf0e10cSrcweir                     }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir                     m_aShapeProps.insert(std::pair<OString,OString>(OString("geoRight"),
279cdf0e10cSrcweir                                 OString::valueOf(sal_Int32(sal_Int32( nRight ) - sal_Int32( nLeft )))));
280cdf0e10cSrcweir                     m_aShapeProps.insert(std::pair<OString,OString>(OString("geoBottom"),
281cdf0e10cSrcweir                                 OString::valueOf(sal_Int32(sal_Int32( nBottom ) - sal_Int32( nTop )))));
282cdf0e10cSrcweir                 }
283cdf0e10cSrcweir                 break;
284cdf0e10cSrcweir             case ESCHER_Prop_pVertices:
285cdf0e10cSrcweir             case ESCHER_Prop_pSegmentInfo:
286cdf0e10cSrcweir                 {
287cdf0e10cSrcweir                     EscherPropSortStruct aVertices;
288cdf0e10cSrcweir                     EscherPropSortStruct aSegments;
289cdf0e10cSrcweir 
290cdf0e10cSrcweir                     if ( rProps.GetOpt( ESCHER_Prop_pVertices, aVertices ) &&
291cdf0e10cSrcweir                          rProps.GetOpt( ESCHER_Prop_pSegmentInfo, aSegments ) )
292cdf0e10cSrcweir                     {
293cdf0e10cSrcweir                         const sal_uInt8 *pVerticesIt = aVertices.pBuf + 6;
294cdf0e10cSrcweir                         const sal_uInt8 *pSegmentIt = aSegments.pBuf;
295cdf0e10cSrcweir 
296cdf0e10cSrcweir                         OStringBuffer aSegmentInfo( 512 );
297cdf0e10cSrcweir                         OStringBuffer aVerticies( 512 );
298cdf0e10cSrcweir 
299cdf0e10cSrcweir                         sal_uInt16 nPointSize = aVertices.pBuf[4] + ( aVertices.pBuf[5] << 8 );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir                         // number of segments
302cdf0e10cSrcweir                         sal_uInt16 nSegments = impl_GetUInt16( pSegmentIt );
303cdf0e10cSrcweir                         sal_Int32 nVertices = 0;
304cdf0e10cSrcweir                         aSegmentInfo.append("2;").append((sal_Int32)nSegments);
305cdf0e10cSrcweir                         pSegmentIt += 4;
306cdf0e10cSrcweir 
307cdf0e10cSrcweir                         for ( ; nSegments; --nSegments )
308cdf0e10cSrcweir                         {
309cdf0e10cSrcweir                             sal_uInt16 nSeg = impl_GetUInt16( pSegmentIt );
310cdf0e10cSrcweir                             aSegmentInfo.append(';').append((sal_Int32)nSeg);
311cdf0e10cSrcweir                             switch ( nSeg )
312cdf0e10cSrcweir                             {
313cdf0e10cSrcweir                                 case 0x0001: // lineto
314cdf0e10cSrcweir                                 case 0x4000: // moveto
315cdf0e10cSrcweir                                     {
316cdf0e10cSrcweir                                         sal_Int32 nX = impl_GetPointComponent( pVerticesIt, nPointSize );
317cdf0e10cSrcweir                                         sal_Int32 nY = impl_GetPointComponent( pVerticesIt, nPointSize );
318cdf0e10cSrcweir                                         aVerticies.append( ";(" ).append( nX ).append( "," ).append( nY ).append( ")" );
319cdf0e10cSrcweir                                         nVertices ++;
320cdf0e10cSrcweir                                     }
321cdf0e10cSrcweir                                     break;
322cdf0e10cSrcweir                                 case 0x2001: // curveto
323cdf0e10cSrcweir                                     {
324cdf0e10cSrcweir                                         for (int i = 0; i < 3; i++)
325cdf0e10cSrcweir                                         {
326cdf0e10cSrcweir                                             sal_Int32 nX = impl_GetPointComponent( pVerticesIt, nPointSize );
327cdf0e10cSrcweir                                             sal_Int32 nY = impl_GetPointComponent( pVerticesIt, nPointSize );
328cdf0e10cSrcweir                                             aVerticies.append( ";(" ).append( nX ).append( "," ).append( nY ).append( ")" );
329cdf0e10cSrcweir                                             nVertices ++;
330cdf0e10cSrcweir                                         }
331cdf0e10cSrcweir                                     }
332cdf0e10cSrcweir                                     break;
333cdf0e10cSrcweir                                 case 0xb300:
334cdf0e10cSrcweir                                 case 0xac00:
335cdf0e10cSrcweir                                 case 0xaa00: // nofill
336cdf0e10cSrcweir                                 case 0xab00: // nostroke
337cdf0e10cSrcweir                                 case 0x6001: // close
338cdf0e10cSrcweir                                 case 0x8000: // end
339cdf0e10cSrcweir                                     break;
340cdf0e10cSrcweir                                 default:
341cdf0e10cSrcweir                                     OSL_TRACE("%s: unhandled segment '%x' in the path", OSL_THIS_FUNC, nSeg);
342cdf0e10cSrcweir                                     break;
343cdf0e10cSrcweir                             }
344cdf0e10cSrcweir                         }
345cdf0e10cSrcweir 
346cdf0e10cSrcweir                         if (aVerticies.getLength() )
347cdf0e10cSrcweir                         {
348cdf0e10cSrcweir                             // We know the number of vertices at the end only, so we have to prepend them here.
349cdf0e10cSrcweir                             OStringBuffer aBuf;
350cdf0e10cSrcweir                             aBuf.append("8;").append((sal_Int32)nVertices);
351cdf0e10cSrcweir                             aBuf.append(aVerticies.makeStringAndClear());
352cdf0e10cSrcweir                             m_aShapeProps.insert(std::pair<OString,OString>(OString("pVerticies"), aBuf.makeStringAndClear()));
353cdf0e10cSrcweir                         }
354cdf0e10cSrcweir                         if ( aSegmentInfo.getLength() )
355cdf0e10cSrcweir                             m_aShapeProps.insert(std::pair<OString,OString>(OString("pSegmentInfo"), aSegmentInfo.makeStringAndClear()));
356cdf0e10cSrcweir                     }
357cdf0e10cSrcweir                     else
358cdf0e10cSrcweir                         OSL_TRACE("%s: unhandled shape path, missing either pVertices or pSegmentInfo", OSL_THIS_FUNC);
359cdf0e10cSrcweir                 }
360cdf0e10cSrcweir                 break;
361cdf0e10cSrcweir             case ESCHER_Prop_shapePath:
362cdf0e10cSrcweir                 // noop, we use pSegmentInfo instead
363cdf0e10cSrcweir                 break;
364cdf0e10cSrcweir             case ESCHER_Prop_fFillOK:
365cdf0e10cSrcweir                 if (!it->nPropValue)
366cdf0e10cSrcweir                     m_aShapeProps.insert(std::pair<OString,OString>(OString("fFillOK"), OString::valueOf(sal_Int32(0))));
367cdf0e10cSrcweir                 break;
368cdf0e10cSrcweir             case ESCHER_Prop_dxTextLeft:
369cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("dxTextLeft"), OString::valueOf(sal_Int32(it->nPropValue))));
370cdf0e10cSrcweir                 break;
371cdf0e10cSrcweir             case ESCHER_Prop_dyTextTop:
372cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("dyTextTop"), OString::valueOf(sal_Int32(it->nPropValue))));
373cdf0e10cSrcweir                 break;
374cdf0e10cSrcweir             case ESCHER_Prop_dxTextRight:
375cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("dxTextRight"), OString::valueOf(sal_Int32(it->nPropValue))));
376cdf0e10cSrcweir                 break;
377cdf0e10cSrcweir             case ESCHER_Prop_dyTextBottom:
378cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("dyTextBottom"), OString::valueOf(sal_Int32(it->nPropValue))));
379cdf0e10cSrcweir                 break;
380cdf0e10cSrcweir             case ESCHER_Prop_FitTextToShape:
381cdf0e10cSrcweir                 // Size text to fit shape size: not supported by RTF
382cdf0e10cSrcweir                 break;
383cdf0e10cSrcweir             case ESCHER_Prop_adjustValue:
384cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("adjustValue"), OString::valueOf(sal_Int32(it->nPropValue))));
385cdf0e10cSrcweir                 break;
386cdf0e10cSrcweir             case ESCHER_Prop_txflTextFlow:
387cdf0e10cSrcweir                 m_aShapeProps.insert(std::pair<OString,OString>(OString("txflTextFlow"), OString::valueOf(sal_Int32(it->nPropValue))));
388cdf0e10cSrcweir                 break;
389cdf0e10cSrcweir             default:
390cdf0e10cSrcweir                 OSL_TRACE("%s: unhandled property: %d (value: %d)", OSL_THIS_FUNC, nId, it->nPropValue);
391cdf0e10cSrcweir                 break;
392cdf0e10cSrcweir         }
393cdf0e10cSrcweir     }
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
AddLineDimensions(const Rectangle & rRectangle)396cdf0e10cSrcweir void RtfSdrExport::AddLineDimensions( const Rectangle& rRectangle )
397cdf0e10cSrcweir {
398cdf0e10cSrcweir     OSL_TRACE("%s", OSL_THIS_FUNC);
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     // We get the position relative to (the current?) character
401cdf0e10cSrcweir     m_aShapeProps.insert(std::pair<OString,OString>(OString("posrelh"), OString::valueOf(sal_Int32(3))));
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     switch ( m_nShapeFlags & 0xC0 )
404cdf0e10cSrcweir     {
405cdf0e10cSrcweir         case 0x40:
406cdf0e10cSrcweir             m_aShapeProps.insert(std::pair<OString,OString>(OString("fFlipV"), OString::valueOf(sal_Int32(1))));
407cdf0e10cSrcweir             break;
408cdf0e10cSrcweir         case 0x80:
409cdf0e10cSrcweir             m_aShapeProps.insert(std::pair<OString,OString>(OString("fFlipH"), OString::valueOf(sal_Int32(1))));
410cdf0e10cSrcweir             break;
411cdf0e10cSrcweir         case 0xC0:
412cdf0e10cSrcweir             m_aShapeProps.insert(std::pair<OString,OString>(OString("fFlipV"), OString::valueOf(sal_Int32(1))));
413cdf0e10cSrcweir             m_aShapeProps.insert(std::pair<OString,OString>(OString("fFlipH"), OString::valueOf(sal_Int32(1))));
414cdf0e10cSrcweir             break;
415cdf0e10cSrcweir     }
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     // the actual dimensions
418cdf0e10cSrcweir     m_pShapeStyle->append(OOO_STRING_SVTOOLS_RTF_SHPLEFT).append(rRectangle.Left());
419cdf0e10cSrcweir     m_pShapeStyle->append(OOO_STRING_SVTOOLS_RTF_SHPTOP).append(rRectangle.Top());
420cdf0e10cSrcweir     m_pShapeStyle->append(OOO_STRING_SVTOOLS_RTF_SHPRIGHT).append(rRectangle.Right());
421cdf0e10cSrcweir     m_pShapeStyle->append(OOO_STRING_SVTOOLS_RTF_SHPBOTTOM).append(rRectangle.Bottom());
422cdf0e10cSrcweir }
423cdf0e10cSrcweir 
AddRectangleDimensions(rtl::OStringBuffer & rBuffer,const Rectangle & rRectangle)424cdf0e10cSrcweir void RtfSdrExport::AddRectangleDimensions( rtl::OStringBuffer& rBuffer, const Rectangle& rRectangle )
425cdf0e10cSrcweir {
426cdf0e10cSrcweir     OSL_TRACE("%s", OSL_THIS_FUNC);
427cdf0e10cSrcweir 
428cdf0e10cSrcweir     // We get the position relative to (the current?) character
429cdf0e10cSrcweir     m_aShapeProps.insert(std::pair<OString,OString>(OString("posrelh"), OString::valueOf(sal_Int32(3))));
430cdf0e10cSrcweir 
431cdf0e10cSrcweir     rBuffer.append(OOO_STRING_SVTOOLS_RTF_SHPLEFT).append(rRectangle.Left());
432cdf0e10cSrcweir     rBuffer.append(OOO_STRING_SVTOOLS_RTF_SHPTOP).append(rRectangle.Top());
433cdf0e10cSrcweir     rBuffer.append(OOO_STRING_SVTOOLS_RTF_SHPRIGHT).append(rRectangle.Right());
434cdf0e10cSrcweir     rBuffer.append(OOO_STRING_SVTOOLS_RTF_SHPBOTTOM).append(rRectangle.Bottom());
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
AddShapeAttribute(sal_Int32,const rtl::OString &)437cdf0e10cSrcweir void RtfSdrExport::AddShapeAttribute( sal_Int32 /*nAttribute*/, const rtl::OString& /*rValue*/ )
438cdf0e10cSrcweir {
439cdf0e10cSrcweir     OSL_TRACE("%s", OSL_THIS_FUNC);
440cdf0e10cSrcweir 
441cdf0e10cSrcweir     /* noop */
442cdf0e10cSrcweir }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir extern const char* pShapeTypes[];
445cdf0e10cSrcweir 
lcl_AppendSP(::rtl::OStringBuffer & rRunText,const char cName[],const::rtl::OString & rValue)446cdf0e10cSrcweir void lcl_AppendSP( ::rtl::OStringBuffer& rRunText, const char cName[], const ::rtl::OString& rValue)
447cdf0e10cSrcweir {
448cdf0e10cSrcweir     rRunText.append('{').append(OOO_STRING_SVTOOLS_RTF_SP)
449cdf0e10cSrcweir         .append('{').append(OOO_STRING_SVTOOLS_RTF_SN " ").append(cName).append('}')
450cdf0e10cSrcweir         .append('{').append(OOO_STRING_SVTOOLS_RTF_SV " ").append(rValue).append('}')
451cdf0e10cSrcweir         .append('}');
452cdf0e10cSrcweir }
StartShape()453cdf0e10cSrcweir sal_Int32 RtfSdrExport::StartShape()
454cdf0e10cSrcweir {
455cdf0e10cSrcweir     OSL_TRACE("%s", OSL_THIS_FUNC);
456cdf0e10cSrcweir 
457cdf0e10cSrcweir     if ( m_nShapeType == ESCHER_ShpInst_Nil )
458cdf0e10cSrcweir         return -1;
459cdf0e10cSrcweir 
460cdf0e10cSrcweir     m_aShapeProps.insert(std::pair<OString,OString>(OString("shapeType"), OString::valueOf(sal_Int32(m_nShapeType))));
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     m_rAttrOutput.RunText().append('{').append(OOO_STRING_SVTOOLS_RTF_SHP);
463cdf0e10cSrcweir     m_rAttrOutput.RunText().append('{').append(OOO_STRING_SVTOOLS_RTF_IGNORE).append(OOO_STRING_SVTOOLS_RTF_SHPINST);
464cdf0e10cSrcweir 
465cdf0e10cSrcweir     m_rAttrOutput.RunText().append(m_pShapeStyle->makeStringAndClear());
466cdf0e10cSrcweir     // Ignore \shpbxpage, \shpbxmargin, and \shpbxcolumn, in favor of the posrelh property.
467cdf0e10cSrcweir     m_rAttrOutput.RunText().append(OOO_STRING_SVTOOLS_RTF_SHPBXIGNORE);
468cdf0e10cSrcweir     // Ignore \shpbypage, \shpbymargin, and \shpbycolumn, in favor of the posrelh property.
469cdf0e10cSrcweir     m_rAttrOutput.RunText().append(OOO_STRING_SVTOOLS_RTF_SHPBYIGNORE);
470cdf0e10cSrcweir 
471cdf0e10cSrcweir     for(std::map<OString,OString>::reverse_iterator i = m_aShapeProps.rbegin(); i != m_aShapeProps.rend(); i++)
472*24c56ab9SHerbert Dürr         lcl_AppendSP(m_rAttrOutput.RunText(), (*i).first.getStr(), (*i).second );
473cdf0e10cSrcweir 
474cdf0e10cSrcweir     lcl_AppendSP(m_rAttrOutput.RunText(), "wzDescription", RtfExport::OutString( m_pSdrObject->GetDescription(), m_rExport.eCurrentEncoding));
475cdf0e10cSrcweir     lcl_AppendSP(m_rAttrOutput.RunText(), "wzName", RtfExport::OutString( m_pSdrObject->GetTitle(), m_rExport.eCurrentEncoding));
476cdf0e10cSrcweir 
477cdf0e10cSrcweir     // now check if we have some text
478cdf0e10cSrcweir     const SdrTextObj* pTxtObj = PTR_CAST(SdrTextObj, m_pSdrObject);
479cdf0e10cSrcweir     if (pTxtObj)
480cdf0e10cSrcweir     {
481cdf0e10cSrcweir         const OutlinerParaObject* pParaObj = 0;
482cdf0e10cSrcweir         bool bOwnParaObj = false;
483cdf0e10cSrcweir 
484cdf0e10cSrcweir         /*
485cdf0e10cSrcweir         #i13885#
486cdf0e10cSrcweir         When the object is actively being edited, that text is not set into
487cdf0e10cSrcweir         the objects normal text object, but lives in a seperate object.
488cdf0e10cSrcweir         */
489cdf0e10cSrcweir         if (pTxtObj->IsTextEditActive())
490cdf0e10cSrcweir         {
491cdf0e10cSrcweir             pParaObj = pTxtObj->GetEditOutlinerParaObject();
492cdf0e10cSrcweir             bOwnParaObj = true;
493cdf0e10cSrcweir         }
494cdf0e10cSrcweir         else
495cdf0e10cSrcweir         {
496cdf0e10cSrcweir             pParaObj = pTxtObj->GetOutlinerParaObject();
497cdf0e10cSrcweir         }
498cdf0e10cSrcweir 
499cdf0e10cSrcweir         if( pParaObj )
500cdf0e10cSrcweir         {
501cdf0e10cSrcweir             // this is reached only in case some text is attached to the shape
502cdf0e10cSrcweir             WriteOutliner(*pParaObj);
503cdf0e10cSrcweir             if( bOwnParaObj )
504cdf0e10cSrcweir                 delete pParaObj;
505cdf0e10cSrcweir         }
506cdf0e10cSrcweir     }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir     return m_nShapeType;
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
WriteOutliner(const OutlinerParaObject & rParaObj)511cdf0e10cSrcweir void RtfSdrExport::WriteOutliner(const OutlinerParaObject& rParaObj)
512cdf0e10cSrcweir {
513cdf0e10cSrcweir     OSL_TRACE("%s start", OSL_THIS_FUNC);
514cdf0e10cSrcweir 
515cdf0e10cSrcweir     const EditTextObject& rEditObj = rParaObj.GetTextObject();
516cdf0e10cSrcweir     MSWord_SdrAttrIter aAttrIter( m_rExport, rEditObj, TXT_HFTXTBOX );
517cdf0e10cSrcweir 
518cdf0e10cSrcweir     sal_uInt16 nPara = rEditObj.GetParagraphCount();
519cdf0e10cSrcweir 
520cdf0e10cSrcweir     m_rAttrOutput.RunText().append('{').append(OOO_STRING_SVTOOLS_RTF_SHPTXT).append(' ');
521cdf0e10cSrcweir     for (sal_uInt16 n = 0; n < nPara; ++n)
522cdf0e10cSrcweir     {
523cdf0e10cSrcweir         if( n )
524cdf0e10cSrcweir             aAttrIter.NextPara( n );
525cdf0e10cSrcweir 
526cdf0e10cSrcweir         rtl_TextEncoding eChrSet = aAttrIter.GetNodeCharSet();
527cdf0e10cSrcweir 
528cdf0e10cSrcweir         String aStr( rEditObj.GetText( n ));
529cdf0e10cSrcweir         xub_StrLen nAktPos = 0;
530cdf0e10cSrcweir         xub_StrLen nEnd = aStr.Len();
531cdf0e10cSrcweir 
532cdf0e10cSrcweir         aAttrIter.OutParaAttr(false);
533cdf0e10cSrcweir         m_rAttrOutput.RunText().append(m_rAttrOutput.Styles().makeStringAndClear());
534cdf0e10cSrcweir 
535cdf0e10cSrcweir         do {
536cdf0e10cSrcweir             xub_StrLen nNextAttr = aAttrIter.WhereNext();
537cdf0e10cSrcweir             rtl_TextEncoding eNextChrSet = aAttrIter.GetNextCharSet();
538cdf0e10cSrcweir 
539cdf0e10cSrcweir             if( nNextAttr > nEnd )
540cdf0e10cSrcweir                 nNextAttr = nEnd;
541cdf0e10cSrcweir 
542cdf0e10cSrcweir             aAttrIter.OutAttr( nAktPos );
543cdf0e10cSrcweir             m_rAttrOutput.RunText().append('{').append(m_rAttrOutput.Styles().makeStringAndClear()).append(m_rExport.sNewLine);
544cdf0e10cSrcweir             bool bTxtAtr = aAttrIter.IsTxtAttr( nAktPos );
545cdf0e10cSrcweir             if( !bTxtAtr )
546cdf0e10cSrcweir             {
547cdf0e10cSrcweir                 String aOut( aStr.Copy( nAktPos, nNextAttr - nAktPos ) );
548cdf0e10cSrcweir                 m_rAttrOutput.RunText().append( m_rExport.OutString( aOut, eChrSet ) );
549cdf0e10cSrcweir             }
550cdf0e10cSrcweir 
551cdf0e10cSrcweir             m_rAttrOutput.RunText().append('}');
552cdf0e10cSrcweir 
553cdf0e10cSrcweir             nAktPos = nNextAttr;
554cdf0e10cSrcweir             eChrSet = eNextChrSet;
555cdf0e10cSrcweir             aAttrIter.NextPos();
556cdf0e10cSrcweir         }
557cdf0e10cSrcweir         while( nAktPos < nEnd );
558cdf0e10cSrcweir     }
559cdf0e10cSrcweir     m_rAttrOutput.RunText().append(OOO_STRING_SVTOOLS_RTF_PAR).append('}');
560cdf0e10cSrcweir 
561cdf0e10cSrcweir     OSL_TRACE("%s end", OSL_THIS_FUNC);
562cdf0e10cSrcweir }
563cdf0e10cSrcweir 
EndShape(sal_Int32 nShapeElement)564cdf0e10cSrcweir void RtfSdrExport::EndShape( sal_Int32 nShapeElement )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir     OSL_TRACE("%s", OSL_THIS_FUNC);
567cdf0e10cSrcweir 
568cdf0e10cSrcweir     if ( nShapeElement >= 0 )
569cdf0e10cSrcweir     {
570cdf0e10cSrcweir         // end of the shape
571cdf0e10cSrcweir         m_rAttrOutput.RunText().append('}').append('}');
572cdf0e10cSrcweir     }
573cdf0e10cSrcweir }
574cdf0e10cSrcweir 
AddSdrObject(const SdrObject & rObj)575cdf0e10cSrcweir sal_uInt32 RtfSdrExport::AddSdrObject( const SdrObject& rObj )
576cdf0e10cSrcweir {
577cdf0e10cSrcweir     m_pSdrObject = &rObj;
578cdf0e10cSrcweir     return EscherEx::AddSdrObject(rObj);
579cdf0e10cSrcweir }
580cdf0e10cSrcweir 
581cdf0e10cSrcweir /* vi:set shiftwidth=4 expandtab: */
582