update dev300-m57
[ooovba.git] / lotuswordpro / source / filter / lwpgrfobj.cxx
blob22e20b167888311ddd36af205889c7f6dd5f5051
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /*****************************************************************************
56 * Change History
57 * 2005/2 draft code for chart
58 ****************************************************************************/
60 /**
61 * @file
62 * For LWP filter architecture prototype
64 #include <stdio.h>
65 #include "lwp9reader.hxx"
66 #include "lwpgrfobj.hxx"
67 #include "lwpsdwfileloader.hxx"
68 #include "bento.hxx"
70 #include "lwpglobalmgr.hxx"
71 #include "xfilter/xfframe.hxx"
72 #include "xfilter/xfimage.hxx"
73 #include "xfilter/xfimagestyle.hxx"
74 #include "xfilter/xfstylemanager.hxx"
75 #include "xfilter/xfparagraph.hxx"
76 #include "xfilter/xfannotation.hxx"
78 //For chart
79 #include "string.h"
80 //#include "lwpchartstreamtools.hxx"
82 #ifndef _OSL_THREAD_H_
83 #include <osl/thread.h>
84 #endif
86 #define EF_NONE 0x0000
87 #define EF_FTP 0x0001
88 #define EF_ODMA 0x0002
89 #define EF_NOS 0x0003
91 LwpGraphicObject::LwpGraphicObject(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
92 :LwpGraphicOleObject(objHdr, pStrm),m_bCompressed(0),m_bIsLinked(0),m_nCachedBaseLine(0)
95 LwpGraphicObject::~LwpGraphicObject()
97 m_vXFDrawObjects.clear();
99 void LwpGraphicObject::Read()
101 LwpGraphicOleObject::Read();
102 sal_uInt16 disksize = m_pObjStrm->QuickReaduInt16();
103 sal_uInt16 strsize = m_pObjStrm->QuickReaduInt16();
104 if (strsize<AFID_MAX_FILE_FORMAT_SIZE)
106 m_pObjStrm->QuickRead(m_sDataFormat,strsize);
107 m_sDataFormat[strsize] = '\0';
110 if (m_sDataFormat!=(unsigned char*)(".lch"))
112 return;
115 sal_uInt32 nServerContextSize = m_pObjStrm->QuickReaduInt32();
116 unsigned char *pServerContext = NULL;
117 if (nServerContextSize > 0)
119 pServerContext = new unsigned char[nServerContextSize];
120 m_pObjStrm->QuickRead(pServerContext, static_cast<sal_uInt16>(nServerContextSize));
121 // add by , 04/05/2005
122 if (nServerContextSize > 44)
124 m_aIPData.nBrightness = pServerContext[14];
125 m_aIPData.nContrast = pServerContext[19];
126 m_aIPData.nEdgeEnchancement = pServerContext[24];
127 m_aIPData.nSmoothing = pServerContext[29];
128 m_aIPData.bInvertImage = (sal_Bool)(pServerContext[34] == 0x01);
129 m_aIPData.bAutoContrast = (sal_Bool)(pServerContext[44] == 0x00);
131 // end add
133 disksize = m_pObjStrm->QuickReaduInt16();
134 strsize = m_pObjStrm->QuickReaduInt16();
135 if (strsize<AFID_MAX_FILE_FORMAT_SIZE)
137 m_pObjStrm->QuickRead(m_sServerContextFormat,strsize);
138 m_sServerContextFormat[strsize] = '\0';
140 if (nServerContextSize == 0)
142 if (strcmp((char *)m_sServerContextFormat, ".cht") == 0 &&
143 strcmp((char *)m_sDataFormat, ".sdw") == 0)
145 strcpy((char *)m_sServerContextFormat, ".lch");
146 strcpy((char *)m_sDataFormat, ".lch");
149 m_nCachedBaseLine = m_pObjStrm->QuickReadInt32();
150 m_bIsLinked = m_pObjStrm->QuickReadInt16();
151 //OUString pLinkedFilePath;
152 unsigned char * pFilterContext = NULL;
153 sal_uInt32 nFilterContextSize = 0;
155 if (m_bIsLinked)
157 m_LinkedFilePath = m_pObjStrm->QuickReadStringPtr();
159 nFilterContextSize = m_pObjStrm->QuickReaduInt32();
160 if (nFilterContextSize > 0)
162 pFilterContext = new unsigned char[nFilterContextSize];
163 m_pObjStrm->QuickRead(pFilterContext, static_cast<sal_uInt16>(nFilterContextSize));
165 if (LwpFileHeader::m_nFileRevision >= 0x000b)
168 // read external file object stuff
169 sal_uInt16 type = m_pObjStrm->QuickReaduInt16();
170 // if (EF_ODMA == type)
171 // ;
172 if ((EF_ODMA != type) && (EF_NONE != type)) // don't know about this
174 sal_uInt32 size = m_pObjStrm->QuickReaduInt32();
175 m_pObjStrm->SeekRel(static_cast<sal_uInt16>(size));
177 // else no external file object
181 if (LwpFileHeader::m_nFileRevision >= 0x000b)
183 m_bCompressed = m_pObjStrm->QuickReadInt16();
184 m_Cache.LinkedFileSize = m_pObjStrm->QuickReaduInt32();
185 m_Cache.LinkedFileTime = m_pObjStrm->QuickReaduInt32();
186 m_Cache.Width = m_pObjStrm->QuickReadInt32();
187 m_Cache.Height = m_pObjStrm->QuickReadInt32();
190 if(LwpFileHeader::m_nFileRevision >= 0x000c)
192 m_WatermarkName = m_pObjStrm->QuickReadStringPtr();
195 if (pServerContext != NULL)
196 delete[] pServerContext;
198 if (pFilterContext != NULL)
199 delete[] pFilterContext;
203 void LwpGraphicObject::XFConvert (XFContentContainer* pCont)
205 if ((m_sServerContextFormat[1]=='s'&&m_sServerContextFormat[2]=='d'&&m_sServerContextFormat[3]=='w'))
207 /* LwpSvStream* pStream = m_pStrm;
208 //test code
209 OpenStormBento::LtcBenContainer* pBentoContainer;
210 ULONG ulRet = OpenStormBento::BenOpenContainer(pStream, &pBentoContainer);
211 std::vector<SvStream*> vStream;
212 std::vector<SvStream*>::iterator iter;
213 pBentoContainer->CreateGraphicStreams(&vStream);
214 for (iter=vStream.begin();iter!=vStream.end();iter++)
216 LwpSdwFileLoader fileLoader(*iter,pOutputStream);
217 fileLoader.LoadObjectList();
218 delete *iter;
220 vStream.clear();*/
222 //XFParagraph* pPara = new XFParagraph();
223 std::vector <XFFrame*>::iterator iter;
224 for (iter = m_vXFDrawObjects.begin(); iter != m_vXFDrawObjects.end(); iter++)
226 //pPara->Add(*iter);
227 pCont->Add(*iter);
230 //pCont->Add(pPara);
233 else if (this->IsGrafFormatValid())
235 XFImage* pImage = static_cast<XFImage*>(m_vXFDrawObjects.front());
237 if (m_bIsLinked)
239 OUString fileURL = LwpTools::convertToFileUrl(OUStringToOString(m_LinkedFilePath, osl_getThreadTextEncoding()));
240 pImage->SetFileURL(fileURL);
242 else
244 sal_uInt8* pGrafData = NULL;
245 sal_uInt32 nDataLen = this->GetRawGrafData(pGrafData);
247 if (pGrafData)
249 pImage->SetImageData(pGrafData, nDataLen);
251 // delete used image data
252 delete [] pGrafData;
253 pGrafData = NULL;
257 pCont->Add(pImage);
259 else if((m_sServerContextFormat[1]=='t'&&m_sServerContextFormat[2]=='e'&&m_sServerContextFormat[3]=='x'))
261 XFConvertEquation(pCont);
263 if (m_sServerContextFormat[1]=='l'&&m_sServerContextFormat[2]=='c'&&m_sServerContextFormat[3]=='h')
265 LwpSvStream* pDocStream = m_pStrm;
266 //LwpChartStreamTools::ParseChart(pDocStream, GetObjectID(),
267 // GetRectIn100thMM(), GetRectInCM(), pOutputStream);
268 //LwpChartStreamTools::ParseChart(pDocStream, GetObjectID(),
269 // GetRectIn100thMM(), GetRectInCM(), pCont, m_strStyleName);
274 * @short Get the rectangle of a chart in 100thMM
275 * @descr
276 * @return the rectangle of the chart
278 Rectangle LwpGraphicObject::GetRectIn100thMM()
280 #define To100thMM(num) (long)(2540* (double(num)/(72 * 65536L)))
281 INT32 nLeft,nTop,nRight,nBottom;
282 GetRect(nLeft,nTop,nRight,nBottom);
283 return Rectangle( To100thMM(nLeft),To100thMM(nTop),To100thMM(nRight),To100thMM(nBottom) );
287 * @short Get the rectangle of a chart in CM
288 * @descr
289 * @return The rectangle of the chart
291 XFRect LwpGraphicObject::GetRectInCM()
293 #define ToCM(num) (2.54*(double(num)/(72 * 65536L)))
294 INT32 nLeft,nTop,nRight,nBottom;
295 GetRect(nLeft,nTop,nRight,nBottom);
296 return XFRect( ToCM(nLeft),ToCM(nTop),ToCM(nRight-nLeft),ToCM(nBottom-nTop) );
300 * @short Get the rectangle of a chart
301 * @descr
302 * @param nLeft
303 * @param nTop
304 * @param nRight
305 * @param nBottom
307 #include "lwpframelayout.hxx"
308 void LwpGraphicObject::GetRect(INT32& nLeft, INT32& nTop, INT32& nRight, INT32& nBottom)
310 nLeft = nTop = nRight = nBottom = 0;
312 LwpObjectID* pObjID = GetLayoutsWithMe()->GetOnlyLayout();
313 if (pObjID)
315 LwpFrameLayout* pLayout = (LwpFrameLayout*)pObjID->obj();
316 if (pLayout)
318 LwpLayoutGeometry* pGeometry =(LwpLayoutGeometry*) pLayout->GetGeometry();
320 if (pGeometry)
322 LwpPoint aOrigin = pGeometry->GetOrigin();
323 // 2005.6
324 //frame width/height are not width/height of a chart
325 // sal_Int32 nWidth = pGeometry->GetWidth();
326 // sal_Int32 nHeight = pGeometry->GetHeight();
327 double fWidth =0;
328 double fHeight = 0;
329 GetGrafScaledSize(fWidth, fHeight);
331 sal_Int32 nWidth = fWidth * UNITS_PER_INCH /CM_PER_INCH;
332 sal_Int32 nHeight = fHeight * UNITS_PER_INCH /CM_PER_INCH;
333 //end
334 nLeft = pLayout->GetMarginsValue(MARGIN_LEFT) * UNITS_PER_INCH /CM_PER_INCH;
335 nTop = pLayout->GetMarginsValue(MARGIN_TOP)* UNITS_PER_INCH /CM_PER_INCH;
336 nRight = nLeft+nWidth;
337 nBottom = nTop+nHeight;
344 * @descr judge if the graphic format is what we can support: bmp, jpg, wmf, gif, tgf(tif). other format will be filtered to
345 * these formats by Word Pro.
346 * @return sal_True if yes sal_False if not.
348 sal_Bool LwpGraphicObject::IsGrafFormatValid()
350 if ((m_sServerContextFormat[1]=='b'&& m_sServerContextFormat[2]=='m' && m_sServerContextFormat[3]=='p')
351 || (m_sServerContextFormat[1]=='j' && m_sServerContextFormat[2]=='p' && m_sServerContextFormat[3]=='g')
352 || (m_sServerContextFormat[1]=='w' && m_sServerContextFormat[2]=='m' && m_sServerContextFormat[3]=='f')
353 || (m_sServerContextFormat[1]=='g' && m_sServerContextFormat[2]=='i' && m_sServerContextFormat[3]=='f')
354 || (m_sServerContextFormat[1]=='t' && m_sServerContextFormat[2]=='g' && m_sServerContextFormat[3]=='f')
355 || (m_sServerContextFormat[1]=='p' && m_sServerContextFormat[2]=='n' && m_sServerContextFormat[3]=='g')
356 || (m_sServerContextFormat[1]=='e' && m_sServerContextFormat[2]=='p' && m_sServerContextFormat[3]=='s'))
358 return sal_True;
360 else
362 return sal_False;
367 * @descr create drawing object and image object.
369 void LwpGraphicObject::RegisterStyle()
371 if (m_sServerContextFormat[1]=='s'&&m_sServerContextFormat[2]=='d'&&m_sServerContextFormat[3]=='w')
373 this->CreateDrawObjects();
375 // test codes for importing pictures
376 else if(this->IsGrafFormatValid())
378 this->CreateGrafObject();
380 /* if (m_sServerContextFormat[1]=='s'&&m_sServerContextFormat[2]=='d'&&m_sServerContextFormat[3]=='w')
382 LwpSvStream* pStream = m_pStrm;
383 //test code
384 OpenStormBento::LtcBenContainer* pBentoContainer;
385 ULONG ulRet = OpenStormBento::BenOpenContainer(pStream, &pBentoContainer);
386 std::vector<SvStream*> vStream;
387 std::vector<SvStream*>::iterator iter;
388 pBentoContainer->CreateGraphicStreams(&vStream);
389 for (iter=vStream.begin();iter!=vStream.end();iter++)
391 LwpSdwFileLoader fileLoader(*iter);
392 fileLoader.RegisterStyle();
393 delete *iter;
395 vStream.clear();
398 if (m_sServerContextFormat[1]=='l'&&m_sServerContextFormat[2]=='c'&&m_sServerContextFormat[3]=='h')
400 LwpVirtualLayout* pMyLayout = GetLayout(NULL);
401 if(pMyLayout->IsFrame())
403 XFFrameStyle* pXFFrameStyle = new XFFrameStyle();
404 pXFFrameStyle->SetXPosType(enumXFFrameXPosFromLeft, enumXFFrameXRelFrame);
405 pXFFrameStyle->SetYPosType(enumXFFrameYPosFromTop, enumXFFrameYRelPara);
406 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
407 m_strStyleName = pXFStyleManager->AddStyle(pXFFrameStyle)->GetStyleName();
413 // add by , 03/25/2005
415 * @descr create drawing object.
417 void LwpGraphicObject::CreateDrawObjects()
419 // if small file, use the compressed stream for BENTO
420 LwpSvStream* pStream = m_pStrm->GetCompressedStream() ? m_pStrm->GetCompressedStream(): m_pStrm;
422 OpenStormBento::LtcBenContainer* pBentoContainer;
423 ULONG ulRet = OpenStormBento::BenOpenContainer(pStream, &pBentoContainer);
424 SvStream* pDrawObjStream = NULL;
426 // get graphic object's bento objet name
427 LwpObjectID* pMyID = this->GetObjectID();
428 std::string aGrfObjName;
429 this->GetBentoNamebyID(pMyID, aGrfObjName);
431 // get bento stream by the name
432 pBentoContainer->CreateGraphicStream(pDrawObjStream, aGrfObjName.c_str());
433 if (pDrawObjStream)
435 LwpSdwFileLoader fileLoader(pDrawObjStream, this);
436 fileLoader.CreateDrawObjects(&m_vXFDrawObjects);
438 delete pDrawObjStream;
439 pDrawObjStream = NULL;
444 * @descr create drawing object.
446 void LwpGraphicObject::GetBentoNamebyID(LwpObjectID* pMyID, std::string& rName)
448 sal_uInt16 nHigh = pMyID->GetHigh();
449 sal_uInt32 nLow = pMyID->GetLow();
450 char pTempStr[32];
451 rName = std::string("Gr");
452 sprintf(pTempStr, "%X,%lX", nHigh, nLow);
453 rName.append(pTempStr);
457 * @descr get the image data read from bento stream according to the VO_GRAPHIC ID.
458 * @param pGrafData the array to store the image data. the pointer need to be deleted outside.
459 * @return the length of the image data.
461 sal_uInt32 LwpGraphicObject::GetRawGrafData(sal_uInt8*& pGrafData)
463 // create graphic object
464 // if small file, use the compressed stream for BENTO
465 LwpSvStream* pStream = m_pStrm->GetCompressedStream() ? m_pStrm->GetCompressedStream(): m_pStrm;
467 OpenStormBento::LtcBenContainer* pBentoContainer;
468 ULONG ulRet = OpenStormBento::BenOpenContainer(pStream, &pBentoContainer);
469 SvStream* pGrafStream = NULL;
471 // get graphic object's bento objet name
472 LwpObjectID* pMyID = this->GetObjectID();
473 std::string aGrfObjName;
474 this->GetBentoNamebyID(pMyID, aGrfObjName);
476 // get bento stream by the name
477 pBentoContainer->CreateGraphicStream(pGrafStream, aGrfObjName.c_str());
478 SvMemoryStream* pMemGrafStream = static_cast<SvMemoryStream*>(pGrafStream);
480 if (pMemGrafStream)
482 // read image data
483 sal_uInt32 nDataLen = pMemGrafStream->GetSize();
484 pGrafData = new sal_uInt8 [nDataLen];
485 pMemGrafStream->Read(pGrafData, nDataLen);
487 delete pMemGrafStream;
488 pMemGrafStream = NULL;
490 return nDataLen;
493 return 0;
497 * @descr get the image data (only -D dara) read from bento stream according to the VO_GRAPHIC ID.
498 * @param pGrafData the array to store the image data. the pointer need to be deleted outside.
499 * @return the length of the image data.
501 sal_uInt32 LwpGraphicObject::GetGrafData(sal_uInt8*& pGrafData)
503 // create graphic object
504 // if small file, use the compressed stream for BENTO
505 LwpSvStream* pStream = m_pStrm->GetCompressedStream() ? m_pStrm->GetCompressedStream(): m_pStrm;
507 OpenStormBento::LtcBenContainer* pBentoContainer;
508 ULONG ulRet = OpenStormBento::BenOpenContainer(pStream, &pBentoContainer);
510 SvStream* pGrafStream = NULL;
512 // get graphic object's bento objet name
513 LwpObjectID* pMyID = this->GetObjectID();
514 std::string aGrfObjName;
515 this->GetBentoNamebyID(pMyID, aGrfObjName);
517 char sDName[64]="";
518 sprintf(sDName, "%s-D", aGrfObjName.c_str());
520 // get bento stream by the name
521 pGrafStream = pBentoContainer->FindValueStreamWithPropertyName(sDName);
523 SvMemoryStream* pMemGrafStream = static_cast<SvMemoryStream*>(pGrafStream);
525 if (pMemGrafStream)
527 // read image data
528 UINT32 nPos = pGrafStream->Tell();
529 pGrafStream->Seek(STREAM_SEEK_TO_END);
530 sal_uInt32 nDataLen = pGrafStream->Tell();
531 pGrafStream->Seek(nPos);
533 pGrafData = new sal_uInt8 [nDataLen];
534 pMemGrafStream->Read(pGrafData, nDataLen);
536 delete pMemGrafStream;
537 pMemGrafStream = NULL;
539 return nDataLen;
542 return 0;
547 * @descr create xf-image object and save it in the container: m_vXFDrawObjects.
549 void LwpGraphicObject::CreateGrafObject()
552 XFImage* pImage = new XFImage();
554 // set image processing styles
555 XFImageStyle* pImageStyle = new XFImageStyle();
556 if (m_sServerContextFormat[1]!='w' || m_sServerContextFormat[2]!='m' || m_sServerContextFormat[3]!='f')
558 if (m_aIPData.nBrightness != 50)
560 sal_Int32 nSODCBrightness = (sal_Int32)m_aIPData.nBrightness*2 - 100;
561 pImageStyle->SetBrightness(nSODCBrightness);
563 if (m_aIPData.nContrast != 50)
565 //sal_Int32 nSODCContrast = (sal_Int32)m_aIPData.nContrast*2 - 100;
566 //lwp [0, 100] map to sodc [80, -80]
567 sal_Int32 nSODCContrast = (sal_Int32)(80 - (double)m_aIPData.nContrast*1.6);
568 pImageStyle->SetContrast(nSODCContrast);
572 // set scale and crop styles
573 LwpAssociatedLayouts* pLayoutWithMe = GetLayoutsWithMe();
574 LwpFrameLayout* pMyFrameLayout =
575 static_cast<LwpFrameLayout*>(pLayoutWithMe->GetOnlyLayout()->obj(VO_FRAMELAYOUT));
576 if (pMyFrameLayout)
578 LwpLayoutScale* pMyScale = pMyFrameLayout->GetLayoutScale();
579 LwpLayoutGeometry* pFrameGeo = pMyFrameLayout->GetGeometry();
581 // original image size
582 double fOrgGrafWidth = (double)m_Cache.Width/TWIPS_PER_CM;
583 double fOrgGrafHeight = (double)m_Cache.Height/TWIPS_PER_CM;
585 // get margin values
586 double fLeftMargin = pMyFrameLayout->GetMarginsValue(MARGIN_LEFT);
587 double fRightMargin = pMyFrameLayout->GetMarginsValue(MARGIN_RIGHT);
588 double fTopMargin = pMyFrameLayout->GetMarginsValue(MARGIN_TOP);
589 double fBottomMargin = pMyFrameLayout->GetMarginsValue(MARGIN_BOTTOM);
591 if (pMyScale && pFrameGeo)
593 // frame size
594 double fFrameWidth = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetWidth());
595 double fFrameHeight = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetHeight());
597 // calculate the displayed size of the frame
598 double fDisFrameWidth = fFrameWidth - (fLeftMargin+fRightMargin);
599 double fDisFrameHeight = fFrameHeight - (fTopMargin+fBottomMargin);
601 // scaled image size
602 double fSclGrafWidth = fOrgGrafWidth;//LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
603 double fSclGrafHeight = fOrgGrafHeight;//LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
605 // get scale mode
606 sal_uInt16 nScalemode = pMyScale->GetScaleMode();
607 if (nScalemode & LwpLayoutScale::CUSTOM)
609 fSclGrafWidth = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
610 fSclGrafHeight = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
612 else if (nScalemode & LwpLayoutScale::PERCENTAGE)
614 double fScalePercentage = (double)pMyScale->GetScalePercentage() / 1000;
615 fSclGrafWidth = fScalePercentage * fOrgGrafWidth;
616 fSclGrafHeight = fScalePercentage * fOrgGrafHeight;
618 else if (nScalemode & LwpLayoutScale::FIT_IN_FRAME)
620 if (pMyFrameLayout->IsFitGraphic())
622 fSclGrafWidth = fOrgGrafWidth;
623 fSclGrafHeight = fOrgGrafHeight;
625 else if (nScalemode & LwpLayoutScale::MAINTAIN_ASPECT_RATIO)
627 if (fOrgGrafWidth/fOrgGrafHeight >= fDisFrameWidth/fDisFrameHeight)
629 fSclGrafWidth = fDisFrameWidth;
630 fSclGrafHeight = (fDisFrameWidth/fOrgGrafWidth) * fOrgGrafHeight;
632 else
634 fSclGrafHeight = fDisFrameHeight;
635 fSclGrafWidth = (fDisFrameHeight/fOrgGrafHeight) * fOrgGrafWidth;
638 else
640 fSclGrafWidth = fDisFrameWidth;
641 fSclGrafHeight = fDisFrameHeight;
645 // scaled ratio
646 double fXRatio = fSclGrafWidth / fOrgGrafWidth;
647 double fYRatio = fSclGrafHeight / fOrgGrafHeight;
649 // set image to scaled size.
650 pImage->SetWidth(fSclGrafWidth);
651 pImage->SetHeight(fSclGrafHeight);
653 // placement:centered or tiled. tiled style is not supported so it's processed together with centered.
654 if (pMyFrameLayout->GetScaleCenter() || pMyFrameLayout->GetScaleTile())
656 // set center alignment
657 pImageStyle->SetXPosType(enumXFFrameXPosCenter, enumXFFrameXRelFrame);
658 pImageStyle->SetYPosType(enumXFFrameYPosMiddle, enumXFFrameYRelFrame);
660 // need horizontal crop?
661 double fClipWidth = 0;
662 double fClipHeight = 0;
663 sal_Bool sal_bCropped = sal_False;
664 if (fSclGrafWidth > fDisFrameWidth)
666 fClipWidth = (fSclGrafWidth-fDisFrameWidth ) / 2 / fXRatio;
667 sal_bCropped = sal_True;
670 // need vertical crop?
671 if (fSclGrafHeight > fDisFrameHeight)
673 fClipHeight = (fSclGrafHeight-fDisFrameHeight ) / 2 / fYRatio;
674 sal_bCropped = sal_True;
677 if (sal_bCropped)
679 pImageStyle->SetClip(fClipWidth, fClipWidth, fClipHeight, fClipHeight);
680 pImage->SetWidth(fDisFrameWidth);
681 pImage->SetHeight(fDisFrameHeight);
684 // placement:automatic
685 else
687 // set left-top alignment
688 // pImageStyle->SetXPosType(enumXFFrameXPosLeft, enumXFFrameXRelFrame);
689 // pImageStyle->SetYPosType(enumXFFrameYPosTop, enumXFFrameYRelFrame);
690 pImageStyle->SetYPosType(enumXFFrameYPosFromTop, enumXFFrameYRelFrame);
691 pImageStyle->SetXPosType(enumXFFrameXPosFromLeft, enumXFFrameXRelFrame);
693 // get image position offset
694 LwpPoint* pOffset = pMyScale->GetOffset();
695 double fOffsetX = LwpTools::ConvertFromUnitsToMetric(pOffset->GetX());
696 double fOffsetY = LwpTools::ConvertFromUnitsToMetric(pOffset->GetY());
698 struct LwpRect
700 double fLeft;
701 double fRight;
702 double fTop;
703 double fBottom;
705 LwpRect()
707 fLeft = 0.00;
708 fRight = 0.00;
709 fTop = 0.00;
710 fBottom = 0.00;
712 LwpRect(double fL, double fR, double fT, double fB)
714 fLeft = fL;
715 fRight = fR;
716 fTop = fT;
717 fBottom = fB;
720 LwpRect aFrameRect(-fOffsetX, (fDisFrameWidth-fOffsetX), (-fOffsetY), ((fDisFrameHeight-fOffsetY)));
721 LwpRect aImageRect(0, fSclGrafWidth, 0, fSclGrafHeight);
722 LwpRect aCropRect;
724 if (aFrameRect.fRight <= aImageRect.fLeft || aFrameRect.fLeft >= aImageRect.fRight
725 ||aFrameRect.fBottom <= aImageRect.fTop|| aFrameRect.fTop >= aImageRect.fBottom)
727 // display blank
729 else// need cropped
731 // horizontal crop
732 if (aFrameRect.fLeft > aImageRect.fLeft)
734 aCropRect.fLeft = (aFrameRect.fLeft - aImageRect.fLeft) / fXRatio;
737 if (aFrameRect.fRight < aImageRect.fRight)
739 aCropRect.fRight = (aImageRect.fRight - aFrameRect.fRight) / fXRatio;
742 // vertical crop
743 if (aFrameRect.fTop > aImageRect.fTop)
745 aCropRect.fTop = (aFrameRect.fTop - aImageRect.fTop) / fYRatio;
747 if (aFrameRect.fBottom < aImageRect.fBottom)
749 aCropRect.fBottom = (aImageRect.fBottom - aFrameRect.fBottom) / fYRatio;
752 pImageStyle->SetClip(aCropRect.fLeft, aCropRect.fRight, aCropRect.fTop, aCropRect.fBottom);
753 double fPicWidth = fSclGrafWidth - (aCropRect.fLeft+aCropRect.fRight)*fXRatio;
754 double fPicHeight = fSclGrafHeight- (aCropRect.fTop+aCropRect.fBottom)*fYRatio;
755 double fX = fOffsetX > 0 ? fOffsetX : 0.00;
756 double fY = fOffsetY > 0 ? fOffsetY : 0.00;
757 pImage->SetPosition((fX+fLeftMargin), (fY+fTopMargin), fPicWidth, fPicHeight);
763 // set style for the image
764 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
765 pImage->SetStyleName(pXFStyleManager->AddStyle(pImageStyle)->GetStyleName());
767 // set archor to frame
768 pImage->SetAnchorType(enumXFAnchorFrame);
769 // pImage->SetAnchorType(enumXFAnchorPara);//enumXFAnchorFrame);
771 // set object name
772 LwpAtomHolder* pHolder = this->GetName();
773 if ( pHolder && pHolder->str().getLength() )
775 pImage->SetName(pHolder->str());
778 // insert image object into array
779 m_vXFDrawObjects.push_back(pImage);
782 // end add
785 * @descr Reserve the equation text in a note in the context.
787 void LwpGraphicObject::XFConvertEquation(XFContentContainer * pCont)
789 sal_uInt8* pGrafData = NULL;
790 sal_uInt32 nDataLen = this->GetGrafData(pGrafData);
791 if(pGrafData)
793 //convert equation
794 XFParagraph* pXFPara = new XFParagraph;
795 pXFPara->Add(A2OUSTR("Formula:"));
796 //add notes
797 XFAnnotation* pXFNote = new XFAnnotation;
798 //add equation to comment notes
799 XFParagraph* pXFNotePara = new XFParagraph;
800 //equation header text: Times New Roman,
801 // 18,12,0,0,0,0,0.
802 // .TCIformat{2}
803 //total head length = 45
804 sal_uInt32 nBegin = 45;
805 sal_uInt32 nEnd = nDataLen -1;
806 sal_uInt32 nIndex = 0;
808 if(pGrafData[nEnd] == '$' && pGrafData[nEnd-1]!= '\\')
810 //equation body is contained by '$';
811 nBegin++;
812 nEnd--;
815 if(nEnd >= nBegin)
817 sal_uInt8* pEquData = new sal_uInt8[nEnd - nBegin + 1];
818 for(nIndex = 0; nIndex < nEnd - nBegin +1 ; nIndex++)
820 pEquData[nIndex] = pGrafData[nBegin + nIndex];
822 pXFNotePara->Add(rtl::OUString((sal_Char*)pEquData, (nEnd - nBegin + 1), gsl_getSystemTextEncoding()));
823 delete pEquData;
825 pXFNote->Add(pXFNotePara);
827 pXFPara->Add(pXFNote);
828 pCont->Add(pXFPara);
830 delete [] pGrafData;
831 pGrafData = NULL;
836 void LwpGraphicObject::GetGrafOrgSize(double & rWidth, double & rHeight)
838 // original image size
839 rWidth = (double)m_Cache.Width/TWIPS_PER_CM;
840 rHeight = (double)m_Cache.Height/TWIPS_PER_CM;