1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 /*****************************************************************************
58 * 2005/2 draft code for chart
59 ****************************************************************************/
63 * For LWP filter architecture prototype
67 #include <boost/scoped_ptr.hpp>
69 #include "lwp9reader.hxx"
70 #include "lwpgrfobj.hxx"
71 #include "lwpsdwfileloader.hxx"
74 #include "lwpglobalmgr.hxx"
75 #include "xfilter/xfframe.hxx"
76 #include "xfilter/xfimage.hxx"
77 #include "xfilter/xfimagestyle.hxx"
78 #include "xfilter/xfstylemanager.hxx"
79 #include "xfilter/xfparagraph.hxx"
80 #include "xfilter/xfannotation.hxx"
85 #include <osl/thread.h>
87 #define EF_NONE 0x0000
88 #define EF_ODMA 0x0002
90 LwpGraphicObject::LwpGraphicObject(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
)
91 : LwpGraphicOleObject(objHdr
, pStrm
)
92 , m_nCachedBaseLine(0)
96 memset(m_sDataFormat
, 0, sizeof(m_sDataFormat
));
97 memset(m_sServerContextFormat
, 0, sizeof(m_sServerContextFormat
));
100 LwpGraphicObject::~LwpGraphicObject()
104 void LwpGraphicObject::Read()
106 LwpGraphicOleObject::Read();
107 m_pObjStrm
->QuickReaduInt16(); //disksize
108 sal_uInt16 strsize
= m_pObjStrm
->QuickReaduInt16();
109 if (strsize
<AFID_MAX_FILE_FORMAT_SIZE
)
111 m_pObjStrm
->QuickRead(m_sDataFormat
,strsize
);
112 m_sDataFormat
[strsize
] = '\0';
114 sal_uInt32 nServerContextSize
= m_pObjStrm
->QuickReaduInt32();
115 unsigned char *pServerContext
= NULL
;
116 if (nServerContextSize
> 0)
118 pServerContext
= new unsigned char[nServerContextSize
];
119 m_pObjStrm
->QuickRead(pServerContext
, static_cast<sal_uInt16
>(nServerContextSize
));
120 if (nServerContextSize
> 44)
122 m_aIPData
.nBrightness
= pServerContext
[14];
123 m_aIPData
.nContrast
= pServerContext
[19];
124 m_aIPData
.nEdgeEnchancement
= pServerContext
[24];
125 m_aIPData
.nSmoothing
= pServerContext
[29];
126 m_aIPData
.bInvertImage
= (pServerContext
[34] == 0x01);
127 m_aIPData
.bAutoContrast
= (pServerContext
[44] == 0x00);
130 m_pObjStrm
->QuickReaduInt16(); //disksize
131 strsize
= m_pObjStrm
->QuickReaduInt16();
132 if (strsize
<AFID_MAX_FILE_FORMAT_SIZE
)
134 m_pObjStrm
->QuickRead(m_sServerContextFormat
,strsize
);
135 m_sServerContextFormat
[strsize
] = '\0';
137 if (nServerContextSize
== 0)
139 if (strcmp(reinterpret_cast<char *>(m_sServerContextFormat
), ".cht") == 0 &&
140 strcmp(reinterpret_cast<char *>(m_sDataFormat
), ".sdw") == 0)
142 strcpy(reinterpret_cast<char *>(m_sServerContextFormat
), ".lch");
143 strcpy(reinterpret_cast<char *>(m_sDataFormat
), ".lch");
146 m_nCachedBaseLine
= m_pObjStrm
->QuickReadInt32();
147 m_bIsLinked
= m_pObjStrm
->QuickReadInt16();
148 unsigned char * pFilterContext
= NULL
;
152 m_LinkedFilePath
= m_pObjStrm
->QuickReadStringPtr();
154 sal_uInt32 nFilterContextSize
= m_pObjStrm
->QuickReaduInt32();
155 if (nFilterContextSize
> 0)
157 pFilterContext
= new unsigned char[nFilterContextSize
];
158 m_pObjStrm
->QuickRead(pFilterContext
, static_cast<sal_uInt16
>(nFilterContextSize
));
160 if (LwpFileHeader::m_nFileRevision
>= 0x000b)
163 // read external file object stuff
164 sal_uInt16 type
= m_pObjStrm
->QuickReaduInt16();
165 if ((EF_ODMA
!= type
) && (EF_NONE
!= type
)) // don't know about this
167 sal_uInt32 size
= m_pObjStrm
->QuickReaduInt32();
168 m_pObjStrm
->SeekRel(static_cast<sal_uInt16
>(size
));
170 // else no external file object
174 if (LwpFileHeader::m_nFileRevision
>= 0x000b)
176 m_bCompressed
= m_pObjStrm
->QuickReadInt16();
177 m_Cache
.LinkedFileSize
= m_pObjStrm
->QuickReaduInt32();
178 m_Cache
.LinkedFileTime
= m_pObjStrm
->QuickReaduInt32();
179 m_Cache
.Width
= m_pObjStrm
->QuickReadInt32();
180 m_Cache
.Height
= m_pObjStrm
->QuickReadInt32();
183 if(LwpFileHeader::m_nFileRevision
>= 0x000c)
185 m_WatermarkName
= m_pObjStrm
->QuickReadStringPtr();
188 if (pServerContext
!= NULL
)
189 delete[] pServerContext
;
191 if (pFilterContext
!= NULL
)
192 delete[] pFilterContext
;
196 void LwpGraphicObject::XFConvert (XFContentContainer
* pCont
)
198 if ((m_sServerContextFormat
[1]=='s'&&m_sServerContextFormat
[2]=='d'&&m_sServerContextFormat
[3]=='w'))
200 std::vector
< rtl::Reference
<XFFrame
> >::iterator iter
;
201 for (iter
= m_vXFDrawObjects
.begin(); iter
!= m_vXFDrawObjects
.end(); ++iter
)
203 pCont
->Add(iter
->get());
206 else if (this->IsGrafFormatValid())
208 XFImage
* pImage
= static_cast<XFImage
*>(m_vXFDrawObjects
.front().get());
212 OUString fileURL
= LwpTools::convertToFileUrl(OUStringToOString(m_LinkedFilePath
, osl_getThreadTextEncoding()));
213 pImage
->SetFileURL(fileURL
);
217 sal_uInt8
* pGrafData
= NULL
;
218 sal_uInt32 nDataLen
= this->GetRawGrafData(pGrafData
);
222 pImage
->SetImageData(pGrafData
, nDataLen
);
224 // delete used image data
232 else if((m_sServerContextFormat
[1]=='t'&&m_sServerContextFormat
[2]=='e'&&m_sServerContextFormat
[3]=='x'))
234 XFConvertEquation(pCont
);
238 #include "lwpframelayout.hxx"
241 * @descr judge if the graphic format is what we can support: bmp, jpg, wmf, gif, tgf(tif). other format will be filtered to
242 * these formats by Word Pro.
243 * @return sal_True if yes sal_False if not.
245 bool LwpGraphicObject::IsGrafFormatValid()
247 if ((m_sServerContextFormat
[1]=='b'&& m_sServerContextFormat
[2]=='m' && m_sServerContextFormat
[3]=='p')
248 || (m_sServerContextFormat
[1]=='j' && m_sServerContextFormat
[2]=='p' && m_sServerContextFormat
[3]=='g')
249 || (m_sServerContextFormat
[1]=='w' && m_sServerContextFormat
[2]=='m' && m_sServerContextFormat
[3]=='f')
250 || (m_sServerContextFormat
[1]=='g' && m_sServerContextFormat
[2]=='i' && m_sServerContextFormat
[3]=='f')
251 || (m_sServerContextFormat
[1]=='t' && m_sServerContextFormat
[2]=='g' && m_sServerContextFormat
[3]=='f')
252 || (m_sServerContextFormat
[1]=='p' && m_sServerContextFormat
[2]=='n' && m_sServerContextFormat
[3]=='g')
253 || (m_sServerContextFormat
[1]=='e' && m_sServerContextFormat
[2]=='p' && m_sServerContextFormat
[3]=='s'))
264 * @descr create drawing object and image object.
266 void LwpGraphicObject::RegisterStyle()
268 if (m_sServerContextFormat
[1]=='s'&&m_sServerContextFormat
[2]=='d'&&m_sServerContextFormat
[3]=='w')
270 this->CreateDrawObjects();
272 // test codes for importing pictures
273 else if(this->IsGrafFormatValid())
275 this->CreateGrafObject();
278 if (m_sServerContextFormat
[1]=='l'&&m_sServerContextFormat
[2]=='c'&&m_sServerContextFormat
[3]=='h')
280 LwpVirtualLayout
* pMyLayout
= GetLayout(NULL
);
281 if (pMyLayout
&& pMyLayout
->IsFrame())
283 XFFrameStyle
* pXFFrameStyle
= new XFFrameStyle();
284 pXFFrameStyle
->SetXPosType(enumXFFrameXPosFromLeft
, enumXFFrameXRelFrame
);
285 pXFFrameStyle
->SetYPosType(enumXFFrameYPosFromTop
, enumXFFrameYRelPara
);
286 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
287 m_strStyleName
= pXFStyleManager
->AddStyle(pXFFrameStyle
).m_pStyle
->GetStyleName();
294 * @descr create drawing object.
296 void LwpGraphicObject::CreateDrawObjects()
298 // if small file, use the compressed stream for BENTO
299 LwpSvStream
* pStream
= m_pStrm
->GetCompressedStream() ? m_pStrm
->GetCompressedStream(): m_pStrm
;
301 OpenStormBento::LtcBenContainer
* pBentoContainer
;
302 sal_uLong ulRet
= OpenStormBento::BenOpenContainer(pStream
, &pBentoContainer
);
303 if (ulRet
!= OpenStormBento::BenErr_OK
)
306 SvStream
* pDrawObjStream
= NULL
;
308 // get graphic object's bento objet name
309 LwpObjectID
& rMyID
= this->GetObjectID();
310 std::string aGrfObjName
;
311 GetBentoNamebyID(rMyID
, aGrfObjName
);
313 // get bento stream by the name
314 pBentoContainer
->CreateGraphicStream(pDrawObjStream
, aGrfObjName
.c_str());
317 LwpSdwFileLoader
fileLoader(pDrawObjStream
, this);
318 fileLoader
.CreateDrawObjects(&m_vXFDrawObjects
);
320 delete pDrawObjStream
;
321 pDrawObjStream
= NULL
;
326 * @descr create drawing object.
328 void LwpGraphicObject::GetBentoNamebyID(LwpObjectID
& rMyID
, std::string
& rName
)
330 sal_uInt16 nHigh
= rMyID
.GetHigh();
331 sal_uInt16 nLow
= rMyID
.GetLow();
333 rName
= std::string("Gr");
334 sprintf(pTempStr
, "%X,%X", nHigh
, nLow
);
335 rName
.append(pTempStr
);
339 * @descr get the image data read from bento stream according to the VO_GRAPHIC ID.
340 * @param pGrafData the array to store the image data. the pointer need to be deleted outside.
341 * @return the length of the image data.
343 sal_uInt32
LwpGraphicObject::GetRawGrafData(sal_uInt8
*& pGrafData
)
345 // create graphic object
346 // if small file, use the compressed stream for BENTO
347 LwpSvStream
* pStream
= m_pStrm
->GetCompressedStream() ? m_pStrm
->GetCompressedStream(): m_pStrm
;
349 boost::scoped_ptr
<OpenStormBento::LtcBenContainer
> pBentoContainer
;
351 OpenStormBento::LtcBenContainer
* pTmp(0);
352 sal_uLong ulRet
= OpenStormBento::BenOpenContainer(pStream
, &pTmp
);
353 pBentoContainer
.reset(pTmp
);
354 if (ulRet
!= OpenStormBento::BenErr_OK
)
358 SvStream
* pGrafStream
= NULL
;
360 // get graphic object's bento objet name
361 LwpObjectID
& rMyID
= this->GetObjectID();
362 std::string aGrfObjName
;
363 GetBentoNamebyID(rMyID
, aGrfObjName
);
365 // get bento stream by the name
366 pBentoContainer
->CreateGraphicStream(pGrafStream
, aGrfObjName
.c_str());
367 SvMemoryStream
* pMemGrafStream
= static_cast<SvMemoryStream
*>(pGrafStream
);
372 sal_uInt32 nDataLen
= pMemGrafStream
->GetEndOfData();
373 pGrafData
= new sal_uInt8
[nDataLen
];
374 pMemGrafStream
->Read(pGrafData
, nDataLen
);
376 delete pMemGrafStream
;
377 pMemGrafStream
= NULL
;
386 * @descr get the image data (only -D dara) read from bento stream according to the VO_GRAPHIC ID.
387 * @param pGrafData the array to store the image data. the pointer need to be deleted outside.
388 * @return the length of the image data.
390 sal_uInt32
LwpGraphicObject::GetGrafData(sal_uInt8
*& pGrafData
)
392 // create graphic object
393 // if small file, use the compressed stream for BENTO
394 LwpSvStream
* pStream
= m_pStrm
->GetCompressedStream() ? m_pStrm
->GetCompressedStream(): m_pStrm
;
396 OpenStormBento::LtcBenContainer
* pBentoContainer
;
397 sal_uLong ulRet
= OpenStormBento::BenOpenContainer(pStream
, &pBentoContainer
);
398 if (ulRet
!= OpenStormBento::BenErr_OK
)
401 SvStream
* pGrafStream
= NULL
;
403 // get graphic object's bento objet name
404 LwpObjectID
& rMyID
= this->GetObjectID();
405 std::string aGrfObjName
;
406 GetBentoNamebyID(rMyID
, aGrfObjName
);
409 sprintf(sDName
, "%s-D", aGrfObjName
.c_str());
411 // get bento stream by the name
412 pGrafStream
= pBentoContainer
->FindValueStreamWithPropertyName(sDName
);
414 SvMemoryStream
* pMemGrafStream
= static_cast<SvMemoryStream
*>(pGrafStream
);
419 sal_uInt32 nPos
= pGrafStream
->Tell();
420 pGrafStream
->Seek(STREAM_SEEK_TO_END
);
421 sal_uInt32 nDataLen
= pGrafStream
->Tell();
422 pGrafStream
->Seek(nPos
);
424 pGrafData
= new sal_uInt8
[nDataLen
];
425 pMemGrafStream
->Read(pGrafData
, nDataLen
);
427 delete pMemGrafStream
;
428 pMemGrafStream
= NULL
;
437 * @descr create xf-image object and save it in the container: m_vXFDrawObjects.
439 void LwpGraphicObject::CreateGrafObject()
441 rtl::Reference
<XFImage
> pImage
= new XFImage();
443 // set image processing styles
444 XFImageStyle
* pImageStyle
= new XFImageStyle();
445 if (m_sServerContextFormat
[1]!='w' || m_sServerContextFormat
[2]!='m' || m_sServerContextFormat
[3]!='f')
447 if (m_aIPData
.nBrightness
!= 50)
449 sal_Int32 nSODCBrightness
= (sal_Int32
)m_aIPData
.nBrightness
*2 - 100;
450 pImageStyle
->SetBrightness(nSODCBrightness
);
452 if (m_aIPData
.nContrast
!= 50)
454 sal_Int32 nSODCContrast
= (sal_Int32
)(80 - (double)m_aIPData
.nContrast
*1.6);
455 pImageStyle
->SetContrast(nSODCContrast
);
459 // set scale and crop styles
460 LwpAssociatedLayouts
& rLayoutWithMe
= GetLayoutsWithMe();
461 LwpFrameLayout
* pMyFrameLayout
=
462 static_cast<LwpFrameLayout
*>(rLayoutWithMe
.GetOnlyLayout().obj(VO_FRAMELAYOUT
).get());
465 LwpLayoutScale
* pMyScale
= pMyFrameLayout
->GetLayoutScale();
466 LwpLayoutGeometry
* pFrameGeo
= pMyFrameLayout
->GetGeometry();
468 // original image size
469 double fOrgGrafWidth
= (double)m_Cache
.Width
/TWIPS_PER_CM
;
470 double fOrgGrafHeight
= (double)m_Cache
.Height
/TWIPS_PER_CM
;
473 double fLeftMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_LEFT
);
474 double fRightMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_RIGHT
);
475 double fTopMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_TOP
);
476 double fBottomMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_BOTTOM
);
478 if (pMyScale
&& pFrameGeo
)
481 double fFrameWidth
= LwpTools::ConvertFromUnitsToMetric(pFrameGeo
->GetWidth());
482 double fFrameHeight
= LwpTools::ConvertFromUnitsToMetric(pFrameGeo
->GetHeight());
484 // calculate the displayed size of the frame
485 double fDisFrameWidth
= fFrameWidth
- (fLeftMargin
+fRightMargin
);
486 double fDisFrameHeight
= fFrameHeight
- (fTopMargin
+fBottomMargin
);
489 double fSclGrafWidth
= fOrgGrafWidth
;
490 double fSclGrafHeight
= fOrgGrafHeight
;
493 sal_uInt16 nScalemode
= pMyScale
->GetScaleMode();
494 if (nScalemode
& LwpLayoutScale::CUSTOM
)
496 fSclGrafWidth
= LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleWidth());
497 fSclGrafHeight
= LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleHeight());
499 else if (nScalemode
& LwpLayoutScale::PERCENTAGE
)
501 double fScalePercentage
= (double)pMyScale
->GetScalePercentage() / 1000;
502 fSclGrafWidth
= fScalePercentage
* fOrgGrafWidth
;
503 fSclGrafHeight
= fScalePercentage
* fOrgGrafHeight
;
505 else if (nScalemode
& LwpLayoutScale::FIT_IN_FRAME
)
507 if (pMyFrameLayout
->IsFitGraphic())
509 fSclGrafWidth
= fOrgGrafWidth
;
510 fSclGrafHeight
= fOrgGrafHeight
;
512 else if (nScalemode
& LwpLayoutScale::MAINTAIN_ASPECT_RATIO
)
514 if (fOrgGrafWidth
/fOrgGrafHeight
>= fDisFrameWidth
/fDisFrameHeight
)
516 fSclGrafWidth
= fDisFrameWidth
;
517 fSclGrafHeight
= (fDisFrameWidth
/fOrgGrafWidth
) * fOrgGrafHeight
;
521 fSclGrafHeight
= fDisFrameHeight
;
522 fSclGrafWidth
= (fDisFrameHeight
/fOrgGrafHeight
) * fOrgGrafWidth
;
527 fSclGrafWidth
= fDisFrameWidth
;
528 fSclGrafHeight
= fDisFrameHeight
;
533 double fXRatio
= fSclGrafWidth
/ fOrgGrafWidth
;
534 double fYRatio
= fSclGrafHeight
/ fOrgGrafHeight
;
536 // set image to scaled size.
537 pImage
->SetWidth(fSclGrafWidth
);
538 pImage
->SetHeight(fSclGrafHeight
);
540 // placement:centered or tiled. tiled style is not supported so it's processed together with centered.
541 if (pMyFrameLayout
->GetScaleCenter() || pMyFrameLayout
->GetScaleTile())
543 // set center alignment
544 pImageStyle
->SetXPosType(enumXFFrameXPosCenter
, enumXFFrameXRelFrame
);
545 pImageStyle
->SetYPosType(enumXFFrameYPosMiddle
, enumXFFrameYRelFrame
);
547 // need horizontal crop?
548 double fClipWidth
= 0;
549 double fClipHeight
= 0;
550 bool sal_bCropped
= false;
551 if (fSclGrafWidth
> fDisFrameWidth
)
553 fClipWidth
= (fSclGrafWidth
-fDisFrameWidth
) / 2 / fXRatio
;
557 // need vertical crop?
558 if (fSclGrafHeight
> fDisFrameHeight
)
560 fClipHeight
= (fSclGrafHeight
-fDisFrameHeight
) / 2 / fYRatio
;
566 pImageStyle
->SetClip(fClipWidth
, fClipWidth
, fClipHeight
, fClipHeight
);
567 pImage
->SetWidth(fDisFrameWidth
);
568 pImage
->SetHeight(fDisFrameHeight
);
571 // placement:automatic
574 // set left-top alignment
575 pImageStyle
->SetYPosType(enumXFFrameYPosFromTop
, enumXFFrameYRelFrame
);
576 pImageStyle
->SetXPosType(enumXFFrameXPosFromLeft
, enumXFFrameXRelFrame
);
578 // get image position offset
579 LwpPoint
& rOffset
= pMyScale
->GetOffset();
580 double fOffsetX
= LwpTools::ConvertFromUnitsToMetric(rOffset
.GetX());
581 double fOffsetY
= LwpTools::ConvertFromUnitsToMetric(rOffset
.GetY());
597 LwpRect(double fL
, double fR
, double fT
, double fB
)
605 LwpRect
aFrameRect(-fOffsetX
, (fDisFrameWidth
-fOffsetX
), (-fOffsetY
), ((fDisFrameHeight
-fOffsetY
)));
606 LwpRect
aImageRect(0, fSclGrafWidth
, 0, fSclGrafHeight
);
609 if (aFrameRect
.fRight
<= aImageRect
.fLeft
|| aFrameRect
.fLeft
>= aImageRect
.fRight
610 ||aFrameRect
.fBottom
<= aImageRect
.fTop
|| aFrameRect
.fTop
>= aImageRect
.fBottom
)
617 if (aFrameRect
.fLeft
> aImageRect
.fLeft
)
619 aCropRect
.fLeft
= (aFrameRect
.fLeft
- aImageRect
.fLeft
) / fXRatio
;
622 if (aFrameRect
.fRight
< aImageRect
.fRight
)
624 aCropRect
.fRight
= (aImageRect
.fRight
- aFrameRect
.fRight
) / fXRatio
;
628 if (aFrameRect
.fTop
> aImageRect
.fTop
)
630 aCropRect
.fTop
= (aFrameRect
.fTop
- aImageRect
.fTop
) / fYRatio
;
632 if (aFrameRect
.fBottom
< aImageRect
.fBottom
)
634 aCropRect
.fBottom
= (aImageRect
.fBottom
- aFrameRect
.fBottom
) / fYRatio
;
637 pImageStyle
->SetClip(aCropRect
.fLeft
, aCropRect
.fRight
, aCropRect
.fTop
, aCropRect
.fBottom
);
638 double fPicWidth
= fSclGrafWidth
- (aCropRect
.fLeft
+aCropRect
.fRight
)*fXRatio
;
639 double fPicHeight
= fSclGrafHeight
- (aCropRect
.fTop
+aCropRect
.fBottom
)*fYRatio
;
640 double fX
= fOffsetX
> 0 ? fOffsetX
: 0.00;
641 double fY
= fOffsetY
> 0 ? fOffsetY
: 0.00;
642 pImage
->SetPosition((fX
+fLeftMargin
), (fY
+fTopMargin
), fPicWidth
, fPicHeight
);
648 // set style for the image
649 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
650 pImage
->SetStyleName(pXFStyleManager
->AddStyle(pImageStyle
).m_pStyle
->GetStyleName());
652 // set archor to frame
653 pImage
->SetAnchorType(enumXFAnchorFrame
);
656 LwpAtomHolder
& rHolder
= this->GetName();
657 if ( !rHolder
.str().isEmpty() )
659 pImage
->SetName(rHolder
.str());
662 // insert image object into array
663 m_vXFDrawObjects
.push_back(pImage
.get());
668 * @descr Reserve the equation text in a note in the context.
670 void LwpGraphicObject::XFConvertEquation(XFContentContainer
* pCont
)
672 sal_uInt8
* pGrafData
= NULL
;
673 sal_uInt32 nDataLen
= this->GetGrafData(pGrafData
);
677 XFParagraph
* pXFPara
= new XFParagraph
;
678 pXFPara
->Add("Formula:");
680 XFAnnotation
* pXFNote
= new XFAnnotation
;
681 //add equation to comment notes
682 XFParagraph
* pXFNotePara
= new XFParagraph
;
683 //equation header text: Times New Roman,
686 //total head length = 45
687 sal_uInt32 nBegin
= 45;
688 sal_uInt32 nEnd
= nDataLen
-1;
690 if(pGrafData
[nEnd
] == '$' && pGrafData
[nEnd
-1]!= '\\')
692 //equation body is contained by '$';
699 sal_uInt8
* pEquData
= new sal_uInt8
[nEnd
- nBegin
+ 1];
700 for(sal_uInt32 nIndex
= 0; nIndex
< nEnd
- nBegin
+1 ; nIndex
++)
702 pEquData
[nIndex
] = pGrafData
[nBegin
+ nIndex
];
704 pXFNotePara
->Add(OUString(reinterpret_cast<char*>(pEquData
), (nEnd
- nBegin
+ 1), osl_getThreadTextEncoding()));
707 pXFNote
->Add(pXFNotePara
);
709 pXFPara
->Add(pXFNote
);
718 void LwpGraphicObject::GetGrafOrgSize(double & rWidth
, double & rHeight
)
720 // original image size
721 rWidth
= (double)m_Cache
.Width
/TWIPS_PER_CM
;
722 rHeight
= (double)m_Cache
.Height
/TWIPS_PER_CM
;
725 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */