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 #include <string.h>
25
26 #include <com/sun/star/awt/Size.hpp>
27 #include <com/sun/star/container/XNamed.hpp>
28 #include <com/sun/star/drawing/ColorMode.hpp>
29 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
30 #include <com/sun/star/drawing/XShape.hpp>
31 #include <com/sun/star/graphic/XGraphic.hpp>
32 #include <com/sun/star/graphic/XGraphicProvider.hpp>
33 #include <com/sun/star/io/XInputStream.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/table/BorderLine.hpp>
36 #include <com/sun/star/text/GraphicCrop.hpp>
37 #include <com/sun/star/text/HoriOrientation.hpp>
38 #include <com/sun/star/text/RelOrientation.hpp>
39 #include <com/sun/star/text/TextContentAnchorType.hpp>
40 #include <com/sun/star/text/VertOrientation.hpp>
41 #include <com/sun/star/text/WrapTextMode.hpp>
42 #include <com/sun/star/text/XTextContent.hpp>
43 #include <com/sun/star/uno/XComponentContext.hpp>
44
45 #include <cppuhelper/implbase1.hxx>
46 #include <rtl/ustrbuf.hxx>
47
48 #include <dmapper/DomainMapper.hxx>
49 #include <doctok/resourceids.hxx>
50 #include <ooxml/resourceids.hxx>
51 #include <resourcemodel/ResourceModelHelper.hxx>
52
53 #include "ConversionHelper.hxx"
54 #include "GraphicHelpers.hxx"
55 #include "GraphicImport.hxx"
56 #include "PropertyMap.hxx"
57 #include "WrapPolygonHandler.hxx"
58 #include "dmapperLoggers.hxx"
59
60 namespace writerfilter {
61
62 using resourcemodel::resolveSprmProps;
63
64 namespace dmapper
65 {
66 using namespace ::std;
67 using namespace ::com::sun::star;
68
69 class XInputStreamHelper : public cppu::WeakImplHelper1
70 < io::XInputStream >
71 {
72 const sal_uInt8* m_pBuffer;
73 const sal_Int32 m_nLength;
74 sal_Int32 m_nPosition;
75 bool m_bBmp;
76
77 const sal_uInt8* m_pBMPHeader; //default BMP-header
78 sal_Int32 m_nHeaderLength;
79 public:
80 XInputStreamHelper(const sal_uInt8* buf, size_t len, bool bBmp);
81 ~XInputStreamHelper();
82
83 virtual ::sal_Int32 SAL_CALL readBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException);
84 virtual ::sal_Int32 SAL_CALL readSomeBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException);
85 virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip ) throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException);
86 virtual ::sal_Int32 SAL_CALL available( ) throw (io::NotConnectedException, io::IOException, uno::RuntimeException);
87 virtual void SAL_CALL closeInput( ) throw (io::NotConnectedException, io::IOException, uno::RuntimeException);
88 };
89 /*-- 01.11.2006 13:56:20---------------------------------------------------
90
91 -----------------------------------------------------------------------*/
XInputStreamHelper(const sal_uInt8 * buf,size_t len,bool bBmp)92 XInputStreamHelper::XInputStreamHelper(const sal_uInt8* buf, size_t len, bool bBmp) :
93 m_pBuffer( buf ),
94 m_nLength( len ),
95 m_nPosition( 0 ),
96 m_bBmp( bBmp )
97 {
98 static const sal_uInt8 aHeader[] =
99 {0x42, 0x4d, 0xe6, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
100 m_pBMPHeader = aHeader;
101 m_nHeaderLength = m_bBmp ? sizeof( aHeader ) / sizeof(sal_uInt8) : 0;
102
103 }
104 /*-- 01.11.2006 13:56:20---------------------------------------------------
105
106 -----------------------------------------------------------------------*/
~XInputStreamHelper()107 XInputStreamHelper::~XInputStreamHelper()
108 {
109 }
110 /*-- 01.11.2006 13:56:21---------------------------------------------------
111
112 -----------------------------------------------------------------------*/
readBytes(uno::Sequence<::sal_Int8> & aData,::sal_Int32 nBytesToRead)113 ::sal_Int32 XInputStreamHelper::readBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead )
114 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
115 {
116 return readSomeBytes( aData, nBytesToRead );
117 }
118 /*-- 01.11.2006 13:56:21---------------------------------------------------
119
120 -----------------------------------------------------------------------*/
readSomeBytes(uno::Sequence<::sal_Int8> & aData,::sal_Int32 nMaxBytesToRead)121 ::sal_Int32 XInputStreamHelper::readSomeBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead )
122 throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
123 {
124 sal_Int32 nRet = 0;
125 if( nMaxBytesToRead > 0 )
126 {
127 if( nMaxBytesToRead > (m_nLength + m_nHeaderLength) - m_nPosition )
128 nRet = (m_nLength + m_nHeaderLength) - m_nPosition;
129 else
130 nRet = nMaxBytesToRead;
131 aData.realloc( nRet );
132 sal_Int8* pData = aData.getArray();
133 sal_Int32 nHeaderRead = 0;
134 if( m_nPosition < m_nHeaderLength)
135 {
136 //copy header content first
137 nHeaderRead = m_nHeaderLength - m_nPosition;
138 memcpy( pData, m_pBMPHeader + (m_nPosition ), nHeaderRead );
139 nRet -= nHeaderRead;
140 m_nPosition += nHeaderRead;
141 }
142 if( nRet )
143 {
144 memcpy( pData + nHeaderRead, m_pBuffer + (m_nPosition - m_nHeaderLength), nRet );
145 m_nPosition += nRet;
146 }
147 }
148 return nRet;
149 }
150 /*-- 01.11.2006 13:56:21---------------------------------------------------
151
152 -----------------------------------------------------------------------*/
skipBytes(::sal_Int32 nBytesToSkip)153 void XInputStreamHelper::skipBytes( ::sal_Int32 nBytesToSkip ) throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
154 {
155 if( nBytesToSkip < 0 || m_nPosition + nBytesToSkip > (m_nLength + m_nHeaderLength))
156 throw io::BufferSizeExceededException();
157 m_nPosition += nBytesToSkip;
158 }
159 /*-- 01.11.2006 13:56:22---------------------------------------------------
160
161 -----------------------------------------------------------------------*/
available()162 ::sal_Int32 XInputStreamHelper::available( ) throw (io::NotConnectedException, io::IOException, uno::RuntimeException)
163 {
164 return ( m_nLength + m_nHeaderLength ) - m_nPosition;
165 }
166 /*-- 01.11.2006 13:56:22---------------------------------------------------
167
168 -----------------------------------------------------------------------*/
closeInput()169 void XInputStreamHelper::closeInput( ) throw (io::NotConnectedException, io::IOException, uno::RuntimeException)
170 {
171 }
172 /*-- 02.11.2006 09:34:29---------------------------------------------------
173
174 -----------------------------------------------------------------------*/
175 struct GraphicBorderLine
176 {
177 sal_Int32 nLineWidth;
178 // sal_Int32 nLineType;
179 sal_Int32 nLineColor;
180 sal_Int32 nLineDistance;
181 bool bHasShadow;
182
GraphicBorderLinewriterfilter::dmapper::GraphicBorderLine183 GraphicBorderLine() :
184 nLineWidth(0)
185 // ,nLineType(0)
186 ,nLineColor(0)
187 ,nLineDistance(0)
188 ,bHasShadow(false)
189 {}
190
191 };
192
193 class GraphicImport_Impl
194 {
195 private:
196 sal_Int32 nXSize;
197 bool bXSizeValid;
198 sal_Int32 nYSize;
199 bool bYSizeValid;
200
201 public:
202 GraphicImportType eGraphicImportType;
203 DomainMapper& rDomainMapper;
204
205 sal_Int32 nHoriScaling;
206 sal_Int32 nVertScaling;
207 sal_Int32 nLeftPosition;
208 sal_Int32 nTopPosition;
209 sal_Int32 nRightPosition;
210 sal_Int32 nBottomPosition;
211 sal_Int32 nLeftCrop;
212 sal_Int32 nTopCrop;
213 sal_Int32 nRightCrop;
214 sal_Int32 nBottomCrop;
215
216 bool bUseSimplePos;
217
218 sal_Int16 nHoriOrient;
219 sal_Int16 nHoriRelation;
220 bool bPageToggle;
221 sal_Int16 nVertOrient;
222 sal_Int16 nVertRelation;
223 sal_Int32 nWrap;
224 bool bOpaque;
225 bool bContour;
226 bool bContourOutside;
227 WrapPolygon::Pointer_t mpWrapPolygon;
228 bool bIgnoreWRK;
229
230 sal_Int32 nLeftMargin;
231 sal_Int32 nRightMargin;
232 sal_Int32 nTopMargin;
233 sal_Int32 nBottomMargin;
234
235 sal_Int32 nContrast;
236 sal_Int32 nBrightness;
237 double fGamma;
238
239 sal_Int32 nFillColor;
240
241 drawing::ColorMode eColorMode;
242
243 GraphicBorderLine aBorders[4];
244 sal_Int32 nCurrentBorderLine;
245
246 sal_Int32 nDffType;
247 bool bIsGraphic;
248 bool bIsBitmap;
249 bool bIsTiff;
250 sal_Int32 nBitsPerPixel;
251
252 bool bHoriFlip;
253 bool bVertFlip;
254
255 bool bSizeProtected;
256 bool bPositionProtected;
257
258 bool bInShapeOptionMode;
259 sal_Int32 nShapeOptionType;
260
261 ::rtl::OUString sName;
262 ::rtl::OUString sAlternativeText;
263
GraphicImport_Impl(GraphicImportType eImportType,DomainMapper & rDMapper)264 GraphicImport_Impl(GraphicImportType eImportType, DomainMapper& rDMapper) :
265 nXSize(0)
266 ,bXSizeValid(false)
267 ,nYSize(0)
268 ,bYSizeValid(false)
269 ,eGraphicImportType( eImportType )
270 ,rDomainMapper( rDMapper )
271 ,nHoriScaling(0)
272 ,nVertScaling(0)
273 ,nLeftPosition(0)
274 ,nTopPosition(0)
275 ,nRightPosition(0)
276 ,nBottomPosition(0)
277 ,nLeftCrop(0)
278 ,nTopCrop (0)
279 ,nRightCrop (0)
280 ,nBottomCrop(0)
281 ,bUseSimplePos(false)
282 ,nHoriOrient( text::HoriOrientation::NONE )
283 ,nHoriRelation( text::RelOrientation::FRAME )
284 ,bPageToggle( false )
285 ,nVertOrient( text::VertOrientation::NONE )
286 ,nVertRelation( text::RelOrientation::FRAME )
287 ,nWrap(0)
288 ,bOpaque( true )
289 ,bContour(false)
290 ,bContourOutside(true)
291 ,bIgnoreWRK(true)
292 ,nLeftMargin(319)
293 ,nRightMargin(319)
294 ,nTopMargin(0)
295 ,nBottomMargin(0)
296 ,nContrast(0)
297 ,nBrightness(0)
298 ,fGamma( -1.0 )
299 ,nFillColor( 0xffffffff )
300 ,eColorMode( drawing::ColorMode_STANDARD )
301 ,nCurrentBorderLine(BORDER_TOP)
302 ,nDffType( 0 )
303 ,bIsGraphic(false)
304 ,bIsBitmap(false)
305 ,bIsTiff(false)
306 ,nBitsPerPixel(0)
307 ,bHoriFlip(false)
308 ,bVertFlip(false)
309 ,bSizeProtected(false)
310 ,bPositionProtected(false)
311 ,bInShapeOptionMode(false)
312 {}
313
setXSize(sal_Int32 _nXSize)314 void setXSize(sal_Int32 _nXSize)
315 {
316 nXSize = _nXSize;
317 bXSizeValid = true;
318 }
319
getXSize() const320 sal_uInt32 getXSize() const
321 {
322 return nXSize;
323 }
324
isXSizeValid() const325 bool isXSizeValid() const
326 {
327 return bXSizeValid;
328 }
329
setYSize(sal_Int32 _nYSize)330 void setYSize(sal_Int32 _nYSize)
331 {
332 nYSize = _nYSize;
333 bYSizeValid = true;
334 }
335
getYSize() const336 sal_uInt32 getYSize() const
337 {
338 return nYSize;
339 }
340
isYSizeValis() const341 bool isYSizeValis () const
342 {
343 return bYSizeValid;
344 }
345 };
346 /*-- 01.11.2006 09:42:42---------------------------------------------------
347
348 -----------------------------------------------------------------------*/
GraphicImport(uno::Reference<uno::XComponentContext> xComponentContext,uno::Reference<lang::XMultiServiceFactory> xTextFactory,DomainMapper & rDMapper,GraphicImportType eImportType)349 GraphicImport::GraphicImport(uno::Reference < uno::XComponentContext > xComponentContext,
350 uno::Reference< lang::XMultiServiceFactory > xTextFactory,
351 DomainMapper& rDMapper,
352 GraphicImportType eImportType )
353 : LoggedProperties(dmapper_logger, "GraphicImport")
354 , LoggedTable(dmapper_logger, "GraphicImport")
355 , LoggedStream(dmapper_logger, "GraphicImport")
356 , m_pImpl( new GraphicImport_Impl( eImportType, rDMapper ))
357 , m_xComponentContext( xComponentContext )
358 , m_xTextFactory( xTextFactory)
359 {
360 }
361 /*-- 01.11.2006 09:42:42---------------------------------------------------
362
363 -----------------------------------------------------------------------*/
~GraphicImport()364 GraphicImport::~GraphicImport()
365 {
366 delete m_pImpl;
367 }
368
handleWrapTextValue(sal_uInt32 nVal)369 void GraphicImport::handleWrapTextValue(sal_uInt32 nVal)
370 {
371 switch (nVal)
372 {
373 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_bothSides: // 90920;
374 m_pImpl->nWrap = text::WrapTextMode_PARALLEL;
375 break;
376 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_left: // 90921;
377 m_pImpl->nWrap = text::WrapTextMode_LEFT;
378 break;
379 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_right: // 90922;
380 m_pImpl->nWrap = text::WrapTextMode_RIGHT;
381 break;
382 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_largest: // 90923;
383 m_pImpl->nWrap = text::WrapTextMode_DYNAMIC;
384 break;
385 default:;
386 }
387 }
388
389 /*-- 01.11.2006 09:45:01---------------------------------------------------
390
391 -----------------------------------------------------------------------*/
lcl_attribute(Id nName,Value & val)392 void GraphicImport::lcl_attribute(Id nName, Value & val)
393 {
394 sal_Int32 nIntValue = val.getInt();
395 /* WRITERFILTERSTATUS: table: PICFattribute */
396 switch( nName )
397 {
398 case NS_rtf::LN_LCB: break;//byte count
399 case NS_rtf::LN_CBHEADER: break;//ignored
400 case NS_rtf::LN_MFP: //MetafilePict
401 case NS_rtf::LN_DffRecord: //dff record - expands to an sprm which expands to ...
402 case NS_rtf::LN_shpopt: //shape options
403 case NS_rtf::LN_shpfbse: //BLIP store entry
404 case NS_rtf::LN_BRCTOP: //top border
405 case NS_rtf::LN_BRCLEFT: //left border
406 case NS_rtf::LN_BRCBOTTOM: //bottom border
407 case NS_rtf::LN_BRCRIGHT: //right border
408 case NS_rtf::LN_shape: //shape
409 case NS_rtf::LN_blip: //the binary graphic data in a shape
410 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
411 {
412 switch(nName)
413 {
414 case NS_rtf::LN_BRCTOP: //top border
415 /* WRITERFILTERSTATUS: */
416 m_pImpl->nCurrentBorderLine = BORDER_TOP;
417 break;
418 case NS_rtf::LN_BRCLEFT: //left border
419 /* WRITERFILTERSTATUS: */
420 m_pImpl->nCurrentBorderLine = BORDER_LEFT;
421 break;
422 case NS_rtf::LN_BRCBOTTOM: //bottom border
423 /* WRITERFILTERSTATUS: */
424 m_pImpl->nCurrentBorderLine = BORDER_BOTTOM;
425 break;
426 case NS_rtf::LN_BRCRIGHT: //right border
427 /* WRITERFILTERSTATUS: */
428 m_pImpl->nCurrentBorderLine = BORDER_RIGHT;
429 break;
430 case NS_rtf::LN_shpopt:
431 /* WRITERFILTERSTATUS: */
432 m_pImpl->bInShapeOptionMode = true;
433 break;
434 default:;
435 }
436 writerfilter::Reference<Properties>::Pointer_t pProperties = val.getProperties();
437 if( pProperties.get())
438 {
439 pProperties->resolve(*this);
440 }
441 switch(nName)
442 {
443 case NS_rtf::LN_shpopt:
444 /* WRITERFILTERSTATUS: */
445 m_pImpl->bInShapeOptionMode = false;
446 break;
447 default:;
448 }
449 }
450 break;
451 case NS_rtf::LN_payload :
452 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
453 {
454 writerfilter::Reference<BinaryObj>::Pointer_t pPictureData = val.getBinary();
455 if( pPictureData.get())
456 pPictureData->resolve(*this);
457 }
458 break;
459 case NS_rtf::LN_BM_RCWINMF: //windows bitmap structure - if it's a bitmap
460 /* WRITERFILTERSTATUS: done: 0, planned: 0.5, spent: 0 */
461 break;
462 case NS_rtf::LN_DXAGOAL: //x-size in twip
463 case NS_rtf::LN_DYAGOAL: //y-size in twip
464 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
465 break;
466 case NS_rtf::LN_MX:
467 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
468 m_pImpl->nHoriScaling = nIntValue;
469 break;// hori scaling in 0.001%
470 case NS_rtf::LN_MY:
471 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
472 m_pImpl->nVertScaling = nIntValue;
473 break;// vert scaling in 0.001%
474 case NS_rtf::LN_DXACROPLEFT:
475 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
476 m_pImpl->nLeftCrop = ConversionHelper::convertTwipToMM100(nIntValue);
477 break;// left crop in twips
478 case NS_rtf::LN_DYACROPTOP:
479 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
480 m_pImpl->nTopCrop = ConversionHelper::convertTwipToMM100(nIntValue);
481 break;// top crop in twips
482 case NS_rtf::LN_DXACROPRIGHT:
483 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
484 m_pImpl->nRightCrop = ConversionHelper::convertTwipToMM100(nIntValue);
485 break;// right crop in twips
486 case NS_rtf::LN_DYACROPBOTTOM:
487 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
488 m_pImpl->nBottomCrop = ConversionHelper::convertTwipToMM100(nIntValue);
489 break;// bottom crop in twips
490 case NS_rtf::LN_BRCL:
491 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
492 break;//border type - legacy -
493 case NS_rtf::LN_FFRAMEEMPTY:
494 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
495 break;// picture consists of a single frame
496 case NS_rtf::LN_FBITMAP:
497 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
498 m_pImpl->bIsBitmap = nIntValue > 0 ? true : false;
499 break;//1 if it's a bitmap ???
500 case NS_rtf::LN_FDRAWHATCH:
501 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
502 break;//1 if it's an active OLE object
503 case NS_rtf::LN_FERROR:
504 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
505 break;// 1 if picture is an error message
506 case NS_rtf::LN_BPP:
507 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
508 m_pImpl->nBitsPerPixel = nIntValue;
509 break;//bits per pixel 0 - unknown, 1- mono, 4 - VGA
510
511 case NS_rtf::LN_DXAORIGIN: //horizontal offset of hand annotation origin
512 case NS_rtf::LN_DYAORIGIN: //vertical offset of hand annotation origin
513 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
514 break;
515 case NS_rtf::LN_CPROPS:break;// unknown - ignored
516 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
517 //metafilepict
518 case NS_rtf::LN_MM:
519 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
520 // according to the documentation 99 or 98 are provided - but they are not!
521 // m_pImpl->bIsBitmap = 99 == nIntValue ? true : false;
522 // m_pImpl->bIsTiff = 98 == nIntValue ? true : false;
523
524 break; //mapmode
525 case NS_rtf::LN_XEXT:
526 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
527 m_pImpl->setXSize(nIntValue);
528 break; // x-size
529 case NS_rtf::LN_YEXT:
530 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
531 m_pImpl->setYSize(nIntValue);
532 break; // y-size
533 case NS_rtf::LN_HMF: break; //identifier - ignored
534 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
535
536 //sprm 0xf004 and 0xf008, 0xf00b
537 case NS_rtf::LN_dfftype://
538 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
539 m_pImpl->nDffType = nIntValue;
540 break;
541 case NS_rtf::LN_dffinstance:
542 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
543 //todo: does this still work for PICF?
544 //in case of LN_dfftype == 0xf01f the instance contains the bitmap type:
545 if(m_pImpl->nDffType == 0xf01f)
546 switch( nIntValue )
547 {
548 case 0x216 : // Metafile header then compressed WMF
549
550 case 0x3D4 : // Metafile header then compressed EMF
551
552 case 0x542 : // Metafile hd. then compressed PICT
553
554 {
555
556 // rBLIPStream.SeekRel( nSkip + 20 );
557 // // read in size of metafile in EMUS
558 // rBLIPStream >> aMtfSize100.Width() >> aMtfSize100.Height();
559 // // scale to 1/100mm
560 // aMtfSize100.Width() /= 360, aMtfSize100.Height() /= 360;
561 // if ( pVisArea ) // seem that we currently are skipping the visarea position
562 // *pVisArea = Rectangle( Point(), aMtfSize100 );
563 // // skip rest of header
564 // nSkip = 6;
565 // bMtfBLIP = bZCodecCompression = TRUE;
566 }
567
568 break;
569
570 case 0x46A : break;// One byte tag then JPEG (= JFIF) data
571
572 case 0x6E0 : break;// One byte tag then PNG data
573
574 case 0x7A8 : m_pImpl->bIsBitmap = true;
575 // nSkip += 1; // One byte tag then DIB data
576 break;
577
578 }
579 break;
580 case NS_rtf::LN_dffversion:// ignored
581 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
582 break;
583
584 //sprm 0xf008
585 case NS_rtf::LN_shptype:
586 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
587 break;
588 case NS_rtf::LN_shpid:
589 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
590 break;
591 case NS_rtf::LN_shpfGroup:
592 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
593 break;// This shape is a group shape
594 case NS_rtf::LN_shpfChild:
595 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
596 break;// Not a top-level shape
597 case NS_rtf::LN_shpfPatriarch:
598 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
599 break;// This is the topmost group shape. Exactly one of these per drawing.
600 case NS_rtf::LN_shpfDeleted:
601 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
602 break;// The shape has been deleted
603 case NS_rtf::LN_shpfOleShape:
604 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
605 break;// The shape is an OLE object
606 case NS_rtf::LN_shpfHaveMaster:
607 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
608 break;// Shape has a hspMaster property
609 case NS_rtf::LN_shpfFlipH: // Shape is flipped horizontally
610 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
611 m_pImpl->bHoriFlip = nIntValue ? true : false;
612 break;
613 case NS_rtf::LN_shpfFlipV: // Shape is flipped vertically
614 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
615 m_pImpl->bVertFlip = nIntValue ? true : false;
616 break;
617 case NS_rtf::LN_shpfConnector:
618 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
619 break;// Connector type of shape
620 case NS_rtf::LN_shpfHaveAnchor:
621 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
622 break;// Shape has an anchor of some kind
623 case NS_rtf::LN_shpfBackground:
624 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
625 break;// Background shape
626 case NS_rtf::LN_shpfHaveSpt:
627 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
628 break;// Shape has a shape type property
629 case NS_rtf::LN_shptypename:
630 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
631 break;// shape type name
632 case NS_rtf::LN_shppid:
633 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
634 m_pImpl->nShapeOptionType = nIntValue;
635 break; //type of shape option
636 case NS_rtf::LN_shpfBid:
637 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
638 break; //ignored
639 case NS_rtf::LN_shpfComplex:
640 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
641 break;
642 case NS_rtf::LN_shpop:
643 /* WRITERFILTERSTATUS: done: 50, planned: 10, spent: 5 */
644 {
645 if(NS_dff::LN_shpwzDescription != sal::static_int_cast<Id>(m_pImpl->nShapeOptionType) )
646 ProcessShapeOptions( val );
647 }
648 break;
649 case NS_rtf::LN_shpname:
650 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
651 break;
652 case NS_rtf::LN_shpvalue:
653 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
654 {
655 if( NS_dff::LN_shpwzDescription == sal::static_int_cast<Id>(m_pImpl->nShapeOptionType) )
656 ProcessShapeOptions( val );
657 }
658 break;
659
660 //BLIP store entry
661 case NS_rtf::LN_shpbtWin32:
662 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
663 break;
664 case NS_rtf::LN_shpbtMacOS:
665 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
666 break;
667 case NS_rtf::LN_shprgbUid:
668 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
669 break;
670 case NS_rtf::LN_shptag:
671 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
672 break;
673 case NS_rtf::LN_shpsize:
674 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
675 break;
676 case NS_rtf::LN_shpcRef:
677 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
678 break;
679 case NS_rtf::LN_shpfoDelay:
680 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
681 break;
682 case NS_rtf::LN_shpusage:
683 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
684 break;
685 case NS_rtf::LN_shpcbName:
686 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
687 break;
688 case NS_rtf::LN_shpunused2:
689 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
690 break;
691 case NS_rtf::LN_shpunused3:
692 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
693 break;
694
695 //border properties
696 case NS_rtf::LN_shpblipbname :
697 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
698 break;
699
700 case NS_rtf::LN_DPTLINEWIDTH: // 0x1759
701 /* WRITERFILTERSTATUS: done: 100, planned: 1, spent: 1 */
702 m_pImpl->aBorders[m_pImpl->nCurrentBorderLine].nLineWidth = nIntValue;
703 break;
704 case NS_rtf::LN_BRCTYPE: // 0x175a
705 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
706 //graphic borders don't support different line types
707 //m_pImpl->aBorders[m_pImpl->nCurrentBorderLine].nLineType = nIntValue;
708 break;
709 case NS_rtf::LN_ICO: // 0x175b
710 /* WRITERFILTERSTATUS: done: 100, planned: 1, spent: 1 */
711 m_pImpl->aBorders[m_pImpl->nCurrentBorderLine].nLineColor = ConversionHelper::ConvertColor( nIntValue );
712 break;
713 case NS_rtf::LN_DPTSPACE: // 0x175c
714 /* WRITERFILTERSTATUS: done: 100, planned: 1, spent: 1 */
715 m_pImpl->aBorders[m_pImpl->nCurrentBorderLine].nLineDistance = nIntValue;
716 break;
717 case NS_rtf::LN_FSHADOW: // 0x175d
718 /* WRITERFILTERSTATUS: done: 0, planned: 1, spent: 0 */
719 m_pImpl->aBorders[m_pImpl->nCurrentBorderLine].bHasShadow = nIntValue ? true : false;
720 break;
721 case NS_rtf::LN_FFRAME: // ignored
722 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
723 case NS_rtf::LN_UNUSED2_15: // ignored
724 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
725 break;
726
727 case NS_rtf::LN_SPID:
728 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
729 break;
730 case NS_rtf::LN_XALEFT:
731 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
732 m_pImpl->nLeftPosition = ConversionHelper::convertTwipToMM100(nIntValue);
733 break; //left position
734 case NS_rtf::LN_YATOP:
735 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
736 m_pImpl->nTopPosition = ConversionHelper::convertTwipToMM100(nIntValue);
737 break; //top position
738 case NS_rtf::LN_XARIGHT:
739 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
740 m_pImpl->nRightPosition = ConversionHelper::convertTwipToMM100(nIntValue);
741 break; //right position
742 case NS_rtf::LN_YABOTTOM:
743 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
744 m_pImpl->nBottomPosition = ConversionHelper::convertTwipToMM100(nIntValue);
745 break;//bottom position
746 case NS_rtf::LN_FHDR:
747 case NS_rtf::LN_XAlign:
748 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
749 /*
750 static const SwHoriOrient aHoriOriTab[ nCntXAlign ] =
751 {
752 HORI_NONE, // From left position
753 HORI_LEFT, // left
754 HORI_CENTER, // centered
755 HORI_RIGHT, // right
756 // --> OD 2004-12-06 #i36649#
757 // - inside -> HORI_LEFT and outside -> HORI_RIGHT
758 HORI_LEFT, // inside
759 HORI_RIGHT // outside
760 */
761 if( nIntValue < 6 && nIntValue > 0 )
762 {
763 static const sal_Int16 aHoriOrientTab[ 6 ] =
764 {
765 text::HoriOrientation::NONE,
766 text::HoriOrientation::LEFT,
767 text::HoriOrientation::CENTER,
768 text::HoriOrientation::RIGHT,
769 text::HoriOrientation::INSIDE,
770 text::HoriOrientation::OUTSIDE
771 };
772 m_pImpl->nHoriOrient = aHoriOrientTab[nIntValue];
773 m_pImpl->bPageToggle = nIntValue > 3;
774 }
775 break;
776 case NS_rtf::LN_YAlign:
777 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
778 /*
779 static const SwVertOrient aVertOriTab[ nCntYAlign ] =
780 {
781 VERT_NONE, // From Top position
782 VERT_TOP, // top
783 VERT_CENTER, // centered
784 VERT_BOTTOM, // bottom
785 VERT_LINE_TOP, // inside (obscure)
786 VERT_LINE_BOTTOM // outside (obscure)
787 };
788 // CMC,OD 24.11.2003 #i22673# - to-line vertical alignment
789 static const SwVertOrient aToLineVertOriTab[ nCntYAlign ] =
790 {
791 VERT_NONE, // below
792 VERT_LINE_BOTTOM, // top
793 VERT_LINE_CENTER, // centered
794 VERT_LINE_TOP, // bottom
795 VERT_LINE_BOTTOM, // inside (obscure)
796 VERT_LINE_TOP // outside (obscure)
797 };
798 if ( eVertRel == REL_VERT_LINE ) //m_pImpl->nVertRelation == text::RelOrientation::TEXT_LINE
799 {
800 eVertOri = aToLineVertOriTab[ nYAlign ];
801 }
802 else
803 {
804 eVertOri = aVertOriTab[ nYAlign ];
805 }
806
807 */
808 if( nIntValue < 6 && nIntValue > 0)
809 {
810 static const sal_Int16 aVertOrientTab[ 6 ] =
811 {
812 text::VertOrientation::NONE, // From Top position
813 text::VertOrientation::TOP, // top
814 text::VertOrientation::CENTER, // centered
815 text::VertOrientation::BOTTOM, // bottom
816 text::VertOrientation::LINE_TOP, // inside (obscure)
817 text::VertOrientation::LINE_BOTTOM // outside (obscure)
818 };
819 static const sal_Int16 aToLineVertOrientTab[ 6 ] =
820 {
821 text::VertOrientation::NONE, // below
822 text::VertOrientation::LINE_BOTTOM, // top
823 text::VertOrientation::LINE_CENTER, // centered
824 text::VertOrientation::LINE_TOP, // bottom
825 text::VertOrientation::LINE_BOTTOM, // inside (obscure)
826 text::VertOrientation::LINE_TOP // outside (obscure)
827 };
828 m_pImpl->nVertOrient = m_pImpl->nVertRelation == text::RelOrientation::TEXT_LINE ?
829 aToLineVertOrientTab[nIntValue] : aVertOrientTab[nIntValue];
830 }
831 break;
832 case NS_rtf::LN_LayoutInTableCell: break; //currently unknown
833 case NS_rtf::LN_XRelTo:
834 case NS_rtf::LN_BX: //hori orient relation
835 switch( nIntValue )
836 {
837 case 0: m_pImpl->nHoriRelation = text::RelOrientation::PAGE_PRINT_AREA; break;
838 case 1: m_pImpl->nHoriRelation = text::RelOrientation::PAGE_FRAME; break;
839 case 2: m_pImpl->nHoriRelation = text::RelOrientation::FRAME; break;
840 //case :
841 default:m_pImpl->nHoriRelation = text::RelOrientation::CHAR;
842 }
843 break;
844 case NS_rtf::LN_YRelTo:
845 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
846 case NS_rtf::LN_BY: //vert orient relation
847 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
848 switch( nIntValue )
849 {
850 case 0: m_pImpl->nVertRelation = text::RelOrientation::PAGE_PRINT_AREA; break;
851 case 1: m_pImpl->nVertRelation = text::RelOrientation::PAGE_FRAME; break;
852 case 2: m_pImpl->nVertRelation = text::RelOrientation::FRAME; break;
853 //case :
854 default:m_pImpl->nVertRelation = text::RelOrientation::TEXT_LINE;
855 }
856
857 break;
858 case NS_rtf::LN_WR: //wrapping
859 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
860 switch( nIntValue )
861 {
862 case 0: //0 like 2, but doesn't require absolute object
863 m_pImpl->bIgnoreWRK = false;
864 case 2: //2 wrap around absolute object
865 m_pImpl->nWrap = text::WrapTextMode_PARALLEL;
866 break;
867 case 1: //1 no text next to shape
868 m_pImpl->nWrap = text::WrapTextMode_NONE;
869 break;
870 case 3: //3 wrap as if no object present
871 m_pImpl->nWrap = text::WrapTextMode_THROUGHT;
872 break;
873 case 4: //4 wrap tightly around object
874 m_pImpl->bIgnoreWRK = false;
875 case 5: //5 wrap tightly, but allow holes
876 m_pImpl->nWrap = text::WrapTextMode_PARALLEL;
877 m_pImpl->bContour = true;
878 break;
879 default:;
880 }
881 break;
882 case NS_rtf::LN_WRK:
883 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
884 if( !m_pImpl->bIgnoreWRK )
885 switch( nIntValue )
886 {
887 case 0: //0 like 2, but doesn't require absolute object
888 case 2: //2 wrap around absolute object
889 m_pImpl->nWrap = text::WrapTextMode_PARALLEL;
890 break;
891 case 1: //1 no text next to shape
892 m_pImpl->nWrap = text::WrapTextMode_NONE;
893 break;
894 case 3: //3 wrap as if no object present
895 m_pImpl->nWrap = text::WrapTextMode_THROUGHT;
896 break;
897 case 4: //4 wrap tightly around object
898 case 5: //5 wrap tightly, but allow holes
899 m_pImpl->nWrap = text::WrapTextMode_PARALLEL;
900 m_pImpl->bContour = true;
901 break;
902 default:;
903 }
904 break;
905 case NS_rtf::LN_FRCASIMPLE:
906 case NS_rtf::LN_FBELOWTEXT:
907 case NS_rtf::LN_FANCHORLOCK:
908 case NS_rtf::LN_CTXBX:
909 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
910 // {
911 // sal_Int32 nValue1 = val.getInt();
912 // nValue1++;
913 // }
914 break;
915 case NS_rtf::LN_shptxt:
916 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
917 //todo: text content
918 break;
919 /* case NS_rtf::LN_CH = 10421;
920 case NS_rtf::LN_UNUSED0_5 = 10422;
921 case NS_rtf::LN_FLT = 10423;
922 case NS_rtf::LN_shpLeft = 10424;
923 case NS_rtf::LN_shpTop = 10425;
924 break;*/
925 case NS_rtf::LN_dffheader: break;
926 case NS_ooxml::LN_CT_PositiveSize2D_cx:// 90407;
927 case NS_ooxml::LN_CT_PositiveSize2D_cy:// 90408;
928 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
929 {
930 sal_Int32 nDim = ConversionHelper::convertEMUToMM100( nIntValue );
931 if( nName == NS_ooxml::LN_CT_PositiveSize2D_cx )
932 m_pImpl->setXSize(nDim);
933 else
934 m_pImpl->setYSize(nDim);
935 }
936 break;
937 case NS_ooxml::LN_CT_EffectExtent_l:// 90907;
938 case NS_ooxml::LN_CT_EffectExtent_t:// 90908;
939 case NS_ooxml::LN_CT_EffectExtent_r:// 90909;
940 case NS_ooxml::LN_CT_EffectExtent_b:// 90910;
941 /* WRITERFILTERSTATUS: done: 0, planned: 0.5, spent: 0 */
942 //todo: extends the wrapping size of the object, e.g. if shadow is added
943 break;
944 case NS_ooxml::LN_CT_NonVisualDrawingProps_id:// 90650;
945 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
946 //id of the object - ignored
947 break;
948 case NS_ooxml::LN_CT_NonVisualDrawingProps_name:// 90651;
949 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
950 //name of the object
951 m_pImpl->sName = val.getString();
952 break;
953 case NS_ooxml::LN_CT_NonVisualDrawingProps_descr:// 90652;
954 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
955 //alternative text
956 m_pImpl->sAlternativeText = val.getString();
957 break;
958 case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noChangeAspect://90644;
959 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
960 //disallow aspect ratio change - ignored
961 break;
962 case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noMove:// 90645;
963 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
964 m_pImpl->bPositionProtected = true;
965 break;
966 case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noResize: // 90646;
967 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
968 m_pImpl->bSizeProtected = true;
969 break;
970 case NS_ooxml::LN_CT_Anchor_distT: // 90983;
971 case NS_ooxml::LN_CT_Anchor_distB: // 90984;
972 case NS_ooxml::LN_CT_Anchor_distL: // 90985;
973 case NS_ooxml::LN_CT_Anchor_distR: // 90986;
974 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
975 {
976 //redirect to shape option processing
977 switch( nName )
978 {
979 case NS_ooxml::LN_CT_Anchor_distT: // 90983;
980 /* WRITERFILTERSTATUS: */
981 m_pImpl->nShapeOptionType = NS_dff::LN_shpdyWrapDistTop;
982 break;
983 case NS_ooxml::LN_CT_Anchor_distB: // 90984;
984 /* WRITERFILTERSTATUS: */
985 m_pImpl->nShapeOptionType = NS_dff::LN_shpdyWrapDistBottom;
986 break;
987 case NS_ooxml::LN_CT_Anchor_distL: // 90985;
988 /* WRITERFILTERSTATUS: */
989 m_pImpl->nShapeOptionType = NS_dff::LN_shpdxWrapDistLeft;
990 break;
991 case NS_ooxml::LN_CT_Anchor_distR: // 90986;
992 /* WRITERFILTERSTATUS: */
993 m_pImpl->nShapeOptionType = NS_dff::LN_shpdxWrapDistRight;
994 break;
995 //m_pImpl->nShapeOptionType = NS_dff::LN_shpcropFromTop
996 default: ;
997 }
998 ProcessShapeOptions(val);
999 }
1000 break;
1001 case NS_ooxml::LN_CT_Anchor_simplePos_attr: // 90987;
1002 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
1003 m_pImpl->bUseSimplePos = nIntValue > 0;
1004 break;
1005 case NS_ooxml::LN_CT_Anchor_relativeHeight: // 90988;
1006 /* WRITERFILTERSTATUS: done: 0, planned: 0.5, spent: 0 */
1007 //z-order
1008 break;
1009 case NS_ooxml::LN_CT_Anchor_behindDoc: // 90989; - in background
1010 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
1011 if( nIntValue > 0 )
1012 m_pImpl->bOpaque = false;
1013 break;
1014 case NS_ooxml::LN_CT_Anchor_locked: // 90990; - ignored
1015 case NS_ooxml::LN_CT_Anchor_layoutInCell: // 90991; - ignored
1016 case NS_ooxml::LN_CT_Anchor_hidden: // 90992; - ignored
1017 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1018 break;
1019 case NS_ooxml::LN_CT_Anchor_allowOverlap: // 90993;
1020 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1021 //enable overlapping - ignored
1022 break;
1023 case NS_ooxml::LN_CT_Point2D_x: // 90405;
1024 case NS_ooxml::LN_CT_Point2D_y: // 90406;
1025 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
1026 if( m_pImpl->bUseSimplePos )
1027 {
1028 //todo: absolute positioning
1029 NS_ooxml::LN_CT_Point2D_x == nName ? m_pImpl->nLeftPosition = ConversionHelper::convertTwipToMM100(nIntValue) :
1030 m_pImpl->nTopPosition = ConversionHelper::convertTwipToMM100(nIntValue);
1031
1032 }
1033 break;
1034 case NS_ooxml::LN_CT_WrapTight_wrapText: // 90934;
1035 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
1036 m_pImpl->bContour = true;
1037 m_pImpl->bContourOutside = true;
1038
1039 handleWrapTextValue(val.getInt());
1040
1041 break;
1042 case NS_ooxml::LN_CT_WrapThrough_wrapText:
1043 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
1044 m_pImpl->bContour = true;
1045 m_pImpl->bContourOutside = false;
1046
1047 handleWrapTextValue(val.getInt());
1048
1049 break;
1050 case NS_ooxml::LN_CT_WrapSquare_wrapText: //90928;
1051 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
1052
1053 handleWrapTextValue(val.getInt());
1054 break;
1055 case NS_ooxml::LN_shape:
1056 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
1057 {
1058 uno::Reference< drawing::XShape> xShape;
1059 val.getAny( ) >>= xShape;
1060
1061 if ( xShape.is( ) )
1062 {
1063 // Is it a graphic image
1064 bool bUseShape = true;
1065 try
1066 {
1067 uno::Reference< beans::XPropertySet > xShapeProps
1068 ( xShape, uno::UNO_QUERY_THROW );
1069
1070 rtl::OUString sUrl;
1071 xShapeProps->getPropertyValue( rtl::OUString::createFromAscii( "GraphicURL" ) ) >>= sUrl;
1072
1073 ::com::sun::star::beans::PropertyValues aMediaProperties( 1 );
1074 aMediaProperties[0].Name = rtl::OUString::createFromAscii( "URL" );
1075 aMediaProperties[0].Value <<= sUrl;
1076
1077 m_xGraphicObject = createGraphicObject( aMediaProperties );
1078
1079 bUseShape = !m_xGraphicObject.is( );
1080
1081 if ( !bUseShape )
1082 {
1083 // Define the object size
1084 uno::Reference< beans::XPropertySet > xGraphProps( m_xGraphicObject,
1085 uno::UNO_QUERY );
1086 awt::Size aSize = xShape->getSize( );
1087 xGraphProps->setPropertyValue( rtl::OUString::createFromAscii( "Height" ),
1088 uno::makeAny( aSize.Height ) );
1089 xGraphProps->setPropertyValue( rtl::OUString::createFromAscii( "Width" ),
1090 uno::makeAny( aSize.Width ) );
1091
1092 {
1093 text::GraphicCrop aGraphicCrop( 0, 0, 0, 0 );
1094 uno::Reference< beans::XPropertySet > xSourceGraphProps( xShape, uno::UNO_QUERY );
1095 uno::Any aAny = xSourceGraphProps->getPropertyValue( rtl::OUString::createFromAscii("GraphicCrop"));
1096 if ( aAny >>= aGraphicCrop )
1097 {
1098 xGraphProps->setPropertyValue(
1099 rtl::OUString::createFromAscii("GraphicCrop"),
1100 uno::makeAny( aGraphicCrop ) );
1101 }
1102 }
1103 }
1104 }
1105 catch( const beans::UnknownPropertyException e )
1106 {
1107 // It isn't a graphic image
1108 }
1109
1110 if ( bUseShape )
1111 m_xShape = xShape;
1112
1113
1114 if ( m_xShape.is( ) )
1115 {
1116 uno::Reference< beans::XPropertySet > xShapeProps
1117 (m_xShape, uno::UNO_QUERY_THROW);
1118
1119
1120 PropertyNameSupplier& rPropNameSupplier =
1121 PropertyNameSupplier::GetPropertyNameSupplier();
1122 xShapeProps->setPropertyValue
1123 (rPropNameSupplier.GetName(PROP_ANCHOR_TYPE),
1124 uno::makeAny
1125 (text::TextContentAnchorType_AS_CHARACTER));
1126 xShapeProps->setPropertyValue
1127 (rPropNameSupplier.GetName(PROP_TEXT_RANGE),
1128 uno::makeAny
1129 (m_pImpl->rDomainMapper.GetCurrentTextRange()));
1130
1131 awt::Point aPoint(m_xShape->getPosition());
1132 awt::Size aSize(m_xShape->getSize());
1133
1134 if (m_pImpl->isXSizeValid())
1135 aSize.Width = m_pImpl->getXSize();
1136 if (m_pImpl->isYSizeValis())
1137 aSize.Height = m_pImpl->getYSize();
1138
1139 m_xShape->setSize(aSize);
1140
1141 m_pImpl->bIsGraphic = true;
1142 }
1143 }
1144 }
1145 break;
1146 case NS_ooxml::LN_CT_Inline_distT:
1147 case NS_ooxml::LN_CT_Inline_distB:
1148 case NS_ooxml::LN_CT_Inline_distL:
1149 case NS_ooxml::LN_CT_Inline_distR:
1150 /* WRITERFILTERSTATUS: done: 0, planned: 0.5, spent: 0 */
1151 //TODO: need to be handled
1152 break;
1153 case NS_ooxml::LN_CT_GraphicalObjectData_uri:
1154 /* WRITERFILTERSTATUS: done: 50, planned: 0.5, spent: 0 */
1155 val.getString();
1156 //TODO: does it need to be handled?
1157 break;
1158 default:
1159 #ifdef DEBUG_DMAPPER_GRAPHIC_IMPORT
1160 dmapper_logger->element("unhandled");
1161 #endif
1162 ;
1163 }
1164 }
1165
GetGraphicObject()1166 uno::Reference<text::XTextContent> GraphicImport::GetGraphicObject()
1167 {
1168 uno::Reference<text::XTextContent> xResult;
1169
1170 if (m_xGraphicObject.is())
1171 xResult = m_xGraphicObject;
1172 else if (m_xShape.is())
1173 {
1174 xResult.set(m_xShape, uno::UNO_QUERY_THROW);
1175 }
1176
1177 return xResult;
1178 }
1179
1180 /*-- 22.11.2006 09:46:48---------------------------------------------------
1181
1182 -----------------------------------------------------------------------*/
ProcessShapeOptions(Value & val)1183 void GraphicImport::ProcessShapeOptions(Value& val)
1184 {
1185 sal_Int32 nIntValue = val.getInt();
1186 sal_Int32 nTwipValue = ConversionHelper::convertTwipToMM100(nIntValue);
1187 /* WRITERFILTERSTATUS: table: ShapeOptionsAttribute */
1188 switch( m_pImpl->nShapeOptionType )
1189 {
1190 case NS_dff::LN_shpcropFromTop /*256*/ :
1191 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
1192 m_pImpl->nTopCrop = nTwipValue;
1193 break;// rtf:shpcropFromTop
1194 case NS_dff::LN_shpcropFromBottom /*257*/ :
1195 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
1196 m_pImpl->nBottomCrop= nTwipValue;
1197 break;// rtf:shpcropFromBottom
1198 case NS_dff::LN_shpcropFromLeft /*258*/ :
1199 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
1200 m_pImpl->nLeftCrop = nTwipValue;
1201 break;// rtf:shpcropFromLeft
1202 case NS_dff::LN_shpcropFromRight/*259*/ :
1203 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
1204 m_pImpl->nRightCrop = nTwipValue;
1205 break;// rtf:shpcropFromRight
1206 case NS_dff::LN_shppib/*260*/:
1207 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1208 break; // rtf:shppib
1209 case NS_dff::LN_shppibName/*261*/:
1210 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1211 break; // rtf:shppibName
1212 case NS_dff::LN_shppibFlags/*262*/: // rtf:shppibFlags
1213 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1214 /*
1215 * // MSOBLIPFLAGS ñ flags for pictures
1216 typedef enum
1217 {
1218 msoblipflagDefault = 0,
1219 msoblipflagComment = 0, // Blip name is a comment
1220 msoblipflagFile, // Blip name is a file name
1221 msoblipflagURL, // Blip name is a full URL
1222 msoblipflagType = 3, // Mask to extract type
1223 // Or the following flags with any of the above.
1224 msoblipflagDontSave = 4, // A "dont" is the depression in the metal
1225 // body work of an automobile caused when a
1226 // cyclist violently thrusts his or her nose
1227 // at it, thus a DontSave is another name for
1228 // a cycle lane.
1229 msoblipflagDoNotSave = 4, // For those who prefer English
1230 msoblipflagLinkToFile = 8,
1231 };
1232 *
1233 * */
1234 break;
1235 case NS_dff::LN_shppictureContrast/*264*/: // rtf:shppictureContrast docu: "1<<16"
1236 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
1237 /*
1238 0x10000 is msoffice 50%
1239 < 0x10000 is in units of 1/50th of 0x10000 per 1%
1240 > 0x10000 is in units where
1241 a msoffice x% is stored as 50/(100-x) * 0x10000
1242
1243 plus, a (ui) microsoft % ranges from 0 to 100, OOO
1244 from -100 to 100, so also normalize into that range
1245 */
1246 if ( nIntValue > 0x10000 )
1247 {
1248 double fX = nIntValue;
1249 fX /= 0x10000;
1250 fX /= 51; // 50 + 1 to round
1251 fX = 1/fX;
1252 m_pImpl->nContrast = static_cast<sal_Int32>(fX);
1253 m_pImpl->nContrast -= 100;
1254 m_pImpl->nContrast = -m_pImpl->nContrast;
1255 m_pImpl->nContrast = (m_pImpl->nContrast-50)*2;
1256 }
1257 else if ( nIntValue == 0x10000 )
1258 m_pImpl->nContrast = 0;
1259 else
1260 {
1261 m_pImpl->nContrast = nIntValue * 101; //100 + 1 to round
1262 m_pImpl->nContrast /= 0x10000;
1263 m_pImpl->nContrast -= 100;
1264 }
1265 break;
1266 case NS_dff::LN_shppictureBrightness/*265*/: // rtf:shppictureBrightness
1267 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
1268 m_pImpl->nBrightness = ( (sal_Int32) nIntValue / 327 );
1269 break;
1270 case NS_dff::LN_shppictureGamma/*266*/: // rtf:shppictureGamma
1271 /* WRITERFILTERSTATUS: done: 50, planned: 0, spent: 0 */
1272 //todo check gamma value with _real_ document
1273 m_pImpl->fGamma = double(nIntValue/655);
1274 break;
1275 case NS_dff::LN_shppictureId /*267*/:
1276 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1277 break; // rtf:shppictureId
1278 case NS_dff::LN_shppictureDblCrMod /*268*/:
1279 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1280 break; // rtf:shppictureDblCrMod
1281 case NS_dff::LN_shppictureFillCrMod /*269*/:
1282 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1283 break; // rtf:shppictureFillCrMod
1284 case NS_dff::LN_shppictureLineCrMod /*270*/:
1285 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1286 break; // rtf:shppictureLineCrMod
1287
1288 case NS_dff::LN_shppictureActive/*319*/: // rtf:shppictureActive
1289 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
1290 switch( nIntValue & 0x06 )
1291 {
1292 case 0 : m_pImpl->eColorMode = drawing::ColorMode_STANDARD; break;
1293 case 4 : m_pImpl->eColorMode = drawing::ColorMode_GREYS; break;
1294 case 6 : m_pImpl->eColorMode = drawing::ColorMode_MONO; break;
1295 default:;
1296 }
1297 break;
1298 case NS_dff::LN_shpfillColor /*385*/:
1299 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1300 m_pImpl->nFillColor = (m_pImpl->nFillColor & 0xff000000) + ConversionHelper::ConvertColor( nIntValue );
1301 break;
1302 case NS_dff::LN_shpfillOpacity /*386*/:
1303 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1304 {
1305 sal_Int32 nTrans = 0xff - ( nIntValue * 0xff ) / 0xffff;
1306 m_pImpl->nFillColor = (nTrans << 0x18 ) + (m_pImpl->nFillColor & 0xffffff);
1307 }
1308 break;
1309 case NS_dff::LN_shpfNoFillHitTest /*447*/:
1310 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1311 break; // rtf:shpfNoFillHitTest
1312 case NS_dff::LN_shplineColor /*448*/:
1313 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
1314 m_pImpl->aBorders[m_pImpl->nCurrentBorderLine].nLineColor = ConversionHelper::ConvertColor( nIntValue );
1315 break;
1316 case NS_dff::LN_shplineWidth /*459*/:
1317 /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
1318 //1pt == 12700 units
1319 m_pImpl->aBorders[m_pImpl->nCurrentBorderLine].nLineWidth = ConversionHelper::convertTwipToMM100(nIntValue / 635);
1320 break;
1321 case NS_dff::LN_shplineDashing /*462*/:
1322 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1323 //graphic borders don't support different dashing
1324 /*MSOLINEDASHING
1325 msolineSolid, // Solid (continuous) pen
1326 msolineDashSys, // PS_DASH system dash style
1327 msolineDotSys, // PS_DOT system dash style
1328 msolineDashDotSys, // PS_DASHDOT system dash style
1329 msolineDashDotDotSys, // PS_DASHDOTDOT system dash style
1330 msolineDotGEL, // square dot style
1331 msolineDashGEL, // dash style
1332 msolineLongDashGEL, // long dash style
1333 msolineDashDotGEL, // dash short dash
1334 msolineLongDashDotGEL, // long dash short dash
1335 msolineLongDashDotDotGEL // long dash short dash short dash*/
1336 //m_pImpl->aBorders[nCurrentBorderLine].nLineType = nIntValue;
1337 break;
1338 case NS_dff::LN_shpfNoLineDrawDash /*511*/:
1339 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1340 break; // rtf:shpfNoLineDrawDash
1341 case NS_dff::LN_shpwzDescription /*897*/: //alternative text
1342 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1343 m_pImpl->sAlternativeText = val.getString();
1344 break;
1345 // case NS_dff::LN_shppihlShape /*898*/:
1346 case NS_dff::LN_shppWrapPolygonVertices/*899*/:
1347 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1348 break; // rtf:shppWrapPolygonVertices
1349 case NS_dff::LN_shpdxWrapDistLeft /*900*/: // contains a twip/635 value
1350 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1351 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustLRWrapForWordMargins()
1352 m_pImpl->nLeftMargin = nIntValue / 360;
1353 break;
1354 case NS_dff::LN_shpdyWrapDistTop /*901*/: // contains a twip/635 value
1355 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1356 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustULWrapForWordMargins()
1357 m_pImpl->nTopMargin = nIntValue / 360;
1358 break;
1359 case NS_dff::LN_shpdxWrapDistRight /*902*/:// contains a twip/635 value
1360 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1361 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustLRWrapForWordMargins()
1362 m_pImpl->nRightMargin = nIntValue / 360;
1363 break;
1364 case NS_dff::LN_shpdyWrapDistBottom /*903*/:// contains a twip/635 value
1365 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1366 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustULWrapForWordMargins()
1367 m_pImpl->nBottomMargin = nIntValue / 360;
1368 break;
1369 case NS_dff::LN_shpfPrint /*959*/:
1370 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
1371 break; // rtf:shpfPrint
1372 default:
1373 OSL_ENSURE( false, "shape option unsupported?");
1374 }
1375 }
1376 /*-- 01.11.2006 09:45:02---------------------------------------------------
1377
1378 -----------------------------------------------------------------------*/
lcl_sprm(Sprm & rSprm)1379 void GraphicImport::lcl_sprm(Sprm & rSprm)
1380 {
1381 sal_uInt32 nSprmId = rSprm.getId();
1382 Value::Pointer_t pValue = rSprm.getValue();
1383
1384 /* WRITERFILTERSTATUS: table: PICFsprmdata */
1385 switch(nSprmId)
1386 {
1387 case 0xf004: //dff record
1388 case 0xf00a: //part of 0xf004 - shape properties
1389 case 0xf00b: //part of 0xf004
1390 case 0xf007:
1391 case 0xf122: //udefprop
1392 case NS_ooxml::LN_CT_Inline_extent: // 90911;
1393 case NS_ooxml::LN_CT_Inline_effectExtent: // 90912;
1394 case NS_ooxml::LN_CT_Inline_docPr: // 90913;
1395 case NS_ooxml::LN_CT_Inline_cNvGraphicFramePr: // 90914;
1396 case NS_ooxml::LN_CT_NonVisualGraphicFrameProperties_graphicFrameLocks:// 90657
1397 case NS_ooxml::LN_CT_Inline_a_graphic:// 90915
1398 case NS_ooxml::LN_CT_Anchor_simplePos_elem: // 90975;
1399 case NS_ooxml::LN_CT_Anchor_extent: // 90978;
1400 case NS_ooxml::LN_CT_Anchor_effectExtent: // 90979;
1401 case NS_ooxml::LN_EG_WrapType_wrapSquare: // 90945;
1402 case NS_ooxml::LN_EG_WrapType_wrapTight: // 90946;
1403 case NS_ooxml::LN_EG_WrapType_wrapThrough:
1404 case NS_ooxml::LN_CT_Anchor_docPr: // 90980;
1405 case NS_ooxml::LN_CT_Anchor_cNvGraphicFramePr: // 90981;
1406 case NS_ooxml::LN_CT_Anchor_a_graphic: // 90982;
1407 case NS_ooxml::LN_CT_WrapPath_start: // 90924;
1408 case NS_ooxml::LN_CT_WrapPath_lineTo: // 90925;
1409 case NS_ooxml::LN_graphic_graphic:
1410 case NS_ooxml::LN_pic_pic:
1411 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
1412 {
1413 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
1414 if( pProperties.get())
1415 {
1416 pProperties->resolve(*this);
1417 }
1418 }
1419 break;
1420 case NS_ooxml::LN_CT_WrapTight_wrapPolygon:
1421 case NS_ooxml::LN_CT_WrapThrough_wrapPolygon:
1422 /* WRITERFILTERSTATUS: done: 100, planned: 4, spent: 2 */
1423 {
1424 WrapPolygonHandler aHandler;
1425
1426 resolveSprmProps(aHandler, rSprm);
1427
1428 m_pImpl->mpWrapPolygon = aHandler.getPolygon();
1429 }
1430 break;
1431 case NS_ooxml::LN_CT_Anchor_positionH: // 90976;
1432 {
1433 // Use a special handler for the positionning
1434 PositionHandlerPtr pHandler( new PositionHandler );
1435 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
1436 if( pProperties.get( ) )
1437 {
1438 pProperties->resolve( *pHandler );
1439
1440 m_pImpl->nHoriRelation = pHandler->m_nRelation;
1441 m_pImpl->nHoriOrient = pHandler->m_nOrient;
1442 m_pImpl->nLeftPosition = pHandler->m_nPosition;
1443 }
1444 }
1445 break;
1446 case NS_ooxml::LN_CT_Anchor_positionV: // 90977;
1447 {
1448 // Use a special handler for the positionning
1449 PositionHandlerPtr pHandler( new PositionHandler );
1450 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
1451 if( pProperties.get( ) )
1452 {
1453 pProperties->resolve( *pHandler );
1454
1455 m_pImpl->nVertRelation = pHandler->m_nRelation;
1456 m_pImpl->nVertOrient = pHandler->m_nOrient;
1457 m_pImpl->nTopPosition = pHandler->m_nPosition;
1458 }
1459 }
1460 break;
1461 case 0x271b:
1462 case 0x271c:
1463 {
1464 if( nSprmId != 0x271c || m_pImpl->nDffType == 0xf01f || m_pImpl->nDffType == 0xf01e )
1465 {
1466 writerfilter::Reference<BinaryObj>::Pointer_t pPictureData = rSprm.getBinary();
1467 if( pPictureData.get())
1468 pPictureData->resolve(*this);
1469 }
1470 }
1471 break;
1472 case NS_ooxml::LN_EG_WrapType_wrapNone: // 90944; - doesn't contain attributes
1473 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
1474 //depending on the behindDoc attribute text wraps through behind or in fron of the object
1475 m_pImpl->nWrap = text::WrapTextMode_THROUGHT;
1476 break;
1477 case NS_ooxml::LN_EG_WrapType_wrapTopAndBottom: // 90948;
1478 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
1479 m_pImpl->nWrap = text::WrapTextMode_NONE;
1480 break;
1481 case 0xf010:
1482 case 0xf011:
1483 //ignore - doesn't contain useful members
1484 break;
1485 case NS_ooxml::LN_CT_GraphicalObject_graphicData:// 90660;
1486 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
1487 {
1488 m_pImpl->bIsGraphic = true;
1489
1490 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
1491 if( pProperties.get())
1492 pProperties->resolve(*this);
1493 }
1494 break;
1495 default:
1496 #if OSL_DEBUG_LEVEL > 0
1497 ::rtl::OString sMessage( "GraphicImport::sprm() - Id: ");
1498 sMessage += ::rtl::OString::valueOf( sal_Int32( nSprmId ), 10 );
1499 sMessage += ::rtl::OString(" / 0x");
1500 sMessage += ::rtl::OString::valueOf( sal_Int32( nSprmId ), 16 );
1501 OSL_ENSURE( false, sMessage.getStr())
1502 #endif
1503 ;
1504 }
1505 }
1506 /*-- 01.11.2006 09:45:02---------------------------------------------------
1507
1508 -----------------------------------------------------------------------*/
lcl_entry(int,writerfilter::Reference<Properties>::Pointer_t)1509 void GraphicImport::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t /*ref*/)
1510 {
1511 }
1512 /*-- 16.11.2006 16:14:32---------------------------------------------------
1513 crop is stored as "fixed float" as 16.16 fraction value
1514 related to width/or height
1515 -----------------------------------------------------------------------*/
lcl_CalcCrop(sal_Int32 & nCrop,sal_Int32 nRef)1516 void lcl_CalcCrop( sal_Int32& nCrop, sal_Int32 nRef )
1517 {
1518 nCrop = ((nCrop >> 16 ) * nRef )
1519 + (((nCrop & 0xffff) * nRef ) >> 16);
1520 }
1521
createGraphicObject(const beans::PropertyValues & aMediaProperties)1522 uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const beans::PropertyValues& aMediaProperties )
1523 {
1524 uno::Reference< text::XTextContent > xGraphicObject;
1525 try
1526 {
1527 uno::Reference< graphic::XGraphicProvider > xGraphicProvider(
1528 m_xComponentContext->getServiceManager()->createInstanceWithContext(
1529 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.graphic.GraphicProvider")),
1530 m_xComponentContext),
1531 uno::UNO_QUERY_THROW );
1532
1533 uno::Reference< graphic::XGraphic > xGraphic = xGraphicProvider->queryGraphic( aMediaProperties );
1534
1535 if(xGraphic.is())
1536 {
1537 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1538
1539 uno::Reference< beans::XPropertySet > xGraphicObjectProperties(
1540 m_xTextFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextGraphicObject"))),
1541 uno::UNO_QUERY_THROW);
1542 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_GRAPHIC), uno::makeAny( xGraphic ));
1543 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_ANCHOR_TYPE),
1544 uno::makeAny( m_pImpl->eGraphicImportType == IMPORT_AS_SHAPE || m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR ?
1545 text::TextContentAnchorType_AT_CHARACTER :
1546 text::TextContentAnchorType_AS_CHARACTER ));
1547 xGraphicObject = uno::Reference< text::XTextContent >( xGraphicObjectProperties, uno::UNO_QUERY_THROW );
1548
1549 //shapes have only one border, PICF might have four
1550 table::BorderLine aBorderLine;
1551 for( sal_Int32 nBorder = 0; nBorder < 4; ++nBorder )
1552 {
1553 if( m_pImpl->eGraphicImportType == IMPORT_AS_GRAPHIC || !nBorder )
1554 {
1555 aBorderLine.Color = m_pImpl->aBorders[m_pImpl->eGraphicImportType == IMPORT_AS_SHAPE ? BORDER_TOP : static_cast<BorderPosition>(nBorder) ].nLineColor;
1556 aBorderLine.InnerLineWidth = 0;
1557 aBorderLine.OuterLineWidth = (sal_Int16)m_pImpl->aBorders[m_pImpl->eGraphicImportType == IMPORT_AS_SHAPE ? BORDER_TOP : static_cast<BorderPosition>(nBorder) ].nLineWidth;
1558 aBorderLine.LineDistance = 0;
1559 }
1560 PropertyIds aBorderProps[4] =
1561 {
1562 PROP_LEFT_BORDER,
1563 PROP_RIGHT_BORDER,
1564 PROP_TOP_BORDER,
1565 PROP_BOTTOM_BORDER
1566 };
1567 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( aBorderProps[nBorder]), uno::makeAny(aBorderLine));
1568 }
1569
1570 // setting properties for all types
1571 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_TITLE ),
1572 uno::makeAny( m_pImpl->sAlternativeText ));
1573 if( m_pImpl->bPositionProtected )
1574 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_POSITION_PROTECTED ),
1575 uno::makeAny(true));
1576 if( m_pImpl->bSizeProtected )
1577 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_SIZE_PROTECTED ),
1578 uno::makeAny(true));
1579
1580 if( m_pImpl->eGraphicImportType == IMPORT_AS_SHAPE || m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR )
1581 {
1582 sal_Int32 nWidth = m_pImpl->nRightPosition - m_pImpl->nLeftPosition;
1583 if( m_pImpl->eGraphicImportType == IMPORT_AS_SHAPE )
1584 {
1585 sal_Int32 nHeight = m_pImpl->nBottomPosition - m_pImpl->nTopPosition;
1586 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_SIZE),
1587 uno::makeAny( awt::Size( nWidth, nHeight )));
1588 }
1589 //adjust margins
1590 if( (m_pImpl->nHoriOrient == text::HoriOrientation::LEFT &&
1591 (m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA ||
1592 m_pImpl->nHoriRelation == text::RelOrientation::FRAME) ) ||
1593 (m_pImpl->nHoriOrient == text::HoriOrientation::INSIDE &&
1594 m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA ))
1595 m_pImpl->nLeftMargin = 0;
1596 if((m_pImpl->nHoriOrient == text::HoriOrientation::RIGHT &&
1597 (m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA ||
1598 m_pImpl->nHoriRelation == text::RelOrientation::FRAME) ) ||
1599 (m_pImpl->nHoriOrient == text::HoriOrientation::INSIDE &&
1600 m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA ))
1601 m_pImpl->nRightMargin = 0;
1602 // adjust top/bottom margins
1603 if( m_pImpl->nVertOrient == text::VertOrientation::TOP &&
1604 ( m_pImpl->nVertRelation == text::RelOrientation::PAGE_PRINT_AREA ||
1605 m_pImpl->nVertRelation == text::RelOrientation::PAGE_FRAME))
1606 m_pImpl->nTopMargin = 0;
1607 if( m_pImpl->nVertOrient == text::VertOrientation::BOTTOM &&
1608 ( m_pImpl->nVertRelation == text::RelOrientation::PAGE_PRINT_AREA ||
1609 m_pImpl->nVertRelation == text::RelOrientation::PAGE_FRAME))
1610 m_pImpl->nBottomMargin = 0;
1611 if( m_pImpl->nVertOrient == text::VertOrientation::BOTTOM &&
1612 m_pImpl->nVertRelation == text::RelOrientation::PAGE_PRINT_AREA )
1613 m_pImpl->nBottomMargin = 0;
1614
1615 //adjust alignment
1616 if( m_pImpl->nHoriOrient == text::HoriOrientation::INSIDE &&
1617 m_pImpl->nHoriRelation == text::RelOrientation::PAGE_FRAME )
1618 {
1619 // convert 'left to page' to 'from left -<width> to page text area'
1620 m_pImpl->nHoriOrient = text::HoriOrientation::NONE;
1621 m_pImpl->nHoriRelation = text::RelOrientation::PAGE_PRINT_AREA;
1622 m_pImpl->nLeftPosition = - nWidth;
1623 }
1624 else if( m_pImpl->nHoriOrient == text::HoriOrientation::OUTSIDE &&
1625 m_pImpl->nHoriRelation == text::RelOrientation::PAGE_FRAME )
1626 {
1627 // convert 'right to page' to 'from left 0 to right page border'
1628 m_pImpl->nHoriOrient = text::HoriOrientation::NONE;
1629 m_pImpl->nHoriRelation = text::RelOrientation::PAGE_RIGHT;
1630 m_pImpl->nLeftPosition = 0;
1631 }
1632
1633 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_ORIENT ),
1634 uno::makeAny(m_pImpl->nHoriOrient));
1635 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_ORIENT_POSITION),
1636 uno::makeAny(m_pImpl->nLeftPosition));
1637 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_ORIENT_RELATION ),
1638 uno::makeAny(m_pImpl->nHoriRelation));
1639 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_PAGE_TOGGLE ),
1640 uno::makeAny(m_pImpl->bPageToggle));
1641 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_ORIENT ),
1642 uno::makeAny(m_pImpl->nVertOrient));
1643 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_ORIENT_POSITION),
1644 uno::makeAny(m_pImpl->nTopPosition));
1645 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_ORIENT_RELATION ),
1646 uno::makeAny(m_pImpl->nVertRelation));
1647 if( !m_pImpl->bOpaque )
1648 {
1649 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_OPAQUE ),
1650 uno::makeAny(m_pImpl->bOpaque));
1651 }
1652 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_SURROUND ),
1653 uno::makeAny(m_pImpl->nWrap));
1654
1655 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_SURROUND_CONTOUR ),
1656 uno::makeAny(m_pImpl->bContour));
1657 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_CONTOUR_OUTSIDE ),
1658 uno::makeAny(m_pImpl->bContourOutside));
1659 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_LEFT_MARGIN ),
1660 uno::makeAny(m_pImpl->nLeftMargin));
1661 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_RIGHT_MARGIN ),
1662 uno::makeAny(m_pImpl->nRightMargin));
1663 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_TOP_MARGIN ),
1664 uno::makeAny(m_pImpl->nTopMargin));
1665 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_BOTTOM_MARGIN ),
1666 uno::makeAny(m_pImpl->nBottomMargin));
1667
1668 if( m_pImpl->eColorMode == drawing::ColorMode_STANDARD &&
1669 m_pImpl->nContrast == -70 &&
1670 m_pImpl->nBrightness == 70 )
1671 {
1672 // strange definition of WATERMARK!
1673 m_pImpl->nContrast = 0;
1674 m_pImpl->nBrightness = 0;
1675 m_pImpl->eColorMode = drawing::ColorMode_WATERMARK;
1676 }
1677
1678 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_ADJUST_CONTRAST ),
1679 uno::makeAny((sal_Int16)m_pImpl->nContrast));
1680 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_ADJUST_LUMINANCE ),
1681 uno::makeAny((sal_Int16)m_pImpl->nBrightness));
1682 if(m_pImpl->eColorMode != drawing::ColorMode_STANDARD)
1683 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_GRAPHIC_COLOR_MODE ),
1684 uno::makeAny(m_pImpl->eColorMode));
1685 if(m_pImpl->fGamma > 0. )
1686 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_GAMMA ),
1687 uno::makeAny(m_pImpl->fGamma ));
1688 if(m_pImpl->bHoriFlip)
1689 {
1690 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_MIRRORED_ON_EVEN_PAGES ),
1691 uno::makeAny( m_pImpl->bHoriFlip ));
1692 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_MIRRORED_ON_ODD_PAGES ),
1693 uno::makeAny( m_pImpl->bHoriFlip ));
1694 }
1695
1696 if( m_pImpl->bVertFlip )
1697 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_MIRRORED ),
1698 uno::makeAny( m_pImpl->bVertFlip ));
1699 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_BACK_COLOR ),
1700 uno::makeAny( m_pImpl->nFillColor ));
1701
1702 //there seems to be no way to detect the original size via _real_ API
1703 uno::Reference< beans::XPropertySet > xGraphicProperties( xGraphic, uno::UNO_QUERY_THROW );
1704 awt::Size aGraphicSize, aGraphicSizePixel;
1705 xGraphicProperties->getPropertyValue(rPropNameSupplier.GetName( PROP_SIZE100th_M_M )) >>= aGraphicSize;
1706 xGraphicProperties->getPropertyValue(rPropNameSupplier.GetName( PROP_SIZE_PIXEL )) >>= aGraphicSizePixel;
1707
1708 uno::Any aContourPolyPolygon;
1709 if( aGraphicSize.Width && aGraphicSize.Height &&
1710 m_pImpl->mpWrapPolygon.get() != NULL)
1711 {
1712 awt::Size aDstSize(m_pImpl->getXSize(), m_pImpl->getYSize());
1713 WrapPolygon::Pointer_t pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygon(aGraphicSize, aDstSize);
1714 aContourPolyPolygon <<= pCorrected->getPointSequenceSequence();
1715 }
1716
1717 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_CONTOUR_POLY_POLYGON),
1718 aContourPolyPolygon);
1719
1720 if( aGraphicSize.Width && aGraphicSize.Height )
1721 {
1722 //todo: i71651 graphic size is not provided by the GraphicDescriptor
1723 lcl_CalcCrop( m_pImpl->nTopCrop, aGraphicSize.Height );
1724 lcl_CalcCrop( m_pImpl->nBottomCrop, aGraphicSize.Height );
1725 lcl_CalcCrop( m_pImpl->nLeftCrop, aGraphicSize.Width );
1726 lcl_CalcCrop( m_pImpl->nRightCrop, aGraphicSize.Width );
1727
1728
1729 xGraphicProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_GRAPHIC_CROP ),
1730 uno::makeAny(text::GraphicCrop(m_pImpl->nTopCrop, m_pImpl->nBottomCrop, m_pImpl->nLeftCrop, m_pImpl->nRightCrop)));
1731 }
1732
1733 }
1734
1735 if(m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_INLINE || m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR)
1736 {
1737 if( m_pImpl->getXSize() && m_pImpl->getYSize() )
1738 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_SIZE),
1739 uno::makeAny( awt::Size( m_pImpl->getXSize(), m_pImpl->getYSize() )));
1740 try
1741 {
1742 if( m_pImpl->sName.getLength() )
1743 {
1744 uno::Reference< container::XNamed > xNamed( xGraphicObjectProperties, uno::UNO_QUERY_THROW );
1745 xNamed->setName( m_pImpl->sName );
1746 }
1747 }
1748 catch( const uno::Exception& )
1749 {
1750 }
1751 }
1752 }
1753 }
1754 catch( const uno::Exception& e )
1755 {
1756 clog << __FILE__ << ":" << __LINE__ << " failed. Message :" ;
1757 clog << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr( ) << endl;
1758 }
1759 return xGraphicObject;
1760 }
1761
1762 /*-- 01.11.2006 09:45:02---------------------------------------------------
1763
1764 -----------------------------------------------------------------------*/
data(const sal_uInt8 * buf,size_t len,writerfilter::Reference<Properties>::Pointer_t)1765 void GraphicImport::data(const sal_uInt8* buf, size_t len, writerfilter::Reference<Properties>::Pointer_t /*ref*/)
1766 {
1767 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1768
1769 ::com::sun::star::beans::PropertyValues aMediaProperties( 1 );
1770 aMediaProperties[0].Name = rPropNameSupplier.GetName(PROP_INPUT_STREAM);
1771
1772 uno::Reference< io::XInputStream > xIStream = new XInputStreamHelper( buf, len, m_pImpl->bIsBitmap );
1773 aMediaProperties[0].Value <<= xIStream;
1774
1775 m_xGraphicObject = createGraphicObject( aMediaProperties );
1776 }
1777 /*-- 01.11.2006 09:45:03---------------------------------------------------
1778
1779 -----------------------------------------------------------------------*/
lcl_startSectionGroup()1780 void GraphicImport::lcl_startSectionGroup()
1781 {
1782 }
1783 /*-- 01.11.2006 09:45:03---------------------------------------------------
1784
1785 -----------------------------------------------------------------------*/
lcl_endSectionGroup()1786 void GraphicImport::lcl_endSectionGroup()
1787 {
1788 }
1789 /*-- 01.11.2006 09:45:03---------------------------------------------------
1790
1791 -----------------------------------------------------------------------*/
lcl_startParagraphGroup()1792 void GraphicImport::lcl_startParagraphGroup()
1793 {
1794 }
1795 /*-- 01.11.2006 09:45:03---------------------------------------------------
1796
1797 -----------------------------------------------------------------------*/
lcl_endParagraphGroup()1798 void GraphicImport::lcl_endParagraphGroup()
1799 {
1800 }
1801 /*-- 01.11.2006 09:45:03---------------------------------------------------
1802
1803 -----------------------------------------------------------------------*/
lcl_startCharacterGroup()1804 void GraphicImport::lcl_startCharacterGroup()
1805 {
1806 }
1807 /*-- 01.11.2006 09:45:04---------------------------------------------------
1808
1809 -----------------------------------------------------------------------*/
lcl_endCharacterGroup()1810 void GraphicImport::lcl_endCharacterGroup()
1811 {
1812 }
1813 /*-- 01.11.2006 09:45:04---------------------------------------------------
1814
1815 -----------------------------------------------------------------------*/
lcl_text(const sal_uInt8 *,size_t)1816 void GraphicImport::lcl_text(const sal_uInt8 * /*_data*/, size_t /*len*/)
1817 {
1818 }
1819 /*-- 01.11.2006 09:45:05---------------------------------------------------
1820
1821 -----------------------------------------------------------------------*/
lcl_utext(const sal_uInt8 *,size_t)1822 void GraphicImport::lcl_utext(const sal_uInt8 * /*_data*/, size_t /*len*/)
1823 {
1824 }
1825 /*-- 01.11.2006 09:45:05---------------------------------------------------
1826
1827 -----------------------------------------------------------------------*/
lcl_props(writerfilter::Reference<Properties>::Pointer_t)1828 void GraphicImport::lcl_props(writerfilter::Reference<Properties>::Pointer_t /*ref*/)
1829 {
1830 }
1831 /*-- 01.11.2006 09:45:06---------------------------------------------------
1832
1833 -----------------------------------------------------------------------*/
lcl_table(Id,writerfilter::Reference<Table>::Pointer_t)1834 void GraphicImport::lcl_table(Id /*name*/, writerfilter::Reference<Table>::Pointer_t /*ref*/)
1835 {
1836 }
1837 /*-- 01.11.2006 09:45:07---------------------------------------------------
1838
1839 -----------------------------------------------------------------------*/
lcl_substream(Id,::writerfilter::Reference<Stream>::Pointer_t)1840 void GraphicImport::lcl_substream(Id /*name*/, ::writerfilter::Reference<Stream>::Pointer_t /*ref*/)
1841 {
1842 }
1843 /*-- 01.11.2006 09:45:07---------------------------------------------------
1844
1845 -----------------------------------------------------------------------*/
lcl_info(const string &)1846 void GraphicImport::lcl_info(const string & /*info*/)
1847 {
1848 }
1849
lcl_startShape(::com::sun::star::uno::Reference<::com::sun::star::drawing::XShape>)1850 void GraphicImport::lcl_startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > /*xShape*/ )
1851 {
1852 }
1853
lcl_endShape()1854 void GraphicImport::lcl_endShape( )
1855 {
1856 }
1857
1858 /*-- 09.08.2007 10:17:00---------------------------------------------------
1859
1860 -----------------------------------------------------------------------*/
IsGraphic() const1861 bool GraphicImport::IsGraphic() const
1862 {
1863 return m_pImpl->bIsGraphic;
1864 }
1865
1866 }
1867 }
1868