Bump version to 4.3-4
[LibreOffice.git] / lotuswordpro / source / filter / lwpdrawobj.cxx
blobd3ac87db2bb8d6ee661d026aa943a53ecd2fd102
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,
29 * MA 02111-1307 USA
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 /**
57 * @file
58 * Implementation file of LwpDrawObjcts and associated class like LwpDrawGroup, LwpDrawRectange
59 * and so on.
61 #include <osl/thread.h>
62 #include "lwpglobalmgr.hxx"
63 #include "lwpdrawobj.hxx"
64 #include "lwptools.hxx"
65 #include <tools/stream.hxx>
67 #include "xfilter/xfframe.hxx"
69 #include "xfilter/xfstylemanager.hxx"
70 #include "xfilter/xfdrawstyle.hxx"
71 #include "xfilter/xftextstyle.hxx"
72 #include "xfilter/xfparastyle.hxx"
73 #include "xfilter/xfimagestyle.hxx"
74 #include "xfilter/xftextboxstyle.hxx"
75 #include "xfilter/xfparagraph.hxx"
76 #include "xfilter/xftextspan.hxx"
77 #include "xfilter/xffont.hxx"
79 #include "xfilter/xfdrawrect.hxx"
80 #include "xfilter/xfdrawpath.hxx"
81 #include "xfilter/xfdrawline.hxx"
82 #include "xfilter/xfdrawpolygon.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_eType(OT_UNDEFINED)
94 , m_pStream(pStream)
95 , m_pTransData(pTransData)
97 this->ReadObjHeaderRecord();
101 * @descr read the header record data of lwp-sdw-object
103 void LwpDrawObj::ReadObjHeaderRecord()
105 //flags
106 m_pStream->SeekRel(1);
108 //record Length
109 m_pStream->ReadUInt16( m_aObjHeader.nRecLen );
111 //boundrect
112 m_pStream->ReadInt16( m_aObjHeader.nLeft );
113 m_pStream->ReadInt16( m_aObjHeader.nTop );
114 m_pStream->ReadInt16( m_aObjHeader.nRight );
115 m_pStream->ReadInt16( m_aObjHeader.nBottom );
117 //nextObj, prevObj
118 m_pStream->SeekRel(4);
122 * @descr read the style of closed lwp-sdw-object like: rectangle, ellipse and so on.
124 void LwpDrawObj::ReadClosedObjStyle()
126 if ((m_eType != OT_POLYGON) && (m_eType != OT_TEXTART))
128 m_pStream->SeekRel(8);
131 m_pStream->ReadUChar( m_aClosedObjStyleRec.nLineWidth );
132 m_pStream->ReadUChar( m_aClosedObjStyleRec.nLineStyle );
134 // pen color
135 m_pStream->ReadUChar( m_aClosedObjStyleRec.aPenColor.nR );
136 m_pStream->ReadUChar( m_aClosedObjStyleRec.aPenColor.nG );
137 m_pStream->ReadUChar( m_aClosedObjStyleRec.aPenColor.nB );
138 m_pStream->ReadUChar( m_aClosedObjStyleRec.aPenColor.unused );
140 // foreground color
141 m_pStream->ReadUChar( m_aClosedObjStyleRec.aForeColor.nR );
142 m_pStream->ReadUChar( m_aClosedObjStyleRec.aForeColor.nG );
143 m_pStream->ReadUChar( m_aClosedObjStyleRec.aForeColor.nB );
144 m_pStream->ReadUChar( m_aClosedObjStyleRec.aForeColor.unused );
146 // background color
147 m_pStream->ReadUChar( m_aClosedObjStyleRec.aBackColor.nR );
148 m_pStream->ReadUChar( m_aClosedObjStyleRec.aBackColor.nG );
149 m_pStream->ReadUChar( m_aClosedObjStyleRec.aBackColor.nB );
150 m_pStream->ReadUChar( m_aClosedObjStyleRec.aBackColor.unused );
152 // fill style
153 m_pStream->ReadUInt16( m_aClosedObjStyleRec.nFillType );
154 m_pStream->Read(m_aClosedObjStyleRec.pFillPattern,
155 sizeof(m_aClosedObjStyleRec.pFillPattern));
159 * @descr set fill style of drawing objects
160 * @param pStyle pointer of the drawing xfstyle.
162 void LwpDrawObj::SetFillStyle(XFDrawStyle* pStyle)
164 if (!pStyle)
166 assert(false);
167 return;
170 XFColor aForeColor(m_aClosedObjStyleRec.aForeColor.nR,
171 m_aClosedObjStyleRec.aForeColor.nG, m_aClosedObjStyleRec.aForeColor.nB);
172 XFColor aBackColor(m_aClosedObjStyleRec.aBackColor.nR,
173 m_aClosedObjStyleRec.aBackColor.nG, m_aClosedObjStyleRec.aBackColor.nB);
175 switch (m_aClosedObjStyleRec.nFillType)
177 default: //fall through!
178 case FT_TRANSPARENT:
180 // set fill style : none
181 break;
183 case FT_SOLID:
185 pStyle->SetAreaColor(aForeColor);
186 break;
188 case FT_HORZHATCH:
190 pStyle->SetAreaColor(aBackColor);
191 pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 0, 0.12, aForeColor);
192 break;
194 case FT_VERTHATCH:
196 pStyle->SetAreaColor(aBackColor);
197 pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 90, 0.12, aForeColor);
198 break;
200 case FT_FDIAGHATCH:
202 pStyle->SetAreaColor(aBackColor);
203 pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 135, 0.09, aForeColor);
204 break;
206 case FT_BDIAGHATCH:
208 pStyle->SetAreaColor(aBackColor);
209 pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 45, 0.09, aForeColor);
210 break;
212 case FT_CROSSHATCH:
214 pStyle->SetAreaColor(aBackColor);
215 pStyle->SetAreaLineStyle(enumXFAreaLineCrossed, 0, 0.12, aForeColor);
216 break;
218 case FT_DIAGCROSSHATCH:
220 pStyle->SetAreaColor(aBackColor);
221 pStyle->SetAreaLineStyle(enumXFAreaLineCrossed, 45, 0.095, aForeColor);
222 break;
228 * @descr set line/border style of drawing objects.
229 * @param pStyle pointer of the drawing xfstyle.
230 * @param nWidth width of line/border.
231 * @param nLineStyle flag of line/border style: none, dot or solid.
232 * @param rColor color of line/border.
234 void LwpDrawObj::SetLineStyle(XFDrawStyle* pStyle, sal_uInt8 nWidth, sal_uInt8 nLineStyle,
235 const SdwColor& rColor)
237 if (!pStyle)
239 assert(false);
240 return;
242 if (nWidth == 0)
244 nLineStyle = LS_NULL;
247 if (nLineStyle == LS_NULL)
249 // set stroke:none
250 return;
253 if (nLineStyle == LS_DOT)
255 pStyle->SetLineDashStyle(enumXFLineDash, 1, 1, 0.05, 0.05, 0.05);
258 // line width
259 double fWidth = (double)nWidth/TWIPS_PER_CM;
261 // line color
262 XFColor aXFColor(rColor.nR, rColor.nG, rColor.nB);
264 pStyle->SetLineStyle(fWidth, aXFColor);
268 * @descr set position of a drawing object in the frame.
269 * @param pObj pointer of the xf-drawing object
271 void LwpDrawObj::SetPosition(XFFrame* pObj)
273 double fOffsetX = 0.00, fOffsetY = 0.00;
274 double fScaleX = 1.00, fScaleY = 1.00;
275 if (m_pTransData)
277 fOffsetX = m_pTransData->fOffsetX;
278 fOffsetY = m_pTransData->fOffsetY;
279 fScaleX = m_pTransData->fScaleX;
280 fScaleY = m_pTransData->fScaleY;
283 pObj->SetPosition((double)m_aObjHeader.nLeft/TWIPS_PER_CM * fScaleX+ fOffsetX,
284 (double)m_aObjHeader.nTop/TWIPS_PER_CM * fScaleY + fOffsetY,
285 (double)(m_aObjHeader.nRight-m_aObjHeader.nLeft)/TWIPS_PER_CM * fScaleX,
286 (double)(m_aObjHeader.nBottom-m_aObjHeader.nTop)/TWIPS_PER_CM * fScaleY);
290 * @descr set arrowhead of a xf-drawing object. only opened drawing objects can be assigned arrowheads
291 * @param pOpenedObjStyle the xf-drawing object which will be set arrowhead.
292 * @param nArrowFlag arrowhead flags of the object.
294 void LwpDrawObj::SetArrowHead(XFDrawStyle* pOpenedObjStyle, sal_uInt8 nArrowFlag, sal_uInt8 nLineWidth)
296 // no arrowhead
297 if (!nArrowFlag)
299 return;
302 if (!pOpenedObjStyle)
304 assert(false);
305 return;
308 // arrowhead flag of an object's start side
309 sal_uInt8 nLeftArrow = nArrowFlag & 0x0F;
311 // arrowhead flag of an object's end side
312 sal_uInt8 nRightArrow = (nArrowFlag & 0xF0) >> 4;
314 double fWidth_inch = (double)nLineWidth/TWIPS_PER_CM;
315 double fArrowSize_inch = fWidth_inch + 0.08;
316 double fArrowSize = fArrowSize_inch * CM_PER_INCH;
318 if (nLeftArrow)
320 pOpenedObjStyle->SetArrowStart( this->GetArrowName(nLeftArrow), fArrowSize, true);
322 if (nRightArrow)
324 pOpenedObjStyle->SetArrowEnd( this->GetArrowName(nRightArrow), fArrowSize, true);
330 * @descr get arrow style name according to the flag.
331 * @param nArrowStyle style of the arrowhead.
332 * @return nWhichSide style name of the arrowhead.
334 OUString LwpDrawObj::GetArrowName(sal_uInt8 nArrowStyle)
336 // style name of arrowhead
337 OUString aArrowName;
339 switch(nArrowStyle)
341 default:
342 case AH_ARROW_FULLARROW:
343 aArrowName = "Symmetric arrow";
344 break;
345 case AH_ARROW_HALFARROW:
346 aArrowName = "Arrow concave";
347 break;
348 case AH_ARROW_LINEARROW:
349 aArrowName = "arrow100";
350 break;
351 case AH_ARROW_INVFULLARROW:
352 aArrowName = "reverse arrow";
353 break;
354 case AH_ARROW_INVHALFARROW:
355 aArrowName = "reverse concave arrow";
356 break;
357 case AH_ARROW_INVLINEARROW:
358 aArrowName = "reverse line arrow";
359 break;
360 case AH_ARROW_TEE:
361 aArrowName = "Dimension lines";
362 break;
363 case AH_ARROW_SQUARE:
364 aArrowName = "Square";
365 break;
366 case AH_ARROW_CIRCLE:
367 aArrowName = "Circle";
368 break;
371 return aArrowName;
375 * @descr template method of creating drawing object from Lwp-Model to XF-Model
376 * @return pointer of the drawing object of XF-Model.
378 XFFrame* LwpDrawObj::CreateXFDrawObject()
380 // read records
381 this->Read();
383 // register style
384 OUString aStyleName = this->RegisterStyle();
386 // create XF-Objects
387 XFFrame* pXFObj = NULL;
388 if (m_pTransData
389 && FABS(m_pTransData->fOffsetX - m_pTransData->fLeftMargin) < THRESHOLD
390 && FABS(m_pTransData->fOffsetY - m_pTransData->fTopMargin) < THRESHOLD
391 && FABS(m_pTransData->fScaleX - 1.0) < THRESHOLD
392 && FABS(m_pTransData->fScaleY - 1.0) < THRESHOLD)
394 pXFObj = this->CreateStandardDrawObj(aStyleName);
396 else
398 pXFObj = this->CreateDrawObj(aStyleName);
401 // set anchor type
402 if (pXFObj)
404 pXFObj->SetAnchorType(enumXFAnchorFrame);
407 return pXFObj;
411 * @descr Constructor of class LwpDrawLine
412 * @param pStream The memory stream which contains the lwp-sdw draw objects
414 LwpDrawLine::LwpDrawLine(SvStream * pStream, DrawingOffsetAndScale* pTransData)
415 : LwpDrawObj(pStream, pTransData)
420 * @descr reading function of class LwpDrawLine
422 void LwpDrawLine::Read()
424 m_pStream->ReadInt16( m_aLineRec.nStartX );
425 m_pStream->ReadInt16( m_aLineRec.nStartY );
426 m_pStream->ReadInt16( m_aLineRec.nEndX );
427 m_pStream->ReadInt16( m_aLineRec.nEndY );
428 m_pStream->ReadUChar( m_aLineRec.nLineWidth );
429 m_pStream->ReadUChar( m_aLineRec.nLineEnd );
430 m_pStream->ReadUChar( m_aLineRec.nLineStyle );
432 m_pStream->ReadUChar( m_aLineRec.aPenColor.nR );
433 m_pStream->ReadUChar( m_aLineRec.aPenColor.nG );
434 m_pStream->ReadUChar( m_aLineRec.aPenColor.nB );
435 m_pStream->ReadUChar( m_aLineRec.aPenColor.unused );
438 OUString LwpDrawLine::RegisterStyle()
440 XFDrawStyle* pStyle = new XFDrawStyle();
442 // set line style
443 this->SetLineStyle(pStyle, m_aLineRec.nLineWidth, m_aLineRec.nLineStyle, m_aLineRec.aPenColor);
445 // set arrow head
446 this->SetArrowHead(pStyle, m_aLineRec.nLineEnd, m_aLineRec.nLineWidth);
448 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
449 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
453 XFFrame* LwpDrawLine::CreateDrawObj(const OUString& rStyleName )
455 XFDrawPath* pLine = new XFDrawPath();
456 pLine->MoveTo(XFPoint((double)(m_aLineRec.nStartX)/TWIPS_PER_CM * m_pTransData->fScaleX,
457 (double)(m_aLineRec.nStartY)/TWIPS_PER_CM * m_pTransData->fScaleY));
458 pLine->LineTo(XFPoint((double)(m_aLineRec.nEndX)/TWIPS_PER_CM * m_pTransData->fScaleX,
459 (double)(m_aLineRec.nEndY)/TWIPS_PER_CM * m_pTransData->fScaleY));
460 this->SetPosition(pLine);
462 pLine->SetStyleName(rStyleName);
464 return pLine;
467 XFFrame* LwpDrawLine::CreateStandardDrawObj(const OUString& rStyleName)
469 XFDrawLine* pLine = new XFDrawLine();
470 pLine->SetStartPoint((double)(m_aLineRec.nStartX)/TWIPS_PER_CM,(double)(m_aLineRec.nStartY)/TWIPS_PER_CM);
471 pLine->SetEndPoint((double)(m_aLineRec.nEndX)/TWIPS_PER_CM,(double)(m_aLineRec.nEndY)/TWIPS_PER_CM);
473 pLine->SetStyleName(rStyleName);
474 return pLine;
478 * @descr Constructor of class LwpDrawPolyLine
479 * @param pStream The memory stream which contains the lwp-sdw draw objects
481 LwpDrawPolyLine::LwpDrawPolyLine(SvStream * pStream, DrawingOffsetAndScale* pTransData)
482 : LwpDrawObj(pStream, pTransData), m_pVector(NULL)
485 LwpDrawPolyLine::~LwpDrawPolyLine()
487 if (m_pVector)
489 delete [] m_pVector;
490 m_pVector = NULL;
495 * @descr reading function of class LwpDrawPolyLine
497 void LwpDrawPolyLine::Read()
499 m_pStream->ReadUChar( m_aPolyLineRec.nLineWidth );
500 m_pStream->ReadUChar( m_aPolyLineRec.nLineEnd );
501 m_pStream->ReadUChar( m_aPolyLineRec.nLineStyle );
502 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.nR );
503 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.nG );
504 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.nB );
505 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.unused );
506 m_pStream->ReadUInt16( m_aPolyLineRec.nNumPoints );
508 m_pVector= new SdwPoint [m_aPolyLineRec.nNumPoints];
510 for (sal_uInt16 nC = 0; nC < m_aPolyLineRec.nNumPoints; nC++)
512 m_pStream->ReadInt16( m_pVector[nC].x );
513 m_pStream->ReadInt16( m_pVector[nC].y );
517 OUString LwpDrawPolyLine::RegisterStyle()
519 XFDrawStyle* pStyle = new XFDrawStyle();
521 // set line style
522 this->SetLineStyle(pStyle, m_aPolyLineRec.nLineWidth, m_aPolyLineRec.nLineStyle,
523 m_aPolyLineRec.aPenColor);
525 // set arrow head
526 this->SetArrowHead(pStyle, m_aPolyLineRec.nLineEnd, m_aPolyLineRec.nLineWidth);
528 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
529 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
532 XFFrame* LwpDrawPolyLine::CreateDrawObj(const OUString& rStyleName )
534 XFDrawPath* pPolyline = new XFDrawPath();
535 pPolyline->MoveTo(XFPoint((double)m_pVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
536 (double)m_pVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
537 for (sal_uInt8 nC = 1; nC < m_aPolyLineRec.nNumPoints; nC++)
539 pPolyline->LineTo(XFPoint((double)m_pVector[nC].x/TWIPS_PER_CM * m_pTransData->fScaleX,
540 (double)m_pVector[nC].y/TWIPS_PER_CM * m_pTransData->fScaleY));
542 this->SetPosition(pPolyline);
544 pPolyline->SetStyleName(rStyleName);
546 return pPolyline;
549 XFFrame* LwpDrawPolyLine::CreateStandardDrawObj(const OUString& rStyleName)
551 XFDrawPolyline* pPolyline = new XFDrawPolyline();
552 for (sal_uInt8 nC = 0; nC < m_aPolyLineRec.nNumPoints; nC++)
554 pPolyline->AddPoint((double)m_pVector[nC].x/TWIPS_PER_CM,
555 (double)m_pVector[nC].y/TWIPS_PER_CM);
558 pPolyline->SetStyleName(rStyleName);
560 return pPolyline;
564 * @descr Constructor of class LwpDrawPolygon
565 * @param pStream The memory stream which contains the lwp-sdw draw objects
567 LwpDrawPolygon::LwpDrawPolygon(SvStream * pStream, DrawingOffsetAndScale* pTransData)
568 : LwpDrawObj(pStream, pTransData)
569 , m_nNumPoints(0)
570 , m_pVector(NULL)
574 LwpDrawPolygon::~LwpDrawPolygon()
576 if (m_pVector)
578 delete [] m_pVector;
579 m_pVector = NULL;
584 * @descr reading function of class LwpDrawPolygon
586 void LwpDrawPolygon::Read()
588 this->ReadClosedObjStyle();
589 m_pStream->ReadUInt16( m_nNumPoints );
591 m_pVector = new SdwPoint [m_nNumPoints];
593 for (sal_uInt16 nC = 0; nC < m_nNumPoints; nC++)
595 m_pStream->ReadInt16( m_pVector[nC].x );
596 m_pStream->ReadInt16( m_pVector[nC].y );
600 OUString LwpDrawPolygon::RegisterStyle()
602 XFDrawStyle* pStyle = new XFDrawStyle();
604 // set line style
605 this->SetLineStyle(pStyle, m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
606 m_aClosedObjStyleRec.aPenColor);
608 // set fill style
609 this->SetFillStyle(pStyle);
611 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
612 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
615 XFFrame* LwpDrawPolygon::CreateDrawObj(const OUString& rStyleName)
617 XFDrawPath* pPolygon = new XFDrawPath();
618 pPolygon->MoveTo(XFPoint((double)m_pVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
619 (double)m_pVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
620 for (sal_uInt16 nC = 1; nC < m_nNumPoints; nC++)
622 pPolygon->LineTo(XFPoint((double)m_pVector[nC].x/TWIPS_PER_CM * m_pTransData->fScaleX,
623 (double)m_pVector[nC].y/TWIPS_PER_CM * m_pTransData->fScaleY));
625 pPolygon->ClosePath();
626 this->SetPosition(pPolygon);
627 pPolygon->SetStyleName(rStyleName);
629 return pPolygon;
632 XFFrame* LwpDrawPolygon::CreateStandardDrawObj(const OUString& rStyleName)
634 XFDrawPolygon* pPolygon = new XFDrawPolygon();
635 for (sal_uInt16 nC = 0; nC < m_nNumPoints; nC++)
637 pPolygon->AddPoint((double)m_pVector[nC].x/TWIPS_PER_CM,
638 (double)m_pVector[nC].y/TWIPS_PER_CM);
641 pPolygon->SetStyleName(rStyleName);
643 return pPolygon;
647 * @descr Constructor of class LwpDrawRectangle
648 * @param pStream The memory stream which contains the lwp-sdw draw objects
650 LwpDrawRectangle::LwpDrawRectangle(SvStream * pStream, DrawingOffsetAndScale* pTransData)
651 : LwpDrawObj(pStream, pTransData)
656 * @descr reading function of class LwpDrawRectangle
658 void LwpDrawRectangle::Read()
660 this->ReadClosedObjStyle();
662 sal_uInt8 nPointsCount;
663 if (m_eType == OT_RNDRECT)
665 nPointsCount = 16;
666 m_pStream->SeekRel(4); // corner points
668 else
670 nPointsCount = 4;
673 for (sal_uInt8 nC = 0; nC < nPointsCount; nC++)
675 m_pStream->ReadInt16( m_aVector[nC].x );
676 m_pStream->ReadInt16( m_aVector[nC].y );
680 OUString LwpDrawRectangle::RegisterStyle()
682 XFDrawStyle* pStyle = new XFDrawStyle();
684 // set line style
685 this->SetLineStyle(pStyle, m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
686 m_aClosedObjStyleRec.aPenColor);
688 // set fill style
689 this->SetFillStyle(pStyle);
691 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
692 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
695 XFFrame* LwpDrawRectangle::CreateDrawObj(const OUString& rStyleName)
697 if (m_eType == OT_RNDRECT)
699 return this->CreateRoundedRect(rStyleName);
701 else
703 XFDrawPath* pRect = new XFDrawPath();
704 pRect->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
705 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
706 for (sal_uInt8 nC = 1; nC < 4; nC++)
708 pRect->LineTo(XFPoint((double)m_aVector[nC].x/TWIPS_PER_CM * m_pTransData->fScaleX,
709 (double)m_aVector[nC].y/TWIPS_PER_CM * m_pTransData->fScaleY));
711 pRect->LineTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
712 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
713 pRect->ClosePath(true);
714 this->SetPosition(pRect);
716 pRect->SetStyleName(rStyleName);
718 return pRect;
722 XFFrame* LwpDrawRectangle::CreateRoundedRect(const OUString& rStyleName)
724 XFDrawPath* pRoundedRect = new XFDrawPath();
725 pRoundedRect->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
726 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
728 sal_uInt8 nPtIndex = 1;
729 for (sal_uInt8 nC = 0; nC < 7; nC++)
731 if (nC%2 == 0)
733 XFPoint aCtrl1((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
734 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
735 nPtIndex++;
736 XFPoint aCtrl2((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
737 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
738 nPtIndex++;
739 XFPoint aDest((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
740 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
741 nPtIndex++;
743 pRoundedRect->CurveTo(aDest, aCtrl1, aCtrl2);
745 else
747 XFPoint aDest((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
748 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
749 nPtIndex++;
751 pRoundedRect->LineTo(aDest);
755 pRoundedRect->LineTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
756 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
757 pRoundedRect->ClosePath(true);
758 this->SetPosition(pRoundedRect);
760 pRoundedRect->SetStyleName(rStyleName);
762 return pRoundedRect;
765 XFFrame* LwpDrawRectangle::CreateStandardDrawObj(const OUString& rStyleName)
767 if (m_eType == OT_RNDRECT)
769 return this->CreateRoundedRect(rStyleName);
771 else
773 XFDrawRect* pRect = new XFDrawRect();
774 double fStartX, fStartY, fWidth, fHeight;
775 double fRotAngle = 0.0;
776 SdwRectangle aSdwRect;
777 Rectangle aOriginalRect;
778 Point aPt0, aPt1, aPt2, aPt3;
780 aPt0.setX(m_aVector[0].x); aPt0.setY(m_aVector[0].y);
781 aPt1.setX(m_aVector[1].x); aPt1.setY(m_aVector[1].y);
782 aPt2.setX(m_aVector[2].x); aPt2.setY(m_aVector[2].y);
783 aPt3.setX(m_aVector[3].x); aPt3.setY(m_aVector[3].y);
785 aSdwRect = SdwRectangle(aPt0, aPt1, aPt2, aPt3);
786 if (aSdwRect.IsRectRotated())
788 aOriginalRect = aSdwRect.GetOriginalRect();
789 fRotAngle = aSdwRect.GetRotationAngle();
791 else
793 aOriginalRect = Rectangle(aPt0, aPt2);
796 fStartX = aOriginalRect.TopLeft().X();
797 fStartY = aOriginalRect.TopLeft().Y();
798 fWidth = aOriginalRect.GetWidth();
799 fHeight = aOriginalRect.GetHeight();
801 pRect->SetStartPoint(XFPoint(fStartX/TWIPS_PER_CM + m_pTransData->fOffsetX,
802 fStartY/TWIPS_PER_CM + m_pTransData->fOffsetY));
803 pRect->SetSize(fWidth/TWIPS_PER_CM, fHeight/TWIPS_PER_CM);
805 if (aSdwRect.IsRectRotated())
807 pRect->SetRotate( fRotAngle / PI * 180);// aXFCenter);
810 pRect->SetStyleName(rStyleName);
812 return pRect;
817 * @descr Constructor of class LwpDrawEllipse
818 * @param pStream The memory stream which contains the lwp-sdw draw objects
820 LwpDrawEllipse::LwpDrawEllipse(SvStream * pStream, DrawingOffsetAndScale* pTransData)
821 : LwpDrawObj(pStream, pTransData)
826 * @descr reading function of class LwpDrawEllipse
828 void LwpDrawEllipse::Read()
830 this->ReadClosedObjStyle();
832 for (sal_uInt8 nC = 0; nC < 13; nC++)
834 m_pStream->ReadInt16( m_aVector[nC].x );
835 m_pStream->ReadInt16( m_aVector[nC].y );
839 OUString LwpDrawEllipse::RegisterStyle()
841 XFDrawStyle* pStyle = new XFDrawStyle();
843 // set line style
844 this->SetLineStyle(pStyle, m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
845 m_aClosedObjStyleRec.aPenColor);
847 // set fill style
848 this->SetFillStyle(pStyle);
850 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
851 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
854 XFFrame* LwpDrawEllipse::CreateDrawObj(const OUString& rStyleName )
856 XFDrawPath* pEllipse = new XFDrawPath();
857 pEllipse->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
858 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
859 sal_uInt8 nPtIndex = 1;
860 for (sal_uInt8 nC = 0; nC < 4; nC++)
862 XFPoint aCtrl1((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
863 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
864 nPtIndex++;
865 XFPoint aCtrl2((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
866 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
867 nPtIndex++;
868 XFPoint aDest((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
869 (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
870 nPtIndex++;
872 pEllipse->CurveTo(aDest, aCtrl1, aCtrl2);
874 pEllipse->ClosePath(true);
875 this->SetPosition(pEllipse);
877 pEllipse->SetStyleName(rStyleName);
879 return pEllipse;
882 XFFrame* LwpDrawEllipse::CreateStandardDrawObj(const OUString& rStyleName)
884 return this->CreateDrawObj(rStyleName);
888 * @descr Constructor of class LwpDrawArc
889 * @param pStream The memory stream which contains the lwp-sdw draw objects
891 LwpDrawArc::LwpDrawArc(SvStream * pStream, DrawingOffsetAndScale* pTransData)
892 : LwpDrawObj(pStream, pTransData)
897 * @descr reading function of class LwpDrawArc
899 void LwpDrawArc::Read()
901 m_pStream->SeekRel(16);// arcRect, startPt, endPt
903 m_pStream->ReadUChar( m_aArcRec.nLineWidth );
904 m_pStream->ReadUChar( m_aArcRec.nLineStyle );
905 m_pStream->ReadUChar( m_aArcRec.aPenColor.nR );
906 m_pStream->ReadUChar( m_aArcRec.aPenColor.nG );
907 m_pStream->ReadUChar( m_aArcRec.aPenColor.nB );
908 m_pStream->ReadUChar( m_aArcRec.aPenColor.unused );
909 m_pStream->ReadUChar( m_aArcRec.nLineEnd );
911 for (sal_uInt8 nC = 0; nC < 4; nC++)
913 m_pStream->ReadInt16( m_aVector[nC].x );
914 m_pStream->ReadInt16( m_aVector[nC].y );
918 OUString LwpDrawArc::RegisterStyle()
920 XFDrawStyle* pStyle = new XFDrawStyle();
922 // set line style
923 this->SetLineStyle(pStyle, m_aArcRec.nLineWidth, m_aArcRec.nLineStyle,
924 m_aArcRec.aPenColor);
926 // set arrow head
927 this->SetArrowHead(pStyle, m_aArcRec.nLineEnd, m_aArcRec.nLineWidth);
929 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
930 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
933 XFFrame* LwpDrawArc::CreateDrawObj(const OUString& rStyleName )
935 XFDrawPath* pArc = new XFDrawPath();
936 pArc->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
937 (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
938 XFPoint aDest((double)m_aVector[3].x/TWIPS_PER_CM * m_pTransData->fScaleX,
939 (double)m_aVector[3].y/TWIPS_PER_CM * m_pTransData->fScaleY);
940 XFPoint aCtl1((double)m_aVector[1].x/TWIPS_PER_CM * m_pTransData->fScaleX,
941 (double)m_aVector[1].y/TWIPS_PER_CM * m_pTransData->fScaleY);
942 XFPoint aCtl2((double)m_aVector[2].x/TWIPS_PER_CM* m_pTransData->fScaleX,
943 (double)m_aVector[2].y/TWIPS_PER_CM * m_pTransData->fScaleY);
944 pArc->CurveTo(aDest, aCtl1, aCtl2);
946 this->SetPosition(pArc);
948 pArc->SetStyleName(rStyleName);
950 return pArc;
953 XFFrame* LwpDrawArc::CreateStandardDrawObj(const OUString& rStyleName)
955 return this->CreateDrawObj(rStyleName);
959 * @descr Constructor of class LwpDrawTextBox
960 * @param pStream The memory stream which contains the lwp-sdw draw objects
962 LwpDrawTextBox::LwpDrawTextBox(SvStream* pStream) : LwpDrawObj(pStream)
966 LwpDrawTextBox::~LwpDrawTextBox()
968 if (m_aTextRec.pTextString)
970 delete [] m_aTextRec.pTextString;
971 m_aTextRec.pTextString = NULL;
975 void LwpDrawTextBox::SetFontStyle(XFFont* pFont, SdwTextBoxRecord* pRec)
977 // color
978 XFColor aXFColor(pRec->aTextColor.nR, pRec->aTextColor.nG,
979 pRec->aTextColor.nB);
980 pFont->SetColor(aXFColor);
981 //size
982 pFont->SetFontSize(pRec->nTextSize/20);
983 // bold
984 pFont->SetBold(((pRec->nTextAttrs & TA_BOLD) != 0));
985 // italic
986 pFont->SetItalic(((pRec->nTextAttrs & TA_ITALIC) != 0));
987 // strike-through
988 if (pRec->nTextAttrs & TA_STRIKETHRU)
990 pFont->SetCrossout(enumXFCrossoutSignel);
992 else
994 pFont->SetCrossout(enumXFCrossoutNone);
996 // underline
997 if (pRec->nTextAttrs & TA_UNDERLINE)
999 pFont->SetUnderline(enumXFUnderlineSingle);
1001 else if (pRec->nTextAttrs & TA_WORDUNDERLINE)
1003 pFont->SetUnderline(enumXFUnderlineSingle, true);
1005 else if (pRec->nTextAttrs & TA_DOUBLEUNDER)
1007 pFont->SetUnderline(enumXFUnderlineDouble);
1009 else
1011 pFont->SetUnderline(enumXFUnderlineNone);
1013 // small-caps
1014 if (pRec->nTextAttrs & TA_SMALLCAPS)
1016 pFont->SetTransform(enumXFTransformSmallCaps);
1021 * @descr reading function of class LwpDrawTextBox
1023 void LwpDrawTextBox::Read()
1025 m_pStream->ReadInt16( m_aVector.x );
1026 m_pStream->ReadInt16( m_aVector.y );
1027 m_pStream->ReadInt16( m_aTextRec.nTextWidth );
1029 if (m_aTextRec.nTextWidth == 0)
1030 m_aTextRec.nTextWidth = 1;
1032 m_pStream->ReadInt16( m_aTextRec.nTextHeight );
1033 m_pStream->Read(m_aTextRec.tmpTextFaceName, DRAW_FACESIZE);
1034 m_pStream->SeekRel(1);// PitchAndFamily
1036 m_pStream->ReadInt16( m_aTextRec.nTextSize );
1038 if (m_aTextRec.nTextSize < 0)
1039 m_aTextRec.nTextSize = -m_aTextRec.nTextSize;
1041 //color
1042 m_pStream->ReadUChar( m_aTextRec.aTextColor.nR );
1043 m_pStream->ReadUChar( m_aTextRec.aTextColor.nG );
1044 m_pStream->ReadUChar( m_aTextRec.aTextColor.nB );
1045 m_pStream->ReadUChar( m_aTextRec.aTextColor.unused );
1047 m_pStream->ReadUInt16( m_aTextRec.nTextAttrs );
1048 m_pStream->ReadUInt16( m_aTextRec.nTextCharacterSet );
1049 m_pStream->ReadInt16( m_aTextRec.nTextRotation );
1050 m_pStream->ReadInt16( m_aTextRec.nTextExtraSpacing );
1052 // some draw files in version 1.2 have an extra byte following '\0'.
1053 // can't rely on that, so read in the whole string into memory.
1055 // the 71 is the fixed length before text content in textbox record
1056 sal_Int16 TextLength = m_aObjHeader.nRecLen - 71;
1057 m_aTextRec.pTextString = new sal_uInt8 [TextLength];
1059 m_pStream->Read(m_aTextRec.pTextString, TextLength);
1062 OUString LwpDrawTextBox::RegisterStyle()
1064 XFParaStyle* pStyle = new XFParaStyle();
1066 // font style
1067 // the pFont need to be deleted myself?
1068 XFFont* pFont = new XFFont();
1070 rtl_TextEncoding aEncoding = RTL_TEXTENCODING_MS_1252;
1071 OUString aFontName = OUString((sal_Char*)m_aTextRec.tmpTextFaceName,
1072 strlen((char*)m_aTextRec.tmpTextFaceName), aEncoding);
1073 pFont->SetFontName(aFontName);
1075 this->SetFontStyle(pFont, &m_aTextRec);
1077 pStyle->SetFont(pFont);
1079 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1080 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
1083 XFFrame* LwpDrawTextBox::CreateDrawObj(const OUString& rStyleName )
1085 XFFrame* pTextBox = new XFFrame(true);
1087 sal_Int16 TextLength = m_aObjHeader.nRecLen - 71;
1088 rtl_TextEncoding aEncoding;
1089 if (!m_aTextRec.nTextCharacterSet)
1091 aEncoding = osl_getThreadTextEncoding();
1093 else
1095 // temporary code, need to create Encoding from the value of nTextCharacterSet
1096 aEncoding = LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
1099 XFParagraph* pXFPara = new XFParagraph();
1100 pXFPara->Add(OUString((sal_Char*)m_aTextRec.pTextString, (TextLength-2), aEncoding));
1101 pXFPara->SetStyleName(rStyleName);
1103 pTextBox->Add(pXFPara);
1104 this->SetPosition(pTextBox);
1106 XFTextBoxStyle* pBoxStyle = new XFTextBoxStyle();
1108 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1109 OUString sName = pXFStyleManager->AddStyle(pBoxStyle)->GetStyleName();
1110 pTextBox->SetStyleName(sName);
1112 //todo: add the interface for rotating textbox
1113 // if (m_aTextRec.nTextRotation)
1114 // {
1115 // double fAngle = double(3600-m_aTextRec.nTextRotation)/10;
1116 // pTextBox->SetRotate(fAngle);
1117 // }
1119 return pTextBox;
1122 XFFrame* LwpDrawTextBox::CreateStandardDrawObj(const OUString& rStyleName)
1124 return this->CreateDrawObj(rStyleName);
1128 * @descr Constructor of class LwpDrawTextBox
1129 * @param pStream The memory stream which contains the lwp-sdw draw objects
1131 LwpDrawTextArt::LwpDrawTextArt(SvStream* pStream, DrawingOffsetAndScale* pTransData)
1132 : LwpDrawObj(pStream, pTransData)
1136 LwpDrawTextArt::~LwpDrawTextArt()
1138 if (m_aTextArtRec.aPath[0].pPts)
1140 delete [] m_aTextArtRec.aPath[0].pPts;
1141 m_aTextArtRec.aPath[0].pPts = NULL;
1143 if (m_aTextArtRec.aPath[1].pPts)
1145 delete [] m_aTextArtRec.aPath[1].pPts;
1146 m_aTextArtRec.aPath[1].pPts = NULL;
1148 if (m_aTextArtRec.pTextString)
1150 delete [] m_aTextArtRec.pTextString;
1151 m_aTextArtRec.pTextString = NULL;
1156 void LwpDrawTextArt::CreateFWPath(XFDrawPath* pPath)
1158 sal_Int16 nX, nY;
1159 nX = (m_aTextArtRec.aPath[0].pPts[0].x + m_aTextArtRec.aPath[1].pPts[0].x) / 2;
1160 nY = (m_aTextArtRec.aPath[0].pPts[0].y + m_aTextArtRec.aPath[1].pPts[0].y) / 2;
1161 XFPoint aStart((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1162 (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1163 pPath->MoveTo(aStart);
1165 sal_uInt8 nPtIndex = 1;
1166 for (sal_uInt8 nC = 1; nC <= m_aTextArtRec.aPath[0].n; nC++)
1168 nX = (m_aTextArtRec.aPath[0].pPts[nPtIndex].x + m_aTextArtRec.aPath[1].pPts[nPtIndex].x) / 2;
1169 nY = (m_aTextArtRec.aPath[0].pPts[nPtIndex].y + m_aTextArtRec.aPath[1].pPts[nPtIndex].y) / 2;
1170 XFPoint aCtrl1((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1171 (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1173 nPtIndex++;
1174 nX = (m_aTextArtRec.aPath[0].pPts[nPtIndex].x + m_aTextArtRec.aPath[1].pPts[nPtIndex].x) / 2;
1175 nY = (m_aTextArtRec.aPath[0].pPts[nPtIndex].y + m_aTextArtRec.aPath[1].pPts[nPtIndex].y) / 2;
1176 XFPoint aCtrl2((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1177 (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1179 nPtIndex++;
1180 nX = (m_aTextArtRec.aPath[0].pPts[nPtIndex].x + m_aTextArtRec.aPath[1].pPts[nPtIndex].x) / 2;
1181 nY = (m_aTextArtRec.aPath[0].pPts[nPtIndex].y + m_aTextArtRec.aPath[1].pPts[nPtIndex].y) / 2;
1182 XFPoint aDest((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1183 (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1185 pPath->CurveTo(aDest, aCtrl1, aCtrl2);
1189 void LwpDrawTextArt::Read()
1191 for (sal_uInt8 nC = 0; nC < 4; nC++)
1193 m_pStream->ReadInt16( m_aVector[nC].x );
1194 m_pStream->ReadInt16( m_aVector[nC].y );
1197 this->ReadClosedObjStyle();
1198 m_aTextArtRec.aTextColor = m_aClosedObjStyleRec.aForeColor;
1200 m_pStream->ReadUChar( m_aTextArtRec.nIndex );
1201 m_pStream->ReadInt16( m_aTextArtRec.nRotation );
1203 sal_uInt16 nPointNumber;
1204 sal_Int16 nX, nY;
1205 m_pStream->ReadUInt16( nPointNumber );
1206 m_aTextArtRec.aPath[0].n = nPointNumber;
1207 m_aTextArtRec.aPath[0].pPts = new SdwPoint [nPointNumber*3+1];
1208 sal_uInt16 nPt = 0;
1209 for ( nPt = 0; nPt <= nPointNumber*3; nPt++)
1211 m_pStream->ReadInt16( nX );
1212 m_pStream->ReadInt16( nY );
1213 m_aTextArtRec.aPath[0].pPts[nPt].x = nX;
1214 m_aTextArtRec.aPath[0].pPts[nPt].y = nY;
1217 m_pStream->ReadUInt16( nPointNumber );
1218 m_aTextArtRec.aPath[1].n = nPointNumber;
1219 m_aTextArtRec.aPath[1].pPts = new SdwPoint [nPointNumber*3+1];
1220 for (nPt = 0; nPt <= nPointNumber*3; nPt++)
1222 m_pStream->ReadInt16( nX );
1223 m_pStream->ReadInt16( nY );
1224 m_aTextArtRec.aPath[1].pPts[nPt].x = nX;
1225 m_aTextArtRec.aPath[1].pPts[nPt].y = nY;
1228 m_pStream->SeekRel(1);
1230 m_pStream->Read(m_aTextArtRec.tmpTextFaceName, DRAW_FACESIZE);
1231 m_pStream->SeekRel(1);// PitchAndFamily
1233 m_pStream->ReadInt16( m_aTextArtRec.nTextSize );
1235 if (m_aTextArtRec.nTextSize < 0)
1236 m_aTextArtRec.nTextSize = -m_aTextArtRec.nTextSize;
1238 m_pStream->ReadUInt16( m_aTextArtRec.nTextAttrs );
1239 m_pStream->ReadUInt16( m_aTextArtRec.nTextCharacterSet );
1240 m_aTextArtRec.nTextRotation = 0;
1241 m_pStream->ReadInt16( m_aTextArtRec.nTextExtraSpacing );
1243 const sal_uInt16 nTextArtFixedLength = 105;
1244 m_aTextArtRec.nTextLen = m_aObjHeader.nRecLen - nTextArtFixedLength
1245 - (m_aTextArtRec.aPath[0].n*3 + 1)*4
1246 - (m_aTextArtRec.aPath[1].n*3 + 1)*4;
1248 m_aTextArtRec.pTextString = new sal_uInt8 [m_aTextArtRec.nTextLen];
1249 m_pStream->Read(m_aTextArtRec.pTextString, m_aTextArtRec.nTextLen);
1250 m_aTextArtRec.pTextString[m_aTextArtRec.nTextLen-1] = 0;
1254 OUString LwpDrawTextArt::RegisterStyle()
1256 XFParaStyle* pStyle = new XFParaStyle();
1258 // font style
1259 // the pFont need to be deleted myself?
1260 XFFont* pFont = new XFFont();
1262 rtl_TextEncoding aEncoding = RTL_TEXTENCODING_MS_1252;
1263 OUString aFontName = OUString((sal_Char*)m_aTextArtRec.tmpTextFaceName,
1264 strlen((char*)m_aTextArtRec.tmpTextFaceName), aEncoding);
1265 pFont->SetFontName(aFontName);
1267 LwpDrawTextBox::SetFontStyle(pFont, &m_aTextArtRec);
1269 pStyle->SetFont(pFont);
1271 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1272 return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
1275 XFFrame* LwpDrawTextArt::CreateDrawObj(const OUString& rStyleName)
1277 XFFrame* pRetObj = NULL;
1278 XFDrawStyle* pStyle = new XFDrawStyle();
1280 pRetObj = new XFDrawPath();
1281 XFDrawPath* pFWPath = static_cast<XFDrawPath*>(pRetObj);
1282 this->CreateFWPath(pFWPath);
1283 pStyle->SetFontWorkStyle(0, enumXFFWSlantY, enumXFFWAdjustAutosize);
1285 this->SetPosition(pRetObj);
1287 rtl_TextEncoding aEncoding;
1288 if (!m_aTextArtRec.nTextCharacterSet)
1290 aEncoding = osl_getThreadTextEncoding();
1292 else
1294 // temporary code, need to create Encoding from the value of nTextCharacterSet
1295 aEncoding = LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
1298 XFParagraph* pXFPara = new XFParagraph();
1299 pXFPara->Add(OUString((sal_Char*)m_aTextArtRec.pTextString, (m_aTextArtRec.nTextLen-1), aEncoding));
1300 pXFPara->SetStyleName(rStyleName);
1301 pRetObj->Add(pXFPara);
1303 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1304 pRetObj->SetStyleName(pXFStyleManager->AddStyle(pStyle)->GetStyleName());
1306 return pRetObj;
1309 XFFrame* LwpDrawTextArt::CreateStandardDrawObj(const OUString& rStyleName )
1311 return this->CreateDrawObj(rStyleName);
1315 * @descr Constructor of class LwpDrawMetafile
1316 * @param pStream The memory stream which contains the lwp-sdw draw objects
1318 LwpDrawMetafile::LwpDrawMetafile(SvStream* pStream) : LwpDrawObj(pStream)
1323 * @descr reading function of class LwpDrawMetafile
1325 void LwpDrawMetafile::Read()
1327 m_pStream->SeekRel(m_aObjHeader.nRecLen -16);
1331 * @descr Constructor of class LwpDrawBitmap
1332 * @param pStream The memory stream which contains the lwp-sdw draw objects
1334 LwpDrawBitmap::LwpDrawBitmap(SvStream* pStream) : LwpDrawObj(pStream), m_pImageData(NULL)
1338 LwpDrawBitmap::~LwpDrawBitmap()
1340 if (m_pImageData)
1342 delete [] m_pImageData;
1343 m_pImageData = NULL;
1348 * @descr reading function of class LwpDrawBitmap
1350 void LwpDrawBitmap::Read()
1352 m_pStream->ReadUInt16( m_aBmpRec.nTranslation );
1353 m_pStream->ReadUInt16( m_aBmpRec.nRotation );
1355 // 20 == length of draw-specific fields.
1356 // 14 == length of bmp file header.
1357 m_aBmpRec.nFileSize = m_aObjHeader.nRecLen - 20 + 14;
1358 m_pImageData = new sal_uInt8 [m_aBmpRec.nFileSize];
1360 BmpInfoHeader2 aInfoHeader2;
1361 m_pStream->ReadUInt32( aInfoHeader2.nHeaderLen );
1363 sal_uInt32 N;
1364 sal_uInt32 rgbTableSize;
1366 if (aInfoHeader2.nHeaderLen == sizeof(BmpInfoHeader))
1368 m_pStream->ReadUInt32( aInfoHeader2.nWidth );
1369 m_pStream->ReadUInt32( aInfoHeader2.nHeight );
1370 m_pStream->ReadUInt16( aInfoHeader2.nPlanes );
1371 m_pStream->ReadUInt16( aInfoHeader2.nBitCount );
1373 N = aInfoHeader2.nPlanes * aInfoHeader2.nBitCount;
1374 if (N == 24)
1376 rgbTableSize = 0;
1378 else
1380 rgbTableSize = 3 * (1 << N);
1383 else
1385 m_pStream->ReadUInt32( aInfoHeader2.nWidth );
1386 m_pStream->ReadUInt32( aInfoHeader2.nHeight );
1387 m_pStream->ReadUInt16( aInfoHeader2.nPlanes );
1388 m_pStream->ReadUInt16( aInfoHeader2.nBitCount );
1389 N = aInfoHeader2.nPlanes * aInfoHeader2.nBitCount;
1390 if (N == 24)
1392 rgbTableSize = 0;
1394 else
1396 rgbTableSize = 4 * (1 << N);
1401 sal_uInt32 nOffBits = 14 + aInfoHeader2.nHeaderLen + rgbTableSize;
1402 m_pImageData[0] = 'B';
1403 m_pImageData[1] = 'M';
1404 m_pImageData[2] = (sal_uInt8)m_aBmpRec.nFileSize;
1405 m_pImageData[3] = (sal_uInt8)(m_aBmpRec.nFileSize >> 8);
1406 m_pImageData[4] = (sal_uInt8)(m_aBmpRec.nFileSize >> 16);
1407 m_pImageData[5] = (sal_uInt8)(m_aBmpRec.nFileSize >> 24);
1408 m_pImageData[6] = 0;
1409 m_pImageData[7] = 0;
1410 m_pImageData[8] = 0;
1411 m_pImageData[9] = 0;
1412 m_pImageData[10] = (sal_uInt8)nOffBits;
1413 m_pImageData[11] = (sal_uInt8)(nOffBits >> 8);
1414 m_pImageData[12] = (sal_uInt8)(nOffBits >> 16);
1415 m_pImageData[13] = (sal_uInt8)(nOffBits >> 24);
1417 sal_uInt32 nDIBRemaining;
1418 sal_uInt8* pPicData = m_pImageData;
1419 if (aInfoHeader2.nHeaderLen== sizeof(BmpInfoHeader))
1421 m_pImageData[14] = (sal_uInt8)aInfoHeader2.nHeaderLen;
1422 m_pImageData[15] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 8);
1423 m_pImageData[16] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 16);
1424 m_pImageData[17] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 24);
1425 m_pImageData[18] = (sal_uInt8)aInfoHeader2.nWidth;
1426 m_pImageData[19] = (sal_uInt8)(aInfoHeader2.nWidth >> 8);
1427 m_pImageData[20] = (sal_uInt8)aInfoHeader2.nHeight;
1428 m_pImageData[21] = (sal_uInt8)(aInfoHeader2.nHeight >> 8);
1429 m_pImageData[22] = (sal_uInt8)aInfoHeader2.nPlanes;
1430 m_pImageData[23] = (sal_uInt8)(aInfoHeader2.nPlanes >> 8);
1431 m_pImageData[24] = (sal_uInt8)aInfoHeader2.nBitCount;
1432 m_pImageData[25] = (sal_uInt8)(aInfoHeader2.nBitCount >> 8);
1434 nDIBRemaining = m_aBmpRec.nFileSize - 26;
1435 pPicData += 26*sizeof(sal_uInt8);
1437 else
1439 m_pImageData[14] = (sal_uInt8)aInfoHeader2.nHeaderLen;
1440 m_pImageData[15] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 8);
1441 m_pImageData[16] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 16);
1442 m_pImageData[17] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 24);
1443 m_pImageData[18] = (sal_uInt8)aInfoHeader2.nWidth;
1444 m_pImageData[19] = (sal_uInt8)(aInfoHeader2.nWidth >> 8);
1445 m_pImageData[20] = (sal_uInt8)(aInfoHeader2.nWidth >> 16);
1446 m_pImageData[21] = (sal_uInt8)(aInfoHeader2.nWidth >> 24);
1447 m_pImageData[22] = (sal_uInt8)aInfoHeader2.nHeight;
1448 m_pImageData[23] = (sal_uInt8)(aInfoHeader2.nHeight >> 8);
1449 m_pImageData[24] = (sal_uInt8)(aInfoHeader2.nHeight >> 16);
1450 m_pImageData[25] = (sal_uInt8)(aInfoHeader2.nHeight >> 24);
1451 m_pImageData[26] = (sal_uInt8)aInfoHeader2.nPlanes;
1452 m_pImageData[27] = (sal_uInt8)(aInfoHeader2.nPlanes >> 8);
1453 m_pImageData[28] = (sal_uInt8)aInfoHeader2.nBitCount;
1454 m_pImageData[29] = (sal_uInt8)(aInfoHeader2.nBitCount >> 8);
1456 nDIBRemaining = m_aBmpRec.nFileSize - 30;
1457 pPicData += 30*sizeof(sal_uInt8);
1460 m_pStream->Read(pPicData, nDIBRemaining);
1463 OUString LwpDrawBitmap::RegisterStyle()
1465 XFImageStyle* pBmpStyle = new XFImageStyle();
1466 pBmpStyle->SetYPosType(enumXFFrameYPosFromTop, enumXFFrameYRelFrame);
1467 pBmpStyle->SetXPosType(enumXFFrameXPosFromLeft, enumXFFrameXRelFrame);
1469 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1470 return pXFStyleManager->AddStyle(pBmpStyle)->GetStyleName();
1473 XFFrame* LwpDrawBitmap::CreateDrawObj(const OUString& rStyleName)
1475 XFImage* pImage = new XFImage();
1476 pImage->SetImageData(m_pImageData, m_aBmpRec.nFileSize);
1477 this->SetPosition(pImage);
1479 pImage->SetStyleName(rStyleName);
1481 return pImage;
1484 XFFrame* LwpDrawBitmap::CreateStandardDrawObj(const OUString& rStyleName)
1486 return this->CreateDrawObj(rStyleName);
1489 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */