merge the formfield patch from ooo-build
[ooovba.git] / lotuswordpro / source / filter / lwpdrawobj.cxx
blob854857faaf650bbf8bea052edfc8e12302d8e6ef
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 * @file
57 * Implementation file of LwpDrawObjcts and associated class like LwpDrawGroup, LwpDrawRectange
58 * and so on.
60 #include "lwpglobalmgr.hxx"
61 #include "lwpdrawobj.hxx"
62 #include "lwptools.hxx"
63 #include <tools/stream.hxx>
65 #include "xfilter/xfframe.hxx"
67 #include "xfilter/xfstylemanager.hxx"
68 #include "xfilter/xfdrawstyle.hxx"
69 #include "xfilter/xftextstyle.hxx"
70 #include "xfilter/xfparastyle.hxx"
71 #include "xfilter/xfimagestyle.hxx"
72 #include "xfilter/xftextboxstyle.hxx"
73 #include "xfilter/xfparagraph.hxx"
74 #include "xfilter/xftextspan.hxx"
75 #include "xfilter/xffont.hxx"
77 #include "xfilter/xfdrawrect.hxx"
78 #include "xfilter/xfdrawpath.hxx"
79 #include "xfilter/xfdrawline.hxx"
80 #include "xfilter/xfdrawpolygon.hxx"
81 #include "xfilter/xfdrawellipse.hxx"
82 #include "xfilter/xfdrawcircle.hxx"
83 #include "xfilter/xfimage.hxx"
85 #include "lwpcharsetmgr.hxx"
86 #include "lwpsdwrect.hxx"
88 /**
89 * @descr Constructor of class LwpDrawObj
90 * @param pStream The memory stream which contains the lwp-sdw draw objects
92 LwpDrawObj::LwpDrawObj(SvStream * pStream, DrawingOffsetAndScale* pTransData) :
93 m_pStream(pStream), m_pTransData(pTransData), m_eType(OT_UNDEFINED)
95 this->ReadObjHeaderRecord();
98 /**
99 * @descr read the header record data of lwp-sdw-object
101 void LwpDrawObj::ReadObjHeaderRecord()
103 //flags
104 m_pStream->SeekRel(1);
106 //record Length
107 m_pStream->Read(&m_aObjHeader.nRecLen, sizeof(m_aObjHeader.nRecLen));
109 //boundrect
110 m_pStream->Read(&m_aObjHeader.nLeft, sizeof(m_aObjHeader.nLeft));
111 m_pStream->Read(&m_aObjHeader.nTop, sizeof(m_aObjHeader.nTop));
112 m_pStream->Read(&m_aObjHeader.nRight, sizeof(m_aObjHeader.nRight));
113 m_pStream->Read(&m_aObjHeader.nBottom, sizeof(m_aObjHeader.nBottom));
115 //nextObj, prevObj
116 m_pStream->SeekRel(4);
120 * @descr read the style of closed lwp-sdw-object like: rectangle, ellipse and so on.
122 void LwpDrawObj::ReadClosedObjStyle()
124 if ((m_eType != OT_POLYGON) && (m_eType != OT_TEXTART))
126 m_pStream->SeekRel(8);
129 m_pStream->Read(&m_aClosedObjStyleRec.nLineWidth, sizeof(m_aClosedObjStyleRec.nLineWidth));
130 m_pStream->Read(&m_aClosedObjStyleRec.nLineStyle, sizeof(m_aClosedObjStyleRec.nLineStyle));
132 // pen color
133 m_pStream->Read(&m_aClosedObjStyleRec.aPenColor.nR, 1);
134 m_pStream->Read(&m_aClosedObjStyleRec.aPenColor.nG, 1);
135 m_pStream->Read(&m_aClosedObjStyleRec.aPenColor.nB, 1);
136 m_pStream->Read(&m_aClosedObjStyleRec.aPenColor.unused, 1);
138 // foreground color
139 m_pStream->Read(&m_aClosedObjStyleRec.aForeColor.nR, 1);
140 m_pStream->Read(&m_aClosedObjStyleRec.aForeColor.nG, 1);
141 m_pStream->Read(&m_aClosedObjStyleRec.aForeColor.nB, 1);
142 m_pStream->Read(&m_aClosedObjStyleRec.aForeColor.unused, 1);
144 // background color
145 m_pStream->Read(&m_aClosedObjStyleRec.aBackColor.nR, 1);
146 m_pStream->Read(&m_aClosedObjStyleRec.aBackColor.nG, 1);
147 m_pStream->Read(&m_aClosedObjStyleRec.aBackColor.nB, 1);
148 m_pStream->Read(&m_aClosedObjStyleRec.aBackColor.unused, 1);
150 // fill style
151 m_pStream->Read(&m_aClosedObjStyleRec.nFillType, sizeof(m_aClosedObjStyleRec.nFillType));
152 m_pStream->Read(m_aClosedObjStyleRec.pFillPattern, sizeof(m_aClosedObjStyleRec.pFillPattern));
156 * @descr set fill style of drawing objects
157 * @param pStyle pointer of the drawing xfstyle.
159 void LwpDrawObj::SetFillStyle(XFDrawStyle* pStyle)
161 if (!pStyle)
163 assert(false);
164 return;
167 XFColor aForeColor(m_aClosedObjStyleRec.aForeColor.nR,
168 m_aClosedObjStyleRec.aForeColor.nG, m_aClosedObjStyleRec.aForeColor.nB);
169 XFColor aBackColor(m_aClosedObjStyleRec.aBackColor.nR,
170 m_aClosedObjStyleRec.aBackColor.nG, m_aClosedObjStyleRec.aBackColor.nB);
172 switch (m_aClosedObjStyleRec.nFillType)
174 default: //fall through!
175 case FT_TRANSPARENT:
177 // set fill style : none
178 break;
180 case FT_SOLID:
182 pStyle->SetAreaColor(aForeColor);
183 break;
185 case FT_HORZHATCH:
187 pStyle->SetAreaColor(aBackColor);
188 pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 0, 0.12, aForeColor);
189 break;
191 case FT_VERTHATCH:
193 pStyle->SetAreaColor(aBackColor);
194 pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 90, 0.12, aForeColor);
195 break;
197 case FT_FDIAGHATCH:
199 pStyle->SetAreaColor(aBackColor);
200 pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 135, 0.09, aForeColor);
201 break;
203 case FT_BDIAGHATCH:
205 pStyle->SetAreaColor(aBackColor);
206 pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 45, 0.09, aForeColor);
207 break;
209 case FT_CROSSHATCH:
211 pStyle->SetAreaColor(aBackColor);
212 pStyle->SetAreaLineStyle(enumXFAreaLineCrossed, 0, 0.12, aForeColor);
213 break;
215 case FT_DIAGCROSSHATCH:
217 pStyle->SetAreaColor(aBackColor);
218 pStyle->SetAreaLineStyle(enumXFAreaLineCrossed, 45, 0.095, aForeColor);
219 break;
225 * @descr set line/border style of drawing objects.
226 * @param pStyle pointer of the drawing xfstyle.
227 * @param nWidth width of line/border.
228 * @param nLineStyle flag of line/border style: none, dot or solid.
229 * @param rColor color of line/border.
231 void LwpDrawObj::SetLineStyle(XFDrawStyle* pStyle, sal_uInt8 nWidth, sal_uInt8 nLineStyle,
232 const SdwColor& rColor)
234 if (!pStyle)
236 assert(false);
237 return;
239 if (nWidth == 0)
241 nLineStyle = LS_NULL;
244 if (nLineStyle == LS_NULL)
246 // set stroke:none
247 return;
250 if (nLineStyle == LS_DOT)
252 pStyle->SetLineDashStyle(enumXFLineDash, 1, 1, 0.05, 0.05, 0.05);
255 // line width
256 double fWidth = (double)nWidth/TWIPS_PER_CM;
258 // line color
259 XFColor aXFColor(rColor.nR, rColor.nG, rColor.nB);
261 pStyle->SetLineStyle(fWidth, aXFColor);
265 * @descr set position of a drawing object in the frame.
266 * @param pObj pointer of the xf-drawing object
268 void LwpDrawObj::SetPosition(XFFrame* pObj)
270 double fOffsetX = 0.00, fOffsetY = 0.00;
271 double fScaleX = 1.00, fScaleY = 1.00;
272 if (m_pTransData)
274 fOffsetX = m_pTransData->fOffsetX;
275 fOffsetY = m_pTransData->fOffsetY;
276 fScaleX = m_pTransData->fScaleX;
277 fScaleY = m_pTransData->fScaleY;
280 pObj->SetPosition((double)m_aObjHeader.nLeft/TWIPS_PER_CM * fScaleX+ fOffsetX,
281 (double)m_aObjHeader.nTop/TWIPS_PER_CM * fScaleY + fOffsetY,
282 (double)(m_aObjHeader.nRight-m_aObjHeader.nLeft)/TWIPS_PER_CM * fScaleX,
283 (double)(m_aObjHeader.nBottom-m_aObjHeader.nTop)/TWIPS_PER_CM * fScaleY);
287 * @descr set arrowhead of a xf-drawing object. only opened drawing objects can be assigned arrowheads
288 * @param pOpenedObjStyle the xf-drawing object which will be set arrowhead.
289 * @param nArrowFlag arrowhead flags of the object.
291 void LwpDrawObj::SetArrowHead(XFDrawStyle* pOpenedObjStyle, sal_uInt8 nArrowFlag, sal_uInt8 nLineWidth)
293 // no arrowhead
294 if (!nArrowFlag)
296 return;
299 if (!pOpenedObjStyle)
301 assert(false);
302 return;
305 // arrowhead flag of an object's start side
306 sal_uInt8 nLeftArrow = nArrowFlag & 0x0F;
308 // arrowhead flag of an object's end side
309 sal_uInt8 nRightArrow = (nArrowFlag & 0xF0) >> 4;
311 double fWidth_inch = (double)nLineWidth/TWIPS_PER_CM;
312 double fArrowSize_inch = fWidth_inch + 0.08;
313 double fArrowSize = fArrowSize_inch * CM_PER_INCH;
315 if (nLeftArrow)
317 pOpenedObjStyle->SetArrowStart( this->GetArrowName(nLeftArrow), fArrowSize, sal_True);
319 if (nRightArrow)
321 pOpenedObjStyle->SetArrowEnd( this->GetArrowName(nRightArrow), fArrowSize, sal_True);
327 * @descr get arrow style name according to the flag.
328 * @param nArrowStyle style of the arrowhead.
329 * @return nWhichSide style name of the arrowhead.
331 rtl::OUString LwpDrawObj::GetArrowName(sal_uInt8 nArrowStyle)
333 // style name of arrowhead
334 rtl::OUString aArrowName;
336 switch(nArrowStyle)
338 default:
339 case AH_ARROW_FULLARROW:
340 aArrowName = rtl::OUString::createFromAscii("Symmetric arrow");
341 break;
342 case AH_ARROW_HALFARROW:
343 aArrowName = rtl::OUString::createFromAscii("Arrow concave");
344 break;
345 case AH_ARROW_LINEARROW:
346 aArrowName = rtl::OUString::createFromAscii("arrow100");
347 break;
348 case AH_ARROW_INVFULLARROW:
349 aArrowName = rtl::OUString::createFromAscii("reverse arrow");
350 break;
351 case AH_ARROW_INVHALFARROW:
352 aArrowName = rtl::OUString::createFromAscii("reverse concave arrow");
353 break;
354 case AH_ARROW_INVLINEARROW:
355 aArrowName = rtl::OUString::createFromAscii("reverse line arrow");
356 break;
357 case AH_ARROW_TEE:
358 aArrowName = rtl::OUString::createFromAscii("Dimension lines");
359 break;
360 case AH_ARROW_SQUARE:
361 aArrowName = rtl::OUString::createFromAscii("Square");
362 break;
363 case AH_ARROW_CIRCLE:
364 aArrowName = rtl::OUString::createFromAscii("Circle");
365 break;
368 return aArrowName;
372 * @descr template method of creating drawing object from Lwp-Model to XF-Model
373 * @return pointer of the drawing object of XF-Model.
375 XFFrame* LwpDrawObj::CreateXFDrawObject()
377 // read records
378 this->Read();
380 // register style
381 rtl::OUString aStyleName = this->RegisterStyle();
383 // create XF-Objects
384 XFFrame* pXFObj = NULL;
385 if (m_pTransData
386 && FABS(m_pTransData->fOffsetX - m_pTransData->fLeftMargin) < THRESHOLD
387 && FABS(m_pTransData->fOffsetY - m_pTransData->fTopMargin) < THRESHOLD
388 && FABS(m_pTransData->fScaleX - 1.0) < THRESHOLD
389 && FABS(m_pTransData->fScaleY - 1.0) < THRESHOLD)
391 pXFObj = this->CreateStandardDrawObj(aStyleName);
393 else
395 pXFObj = this->CreateDrawObj(aStyleName);
398 // set anchor type
399 if (pXFObj)
401 pXFObj->SetAnchorType(enumXFAnchorFrame);
404 return pXFObj;
408 * @descr Constructor of class LwpDrawLine
409 * @param pStream The memory stream which contains the lwp-sdw draw objects
411 LwpDrawLine::LwpDrawLine(SvStream * pStream, DrawingOffsetAndScale* pTransData)
412 : LwpDrawObj(pStream, pTransData)
417 * @descr reading function of class LwpDrawLine
419 void LwpDrawLine::Read()
421 m_pStream->Read(&m_aLineRec.nStartX, sizeof(m_aLineRec.nStartX));
422 m_pStream->Read(&m_aLineRec.nStartY, sizeof(m_aLineRec.nStartY));
423 m_pStream->Read(&m_aLineRec.nEndX, sizeof(m_aLineRec.nEndX));
424 m_pStream->Read(&m_aLineRec.nEndY, sizeof(m_aLineRec.nEndY));
425 m_pStream->Read(&m_aLineRec.nLineWidth, sizeof(m_aLineRec.nLineWidth));
426 m_pStream->Read(&m_aLineRec.nLineEnd,sizeof(m_aLineRec.nLineEnd));
427 m_pStream->Read(&m_aLineRec.nLineStyle, sizeof(m_aLineRec.nLineStyle));
429 m_pStream->Read(&m_aLineRec.aPenColor.nR, 1);
430 m_pStream->Read(&m_aLineRec.aPenColor.nG, 1);
431 m_pStream->Read(&m_aLineRec.aPenColor.nB, 1);
432 m_pStream->Read(&m_aLineRec.aPenColor.unused, 1);
435 rtl::OUString LwpDrawLine::RegisterStyle()
437 XFDrawStyle* pStyle = new XFDrawStyle();
439 // set line style
440 this->SetLineStyle(pStyle, m_aLineRec.nLineWidth, m_aLineRec.nLineStyle, m_aLineRec.aPenColor);
442 // set arrow head
443 this->SetArrowHead(pStyle, m_aLineRec.nLineEnd, m_aLineRec.nLineWidth);
445 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
446 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
450 XFFrame* LwpDrawLine::CreateDrawObj(const rtl::OUString& rStyleName )
452 XFDrawPath* pLine = new XFDrawPath();
453 pLine->MoveTo(XFPoint((double)(m_aLineRec.nStartX)/TWIPS_PER_CM * m_pTransData->fScaleX,
454 (double)(m_aLineRec.nStartY)/TWIPS_PER_CM * m_pTransData->fScaleY));
455 pLine->LineTo(XFPoint((double)(m_aLineRec.nEndX)/TWIPS_PER_CM * m_pTransData->fScaleX,
456 (double)(m_aLineRec.nEndY)/TWIPS_PER_CM * m_pTransData->fScaleY));
457 this->SetPosition(pLine);
459 pLine->SetStyleName(rStyleName);
461 return pLine;
464 XFFrame* LwpDrawLine::CreateStandardDrawObj(const OUString& rStyleName)
466 XFDrawLine* pLine = new XFDrawLine();
467 pLine->SetStartPoint((double)(m_aLineRec.nStartX)/TWIPS_PER_CM,(double)(m_aLineRec.nStartY)/TWIPS_PER_CM);
468 pLine->SetEndPoint((double)(m_aLineRec.nEndX)/TWIPS_PER_CM,(double)(m_aLineRec.nEndY)/TWIPS_PER_CM);
470 pLine->SetStyleName(rStyleName);
471 return pLine;
475 * @descr Constructor of class LwpDrawPolyLine
476 * @param pStream The memory stream which contains the lwp-sdw draw objects
478 LwpDrawPolyLine::LwpDrawPolyLine(SvStream * pStream, DrawingOffsetAndScale* pTransData)
479 : LwpDrawObj(pStream, pTransData), m_pVector(NULL)
482 LwpDrawPolyLine::~LwpDrawPolyLine()
484 if (m_pVector)
486 delete [] m_pVector;
487 m_pVector = NULL;
492 * @descr reading function of class LwpDrawPolyLine
494 void LwpDrawPolyLine::Read()
496 m_pStream->Read(&m_aPolyLineRec.nLineWidth, 1);
497 m_pStream->Read(&m_aPolyLineRec.nLineEnd, 1);
498 m_pStream->Read(&m_aPolyLineRec.nLineStyle, 1);
499 m_pStream->Read(&m_aPolyLineRec.aPenColor.nR, 1);
500 m_pStream->Read(&m_aPolyLineRec.aPenColor.nG, 1);
501 m_pStream->Read(&m_aPolyLineRec.aPenColor.nB, 1);
502 m_pStream->Read(&m_aPolyLineRec.aPenColor.unused, 1);
503 m_pStream->Read(&m_aPolyLineRec.nNumPoints, 2);
505 m_pVector= new SdwPoint [m_aPolyLineRec.nNumPoints];
507 for (sal_uInt16 nC = 0; nC < m_aPolyLineRec.nNumPoints; nC++)
509 m_pStream->Read(&m_pVector[nC].x,2);
510 m_pStream->Read(&m_pVector[nC].y,2);
514 rtl::OUString LwpDrawPolyLine::RegisterStyle()
516 XFDrawStyle* pStyle = new XFDrawStyle();
518 // set line style
519 this->SetLineStyle(pStyle, m_aPolyLineRec.nLineWidth, m_aPolyLineRec.nLineStyle,
520 m_aPolyLineRec.aPenColor);
522 // set arrow head
523 this->SetArrowHead(pStyle, m_aPolyLineRec.nLineEnd, m_aPolyLineRec.nLineWidth);
525 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
526 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
529 XFFrame* LwpDrawPolyLine::CreateDrawObj(const rtl::OUString& rStyleName )
531 XFDrawPath* pPolyline = new XFDrawPath();
532 pPolyline->MoveTo(XFPoint((double)m_pVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
533 (double)m_pVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
534 for (sal_uInt8 nC = 1; nC < m_aPolyLineRec.nNumPoints; nC++)
536 pPolyline->LineTo(XFPoint((double)m_pVector[nC].x/TWIPS_PER_CM * m_pTransData->fScaleX,
537 (double)m_pVector[nC].y/TWIPS_PER_CM * m_pTransData->fScaleY));
539 this->SetPosition(pPolyline);
541 pPolyline->SetStyleName(rStyleName);
543 return pPolyline;
546 XFFrame* LwpDrawPolyLine::CreateStandardDrawObj(const OUString& rStyleName)
548 XFDrawPolyline* pPolyline = new XFDrawPolyline();
549 for (sal_uInt8 nC = 0; nC < m_aPolyLineRec.nNumPoints; nC++)
551 pPolyline->AddPoint((double)m_pVector[nC].x/TWIPS_PER_CM,
552 (double)m_pVector[nC].y/TWIPS_PER_CM);
555 pPolyline->SetStyleName(rStyleName);
557 return pPolyline;
561 * @descr Constructor of class LwpDrawPolygon
562 * @param pStream The memory stream which contains the lwp-sdw draw objects
564 LwpDrawPolygon::LwpDrawPolygon(SvStream * pStream, DrawingOffsetAndScale* pTransData)
565 : LwpDrawObj(pStream, pTransData)
568 LwpDrawPolygon::~LwpDrawPolygon()
570 if (m_pVector)
572 delete m_pVector;
573 m_pVector = NULL;
578 * @descr reading function of class LwpDrawPolygon
580 void LwpDrawPolygon::Read()
582 this->ReadClosedObjStyle();
583 m_pStream->Read(&m_nNumPoints, sizeof(m_nNumPoints));
585 m_pVector = new SdwPoint [m_nNumPoints];
587 for (sal_uInt16 nC = 0; nC < m_nNumPoints; nC++)
589 m_pStream->Read(&m_pVector[nC].x, 2);
590 m_pStream->Read(&m_pVector[nC].y, 2);
594 rtl::OUString LwpDrawPolygon::RegisterStyle()
596 XFDrawStyle* pStyle = new XFDrawStyle();
598 // set line style
599 this->SetLineStyle(pStyle, m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
600 m_aClosedObjStyleRec.aPenColor);
602 // set fill style
603 this->SetFillStyle(pStyle);
605 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
606 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
609 XFFrame* LwpDrawPolygon::CreateDrawObj(const rtl::OUString& rStyleName)
611 XFDrawPath* pPolygon = new XFDrawPath();
612 pPolygon->MoveTo(XFPoint((double)m_pVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
613 (double)m_pVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
614 for (sal_uInt16 nC = 1; nC < m_nNumPoints; nC++)
616 pPolygon->LineTo(XFPoint((double)m_pVector[nC].x/TWIPS_PER_CM * m_pTransData->fScaleX,
617 (double)m_pVector[nC].y/TWIPS_PER_CM * m_pTransData->fScaleY));
619 pPolygon->ClosePath();
620 this->SetPosition(pPolygon);
621 pPolygon->SetStyleName(rStyleName);
623 return pPolygon;
626 XFFrame* LwpDrawPolygon::CreateStandardDrawObj(const OUString& rStyleName)
628 XFDrawPolygon* pPolygon = new XFDrawPolygon();
629 for (sal_uInt16 nC = 0; nC < m_nNumPoints; nC++)
631 pPolygon->AddPoint((double)m_pVector[nC].x/TWIPS_PER_CM,
632 (double)m_pVector[nC].y/TWIPS_PER_CM);
635 pPolygon->SetStyleName(rStyleName);
637 return pPolygon;
641 * @descr Constructor of class LwpDrawRectangle
642 * @param pStream The memory stream which contains the lwp-sdw draw objects
644 LwpDrawRectangle::LwpDrawRectangle(SvStream * pStream, DrawingOffsetAndScale* pTransData)
645 : LwpDrawObj(pStream, pTransData)
650 * @descr reading function of class LwpDrawRectangle
652 void LwpDrawRectangle::Read()
654 this->ReadClosedObjStyle();
657 sal_uInt8 nPointsCount;
658 if (m_eType == OT_RNDRECT)
660 nPointsCount = 16;
661 m_pStream->SeekRel(4); // corner points
663 else
665 nPointsCount = 4;
668 for (sal_uInt8 nC = 0; nC < nPointsCount; nC++)
670 m_pStream->Read(&m_aVector[nC].x,2);
671 m_pStream->Read(&m_aVector[nC].y,2);
675 rtl::OUString LwpDrawRectangle::RegisterStyle()
677 XFDrawStyle* pStyle = new XFDrawStyle();
679 // set line style
680 this->SetLineStyle(pStyle, m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
681 m_aClosedObjStyleRec.aPenColor);
683 // set fill style
684 this->SetFillStyle(pStyle);
686 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
687 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
690 XFFrame* LwpDrawRectangle::CreateDrawObj(const rtl::OUString& rStyleName)
692 if (m_eType == OT_RNDRECT)
694 return this->CreateRoundedRect(rStyleName);
696 else
698 XFDrawPath* pRect = new XFDrawPath();
699 pRect->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
700 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
701 for (sal_uInt8 nC = 1; nC < 4; nC++)
703 pRect->LineTo(XFPoint((double)m_aVector[nC].x/TWIPS_PER_CM * m_pTransData->fScaleX,
704 (double)m_aVector[nC].y/TWIPS_PER_CM * m_pTransData->fScaleY));
706 pRect->LineTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
707 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
708 pRect->ClosePath(sal_True);
709 this->SetPosition(pRect);
711 pRect->SetStyleName(rStyleName);
713 return pRect;
717 XFFrame* LwpDrawRectangle::CreateRoundedRect(const rtl::OUString& rStyleName)
719 XFDrawPath* pRoundedRect = new XFDrawPath();
720 pRoundedRect->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
721 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
723 sal_uInt8 nPtIndex = 1;
724 for (sal_uInt8 nC = 0; nC < 7; nC++)
726 if (nC%2 == 0)
728 XFPoint aCtrl1((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
729 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
730 nPtIndex++;
731 XFPoint aCtrl2((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
732 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
733 nPtIndex++;
734 XFPoint aDest((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
735 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
736 nPtIndex++;
738 pRoundedRect->CurveTo(aDest, aCtrl1, aCtrl2);
740 else
742 XFPoint aDest((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
743 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
744 nPtIndex++;
746 pRoundedRect->LineTo(aDest);
750 pRoundedRect->LineTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
751 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
752 pRoundedRect->ClosePath(sal_True);
753 this->SetPosition(pRoundedRect);
755 pRoundedRect->SetStyleName(rStyleName);
757 return pRoundedRect;
760 XFFrame* LwpDrawRectangle::CreateStandardDrawObj(const OUString& rStyleName)
762 if (m_eType == OT_RNDRECT)
764 return this->CreateRoundedRect(rStyleName);
766 else
768 XFDrawRect* pRect = new XFDrawRect();
769 double fStartX, fStartY, fWidth, fHeight;
770 double fRotAngle = 0.0;
771 SdwRectangle aSdwRect;
772 Rectangle aOriginalRect;
773 Point aPt0, aPt1, aPt2, aPt3;
775 aPt0.setX(m_aVector[0].x); aPt0.setY(m_aVector[0].y);
776 aPt1.setX(m_aVector[1].x); aPt1.setY(m_aVector[1].y);
777 aPt2.setX(m_aVector[2].x); aPt2.setY(m_aVector[2].y);
778 aPt3.setX(m_aVector[3].x); aPt3.setY(m_aVector[3].y);
780 aSdwRect = SdwRectangle(aPt0, aPt1, aPt2, aPt3);
781 if (aSdwRect.IsRectRotated())
783 aOriginalRect = aSdwRect.GetOriginalRect();
784 fRotAngle = aSdwRect.GetRotationAngle();
786 else
788 aOriginalRect = Rectangle(aPt0, aPt2);
791 fStartX = aOriginalRect.TopLeft().X();
792 fStartY = aOriginalRect.TopLeft().Y();
793 fWidth = aOriginalRect.GetWidth();
794 fHeight = aOriginalRect.GetHeight();
796 pRect->SetStartPoint(XFPoint(fStartX/TWIPS_PER_CM + m_pTransData->fOffsetX,
797 fStartY/TWIPS_PER_CM + m_pTransData->fOffsetY));
798 pRect->SetSize(fWidth/TWIPS_PER_CM, fHeight/TWIPS_PER_CM);
800 if (aSdwRect.IsRectRotated())
802 pRect->SetRotate( fRotAngle / PI * 180);// aXFCenter);
805 pRect->SetStyleName(rStyleName);
807 return pRect;
812 * @descr Constructor of class LwpDrawEllipse
813 * @param pStream The memory stream which contains the lwp-sdw draw objects
815 LwpDrawEllipse::LwpDrawEllipse(SvStream * pStream, DrawingOffsetAndScale* pTransData)
816 : LwpDrawObj(pStream, pTransData)
821 * @descr reading function of class LwpDrawEllipse
823 void LwpDrawEllipse::Read()
825 this->ReadClosedObjStyle();
827 for (sal_uInt8 nC = 0; nC < 13; nC++)
829 m_pStream->Read(&m_aVector[nC].x,2);
830 m_pStream->Read(&m_aVector[nC].y,2);
834 rtl::OUString LwpDrawEllipse::RegisterStyle()
836 XFDrawStyle* pStyle = new XFDrawStyle();
838 // set line style
839 this->SetLineStyle(pStyle, m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
840 m_aClosedObjStyleRec.aPenColor);
842 // set fill style
843 this->SetFillStyle(pStyle);
845 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
846 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
849 XFFrame* LwpDrawEllipse::CreateDrawObj(const rtl::OUString& rStyleName )
851 XFDrawPath* pEllipse = new XFDrawPath();
852 pEllipse->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
853 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
854 sal_uInt8 nPtIndex = 1;
855 for (sal_uInt8 nC = 0; nC < 4; nC++)
857 XFPoint aCtrl1((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
858 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
859 nPtIndex++;
860 XFPoint aCtrl2((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
861 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
862 nPtIndex++;
863 XFPoint aDest((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
864 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
865 nPtIndex++;
867 pEllipse->CurveTo(aDest, aCtrl1, aCtrl2);
869 pEllipse->ClosePath(sal_True);
870 this->SetPosition(pEllipse);
872 pEllipse->SetStyleName(rStyleName);
874 return pEllipse;
877 XFFrame* LwpDrawEllipse::CreateStandardDrawObj(const OUString& rStyleName)
879 return this->CreateDrawObj(rStyleName);
883 * @descr Constructor of class LwpDrawArc
884 * @param pStream The memory stream which contains the lwp-sdw draw objects
886 LwpDrawArc::LwpDrawArc(SvStream * pStream, DrawingOffsetAndScale* pTransData)
887 : LwpDrawObj(pStream, pTransData)
892 * @descr reading function of class LwpDrawArc
894 void LwpDrawArc::Read()
896 m_pStream->SeekRel(16);// arcRect, startPt, endPt
898 m_pStream->Read(&m_aArcRec.nLineWidth, sizeof(m_aArcRec.nLineWidth));
899 m_pStream->Read(&m_aArcRec.nLineStyle, sizeof(m_aArcRec.nLineStyle));
900 m_pStream->Read(&m_aArcRec.aPenColor.nR, 1);
901 m_pStream->Read(&m_aArcRec.aPenColor.nG, 1);
902 m_pStream->Read(&m_aArcRec.aPenColor.nB, 1);
903 m_pStream->Read(&m_aArcRec.aPenColor.unused, 1);
904 m_pStream->Read(&m_aArcRec.nLineEnd, sizeof(m_aArcRec.nLineEnd));
906 for (sal_uInt8 nC = 0; nC < 4; nC++)
908 m_pStream->Read(&m_aVector[nC].x,2);
909 m_pStream->Read(&m_aVector[nC].y,2);
913 rtl::OUString LwpDrawArc::RegisterStyle()
915 XFDrawStyle* pStyle = new XFDrawStyle();
917 // set line style
918 this->SetLineStyle(pStyle, m_aArcRec.nLineWidth, m_aArcRec.nLineStyle,
919 m_aArcRec.aPenColor);
921 // set arrow head
922 this->SetArrowHead(pStyle, m_aArcRec.nLineEnd, m_aArcRec.nLineWidth);
924 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
925 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
928 XFFrame* LwpDrawArc::CreateDrawObj(const rtl::OUString& rStyleName )
930 XFDrawPath* pArc = new XFDrawPath();
931 pArc->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
932 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
933 XFPoint aDest((double)m_aVector[3].x/TWIPS_PER_CM * m_pTransData->fScaleX,
934 (double)m_aVector[3].y/TWIPS_PER_CM * m_pTransData->fScaleY);
935 XFPoint aCtl1((double)m_aVector[1].x/TWIPS_PER_CM * m_pTransData->fScaleX,
936 (double)m_aVector[1].y/TWIPS_PER_CM * m_pTransData->fScaleY);
937 XFPoint aCtl2((double)m_aVector[2].x/TWIPS_PER_CM* m_pTransData->fScaleX,
938 (double)m_aVector[2].y/TWIPS_PER_CM * m_pTransData->fScaleY);
939 pArc->CurveTo(aDest, aCtl1, aCtl2);
940 // pArc->CurveTo(XFPoint((double)m_aVector[3].x/TWIPS_PER_CM, (double)m_aVector[3].y/TWIPS_PER_CM),
941 // XFPoint((double)m_aVector[1].x/TWIPS_PER_CM, (double)m_aVector[1].y/TWIPS_PER_CM),
942 // XFPoint((double)m_aVector[2].x/TWIPS_PER_CM, (double)m_aVector[2].y/TWIPS_PER_CM));
943 this->SetPosition(pArc);
945 pArc->SetStyleName(rStyleName);
947 return pArc;
950 XFFrame* LwpDrawArc::CreateStandardDrawObj(const OUString& rStyleName)
952 return this->CreateDrawObj(rStyleName);
956 * @descr Constructor of class LwpDrawTextBox
957 * @param pStream The memory stream which contains the lwp-sdw draw objects
959 LwpDrawTextBox::LwpDrawTextBox(SvStream* pStream) : LwpDrawObj(pStream)
963 LwpDrawTextBox::~LwpDrawTextBox()
965 if (m_aTextRec.pTextString)
967 delete [] m_aTextRec.pTextString;
968 m_aTextRec.pTextString = NULL;
972 void LwpDrawTextBox::SetFontStyle(XFFont* pFont, SdwTextBoxRecord* pRec)
974 // color
975 XFColor aXFColor(pRec->aTextColor.nR, pRec->aTextColor.nG,
976 pRec->aTextColor.nB);
977 pFont->SetColor(aXFColor);
978 //size
979 pFont->SetFontSize(pRec->nTextSize/20);
980 // bold
981 pFont->SetBold((sal_Bool)((pRec->nTextAttrs & TA_BOLD) != 0));
982 // italic
983 pFont->SetItalic((sal_Bool)((pRec->nTextAttrs & TA_ITALIC) != 0));
984 // strike-through
985 if (pRec->nTextAttrs & TA_STRIKETHRU)
987 pFont->SetCrossout(enumXFCrossoutSignel);
989 else
991 pFont->SetCrossout(enumXFCrossoutNone);
993 // underline
994 if (pRec->nTextAttrs & TA_UNDERLINE)
996 pFont->SetUnderline(enumXFUnderlineSingle);
998 else if (pRec->nTextAttrs & TA_WORDUNDERLINE)
1000 pFont->SetUnderline(enumXFUnderlineSingle, sal_True);
1002 else if (pRec->nTextAttrs & TA_DOUBLEUNDER)
1004 pFont->SetUnderline(enumXFUnderlineDouble);
1006 else
1008 pFont->SetUnderline(enumXFUnderlineNone);
1010 // small-caps
1011 if (pRec->nTextAttrs & TA_SMALLCAPS)
1013 pFont->SetTransform(enumXFTransformSmallCaps);
1018 * @descr reading function of class LwpDrawTextBox
1020 void LwpDrawTextBox::Read()
1022 m_pStream->Read(&m_aVector.x, 2);
1023 m_pStream->Read(&m_aVector.y, 2);
1024 m_pStream->Read(&m_aTextRec.nTextWidth, sizeof(m_aTextRec.nTextWidth));
1026 if (m_aTextRec.nTextWidth == 0)
1028 m_aTextRec.nTextWidth = 1;
1031 m_pStream->Read(&m_aTextRec.nTextHeight, sizeof(m_aTextRec.nTextHeight));
1032 m_pStream->Read(m_aTextRec.tmpTextFaceName, DRAW_FACESIZE);
1033 m_pStream->SeekRel(1);// PitchAndFamily
1035 m_pStream->Read(&m_aTextRec.nTextSize, sizeof(m_aTextRec.nTextSize));
1037 bool TextSizeIsCellHeight = true;
1038 if (m_aTextRec.nTextSize < 0)
1040 TextSizeIsCellHeight = false;
1041 m_aTextRec.nTextSize = -m_aTextRec.nTextSize;
1044 //color
1045 m_pStream->Read(&m_aTextRec.aTextColor.nR, 1);
1046 m_pStream->Read(&m_aTextRec.aTextColor.nG, 1);
1047 m_pStream->Read(&m_aTextRec.aTextColor.nB, 1);
1048 m_pStream->Read(&m_aTextRec.aTextColor.unused, 1);
1050 m_pStream->Read(&m_aTextRec.nTextAttrs, sizeof(m_aTextRec.nTextAttrs));
1051 m_pStream->Read(&m_aTextRec.nTextCharacterSet, sizeof(m_aTextRec.nTextCharacterSet));
1052 m_pStream->Read(&m_aTextRec.nTextRotation, sizeof(m_aTextRec.nTextRotation));
1053 m_pStream->Read(&m_aTextRec.nTextExtraSpacing, sizeof(m_aTextRec.nTextExtraSpacing));
1055 /*#ifdef JAPANESE_ENABLED //For Amipro Support KOBA-WADA
1056 lubyte compText[3];
1057 lsshort TextLength;
1058 lubyte * pTextString;
1059 cBinaryData.GetUBytes(compText, 2);
1060 compText[2] = '\0';
1061 if (compText[0] == 0 && compText[1] == 0 && recLen > 105 )
1063 // AmiPro R3.1J's extended text object format
1064 TextLength = recLen - 71 - 34;
1065 cBinaryData.SkipUBytes(32);
1067 pTextString = new lubyte[TextLength];
1069 LASSERT(pTextString != LNULL);
1071 cBinaryData.GetUBytes(pTextString, TextLength);
1073 else
1075 // AmiPro R3.X original text object format
1077 // some draw files in version 1.2 have an extra byte following '\0'.
1078 // can't rely on that, so read in the whole string into memory.
1079 TextLength = recLen - 71;
1080 pTextString = new lubyte[TextLength];
1082 LASSERT(pTextString != LNULL);
1084 strcpy((char *)pTextString, (const char *)compText);
1085 cBinaryData.GetUBytes(pTextString + 2, TextLength - 2);
1087 #else*/
1088 // some draw files in version 1.2 have an extra byte following '\0'.
1089 // can't rely on that, so read in the whole string into memory.
1091 // the 71 is the fixed length before text content in textbox record
1092 sal_Int16 TextLength = m_aObjHeader.nRecLen - 71;
1093 m_aTextRec.pTextString = new sal_uInt8 [TextLength];
1095 m_pStream->Read(m_aTextRec.pTextString, TextLength);
1097 //#endif // AmiPro
1101 rtl::OUString LwpDrawTextBox::RegisterStyle()
1103 XFParaStyle* pStyle = new XFParaStyle();
1105 // font style
1106 // the pFont need to be deleted myself?
1107 XFFont* pFont = new XFFont();
1109 rtl_TextEncoding aEncoding = RTL_TEXTENCODING_MS_1252;
1110 rtl::OUString aFontName = rtl::OUString((sal_Char*)m_aTextRec.tmpTextFaceName,
1111 strlen((char*)m_aTextRec.tmpTextFaceName), aEncoding);
1112 pFont->SetFontName(aFontName);
1114 this->SetFontStyle(pFont, &m_aTextRec);
1116 pStyle->SetFont(pFont);
1118 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1119 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
1122 XFFrame* LwpDrawTextBox::CreateDrawObj(const rtl::OUString& rStyleName )
1124 XFFrame* pTextBox = new XFFrame(sal_True);
1125 /* this->SetPosition(pTextBox);
1126 XFRect aBoundRect((double)m_aObjHeader.nLeft/TWIPS_PER_CM, (double)m_aObjHeader.nTop/TWIPS_PER_CM,
1127 (double)(m_aObjHeader.nRight-m_aObjHeader.nLeft)/TWIPS_PER_CM, (double)(m_aObjHeader.nBottom-m_aObjHeader.nTop)/TWIPS_PER_CM);
1128 pTextBox->SetPosition(aBoundRect);*/
1130 sal_Int16 TextLength = m_aObjHeader.nRecLen - 71;
1131 rtl_TextEncoding aEncoding;
1132 if (!m_aTextRec.nTextCharacterSet)
1134 aEncoding = gsl_getSystemTextEncoding();
1136 else
1138 // temporary code, need to create Encoding from the value of nTextCharacterSet
1139 aEncoding = LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
1142 // XFTextSpan* pTextSpan = new XFTextSpan();
1143 // pTextSpan->SetText(rtl::OUString((sal_Char*)m_aTextRec.pTextString, (TextLength-2), aEncoding));
1144 // pTextSpan->SetStyleName(rStyleName);
1146 XFParagraph* pXFPara = new XFParagraph();
1147 pXFPara->Add(rtl::OUString((sal_Char*)m_aTextRec.pTextString, (TextLength-2), aEncoding));
1148 pXFPara->SetStyleName(rStyleName);
1150 pTextBox->Add(pXFPara);
1151 this->SetPosition(pTextBox);
1154 XFFrameStyle* pBoxStyle = new XFFrameStyle();
1155 pBoxStyle->SetYPosType(enumXFFrameYPosFromTop, enumXFFrameYRelFrame);
1156 pBoxStyle->SetXPosType(enumXFFrameXPosFromLeft, enumXFFrameXRelFrame);
1157 pBoxStyle->SetPadding(0.0, 0.0, 0.0, 0.0);
1159 XFTextBoxStyle* pBoxStyle = new XFTextBoxStyle();
1161 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1162 OUString sName = pXFStyleManager->AddStyle(pBoxStyle)->GetStyleName();
1163 pTextBox->SetStyleName(sName);
1165 //todo: add the interface for rotating textbox
1166 // if (m_aTextRec.nTextRotation)
1167 // {
1168 // double fAngle = double(3600-m_aTextRec.nTextRotation)/10;
1169 // pTextBox->SetRotate(fAngle);
1170 // }
1172 return pTextBox;
1175 XFFrame* LwpDrawTextBox::CreateStandardDrawObj(const OUString& rStyleName)
1177 return this->CreateDrawObj(rStyleName);
1181 * @descr Constructor of class LwpDrawTextBox
1182 * @param pStream The memory stream which contains the lwp-sdw draw objects
1184 LwpDrawTextArt::LwpDrawTextArt(SvStream* pStream, DrawingOffsetAndScale* pTransData)
1185 : LwpDrawObj(pStream, pTransData)
1189 LwpDrawTextArt::~LwpDrawTextArt()
1191 if (m_aTextArtRec.aPath[0].pPts)
1193 delete [] m_aTextArtRec.aPath[0].pPts;
1194 m_aTextArtRec.aPath[0].pPts = NULL;
1196 if (m_aTextArtRec.aPath[1].pPts)
1198 delete [] m_aTextArtRec.aPath[1].pPts;
1199 m_aTextArtRec.aPath[1].pPts = NULL;
1201 if (m_aTextArtRec.pTextString)
1203 delete [] m_aTextArtRec.pTextString;
1204 m_aTextArtRec.pTextString = NULL;
1209 void LwpDrawTextArt::CreateFWPath(XFDrawPath* pPath)
1211 sal_Int16 nX, nY;
1212 nX = (m_aTextArtRec.aPath[0].pPts[0].x + m_aTextArtRec.aPath[1].pPts[0].x) / 2;
1213 nY = (m_aTextArtRec.aPath[0].pPts[0].y + m_aTextArtRec.aPath[1].pPts[0].y) / 2;
1214 XFPoint aStart((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1215 (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1216 pPath->MoveTo(aStart);
1218 sal_uInt8 nPtIndex = 1;
1219 for (sal_uInt8 nC = 1; nC <= m_aTextArtRec.aPath[0].n; nC++)
1221 nX = (m_aTextArtRec.aPath[0].pPts[nPtIndex].x + m_aTextArtRec.aPath[1].pPts[nPtIndex].x) / 2;
1222 nY = (m_aTextArtRec.aPath[0].pPts[nPtIndex].y + m_aTextArtRec.aPath[1].pPts[nPtIndex].y) / 2;
1223 XFPoint aCtrl1((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1224 (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1226 nPtIndex++;
1227 nX = (m_aTextArtRec.aPath[0].pPts[nPtIndex].x + m_aTextArtRec.aPath[1].pPts[nPtIndex].x) / 2;
1228 nY = (m_aTextArtRec.aPath[0].pPts[nPtIndex].y + m_aTextArtRec.aPath[1].pPts[nPtIndex].y) / 2;
1229 XFPoint aCtrl2((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1230 (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1232 nPtIndex++;
1233 nX = (m_aTextArtRec.aPath[0].pPts[nPtIndex].x + m_aTextArtRec.aPath[1].pPts[nPtIndex].x) / 2;
1234 nY = (m_aTextArtRec.aPath[0].pPts[nPtIndex].y + m_aTextArtRec.aPath[1].pPts[nPtIndex].y) / 2;
1235 XFPoint aDest((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1236 (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1238 pPath->CurveTo(aDest, aCtrl1, aCtrl2);
1242 void LwpDrawTextArt::Read()
1244 for (sal_uInt8 nC = 0; nC < 4; nC++)
1246 m_pStream->Read(&m_aVector[nC].x, 2);
1247 m_pStream->Read(&m_aVector[nC].y, 2);
1250 this->ReadClosedObjStyle();
1251 m_aTextArtRec.aTextColor = m_aClosedObjStyleRec.aForeColor;
1253 m_pStream->Read(&m_aTextArtRec.nIndex, 1);
1254 m_pStream->Read(&m_aTextArtRec.nRotation, 2);
1256 sal_uInt16 nPointNumber;
1257 sal_Int16 nX, nY;
1258 m_pStream->Read(&nPointNumber, 2);
1259 m_aTextArtRec.aPath[0].n = nPointNumber;
1260 m_aTextArtRec.aPath[0].pPts = new SdwPoint [nPointNumber*3+1];
1261 sal_uInt16 nPt = 0;
1262 for ( nPt = 0; nPt <= nPointNumber*3; nPt++)
1264 m_pStream->Read(&nX, 2);
1265 m_pStream->Read(&nY, 2);
1266 m_aTextArtRec.aPath[0].pPts[nPt].x = nX;
1267 m_aTextArtRec.aPath[0].pPts[nPt].y = nY;
1270 m_pStream->Read(&nPointNumber, 2);
1271 m_aTextArtRec.aPath[1].n = nPointNumber;
1272 m_aTextArtRec.aPath[1].pPts = new SdwPoint [nPointNumber*3+1];
1273 for (nPt = 0; nPt <= nPointNumber*3; nPt++)
1275 m_pStream->Read(&nX, 2);
1276 m_pStream->Read(&nY, 2);
1277 m_aTextArtRec.aPath[1].pPts[nPt].x = nX;
1278 m_aTextArtRec.aPath[1].pPts[nPt].y = nY;
1281 m_pStream->SeekRel(1);
1283 m_pStream->Read(m_aTextArtRec.tmpTextFaceName, DRAW_FACESIZE);
1284 m_pStream->SeekRel(1);// PitchAndFamily
1286 m_pStream->Read(&m_aTextArtRec.nTextSize, sizeof(m_aTextArtRec.nTextSize));
1287 bool TextSizeIsCellHeight = true;
1288 if (m_aTextArtRec.nTextSize < 0)
1290 TextSizeIsCellHeight = false;
1291 m_aTextArtRec.nTextSize = -m_aTextArtRec.nTextSize;
1294 m_pStream->Read(&m_aTextArtRec.nTextAttrs, sizeof(m_aTextArtRec.nTextAttrs));
1295 m_pStream->Read(&m_aTextArtRec.nTextCharacterSet, sizeof(m_aTextArtRec.nTextCharacterSet));
1296 // m_pStream->Read(&m_aTextArtRec.nTextRotation, sizeof(m_aTextArtRec.nTextRotation));
1297 m_aTextArtRec.nTextRotation = 0;
1298 m_pStream->Read(&m_aTextArtRec.nTextExtraSpacing, sizeof(m_aTextArtRec.nTextExtraSpacing));
1300 const sal_uInt16 nTextArtFixedLength = 105;
1301 m_aTextArtRec.nTextLen = m_aObjHeader.nRecLen - nTextArtFixedLength
1302 - (m_aTextArtRec.aPath[0].n*3 + 1)*4
1303 - (m_aTextArtRec.aPath[1].n*3 + 1)*4;
1305 m_aTextArtRec.pTextString = new sal_uInt8 [m_aTextArtRec.nTextLen];
1306 m_pStream->Read(m_aTextArtRec.pTextString, m_aTextArtRec.nTextLen);
1307 m_aTextArtRec.pTextString[m_aTextArtRec.nTextLen-1] = 0;
1311 rtl::OUString LwpDrawTextArt::RegisterStyle()
1313 XFParaStyle* pStyle = new XFParaStyle();
1315 // font style
1316 // the pFont need to be deleted myself?
1317 XFFont* pFont = new XFFont();
1319 rtl_TextEncoding aEncoding = RTL_TEXTENCODING_MS_1252;
1320 rtl::OUString aFontName = rtl::OUString((sal_Char*)m_aTextArtRec.tmpTextFaceName,
1321 strlen((char*)m_aTextArtRec.tmpTextFaceName), aEncoding);
1322 pFont->SetFontName(aFontName);
1324 LwpDrawTextBox::SetFontStyle(pFont, &m_aTextArtRec);
1326 pStyle->SetFont(pFont);
1328 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1329 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
1332 XFFrame* LwpDrawTextArt::CreateDrawObj(const rtl::OUString& rStyleName)
1334 XFFrame* pRetObj = NULL;
1335 XFDrawStyle* pStyle = new XFDrawStyle();
1337 pRetObj = new XFDrawPath();
1338 XFDrawPath* pFWPath = static_cast<XFDrawPath*>(pRetObj);
1339 this->CreateFWPath(pFWPath);
1340 pStyle->SetFontWorkStyle(0, enumXFFWSlantY, enumXFFWAdjustAutosize);
1342 this->SetPosition(pRetObj);
1344 rtl_TextEncoding aEncoding;
1345 if (!m_aTextArtRec.nTextCharacterSet)
1347 aEncoding = gsl_getSystemTextEncoding();
1349 else
1351 // temporary code, need to create Encoding from the value of nTextCharacterSet
1352 aEncoding = LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
1355 XFParagraph* pXFPara = new XFParagraph();
1356 pXFPara->Add(rtl::OUString((sal_Char*)m_aTextArtRec.pTextString, (m_aTextArtRec.nTextLen-1), aEncoding));
1357 pXFPara->SetStyleName(rStyleName);
1358 pRetObj->Add(pXFPara);
1360 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1361 pRetObj->SetStyleName(pXFStyleManager->AddStyle(pStyle)->GetStyleName());
1363 return pRetObj;
1366 XFFrame* LwpDrawTextArt::CreateStandardDrawObj(const rtl::OUString& rStyleName )
1368 return this->CreateDrawObj(rStyleName);
1373 * @descr Constructor of class LwpDrawMetafile
1374 * @param pStream The memory stream which contains the lwp-sdw draw objects
1376 LwpDrawMetafile::LwpDrawMetafile(SvStream* pStream) : LwpDrawObj(pStream)
1381 * @descr reading function of class LwpDrawMetafile
1383 void LwpDrawMetafile::Read()
1385 m_pStream->SeekRel(m_aObjHeader.nRecLen -16);
1389 * @descr Constructor of class LwpDrawBitmap
1390 * @param pStream The memory stream which contains the lwp-sdw draw objects
1392 LwpDrawBitmap::LwpDrawBitmap(SvStream* pStream) : LwpDrawObj(pStream), m_pImageData(NULL)
1396 LwpDrawBitmap::~LwpDrawBitmap()
1398 if (m_pImageData)
1400 delete [] m_pImageData;
1401 m_pImageData = NULL;
1406 * @descr reading function of class LwpDrawBitmap
1408 void LwpDrawBitmap::Read()
1410 m_pStream->Read(&m_aBmpRec.nTranslation, sizeof(m_aBmpRec.nTranslation));
1411 m_pStream->Read(&m_aBmpRec.nRotation, sizeof(m_aBmpRec.nRotation));
1413 // 20 == length of draw-specific fields.
1414 // 14 == length of bmp file header.
1415 m_aBmpRec.nFileSize = m_aObjHeader.nRecLen - 20 + 14;
1416 m_pImageData = new sal_uInt8 [m_aBmpRec.nFileSize];
1418 BmpInfoHeader2 aInfoHeader2;
1419 m_pStream->Read(&aInfoHeader2.nHeaderLen, 4);
1421 sal_uInt32 N;
1422 sal_uInt32 rgbTableSize;
1424 if (aInfoHeader2.nHeaderLen == sizeof(BmpInfoHeader))
1426 m_pStream->Read(&aInfoHeader2.nWidth, 2);
1427 m_pStream->Read(&aInfoHeader2.nHeight, 2);
1428 m_pStream->Read(&aInfoHeader2.nPlanes, 2);
1429 m_pStream->Read(&aInfoHeader2.nBitCount, 2);
1431 N = aInfoHeader2.nPlanes * aInfoHeader2.nBitCount;
1432 if (N == 24)
1434 rgbTableSize = 0;
1436 else
1438 rgbTableSize = 3 * (1 << N);
1441 else
1443 m_pStream->Read(&aInfoHeader2.nWidth, 4);
1444 m_pStream->Read(&aInfoHeader2.nHeight, 4);
1445 m_pStream->Read(&aInfoHeader2.nPlanes, 2);
1446 m_pStream->Read(&aInfoHeader2.nBitCount, 2);
1447 N = aInfoHeader2.nPlanes * aInfoHeader2.nBitCount;
1448 if (N == 24)
1450 rgbTableSize = 0;
1452 else
1454 rgbTableSize = 4 * (1 << N);
1459 sal_uInt32 nOffBits = 14 + aInfoHeader2.nHeaderLen + rgbTableSize;
1460 m_pImageData[0] = 'B';
1461 m_pImageData[1] = 'M';
1462 m_pImageData[2] = (sal_uInt8)m_aBmpRec.nFileSize;
1463 m_pImageData[3] = (sal_uInt8)(m_aBmpRec.nFileSize >> 8);
1464 m_pImageData[4] = (sal_uInt8)(m_aBmpRec.nFileSize >> 16);
1465 m_pImageData[5] = (sal_uInt8)(m_aBmpRec.nFileSize >> 24);
1466 m_pImageData[6] = 0;
1467 m_pImageData[7] = 0;
1468 m_pImageData[8] = 0;
1469 m_pImageData[9] = 0;
1470 m_pImageData[10] = (sal_uInt8)nOffBits;
1471 m_pImageData[11] = (sal_uInt8)(nOffBits >> 8);
1472 m_pImageData[12] = (sal_uInt8)(nOffBits >> 16);
1473 m_pImageData[13] = (sal_uInt8)(nOffBits >> 24);
1475 sal_uInt32 nDIBRemaining;
1476 sal_uInt8* pPicData = m_pImageData;
1477 if (aInfoHeader2.nHeaderLen== sizeof(BmpInfoHeader))
1479 m_pImageData[14] = (sal_uInt8)aInfoHeader2.nHeaderLen;
1480 m_pImageData[15] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 8);
1481 m_pImageData[16] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 16);
1482 m_pImageData[17] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 24);
1483 m_pImageData[18] = (sal_uInt8)aInfoHeader2.nWidth;
1484 m_pImageData[19] = (sal_uInt8)(aInfoHeader2.nWidth >> 8);
1485 m_pImageData[20] = (sal_uInt8)aInfoHeader2.nHeight;
1486 m_pImageData[21] = (sal_uInt8)(aInfoHeader2.nHeight >> 8);
1487 m_pImageData[22] = (sal_uInt8)aInfoHeader2.nPlanes;
1488 m_pImageData[23] = (sal_uInt8)(aInfoHeader2.nPlanes >> 8);
1489 m_pImageData[24] = (sal_uInt8)aInfoHeader2.nBitCount;
1490 m_pImageData[25] = (sal_uInt8)(aInfoHeader2.nBitCount >> 8);
1492 nDIBRemaining = m_aBmpRec.nFileSize - 26;
1493 pPicData += 26*sizeof(sal_uInt8);
1495 else
1497 m_pImageData[14] = (sal_uInt8)aInfoHeader2.nHeaderLen;
1498 m_pImageData[15] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 8);
1499 m_pImageData[16] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 16);
1500 m_pImageData[17] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 24);
1501 m_pImageData[18] = (sal_uInt8)aInfoHeader2.nWidth;
1502 m_pImageData[19] = (sal_uInt8)(aInfoHeader2.nWidth >> 8);
1503 m_pImageData[20] = (sal_uInt8)(aInfoHeader2.nWidth >> 16);
1504 m_pImageData[21] = (sal_uInt8)(aInfoHeader2.nWidth >> 24);
1505 m_pImageData[22] = (sal_uInt8)aInfoHeader2.nHeight;
1506 m_pImageData[23] = (sal_uInt8)(aInfoHeader2.nHeight >> 8);
1507 m_pImageData[24] = (sal_uInt8)(aInfoHeader2.nHeight >> 16);
1508 m_pImageData[25] = (sal_uInt8)(aInfoHeader2.nHeight >> 24);
1509 m_pImageData[26] = (sal_uInt8)aInfoHeader2.nPlanes;
1510 m_pImageData[27] = (sal_uInt8)(aInfoHeader2.nPlanes >> 8);
1511 m_pImageData[28] = (sal_uInt8)aInfoHeader2.nBitCount;
1512 m_pImageData[29] = (sal_uInt8)(aInfoHeader2.nBitCount >> 8);
1514 nDIBRemaining = m_aBmpRec.nFileSize - 30;
1515 pPicData += 30*sizeof(sal_uInt8);
1518 m_pStream->Read(pPicData, nDIBRemaining);
1520 /* FILE* pStream;
1521 pStream = fopen( "drawing_test.bmp", "w+" );
1522 fwrite(m_pImageData, sizeof(sal_uInt8), m_aBmpRec.nFileSize, pStream);
1523 fclose( pStream );
1527 rtl::OUString LwpDrawBitmap::RegisterStyle()
1529 XFImageStyle* pBmpStyle = new XFImageStyle();
1530 pBmpStyle->SetYPosType(enumXFFrameYPosFromTop, enumXFFrameYRelFrame);
1531 pBmpStyle->SetXPosType(enumXFFrameXPosFromLeft, enumXFFrameXRelFrame);
1533 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1534 return pXFStyleManager->AddStyle(pBmpStyle)->GetStyleName();
1537 XFFrame* LwpDrawBitmap::CreateDrawObj(const rtl::OUString& rStyleName)
1539 XFImage* pImage = new XFImage();
1540 pImage->SetImageData(m_pImageData, m_aBmpRec.nFileSize);
1541 this->SetPosition(pImage);
1543 pImage->SetStyleName(rStyleName);
1545 return pImage;
1548 XFFrame* LwpDrawBitmap::CreateStandardDrawObj(const OUString& rStyleName)
1550 return this->CreateDrawObj(rStyleName);