tdf#131098 docx export: write fill property of graphic
[LibreOffice.git] / lotuswordpro / source / filter / lwpdrawobj.cxx
blob4e2f9e1387dff9b11a56521a00a7cd1c70a1aac0
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 LwpDrawObjects and associated class like LwpDrawGroup, LwpDrawRectangle
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>
66 #include <basegfx/numeric/ftools.hxx>
68 #include <xfilter/xfframe.hxx>
70 #include <xfilter/xfglobal.hxx>
71 #include <xfilter/xfstylemanager.hxx>
72 #include <xfilter/xfdrawstyle.hxx>
73 #include <xfilter/xfparastyle.hxx>
74 #include <xfilter/xfimagestyle.hxx>
75 #include <xfilter/xftextboxstyle.hxx>
76 #include <xfilter/xfparagraph.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 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->ReadBytes(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, 0.05, 0.05, 0.05);
258 // line width
259 double fWidth = LwpTools::ConvertFromTwips(nWidth);
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(
284 LwpTools::ConvertFromTwips(m_aObjHeader.nLeft) * fScaleX + fOffsetX,
285 LwpTools::ConvertFromTwips(m_aObjHeader.nTop) * fScaleY + fOffsetY,
286 LwpTools::ConvertFromTwips(m_aObjHeader.nRight-m_aObjHeader.nLeft) * fScaleX,
287 LwpTools::ConvertFromTwips(m_aObjHeader.nBottom-m_aObjHeader.nTop) * fScaleY);
291 * @descr set arrowhead of a xf-drawing object. only opened drawing objects can be assigned arrowheads
292 * @param pOpenedObjStyle the xf-drawing object which will be set arrowhead.
293 * @param nArrowFlag arrowhead flags of the object.
295 void LwpDrawObj::SetArrowHead(XFDrawStyle* pOpenedObjStyle, sal_uInt8 nArrowFlag, sal_uInt8 nLineWidth)
297 // no arrowhead
298 if (!nArrowFlag)
300 return;
303 if (!pOpenedObjStyle)
305 assert(false);
306 return;
309 // arrowhead flag of an object's start side
310 sal_uInt8 nLeftArrow = nArrowFlag & 0x0F;
312 // arrowhead flag of an object's end side
313 sal_uInt8 nRightArrow = (nArrowFlag & 0xF0) >> 4;
315 // FIXME: this can't be correct: converting something to cm, then treating it as inches
316 double fWidth_inch = LwpTools::ConvertFromTwips(nLineWidth);
317 double fArrowSize_inch = fWidth_inch + 0.08;
318 double fArrowSize = o3tl::convert(fArrowSize_inch, o3tl::Length::in, o3tl::Length::cm);
320 if (nLeftArrow)
322 pOpenedObjStyle->SetArrowStart( GetArrowName(nLeftArrow), fArrowSize);
324 if (nRightArrow)
326 pOpenedObjStyle->SetArrowEnd( GetArrowName(nRightArrow), fArrowSize);
332 * @descr get arrow style name according to the flag.
333 * @param nArrowStyle style of the arrowhead.
334 * @return nWhichSide style name of the arrowhead.
336 OUString LwpDrawObj::GetArrowName(sal_uInt8 nArrowStyle)
338 // style name of arrowhead
339 OUString aArrowName;
341 switch(nArrowStyle)
343 default:
344 case AH_ARROW_FULLARROW:
345 aArrowName = "Symmetric arrow";
346 break;
347 case AH_ARROW_HALFARROW:
348 aArrowName = "Arrow concave";
349 break;
350 case AH_ARROW_LINEARROW:
351 aArrowName = "arrow100";
352 break;
353 case AH_ARROW_INVFULLARROW:
354 aArrowName = "reverse arrow";
355 break;
356 case AH_ARROW_INVHALFARROW:
357 aArrowName = "reverse concave arrow";
358 break;
359 case AH_ARROW_INVLINEARROW:
360 aArrowName = "reverse line arrow";
361 break;
362 case AH_ARROW_TEE:
363 aArrowName = "Dimension lines";
364 break;
365 case AH_ARROW_SQUARE:
366 aArrowName = "Square";
367 break;
368 case AH_ARROW_CIRCLE:
369 aArrowName = "Circle";
370 break;
373 return aArrowName;
377 * @descr template method of creating drawing object from Lwp-Model to XF-Model
378 * @return pointer of the drawing object of XF-Model.
380 rtl::Reference<XFFrame> LwpDrawObj::CreateXFDrawObject()
382 // read records
383 Read();
385 // register style
386 OUString aStyleName = RegisterStyle();
388 // create XF-Objects
389 rtl::Reference<XFFrame> xXFObj;
390 if (m_pTransData
391 && FABS(m_pTransData->fOffsetX - m_pTransData->fLeftMargin) < THRESHOLD
392 && FABS(m_pTransData->fOffsetY - m_pTransData->fTopMargin) < THRESHOLD
393 && FABS(m_pTransData->fScaleX - 1.0) < THRESHOLD
394 && FABS(m_pTransData->fScaleY - 1.0) < THRESHOLD)
396 xXFObj = CreateStandardDrawObj(aStyleName);
398 else
400 xXFObj = CreateDrawObj(aStyleName);
403 // set anchor type
404 if (xXFObj)
406 xXFObj->SetAnchorType(enumXFAnchorFrame);
409 return xXFObj;
413 * @descr Constructor of class LwpDrawLine
414 * @param pStream The memory stream which contains the lwp-sdw draw objects
416 LwpDrawLine::LwpDrawLine(SvStream * pStream, DrawingOffsetAndScale* pTransData)
417 : LwpDrawObj(pStream, pTransData)
422 * @descr reading function of class LwpDrawLine
424 void LwpDrawLine::Read()
426 m_pStream->ReadInt16( m_aLineRec.nStartX );
427 m_pStream->ReadInt16( m_aLineRec.nStartY );
428 m_pStream->ReadInt16( m_aLineRec.nEndX );
429 m_pStream->ReadInt16( m_aLineRec.nEndY );
430 m_pStream->ReadUChar( m_aLineRec.nLineWidth );
431 m_pStream->ReadUChar( m_aLineRec.nLineEnd );
432 m_pStream->ReadUChar( m_aLineRec.nLineStyle );
434 m_pStream->ReadUChar( m_aLineRec.aPenColor.nR );
435 m_pStream->ReadUChar( m_aLineRec.aPenColor.nG );
436 m_pStream->ReadUChar( m_aLineRec.aPenColor.nB );
437 m_pStream->ReadUChar( m_aLineRec.aPenColor.unused );
440 OUString LwpDrawLine::RegisterStyle()
442 std::unique_ptr<XFDrawStyle> pStyle( new XFDrawStyle() );
444 // set line style
445 SetLineStyle(pStyle.get(), m_aLineRec.nLineWidth, m_aLineRec.nLineStyle, m_aLineRec.aPenColor);
447 // set arrow head
448 SetArrowHead(pStyle.get(), m_aLineRec.nLineEnd, m_aLineRec.nLineWidth);
450 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
451 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
454 rtl::Reference<XFFrame> LwpDrawLine::CreateDrawObj(const OUString& rStyleName )
456 rtl::Reference<XFDrawPath> xLine(new XFDrawPath());
457 xLine->MoveTo(XFPoint(LwpTools::ConvertFromTwips(m_aLineRec.nStartX) * m_pTransData->fScaleX,
458 LwpTools::ConvertFromTwips(m_aLineRec.nStartY) * m_pTransData->fScaleY));
459 xLine->LineTo(XFPoint(LwpTools::ConvertFromTwips(m_aLineRec.nEndX) * m_pTransData->fScaleX,
460 LwpTools::ConvertFromTwips(m_aLineRec.nEndY) * m_pTransData->fScaleY));
461 SetPosition(xLine.get());
463 xLine->SetStyleName(rStyleName);
465 return xLine;
468 rtl::Reference<XFFrame> LwpDrawLine::CreateStandardDrawObj(const OUString& rStyleName)
470 rtl::Reference<XFDrawLine> xLine(new XFDrawLine());
471 xLine->SetStartPoint(LwpTools::ConvertFromTwips(m_aLineRec.nStartX),
472 LwpTools::ConvertFromTwips(m_aLineRec.nStartY));
473 xLine->SetEndPoint(LwpTools::ConvertFromTwips(m_aLineRec.nEndX),
474 LwpTools::ConvertFromTwips(m_aLineRec.nEndY));
476 xLine->SetStyleName(rStyleName);
477 return xLine;
481 * @descr Constructor of class LwpDrawPolyLine
482 * @param pStream The memory stream which contains the lwp-sdw draw objects
484 LwpDrawPolyLine::LwpDrawPolyLine(SvStream * pStream, DrawingOffsetAndScale* pTransData)
485 : LwpDrawObj(pStream, pTransData)
488 LwpDrawPolyLine::~LwpDrawPolyLine()
493 * @descr reading function of class LwpDrawPolyLine
495 void LwpDrawPolyLine::Read()
497 m_pStream->ReadUChar( m_aPolyLineRec.nLineWidth );
498 m_pStream->ReadUChar( m_aPolyLineRec.nLineEnd );
499 m_pStream->ReadUChar( m_aPolyLineRec.nLineStyle );
500 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.nR );
501 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.nG );
502 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.nB );
503 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.unused );
504 m_pStream->ReadUInt16( m_aPolyLineRec.nNumPoints );
506 if (!m_pStream->good() || m_aPolyLineRec.nNumPoints > m_pStream->remainingSize() / 4)
507 throw BadRead();
509 m_pVector.reset( new SdwPoint[m_aPolyLineRec.nNumPoints] );
511 for (sal_uInt16 nC = 0; nC < m_aPolyLineRec.nNumPoints; nC++)
513 m_pStream->ReadInt16( m_pVector[nC].x );
514 m_pStream->ReadInt16( m_pVector[nC].y );
518 OUString LwpDrawPolyLine::RegisterStyle()
520 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
522 // set line style
523 SetLineStyle(pStyle.get(), m_aPolyLineRec.nLineWidth, m_aPolyLineRec.nLineStyle,
524 m_aPolyLineRec.aPenColor);
526 // set arrow head
527 SetArrowHead(pStyle.get(), m_aPolyLineRec.nLineEnd, m_aPolyLineRec.nLineWidth);
529 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
530 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
533 rtl::Reference<XFFrame> LwpDrawPolyLine::CreateDrawObj(const OUString& rStyleName )
535 rtl::Reference<XFDrawPath> xPolyline(new XFDrawPath());
536 xPolyline->MoveTo(XFPoint(LwpTools::ConvertFromTwips(m_pVector[0].x) * m_pTransData->fScaleX,
537 LwpTools::ConvertFromTwips(m_pVector[0].y) * m_pTransData->fScaleY));
538 for (sal_uInt16 nC = 1; nC < m_aPolyLineRec.nNumPoints; nC++)
540 xPolyline->LineTo(XFPoint(LwpTools::ConvertFromTwips(m_pVector[nC].x) * m_pTransData->fScaleX,
541 LwpTools::ConvertFromTwips(m_pVector[nC].y) * m_pTransData->fScaleY));
543 SetPosition(xPolyline.get());
545 xPolyline->SetStyleName(rStyleName);
547 return xPolyline;
550 rtl::Reference<XFFrame> LwpDrawPolyLine::CreateStandardDrawObj(const OUString& rStyleName)
552 rtl::Reference<XFDrawPolyline> xPolyline(new XFDrawPolyline());
553 for (sal_uInt16 nC = 0; nC < m_aPolyLineRec.nNumPoints; nC++)
555 xPolyline->AddPoint(LwpTools::ConvertFromTwips(m_pVector[nC].x),
556 LwpTools::ConvertFromTwips(m_pVector[nC].y));
559 xPolyline->SetStyleName(rStyleName);
561 return xPolyline;
565 * @descr Constructor of class LwpDrawPolygon
566 * @param pStream The memory stream which contains the lwp-sdw draw objects
568 LwpDrawPolygon::LwpDrawPolygon(SvStream * pStream, DrawingOffsetAndScale* pTransData)
569 : LwpDrawObj(pStream, pTransData)
570 , m_nNumPoints(0)
574 LwpDrawPolygon::~LwpDrawPolygon()
579 * @descr reading function of class LwpDrawPolygon
581 void LwpDrawPolygon::Read()
583 ReadClosedObjStyle();
584 m_pStream->ReadUInt16( m_nNumPoints );
586 if (!m_pStream->good() || m_nNumPoints > m_pStream->remainingSize() / 4)
587 throw BadRead();
589 m_pVector.reset( new SdwPoint[m_nNumPoints] );
591 for (sal_uInt16 nC = 0; nC < m_nNumPoints; nC++)
593 m_pStream->ReadInt16( m_pVector[nC].x );
594 m_pStream->ReadInt16( m_pVector[nC].y );
598 OUString LwpDrawPolygon::RegisterStyle()
600 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
602 // set line style
603 SetLineStyle(pStyle.get(), m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
604 m_aClosedObjStyleRec.aPenColor);
606 // set fill style
607 SetFillStyle(pStyle.get());
609 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
610 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
613 rtl::Reference<XFFrame> LwpDrawPolygon::CreateDrawObj(const OUString& rStyleName)
615 rtl::Reference<XFDrawPath> xPolygon(new XFDrawPath());
616 xPolygon->MoveTo(XFPoint(LwpTools::ConvertFromTwips(m_pVector[0].x) * m_pTransData->fScaleX,
617 LwpTools::ConvertFromTwips(m_pVector[0].y) * m_pTransData->fScaleY));
618 for (sal_uInt16 nC = 1; nC < m_nNumPoints; nC++)
620 xPolygon->LineTo(XFPoint(LwpTools::ConvertFromTwips(m_pVector[nC].x) * m_pTransData->fScaleX,
621 LwpTools::ConvertFromTwips(m_pVector[nC].y) * m_pTransData->fScaleY));
623 xPolygon->ClosePath();
624 SetPosition(xPolygon.get());
625 xPolygon->SetStyleName(rStyleName);
627 return xPolygon;
630 rtl::Reference<XFFrame> LwpDrawPolygon::CreateStandardDrawObj(const OUString& rStyleName)
632 rtl::Reference<XFDrawPolygon> xPolygon(new XFDrawPolygon());
633 for (sal_uInt16 nC = 0; nC < m_nNumPoints; nC++)
635 xPolygon->AddPoint(LwpTools::ConvertFromTwips(m_pVector[nC].x),
636 LwpTools::ConvertFromTwips(m_pVector[nC].y));
639 xPolygon->SetStyleName(rStyleName);
641 return xPolygon;
645 * @descr Constructor of class LwpDrawRectangle
646 * @param pStream The memory stream which contains the lwp-sdw draw objects
648 LwpDrawRectangle::LwpDrawRectangle(SvStream * pStream, DrawingOffsetAndScale* pTransData)
649 : LwpDrawObj(pStream, pTransData)
654 * @descr reading function of class LwpDrawRectangle
656 void LwpDrawRectangle::Read()
658 ReadClosedObjStyle();
660 sal_uInt8 nPointsCount;
661 if (m_eType == OT_RNDRECT)
663 nPointsCount = 16;
664 m_pStream->SeekRel(4); // corner points
666 else
668 nPointsCount = 4;
671 for (sal_uInt8 nC = 0; nC < nPointsCount; nC++)
673 m_pStream->ReadInt16( m_aVector[nC].x );
674 m_pStream->ReadInt16( m_aVector[nC].y );
678 OUString LwpDrawRectangle::RegisterStyle()
680 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
682 // set line style
683 SetLineStyle(pStyle.get(), m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
684 m_aClosedObjStyleRec.aPenColor);
686 // set fill style
687 SetFillStyle(pStyle.get());
689 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
690 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
693 rtl::Reference<XFFrame> LwpDrawRectangle::CreateDrawObj(const OUString& rStyleName)
695 if (m_eType == OT_RNDRECT)
697 return CreateRoundedRect(rStyleName);
699 else
701 rtl::Reference<XFDrawPath> xRect(new XFDrawPath());
702 xRect->MoveTo(XFPoint(LwpTools::ConvertFromTwips(m_aVector[0].x) * m_pTransData->fScaleX,
703 LwpTools::ConvertFromTwips(m_aVector[0].y) * m_pTransData->fScaleY));
704 for (sal_uInt8 nC = 1; nC < 4; nC++)
706 xRect->LineTo(XFPoint(LwpTools::ConvertFromTwips(m_aVector[nC].x) * m_pTransData->fScaleX,
707 LwpTools::ConvertFromTwips(m_aVector[nC].y) * m_pTransData->fScaleY));
709 xRect->LineTo(XFPoint(LwpTools::ConvertFromTwips(m_aVector[0].x) * m_pTransData->fScaleX,
710 LwpTools::ConvertFromTwips(m_aVector[0].y) * m_pTransData->fScaleY));
711 xRect->ClosePath();
712 SetPosition(xRect.get());
714 xRect->SetStyleName(rStyleName);
716 return xRect;
720 XFFrame* LwpDrawRectangle::CreateRoundedRect(const OUString& rStyleName)
722 XFDrawPath* pRoundedRect = new XFDrawPath();
723 pRoundedRect->MoveTo(XFPoint(LwpTools::ConvertFromTwips(m_aVector[0].x) * m_pTransData->fScaleX,
724 LwpTools::ConvertFromTwips(m_aVector[0].y) * m_pTransData->fScaleY));
726 sal_uInt8 nPtIndex = 1;
727 for (sal_uInt8 nC = 0; nC < 7; nC++)
729 if (nC%2 == 0)
731 XFPoint aCtrl1(LwpTools::ConvertFromTwips(m_aVector[nPtIndex].x) * m_pTransData->fScaleX,
732 LwpTools::ConvertFromTwips(m_aVector[nPtIndex].y) * m_pTransData->fScaleY);
733 nPtIndex++;
734 XFPoint aCtrl2(LwpTools::ConvertFromTwips(m_aVector[nPtIndex].x) * m_pTransData->fScaleX,
735 LwpTools::ConvertFromTwips(m_aVector[nPtIndex].y) * m_pTransData->fScaleY);
736 nPtIndex++;
737 XFPoint aDest(LwpTools::ConvertFromTwips(m_aVector[nPtIndex].x) * m_pTransData->fScaleX,
738 LwpTools::ConvertFromTwips(m_aVector[nPtIndex].y) * m_pTransData->fScaleY);
739 nPtIndex++;
741 pRoundedRect->CurveTo(aDest, aCtrl1, aCtrl2);
743 else
745 XFPoint aDest(LwpTools::ConvertFromTwips(m_aVector[nPtIndex].x) * m_pTransData->fScaleX,
746 LwpTools::ConvertFromTwips(m_aVector[nPtIndex].y) * m_pTransData->fScaleY);
747 nPtIndex++;
749 pRoundedRect->LineTo(aDest);
753 pRoundedRect->LineTo(XFPoint(LwpTools::ConvertFromTwips(m_aVector[0].x) * m_pTransData->fScaleX,
754 LwpTools::ConvertFromTwips(m_aVector[0].y) * m_pTransData->fScaleY));
755 pRoundedRect->ClosePath();
756 SetPosition(pRoundedRect);
758 pRoundedRect->SetStyleName(rStyleName);
760 return pRoundedRect;
763 rtl::Reference<XFFrame> LwpDrawRectangle::CreateStandardDrawObj(const OUString& rStyleName)
765 if (m_eType == OT_RNDRECT)
767 return CreateRoundedRect(rStyleName);
769 else
771 rtl::Reference<XFDrawRect> xRect(new XFDrawRect());
772 double fStartX, fStartY, fWidth, fHeight;
773 double fRotAngle = 0.0;
774 SdwRectangle aSdwRect;
775 tools::Rectangle aOriginalRect;
776 Point aPt0, aPt1, aPt2, aPt3;
778 aPt0.setX(m_aVector[0].x); aPt0.setY(m_aVector[0].y);
779 aPt1.setX(m_aVector[1].x); aPt1.setY(m_aVector[1].y);
780 aPt2.setX(m_aVector[2].x); aPt2.setY(m_aVector[2].y);
781 aPt3.setX(m_aVector[3].x); aPt3.setY(m_aVector[3].y);
783 aSdwRect = SdwRectangle(aPt0, aPt1, aPt2, aPt3);
784 if (aSdwRect.IsRectRotated())
786 aOriginalRect = aSdwRect.GetOriginalRect();
787 fRotAngle = aSdwRect.GetRotationAngle();
789 else
791 aOriginalRect = tools::Rectangle(aPt0, aPt2);
794 fStartX = aOriginalRect.Left();
795 fStartY = aOriginalRect.Top();
796 fWidth = aOriginalRect.GetWidth();
797 fHeight = aOriginalRect.GetHeight();
799 xRect->SetStartPoint(XFPoint(LwpTools::ConvertFromTwips(fStartX) + m_pTransData->fOffsetX,
800 LwpTools::ConvertFromTwips(fStartY) + m_pTransData->fOffsetY));
801 xRect->SetSize(LwpTools::ConvertFromTwips(fWidth), LwpTools::ConvertFromTwips(fHeight));
803 if (aSdwRect.IsRectRotated())
805 xRect->SetRotate( basegfx::rad2deg(fRotAngle) );// aXFCenter);
808 xRect->SetStyleName(rStyleName);
810 return xRect;
815 * @descr Constructor of class LwpDrawEllipse
816 * @param pStream The memory stream which contains the lwp-sdw draw objects
818 LwpDrawEllipse::LwpDrawEllipse(SvStream * pStream, DrawingOffsetAndScale* pTransData)
819 : LwpDrawObj(pStream, pTransData)
824 * @descr reading function of class LwpDrawEllipse
826 void LwpDrawEllipse::Read()
828 ReadClosedObjStyle();
830 for (SdwPoint & nC : m_aVector)
832 m_pStream->ReadInt16( nC.x );
833 m_pStream->ReadInt16( nC.y );
837 OUString LwpDrawEllipse::RegisterStyle()
839 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
841 // set line style
842 SetLineStyle(pStyle.get(), m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
843 m_aClosedObjStyleRec.aPenColor);
845 // set fill style
846 SetFillStyle(pStyle.get());
848 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
849 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
852 rtl::Reference<XFFrame> LwpDrawEllipse::CreateDrawObj(const OUString& rStyleName )
854 rtl::Reference<XFDrawPath> xEllipse(new XFDrawPath());
855 xEllipse->MoveTo(XFPoint(LwpTools::ConvertFromTwips(m_aVector[0].x) * m_pTransData->fScaleX,
856 LwpTools::ConvertFromTwips(m_aVector[0].y) * m_pTransData->fScaleY));
857 sal_uInt8 nPtIndex = 1;
858 for (sal_uInt8 nC = 0; nC < 4; nC++)
860 XFPoint aCtrl1(LwpTools::ConvertFromTwips(m_aVector[nPtIndex].x) * m_pTransData->fScaleX,
861 LwpTools::ConvertFromTwips(m_aVector[nPtIndex].y) * m_pTransData->fScaleY);
862 nPtIndex++;
863 XFPoint aCtrl2(LwpTools::ConvertFromTwips(m_aVector[nPtIndex].x) * m_pTransData->fScaleX,
864 LwpTools::ConvertFromTwips(m_aVector[nPtIndex].y) * m_pTransData->fScaleY);
865 nPtIndex++;
866 XFPoint aDest(LwpTools::ConvertFromTwips(m_aVector[nPtIndex].x) * m_pTransData->fScaleX,
867 LwpTools::ConvertFromTwips(m_aVector[nPtIndex].y) * m_pTransData->fScaleY);
868 nPtIndex++;
870 xEllipse->CurveTo(aDest, aCtrl1, aCtrl2);
872 xEllipse->ClosePath();
873 SetPosition(xEllipse.get());
875 xEllipse->SetStyleName(rStyleName);
877 return xEllipse;
880 rtl::Reference<XFFrame> LwpDrawEllipse::CreateStandardDrawObj(const OUString& rStyleName)
882 return CreateDrawObj(rStyleName);
886 * @descr Constructor of class LwpDrawArc
887 * @param pStream The memory stream which contains the lwp-sdw draw objects
889 LwpDrawArc::LwpDrawArc(SvStream * pStream, DrawingOffsetAndScale* pTransData)
890 : LwpDrawObj(pStream, pTransData)
895 * @descr reading function of class LwpDrawArc
897 void LwpDrawArc::Read()
899 m_pStream->SeekRel(16);// arcRect, startPt, endPt
901 m_pStream->ReadUChar( m_aArcRec.nLineWidth );
902 m_pStream->ReadUChar( m_aArcRec.nLineStyle );
903 m_pStream->ReadUChar( m_aArcRec.aPenColor.nR );
904 m_pStream->ReadUChar( m_aArcRec.aPenColor.nG );
905 m_pStream->ReadUChar( m_aArcRec.aPenColor.nB );
906 m_pStream->ReadUChar( m_aArcRec.aPenColor.unused );
907 m_pStream->ReadUChar( m_aArcRec.nLineEnd );
909 for (SdwPoint & nC : m_aVector)
911 m_pStream->ReadInt16( nC.x );
912 m_pStream->ReadInt16( nC.y );
916 OUString LwpDrawArc::RegisterStyle()
918 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
920 // set line style
921 SetLineStyle(pStyle.get(), m_aArcRec.nLineWidth, m_aArcRec.nLineStyle,
922 m_aArcRec.aPenColor);
924 // set arrow head
925 SetArrowHead(pStyle.get(), m_aArcRec.nLineEnd, m_aArcRec.nLineWidth);
927 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
928 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
931 rtl::Reference<XFFrame> LwpDrawArc::CreateDrawObj(const OUString& rStyleName )
933 rtl::Reference<XFDrawPath> xArc(new XFDrawPath());
934 xArc->MoveTo(XFPoint(LwpTools::ConvertFromTwips(m_aVector[0].x) * m_pTransData->fScaleX,
935 LwpTools::ConvertFromTwips(m_aVector[0].y) * m_pTransData->fScaleY));
936 XFPoint aDest(LwpTools::ConvertFromTwips(m_aVector[3].x) * m_pTransData->fScaleX,
937 LwpTools::ConvertFromTwips(m_aVector[3].y) * m_pTransData->fScaleY);
938 XFPoint aCtl1(LwpTools::ConvertFromTwips(m_aVector[1].x) * m_pTransData->fScaleX,
939 LwpTools::ConvertFromTwips(m_aVector[1].y) * m_pTransData->fScaleY);
940 XFPoint aCtl2(LwpTools::ConvertFromTwips(m_aVector[2].x) * m_pTransData->fScaleX,
941 LwpTools::ConvertFromTwips(m_aVector[2].y) * m_pTransData->fScaleY);
942 xArc->CurveTo(aDest, aCtl1, aCtl2);
944 SetPosition(xArc.get());
946 xArc->SetStyleName(rStyleName);
948 return xArc;
951 rtl::Reference<XFFrame> LwpDrawArc::CreateStandardDrawObj(const OUString& rStyleName)
953 return CreateDrawObj(rStyleName);
957 * @descr Constructor of class LwpDrawTextBox
958 * @param pStream The memory stream which contains the lwp-sdw draw objects
960 LwpDrawTextBox::LwpDrawTextBox(SvStream* pStream) : LwpDrawObj(pStream)
964 LwpDrawTextBox::~LwpDrawTextBox()
966 if (m_aTextRec.pTextString)
968 delete [] m_aTextRec.pTextString;
969 m_aTextRec.pTextString = nullptr;
973 void LwpDrawTextBox::SetFontStyle(rtl::Reference<XFFont> const & pFont, SdwTextBoxRecord const * pRec)
975 // color
976 XFColor aXFColor(pRec->aTextColor.nR, pRec->aTextColor.nG,
977 pRec->aTextColor.nB);
978 pFont->SetColor(aXFColor);
979 //size
980 pFont->SetFontSize(pRec->nTextSize/20);
981 // bold
982 pFont->SetBold((pRec->nTextAttrs & TA_BOLD) != 0);
983 // italic
984 pFont->SetItalic((pRec->nTextAttrs & TA_ITALIC) != 0);
985 // strike-through
986 if (pRec->nTextAttrs & TA_STRIKETHRU)
988 pFont->SetCrossout(enumXFCrossoutSignel);
990 else
992 pFont->SetCrossout(enumXFCrossoutNone);
994 // underline
995 if (pRec->nTextAttrs & TA_UNDERLINE)
997 pFont->SetUnderline(enumXFUnderlineSingle);
999 else if (pRec->nTextAttrs & TA_WORDUNDERLINE)
1001 pFont->SetUnderline(enumXFUnderlineSingle, true);
1003 else if (pRec->nTextAttrs & TA_DOUBLEUNDER)
1005 pFont->SetUnderline(enumXFUnderlineDouble);
1007 else
1009 pFont->SetUnderline(enumXFUnderlineNone);
1011 // small-caps
1012 if (pRec->nTextAttrs & TA_SMALLCAPS)
1014 pFont->SetTransform(enumXFTransformSmallCaps);
1019 * @descr reading function of class LwpDrawTextBox
1021 void LwpDrawTextBox::Read()
1023 m_pStream->ReadInt16( m_aVector.x );
1024 m_pStream->ReadInt16( m_aVector.y );
1025 m_pStream->ReadInt16( m_aTextRec.nTextWidth );
1027 if (m_aTextRec.nTextWidth == 0)
1028 m_aTextRec.nTextWidth = 1;
1030 m_pStream->ReadInt16( m_aTextRec.nTextHeight );
1031 m_pStream->ReadBytes(m_aTextRec.tmpTextFaceName, DRAW_FACESIZE);
1032 m_aTextRec.tmpTextFaceName[DRAW_FACESIZE - 1] = 0;
1033 m_pStream->SeekRel(1);// PitchAndFamily
1035 m_pStream->ReadInt16( m_aTextRec.nTextSize );
1037 if (m_aTextRec.nTextSize < 0)
1038 m_aTextRec.nTextSize = -m_aTextRec.nTextSize;
1040 //color
1041 m_pStream->ReadUChar( m_aTextRec.aTextColor.nR );
1042 m_pStream->ReadUChar( m_aTextRec.aTextColor.nG );
1043 m_pStream->ReadUChar( m_aTextRec.aTextColor.nB );
1044 m_pStream->ReadUChar( m_aTextRec.aTextColor.unused );
1046 m_pStream->ReadUInt16( m_aTextRec.nTextAttrs );
1047 m_pStream->ReadUInt16( m_aTextRec.nTextCharacterSet );
1048 m_pStream->ReadInt16( m_aTextRec.nTextRotation );
1049 m_pStream->ReadInt16( m_aTextRec.nTextExtraSpacing );
1051 if (!m_pStream->good())
1052 throw BadRead();
1054 // some draw files in version 1.2 have an extra byte following '\0'.
1055 // can't rely on that, so read in the whole string into memory.
1057 // the 71 is the fixed length before text content in textbox record
1058 sal_Int16 TextLength = m_aObjHeader.nRecLen - 71;
1059 if (TextLength < 0)
1060 throw BadRead();
1061 m_aTextRec.pTextString = new sal_uInt8[TextLength];
1062 if (m_pStream->ReadBytes(m_aTextRec.pTextString, TextLength) != o3tl::make_unsigned(TextLength))
1063 throw BadRead();
1066 OUString LwpDrawTextBox::RegisterStyle()
1068 std::unique_ptr<XFParaStyle> pStyle(new XFParaStyle());
1070 // font style
1071 // the pFont need to be deleted myself?
1072 rtl::Reference<XFFont> pFont = new XFFont();
1074 OUString aFontName(reinterpret_cast<char*>(m_aTextRec.tmpTextFaceName),
1075 strlen(reinterpret_cast<char*>(m_aTextRec.tmpTextFaceName)), RTL_TEXTENCODING_MS_1252);
1076 pFont->SetFontName(aFontName);
1078 SetFontStyle(pFont, &m_aTextRec);
1080 pStyle->SetFont(pFont);
1082 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1083 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
1086 rtl::Reference<XFFrame> LwpDrawTextBox::CreateDrawObj(const OUString& rStyleName )
1088 rtl::Reference<XFFrame> xTextBox(new XFFrame(true));
1090 sal_Int16 TextLength = m_aObjHeader.nRecLen - 71;
1091 rtl_TextEncoding aEncoding;
1092 if (!m_aTextRec.nTextCharacterSet)
1094 aEncoding = osl_getThreadTextEncoding();
1096 else
1098 // temporary code, need to create Encoding from the value of nTextCharacterSet
1099 aEncoding = LwpCharSetMgr::GetTextCharEncoding();
1102 if (TextLength < 2)
1103 throw BadRead();
1105 XFParagraph* pXFPara = new XFParagraph();
1106 pXFPara->Add(OUString(reinterpret_cast<char*>(m_aTextRec.pTextString), (TextLength-2), aEncoding));
1107 pXFPara->SetStyleName(rStyleName);
1109 xTextBox->Add(pXFPara);
1110 SetPosition(xTextBox.get());
1112 std::unique_ptr<XFTextBoxStyle> pBoxStyle(new XFTextBoxStyle());
1114 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1115 OUString sName = pXFStyleManager->AddStyle(std::move(pBoxStyle)).m_pStyle->GetStyleName();
1116 xTextBox->SetStyleName(sName);
1118 return xTextBox;
1121 rtl::Reference<XFFrame> LwpDrawTextBox::CreateStandardDrawObj(const OUString& rStyleName)
1123 return CreateDrawObj(rStyleName);
1127 * @descr Constructor of class LwpDrawTextBox
1128 * @param pStream The memory stream which contains the lwp-sdw draw objects
1130 LwpDrawTextArt::LwpDrawTextArt(SvStream* pStream, DrawingOffsetAndScale* pTransData)
1131 : LwpDrawObj(pStream, pTransData)
1135 LwpDrawTextArt::~LwpDrawTextArt()
1137 m_aTextArtRec.aPath[0].aPts.clear();
1138 m_aTextArtRec.aPath[1].aPts.clear();
1139 if (m_aTextArtRec.pTextString)
1141 delete [] m_aTextArtRec.pTextString;
1142 m_aTextArtRec.pTextString = nullptr;
1147 void LwpDrawTextArt::CreateFWPath(XFDrawPath* pPath)
1149 sal_Int16 nX, nY;
1150 nX = (m_aTextArtRec.aPath[0].aPts[0].x + m_aTextArtRec.aPath[1].aPts[0].x) / 2;
1151 nY = (m_aTextArtRec.aPath[0].aPts[0].y + m_aTextArtRec.aPath[1].aPts[0].y) / 2;
1152 XFPoint aStart(LwpTools::ConvertFromTwips(nX) * m_pTransData->fScaleX,
1153 LwpTools::ConvertFromTwips(nY) * m_pTransData->fScaleY);
1154 pPath->MoveTo(aStart);
1156 sal_uInt8 nPtIndex = 1;
1157 for (sal_uInt16 nC = 1; nC <= m_aTextArtRec.aPath[0].n; nC++)
1159 nX = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).x + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).x) / 2;
1160 nY = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).y + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).y) / 2;
1161 XFPoint aCtrl1(LwpTools::ConvertFromTwips(nX) * m_pTransData->fScaleX,
1162 LwpTools::ConvertFromTwips(nY) * m_pTransData->fScaleY);
1164 nPtIndex++;
1165 nX = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).x + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).x) / 2;
1166 nY = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).y + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).y) / 2;
1167 XFPoint aCtrl2(LwpTools::ConvertFromTwips(nX) * m_pTransData->fScaleX,
1168 LwpTools::ConvertFromTwips(nY) * m_pTransData->fScaleY);
1170 nPtIndex++;
1171 nX = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).x + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).x) / 2;
1172 nY = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).y + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).y) / 2;
1173 XFPoint aDest(LwpTools::ConvertFromTwips(nX) * m_pTransData->fScaleX,
1174 LwpTools::ConvertFromTwips(nY) * m_pTransData->fScaleY);
1176 pPath->CurveTo(aDest, aCtrl1, aCtrl2);
1180 void LwpDrawTextArt::Read()
1182 for (SdwPoint & nC : m_aVector)
1184 m_pStream->ReadInt16( nC.x );
1185 m_pStream->ReadInt16( nC.y );
1188 ReadClosedObjStyle();
1189 m_aTextArtRec.aTextColor = m_aClosedObjStyleRec.aForeColor;
1191 m_pStream->ReadUChar( m_aTextArtRec.nIndex );
1192 m_pStream->ReadInt16( m_aTextArtRec.nRotation );
1194 sal_uInt16 nPointNumber;
1195 m_pStream->ReadUInt16( nPointNumber );
1197 size_t nPoints = nPointNumber*3+1;
1198 if (!m_pStream->good() || nPoints > m_pStream->remainingSize() / 4)
1199 throw BadRead();
1201 m_aTextArtRec.aPath[0].n = nPointNumber;
1202 m_aTextArtRec.aPath[0].aPts.resize(nPoints);
1203 for (size_t nPt = 0; nPt < nPoints; ++nPt)
1205 sal_Int16 nX, nY;
1206 m_pStream->ReadInt16( nX );
1207 m_pStream->ReadInt16( nY );
1208 m_aTextArtRec.aPath[0].aPts[nPt].x = nX;
1209 m_aTextArtRec.aPath[0].aPts[nPt].y = nY;
1212 m_pStream->ReadUInt16( nPointNumber );
1214 nPoints = nPointNumber*3+1;
1215 if (!m_pStream->good() || nPoints > m_pStream->remainingSize() / 4)
1216 throw BadRead();
1218 m_aTextArtRec.aPath[1].n = nPointNumber;
1219 m_aTextArtRec.aPath[1].aPts.resize(nPoints);
1220 for (size_t nPt = 0; nPt < nPoints; ++nPt)
1222 sal_Int16 nX, nY;
1223 m_pStream->ReadInt16( nX );
1224 m_pStream->ReadInt16( nY );
1225 m_aTextArtRec.aPath[1].aPts[nPt].x = nX;
1226 m_aTextArtRec.aPath[1].aPts[nPt].y = nY;
1229 m_pStream->SeekRel(1);
1231 m_pStream->ReadBytes(m_aTextArtRec.tmpTextFaceName, DRAW_FACESIZE);
1232 m_aTextArtRec.tmpTextFaceName[DRAW_FACESIZE - 1] = 0;
1233 m_pStream->SeekRel(1);// PitchAndFamily
1235 m_pStream->ReadInt16( m_aTextArtRec.nTextSize );
1237 if (m_aTextArtRec.nTextSize < 0)
1238 m_aTextArtRec.nTextSize = -m_aTextArtRec.nTextSize;
1240 m_pStream->ReadUInt16( m_aTextArtRec.nTextAttrs );
1241 m_pStream->ReadUInt16( m_aTextArtRec.nTextCharacterSet );
1242 m_aTextArtRec.nTextRotation = 0;
1243 m_pStream->ReadInt16( m_aTextArtRec.nTextExtraSpacing );
1245 const sal_uInt16 nTextArtFixedLength = 105;
1246 m_aTextArtRec.nTextLen = m_aObjHeader.nRecLen - nTextArtFixedLength
1247 - (m_aTextArtRec.aPath[0].n*3 + 1)*4
1248 - (m_aTextArtRec.aPath[1].n*3 + 1)*4;
1251 if (!m_pStream->good())
1252 throw BadRead();
1253 if (m_aTextArtRec.nTextLen > m_pStream->remainingSize())
1254 throw BadRead();
1255 if (m_aTextArtRec.nTextLen < 1)
1256 throw BadRead();
1258 m_aTextArtRec.pTextString = new sal_uInt8 [m_aTextArtRec.nTextLen];
1259 m_pStream->ReadBytes(m_aTextArtRec.pTextString, m_aTextArtRec.nTextLen);
1260 m_aTextArtRec.pTextString[m_aTextArtRec.nTextLen-1] = 0;
1264 OUString LwpDrawTextArt::RegisterStyle()
1266 std::unique_ptr<XFParaStyle> pStyle(new XFParaStyle());
1268 // font style
1269 // the pFont need to be deleted myself?
1270 rtl::Reference<XFFont> pFont = new XFFont();
1272 OUString aFontName(reinterpret_cast<char*>(m_aTextArtRec.tmpTextFaceName),
1273 strlen(reinterpret_cast<char*>(m_aTextArtRec.tmpTextFaceName)), RTL_TEXTENCODING_MS_1252);
1274 pFont->SetFontName(aFontName);
1276 LwpDrawTextBox::SetFontStyle(pFont, &m_aTextArtRec);
1278 pStyle->SetFont(pFont);
1280 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1281 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
1284 rtl::Reference<XFFrame> LwpDrawTextArt::CreateDrawObj(const OUString& rStyleName)
1286 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
1288 rtl::Reference<XFFrame> xRetObj(new XFDrawPath());
1289 XFDrawPath* pFWPath = static_cast<XFDrawPath*>(xRetObj.get());
1290 CreateFWPath(pFWPath);
1291 pStyle->SetFontWorkStyle(enumXFFWSlantY, enumXFFWAdjustAutosize);
1293 SetPosition(xRetObj.get());
1295 rtl_TextEncoding aEncoding;
1296 if (!m_aTextArtRec.nTextCharacterSet)
1298 aEncoding = osl_getThreadTextEncoding();
1300 else
1302 // temporary code, need to create Encoding from the value of nTextCharacterSet
1303 aEncoding = LwpCharSetMgr::GetTextCharEncoding();
1306 XFParagraph* pXFPara = new XFParagraph();
1307 pXFPara->Add(OUString(reinterpret_cast<char*>(m_aTextArtRec.pTextString), (m_aTextArtRec.nTextLen-1), aEncoding));
1308 pXFPara->SetStyleName(rStyleName);
1309 xRetObj->Add(pXFPara);
1311 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1312 xRetObj->SetStyleName(pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName());
1314 return xRetObj;
1317 rtl::Reference<XFFrame> LwpDrawTextArt::CreateStandardDrawObj(const OUString& rStyleName )
1319 return CreateDrawObj(rStyleName);
1323 * @descr Constructor of class LwpDrawMetafile
1324 * @param pStream The memory stream which contains the lwp-sdw draw objects
1326 LwpDrawMetafile::LwpDrawMetafile(SvStream* pStream) : LwpDrawObj(pStream)
1331 * @descr reading function of class LwpDrawMetafile
1333 void LwpDrawMetafile::Read()
1335 m_pStream->SeekRel(m_aObjHeader.nRecLen -16);
1339 * @descr Constructor of class LwpDrawBitmap
1340 * @param pStream The memory stream which contains the lwp-sdw draw objects
1342 LwpDrawBitmap::LwpDrawBitmap(SvStream* pStream) : LwpDrawObj(pStream)
1346 LwpDrawBitmap::~LwpDrawBitmap()
1350 static bool IsValid(const BmpInfoHeader2& rHeader)
1352 if (rHeader.nPlanes != 1)
1353 return false;
1355 if (rHeader.nBitCount != 0 && rHeader.nBitCount != 1 &&
1356 rHeader.nBitCount != 4 && rHeader.nBitCount != 8 &&
1357 rHeader.nBitCount != 16 && rHeader.nBitCount != 24 &&
1358 rHeader.nBitCount != 32)
1360 return false;
1363 return true;
1367 * @descr reading function of class LwpDrawBitmap
1369 void LwpDrawBitmap::Read()
1371 m_pStream->ReadUInt16( m_aBmpRec.nTranslation );
1372 m_pStream->ReadUInt16( m_aBmpRec.nRotation );
1374 // 20 == length of draw-specific fields.
1375 if (m_aObjHeader.nRecLen < 20)
1376 throw BadRead();
1378 sal_uInt64 nBmpPos = m_pStream->Tell();
1379 sal_uInt64 nBmpLen =
1380 std::min<sal_uInt64>(m_aObjHeader.nRecLen - 20, m_pStream->remainingSize());
1382 BmpInfoHeader2 aInfoHeader2;
1383 m_pStream->ReadUInt32( aInfoHeader2.nHeaderLen );
1385 if (!m_pStream->good() || nBmpLen < aInfoHeader2.nHeaderLen)
1386 throw BadRead();
1388 sal_uInt32 N;
1389 sal_uInt32 rgbTableSize;
1391 if (aInfoHeader2.nHeaderLen == sizeof(BmpInfoHeader))
1393 sal_uInt16 nTmp;
1395 m_pStream->ReadUInt16( nTmp );
1396 aInfoHeader2.nWidth = nTmp;
1397 m_pStream->ReadUInt16( nTmp );
1398 aInfoHeader2.nHeight = nTmp;
1399 m_pStream->ReadUInt16( aInfoHeader2.nPlanes );
1400 m_pStream->ReadUInt16( aInfoHeader2.nBitCount );
1402 if (!m_pStream->good() || !IsValid(aInfoHeader2))
1403 throw BadRead();
1405 N = aInfoHeader2.nPlanes * aInfoHeader2.nBitCount;
1406 if (N >= 16)
1408 rgbTableSize = 0;
1410 else
1412 rgbTableSize = 3 * (1 << N);
1415 else if (aInfoHeader2.nHeaderLen >= sizeof(BmpInfoHeader2))
1417 m_pStream->ReadUInt32( aInfoHeader2.nWidth );
1418 m_pStream->ReadUInt32( aInfoHeader2.nHeight );
1419 m_pStream->ReadUInt16( aInfoHeader2.nPlanes );
1420 m_pStream->ReadUInt16( aInfoHeader2.nBitCount );
1422 if (!m_pStream->good() || !IsValid(aInfoHeader2))
1423 throw BadRead();
1425 N = aInfoHeader2.nPlanes * aInfoHeader2.nBitCount;
1426 if (N >= 16)
1428 rgbTableSize = 0;
1430 else
1432 rgbTableSize = 4 * (1 << N);
1435 else
1437 throw BadRead();
1440 m_aBmpRec.nFileSize = static_cast<sal_uInt32>(nBmpLen + 14);
1441 m_pImageData.reset( new sal_uInt8 [m_aBmpRec.nFileSize] );
1443 sal_uInt32 nOffBits = 14 + aInfoHeader2.nHeaderLen + rgbTableSize;
1444 m_pImageData[0] = 'B';
1445 m_pImageData[1] = 'M';
1446 m_pImageData[2] = static_cast<sal_uInt8>(m_aBmpRec.nFileSize);
1447 m_pImageData[3] = static_cast<sal_uInt8>(m_aBmpRec.nFileSize >> 8);
1448 m_pImageData[4] = static_cast<sal_uInt8>(m_aBmpRec.nFileSize >> 16);
1449 m_pImageData[5] = static_cast<sal_uInt8>(m_aBmpRec.nFileSize >> 24);
1450 m_pImageData[6] = 0;
1451 m_pImageData[7] = 0;
1452 m_pImageData[8] = 0;
1453 m_pImageData[9] = 0;
1454 m_pImageData[10] = static_cast<sal_uInt8>(nOffBits);
1455 m_pImageData[11] = static_cast<sal_uInt8>(nOffBits >> 8);
1456 m_pImageData[12] = static_cast<sal_uInt8>(nOffBits >> 16);
1457 m_pImageData[13] = static_cast<sal_uInt8>(nOffBits >> 24);
1459 sal_uInt8* pPicData = m_pImageData.get();
1461 m_pStream->Seek(nBmpPos);
1462 if (nBmpLen != m_pStream->ReadBytes(pPicData + 14, nBmpLen))
1463 throw BadRead();
1466 OUString LwpDrawBitmap::RegisterStyle()
1468 std::unique_ptr<XFImageStyle> pBmpStyle(new XFImageStyle());
1469 pBmpStyle->SetYPosType(enumXFFrameYPosFromTop, enumXFFrameYRelFrame);
1470 pBmpStyle->SetXPosType(enumXFFrameXPosFromLeft, enumXFFrameXRelFrame);
1472 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1473 return pXFStyleManager->AddStyle(std::move(pBmpStyle)).m_pStyle->GetStyleName();
1476 rtl::Reference<XFFrame> LwpDrawBitmap::CreateDrawObj(const OUString& rStyleName)
1478 rtl::Reference<XFImage> xImage(new XFImage());
1479 xImage->SetImageData(m_pImageData.get(), m_aBmpRec.nFileSize);
1480 SetPosition(xImage.get());
1482 xImage->SetStyleName(rStyleName);
1484 return xImage;
1487 rtl::Reference<XFFrame> LwpDrawBitmap::CreateStandardDrawObj(const OUString& rStyleName)
1489 return CreateDrawObj(rStyleName);
1492 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */