android: Update app-specific/MIME type icons
[LibreOffice.git] / lotuswordpro / source / filter / lwpdrawobj.cxx
blob5b704c1d5065a8f80341a239cf32f835a426a475
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 = static_cast<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(static_cast<double>(m_aObjHeader.nLeft)/TWIPS_PER_CM * fScaleX+ fOffsetX,
284 static_cast<double>(m_aObjHeader.nTop)/TWIPS_PER_CM * fScaleY + fOffsetY,
285 static_cast<double>(m_aObjHeader.nRight-m_aObjHeader.nLeft)/TWIPS_PER_CM * fScaleX,
286 static_cast<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 = static_cast<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( GetArrowName(nLeftArrow), fArrowSize);
322 if (nRightArrow)
324 pOpenedObjStyle->SetArrowEnd( GetArrowName(nRightArrow), fArrowSize);
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 rtl::Reference<XFFrame> LwpDrawObj::CreateXFDrawObject()
380 // read records
381 Read();
383 // register style
384 OUString aStyleName = RegisterStyle();
386 // create XF-Objects
387 rtl::Reference<XFFrame> xXFObj;
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 xXFObj = CreateStandardDrawObj(aStyleName);
396 else
398 xXFObj = CreateDrawObj(aStyleName);
401 // set anchor type
402 if (xXFObj)
404 xXFObj->SetAnchorType(enumXFAnchorFrame);
407 return xXFObj;
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 std::unique_ptr<XFDrawStyle> pStyle( new XFDrawStyle() );
442 // set line style
443 SetLineStyle(pStyle.get(), m_aLineRec.nLineWidth, m_aLineRec.nLineStyle, m_aLineRec.aPenColor);
445 // set arrow head
446 SetArrowHead(pStyle.get(), m_aLineRec.nLineEnd, m_aLineRec.nLineWidth);
448 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
449 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
452 rtl::Reference<XFFrame> LwpDrawLine::CreateDrawObj(const OUString& rStyleName )
454 rtl::Reference<XFDrawPath> xLine(new XFDrawPath());
455 xLine->MoveTo(XFPoint(static_cast<double>(m_aLineRec.nStartX)/TWIPS_PER_CM * m_pTransData->fScaleX,
456 static_cast<double>(m_aLineRec.nStartY)/TWIPS_PER_CM * m_pTransData->fScaleY));
457 xLine->LineTo(XFPoint(static_cast<double>(m_aLineRec.nEndX)/TWIPS_PER_CM * m_pTransData->fScaleX,
458 static_cast<double>(m_aLineRec.nEndY)/TWIPS_PER_CM * m_pTransData->fScaleY));
459 SetPosition(xLine.get());
461 xLine->SetStyleName(rStyleName);
463 return xLine;
466 rtl::Reference<XFFrame> LwpDrawLine::CreateStandardDrawObj(const OUString& rStyleName)
468 rtl::Reference<XFDrawLine> xLine(new XFDrawLine());
469 xLine->SetStartPoint(static_cast<double>(m_aLineRec.nStartX)/TWIPS_PER_CM,static_cast<double>(m_aLineRec.nStartY)/TWIPS_PER_CM);
470 xLine->SetEndPoint(static_cast<double>(m_aLineRec.nEndX)/TWIPS_PER_CM,static_cast<double>(m_aLineRec.nEndY)/TWIPS_PER_CM);
472 xLine->SetStyleName(rStyleName);
473 return xLine;
477 * @descr Constructor of class LwpDrawPolyLine
478 * @param pStream The memory stream which contains the lwp-sdw draw objects
480 LwpDrawPolyLine::LwpDrawPolyLine(SvStream * pStream, DrawingOffsetAndScale* pTransData)
481 : LwpDrawObj(pStream, pTransData)
484 LwpDrawPolyLine::~LwpDrawPolyLine()
489 * @descr reading function of class LwpDrawPolyLine
491 void LwpDrawPolyLine::Read()
493 m_pStream->ReadUChar( m_aPolyLineRec.nLineWidth );
494 m_pStream->ReadUChar( m_aPolyLineRec.nLineEnd );
495 m_pStream->ReadUChar( m_aPolyLineRec.nLineStyle );
496 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.nR );
497 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.nG );
498 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.nB );
499 m_pStream->ReadUChar( m_aPolyLineRec.aPenColor.unused );
500 m_pStream->ReadUInt16( m_aPolyLineRec.nNumPoints );
502 if (!m_pStream->good() || m_aPolyLineRec.nNumPoints > m_pStream->remainingSize() / 4)
503 throw BadRead();
505 m_pVector.reset( new SdwPoint[m_aPolyLineRec.nNumPoints] );
507 for (sal_uInt16 nC = 0; nC < m_aPolyLineRec.nNumPoints; nC++)
509 m_pStream->ReadInt16( m_pVector[nC].x );
510 m_pStream->ReadInt16( m_pVector[nC].y );
514 OUString LwpDrawPolyLine::RegisterStyle()
516 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
518 // set line style
519 SetLineStyle(pStyle.get(), m_aPolyLineRec.nLineWidth, m_aPolyLineRec.nLineStyle,
520 m_aPolyLineRec.aPenColor);
522 // set arrow head
523 SetArrowHead(pStyle.get(), m_aPolyLineRec.nLineEnd, m_aPolyLineRec.nLineWidth);
525 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
526 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
529 rtl::Reference<XFFrame> LwpDrawPolyLine::CreateDrawObj(const OUString& rStyleName )
531 rtl::Reference<XFDrawPath> xPolyline(new XFDrawPath());
532 xPolyline->MoveTo(XFPoint(static_cast<double>(m_pVector[0].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
533 static_cast<double>(m_pVector[0].y)/TWIPS_PER_CM * m_pTransData->fScaleY));
534 for (sal_uInt16 nC = 1; nC < m_aPolyLineRec.nNumPoints; nC++)
536 xPolyline->LineTo(XFPoint(static_cast<double>(m_pVector[nC].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
537 static_cast<double>(m_pVector[nC].y)/TWIPS_PER_CM * m_pTransData->fScaleY));
539 SetPosition(xPolyline.get());
541 xPolyline->SetStyleName(rStyleName);
543 return xPolyline;
546 rtl::Reference<XFFrame> LwpDrawPolyLine::CreateStandardDrawObj(const OUString& rStyleName)
548 rtl::Reference<XFDrawPolyline> xPolyline(new XFDrawPolyline());
549 for (sal_uInt16 nC = 0; nC < m_aPolyLineRec.nNumPoints; nC++)
551 xPolyline->AddPoint(static_cast<double>(m_pVector[nC].x)/TWIPS_PER_CM,
552 static_cast<double>(m_pVector[nC].y)/TWIPS_PER_CM);
555 xPolyline->SetStyleName(rStyleName);
557 return xPolyline;
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)
566 , m_nNumPoints(0)
570 LwpDrawPolygon::~LwpDrawPolygon()
575 * @descr reading function of class LwpDrawPolygon
577 void LwpDrawPolygon::Read()
579 ReadClosedObjStyle();
580 m_pStream->ReadUInt16( m_nNumPoints );
582 if (!m_pStream->good() || m_nNumPoints > m_pStream->remainingSize() / 4)
583 throw BadRead();
585 m_pVector.reset( new SdwPoint[m_nNumPoints] );
587 for (sal_uInt16 nC = 0; nC < m_nNumPoints; nC++)
589 m_pStream->ReadInt16( m_pVector[nC].x );
590 m_pStream->ReadInt16( m_pVector[nC].y );
594 OUString LwpDrawPolygon::RegisterStyle()
596 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
598 // set line style
599 SetLineStyle(pStyle.get(), m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
600 m_aClosedObjStyleRec.aPenColor);
602 // set fill style
603 SetFillStyle(pStyle.get());
605 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
606 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
609 rtl::Reference<XFFrame> LwpDrawPolygon::CreateDrawObj(const OUString& rStyleName)
611 rtl::Reference<XFDrawPath> xPolygon(new XFDrawPath());
612 xPolygon->MoveTo(XFPoint(static_cast<double>(m_pVector[0].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
613 static_cast<double>(m_pVector[0].y)/TWIPS_PER_CM * m_pTransData->fScaleY));
614 for (sal_uInt16 nC = 1; nC < m_nNumPoints; nC++)
616 xPolygon->LineTo(XFPoint(static_cast<double>(m_pVector[nC].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
617 static_cast<double>(m_pVector[nC].y)/TWIPS_PER_CM * m_pTransData->fScaleY));
619 xPolygon->ClosePath();
620 SetPosition(xPolygon.get());
621 xPolygon->SetStyleName(rStyleName);
623 return xPolygon;
626 rtl::Reference<XFFrame> LwpDrawPolygon::CreateStandardDrawObj(const OUString& rStyleName)
628 rtl::Reference<XFDrawPolygon> xPolygon(new XFDrawPolygon());
629 for (sal_uInt16 nC = 0; nC < m_nNumPoints; nC++)
631 xPolygon->AddPoint(static_cast<double>(m_pVector[nC].x)/TWIPS_PER_CM,
632 static_cast<double>(m_pVector[nC].y)/TWIPS_PER_CM);
635 xPolygon->SetStyleName(rStyleName);
637 return xPolygon;
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 ReadClosedObjStyle();
656 sal_uInt8 nPointsCount;
657 if (m_eType == OT_RNDRECT)
659 nPointsCount = 16;
660 m_pStream->SeekRel(4); // corner points
662 else
664 nPointsCount = 4;
667 for (sal_uInt8 nC = 0; nC < nPointsCount; nC++)
669 m_pStream->ReadInt16( m_aVector[nC].x );
670 m_pStream->ReadInt16( m_aVector[nC].y );
674 OUString LwpDrawRectangle::RegisterStyle()
676 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
678 // set line style
679 SetLineStyle(pStyle.get(), m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
680 m_aClosedObjStyleRec.aPenColor);
682 // set fill style
683 SetFillStyle(pStyle.get());
685 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
686 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
689 rtl::Reference<XFFrame> LwpDrawRectangle::CreateDrawObj(const OUString& rStyleName)
691 if (m_eType == OT_RNDRECT)
693 return CreateRoundedRect(rStyleName);
695 else
697 rtl::Reference<XFDrawPath> xRect(new XFDrawPath());
698 xRect->MoveTo(XFPoint(static_cast<double>(m_aVector[0].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
699 static_cast<double>(m_aVector[0].y)/TWIPS_PER_CM * m_pTransData->fScaleY));
700 for (sal_uInt8 nC = 1; nC < 4; nC++)
702 xRect->LineTo(XFPoint(static_cast<double>(m_aVector[nC].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
703 static_cast<double>(m_aVector[nC].y)/TWIPS_PER_CM * m_pTransData->fScaleY));
705 xRect->LineTo(XFPoint(static_cast<double>(m_aVector[0].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
706 static_cast<double>(m_aVector[0].y)/TWIPS_PER_CM * m_pTransData->fScaleY));
707 xRect->ClosePath();
708 SetPosition(xRect.get());
710 xRect->SetStyleName(rStyleName);
712 return xRect;
716 XFFrame* LwpDrawRectangle::CreateRoundedRect(const OUString& rStyleName)
718 XFDrawPath* pRoundedRect = new XFDrawPath();
719 pRoundedRect->MoveTo(XFPoint(static_cast<double>(m_aVector[0].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
720 static_cast<double>(m_aVector[0].y)/TWIPS_PER_CM * m_pTransData->fScaleY));
722 sal_uInt8 nPtIndex = 1;
723 for (sal_uInt8 nC = 0; nC < 7; nC++)
725 if (nC%2 == 0)
727 XFPoint aCtrl1(static_cast<double>(m_aVector[nPtIndex].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
728 static_cast<double>(m_aVector[nPtIndex].y)/TWIPS_PER_CM * m_pTransData->fScaleY);
729 nPtIndex++;
730 XFPoint aCtrl2(static_cast<double>(m_aVector[nPtIndex].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
731 static_cast<double>(m_aVector[nPtIndex].y)/TWIPS_PER_CM * m_pTransData->fScaleY);
732 nPtIndex++;
733 XFPoint aDest(static_cast<double>(m_aVector[nPtIndex].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
734 static_cast<double>(m_aVector[nPtIndex].y)/TWIPS_PER_CM * m_pTransData->fScaleY);
735 nPtIndex++;
737 pRoundedRect->CurveTo(aDest, aCtrl1, aCtrl2);
739 else
741 XFPoint aDest(static_cast<double>(m_aVector[nPtIndex].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
742 static_cast<double>(m_aVector[nPtIndex].y)/TWIPS_PER_CM * m_pTransData->fScaleY);
743 nPtIndex++;
745 pRoundedRect->LineTo(aDest);
749 pRoundedRect->LineTo(XFPoint(static_cast<double>(m_aVector[0].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
750 static_cast<double>(m_aVector[0].y)/TWIPS_PER_CM * m_pTransData->fScaleY));
751 pRoundedRect->ClosePath();
752 SetPosition(pRoundedRect);
754 pRoundedRect->SetStyleName(rStyleName);
756 return pRoundedRect;
759 rtl::Reference<XFFrame> LwpDrawRectangle::CreateStandardDrawObj(const OUString& rStyleName)
761 if (m_eType == OT_RNDRECT)
763 return CreateRoundedRect(rStyleName);
765 else
767 rtl::Reference<XFDrawRect> xRect(new XFDrawRect());
768 double fStartX, fStartY, fWidth, fHeight;
769 double fRotAngle = 0.0;
770 SdwRectangle aSdwRect;
771 tools::Rectangle aOriginalRect;
772 Point aPt0, aPt1, aPt2, aPt3;
774 aPt0.setX(m_aVector[0].x); aPt0.setY(m_aVector[0].y);
775 aPt1.setX(m_aVector[1].x); aPt1.setY(m_aVector[1].y);
776 aPt2.setX(m_aVector[2].x); aPt2.setY(m_aVector[2].y);
777 aPt3.setX(m_aVector[3].x); aPt3.setY(m_aVector[3].y);
779 aSdwRect = SdwRectangle(aPt0, aPt1, aPt2, aPt3);
780 if (aSdwRect.IsRectRotated())
782 aOriginalRect = aSdwRect.GetOriginalRect();
783 fRotAngle = aSdwRect.GetRotationAngle();
785 else
787 aOriginalRect = tools::Rectangle(aPt0, aPt2);
790 fStartX = aOriginalRect.Left();
791 fStartY = aOriginalRect.Top();
792 fWidth = aOriginalRect.GetWidth();
793 fHeight = aOriginalRect.GetHeight();
795 xRect->SetStartPoint(XFPoint(fStartX/TWIPS_PER_CM + m_pTransData->fOffsetX,
796 fStartY/TWIPS_PER_CM + m_pTransData->fOffsetY));
797 xRect->SetSize(fWidth/TWIPS_PER_CM, fHeight/TWIPS_PER_CM);
799 if (aSdwRect.IsRectRotated())
801 xRect->SetRotate( basegfx::rad2deg(fRotAngle) );// aXFCenter);
804 xRect->SetStyleName(rStyleName);
806 return xRect;
811 * @descr Constructor of class LwpDrawEllipse
812 * @param pStream The memory stream which contains the lwp-sdw draw objects
814 LwpDrawEllipse::LwpDrawEllipse(SvStream * pStream, DrawingOffsetAndScale* pTransData)
815 : LwpDrawObj(pStream, pTransData)
820 * @descr reading function of class LwpDrawEllipse
822 void LwpDrawEllipse::Read()
824 ReadClosedObjStyle();
826 for (SdwPoint & nC : m_aVector)
828 m_pStream->ReadInt16( nC.x );
829 m_pStream->ReadInt16( nC.y );
833 OUString LwpDrawEllipse::RegisterStyle()
835 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
837 // set line style
838 SetLineStyle(pStyle.get(), m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
839 m_aClosedObjStyleRec.aPenColor);
841 // set fill style
842 SetFillStyle(pStyle.get());
844 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
845 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
848 rtl::Reference<XFFrame> LwpDrawEllipse::CreateDrawObj(const OUString& rStyleName )
850 rtl::Reference<XFDrawPath> xEllipse(new XFDrawPath());
851 xEllipse->MoveTo(XFPoint(static_cast<double>(m_aVector[0].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
852 static_cast<double>(m_aVector[0].y)/TWIPS_PER_CM * m_pTransData->fScaleY));
853 sal_uInt8 nPtIndex = 1;
854 for (sal_uInt8 nC = 0; nC < 4; nC++)
856 XFPoint aCtrl1(static_cast<double>(m_aVector[nPtIndex].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
857 static_cast<double>(m_aVector[nPtIndex].y)/TWIPS_PER_CM * m_pTransData->fScaleY);
858 nPtIndex++;
859 XFPoint aCtrl2(static_cast<double>(m_aVector[nPtIndex].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
860 static_cast<double>(m_aVector[nPtIndex].y)/TWIPS_PER_CM * m_pTransData->fScaleY);
861 nPtIndex++;
862 XFPoint aDest(static_cast<double>(m_aVector[nPtIndex].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
863 static_cast<double>(m_aVector[nPtIndex].y)/TWIPS_PER_CM * m_pTransData->fScaleY);
864 nPtIndex++;
866 xEllipse->CurveTo(aDest, aCtrl1, aCtrl2);
868 xEllipse->ClosePath();
869 SetPosition(xEllipse.get());
871 xEllipse->SetStyleName(rStyleName);
873 return xEllipse;
876 rtl::Reference<XFFrame> LwpDrawEllipse::CreateStandardDrawObj(const OUString& rStyleName)
878 return CreateDrawObj(rStyleName);
882 * @descr Constructor of class LwpDrawArc
883 * @param pStream The memory stream which contains the lwp-sdw draw objects
885 LwpDrawArc::LwpDrawArc(SvStream * pStream, DrawingOffsetAndScale* pTransData)
886 : LwpDrawObj(pStream, pTransData)
891 * @descr reading function of class LwpDrawArc
893 void LwpDrawArc::Read()
895 m_pStream->SeekRel(16);// arcRect, startPt, endPt
897 m_pStream->ReadUChar( m_aArcRec.nLineWidth );
898 m_pStream->ReadUChar( m_aArcRec.nLineStyle );
899 m_pStream->ReadUChar( m_aArcRec.aPenColor.nR );
900 m_pStream->ReadUChar( m_aArcRec.aPenColor.nG );
901 m_pStream->ReadUChar( m_aArcRec.aPenColor.nB );
902 m_pStream->ReadUChar( m_aArcRec.aPenColor.unused );
903 m_pStream->ReadUChar( m_aArcRec.nLineEnd );
905 for (SdwPoint & nC : m_aVector)
907 m_pStream->ReadInt16( nC.x );
908 m_pStream->ReadInt16( nC.y );
912 OUString LwpDrawArc::RegisterStyle()
914 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
916 // set line style
917 SetLineStyle(pStyle.get(), m_aArcRec.nLineWidth, m_aArcRec.nLineStyle,
918 m_aArcRec.aPenColor);
920 // set arrow head
921 SetArrowHead(pStyle.get(), m_aArcRec.nLineEnd, m_aArcRec.nLineWidth);
923 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
924 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
927 rtl::Reference<XFFrame> LwpDrawArc::CreateDrawObj(const OUString& rStyleName )
929 rtl::Reference<XFDrawPath> xArc(new XFDrawPath());
930 xArc->MoveTo(XFPoint(static_cast<double>(m_aVector[0].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
931 static_cast<double>(m_aVector[0].y)/TWIPS_PER_CM * m_pTransData->fScaleY));
932 XFPoint aDest(static_cast<double>(m_aVector[3].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
933 static_cast<double>(m_aVector[3].y)/TWIPS_PER_CM * m_pTransData->fScaleY);
934 XFPoint aCtl1(static_cast<double>(m_aVector[1].x)/TWIPS_PER_CM * m_pTransData->fScaleX,
935 static_cast<double>(m_aVector[1].y)/TWIPS_PER_CM * m_pTransData->fScaleY);
936 XFPoint aCtl2(static_cast<double>(m_aVector[2].x)/TWIPS_PER_CM* m_pTransData->fScaleX,
937 static_cast<double>(m_aVector[2].y)/TWIPS_PER_CM * m_pTransData->fScaleY);
938 xArc->CurveTo(aDest, aCtl1, aCtl2);
940 SetPosition(xArc.get());
942 xArc->SetStyleName(rStyleName);
944 return xArc;
947 rtl::Reference<XFFrame> LwpDrawArc::CreateStandardDrawObj(const OUString& rStyleName)
949 return CreateDrawObj(rStyleName);
953 * @descr Constructor of class LwpDrawTextBox
954 * @param pStream The memory stream which contains the lwp-sdw draw objects
956 LwpDrawTextBox::LwpDrawTextBox(SvStream* pStream) : LwpDrawObj(pStream)
960 LwpDrawTextBox::~LwpDrawTextBox()
962 if (m_aTextRec.pTextString)
964 delete [] m_aTextRec.pTextString;
965 m_aTextRec.pTextString = nullptr;
969 void LwpDrawTextBox::SetFontStyle(rtl::Reference<XFFont> const & pFont, SdwTextBoxRecord const * pRec)
971 // color
972 XFColor aXFColor(pRec->aTextColor.nR, pRec->aTextColor.nG,
973 pRec->aTextColor.nB);
974 pFont->SetColor(aXFColor);
975 //size
976 pFont->SetFontSize(pRec->nTextSize/20);
977 // bold
978 pFont->SetBold((pRec->nTextAttrs & TA_BOLD) != 0);
979 // italic
980 pFont->SetItalic((pRec->nTextAttrs & TA_ITALIC) != 0);
981 // strike-through
982 if (pRec->nTextAttrs & TA_STRIKETHRU)
984 pFont->SetCrossout(enumXFCrossoutSignel);
986 else
988 pFont->SetCrossout(enumXFCrossoutNone);
990 // underline
991 if (pRec->nTextAttrs & TA_UNDERLINE)
993 pFont->SetUnderline(enumXFUnderlineSingle);
995 else if (pRec->nTextAttrs & TA_WORDUNDERLINE)
997 pFont->SetUnderline(enumXFUnderlineSingle, true);
999 else if (pRec->nTextAttrs & TA_DOUBLEUNDER)
1001 pFont->SetUnderline(enumXFUnderlineDouble);
1003 else
1005 pFont->SetUnderline(enumXFUnderlineNone);
1007 // small-caps
1008 if (pRec->nTextAttrs & TA_SMALLCAPS)
1010 pFont->SetTransform(enumXFTransformSmallCaps);
1015 * @descr reading function of class LwpDrawTextBox
1017 void LwpDrawTextBox::Read()
1019 m_pStream->ReadInt16( m_aVector.x );
1020 m_pStream->ReadInt16( m_aVector.y );
1021 m_pStream->ReadInt16( m_aTextRec.nTextWidth );
1023 if (m_aTextRec.nTextWidth == 0)
1024 m_aTextRec.nTextWidth = 1;
1026 m_pStream->ReadInt16( m_aTextRec.nTextHeight );
1027 m_pStream->ReadBytes(m_aTextRec.tmpTextFaceName, DRAW_FACESIZE);
1028 m_aTextRec.tmpTextFaceName[DRAW_FACESIZE - 1] = 0;
1029 m_pStream->SeekRel(1);// PitchAndFamily
1031 m_pStream->ReadInt16( m_aTextRec.nTextSize );
1033 if (m_aTextRec.nTextSize < 0)
1034 m_aTextRec.nTextSize = -m_aTextRec.nTextSize;
1036 //color
1037 m_pStream->ReadUChar( m_aTextRec.aTextColor.nR );
1038 m_pStream->ReadUChar( m_aTextRec.aTextColor.nG );
1039 m_pStream->ReadUChar( m_aTextRec.aTextColor.nB );
1040 m_pStream->ReadUChar( m_aTextRec.aTextColor.unused );
1042 m_pStream->ReadUInt16( m_aTextRec.nTextAttrs );
1043 m_pStream->ReadUInt16( m_aTextRec.nTextCharacterSet );
1044 m_pStream->ReadInt16( m_aTextRec.nTextRotation );
1045 m_pStream->ReadInt16( m_aTextRec.nTextExtraSpacing );
1047 if (!m_pStream->good())
1048 throw BadRead();
1050 // some draw files in version 1.2 have an extra byte following '\0'.
1051 // can't rely on that, so read in the whole string into memory.
1053 // the 71 is the fixed length before text content in textbox record
1054 sal_Int16 TextLength = m_aObjHeader.nRecLen - 71;
1055 if (TextLength < 0)
1056 throw BadRead();
1057 m_aTextRec.pTextString = new sal_uInt8[TextLength];
1058 if (m_pStream->ReadBytes(m_aTextRec.pTextString, TextLength) != o3tl::make_unsigned(TextLength))
1059 throw BadRead();
1062 OUString LwpDrawTextBox::RegisterStyle()
1064 std::unique_ptr<XFParaStyle> pStyle(new XFParaStyle());
1066 // font style
1067 // the pFont need to be deleted myself?
1068 rtl::Reference<XFFont> pFont = new XFFont();
1070 OUString aFontName(reinterpret_cast<char*>(m_aTextRec.tmpTextFaceName),
1071 strlen(reinterpret_cast<char*>(m_aTextRec.tmpTextFaceName)), RTL_TEXTENCODING_MS_1252);
1072 pFont->SetFontName(aFontName);
1074 SetFontStyle(pFont, &m_aTextRec);
1076 pStyle->SetFont(pFont);
1078 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1079 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
1082 rtl::Reference<XFFrame> LwpDrawTextBox::CreateDrawObj(const OUString& rStyleName )
1084 rtl::Reference<XFFrame> xTextBox(new XFFrame(true));
1086 sal_Int16 TextLength = m_aObjHeader.nRecLen - 71;
1087 rtl_TextEncoding aEncoding;
1088 if (!m_aTextRec.nTextCharacterSet)
1090 aEncoding = osl_getThreadTextEncoding();
1092 else
1094 // temporary code, need to create Encoding from the value of nTextCharacterSet
1095 aEncoding = LwpCharSetMgr::GetTextCharEncoding();
1098 if (TextLength < 2)
1099 throw BadRead();
1101 XFParagraph* pXFPara = new XFParagraph();
1102 pXFPara->Add(OUString(reinterpret_cast<char*>(m_aTextRec.pTextString), (TextLength-2), aEncoding));
1103 pXFPara->SetStyleName(rStyleName);
1105 xTextBox->Add(pXFPara);
1106 SetPosition(xTextBox.get());
1108 std::unique_ptr<XFTextBoxStyle> pBoxStyle(new XFTextBoxStyle());
1110 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1111 OUString sName = pXFStyleManager->AddStyle(std::move(pBoxStyle)).m_pStyle->GetStyleName();
1112 xTextBox->SetStyleName(sName);
1114 return xTextBox;
1117 rtl::Reference<XFFrame> LwpDrawTextBox::CreateStandardDrawObj(const OUString& rStyleName)
1119 return CreateDrawObj(rStyleName);
1123 * @descr Constructor of class LwpDrawTextBox
1124 * @param pStream The memory stream which contains the lwp-sdw draw objects
1126 LwpDrawTextArt::LwpDrawTextArt(SvStream* pStream, DrawingOffsetAndScale* pTransData)
1127 : LwpDrawObj(pStream, pTransData)
1131 LwpDrawTextArt::~LwpDrawTextArt()
1133 m_aTextArtRec.aPath[0].aPts.clear();
1134 m_aTextArtRec.aPath[1].aPts.clear();
1135 if (m_aTextArtRec.pTextString)
1137 delete [] m_aTextArtRec.pTextString;
1138 m_aTextArtRec.pTextString = nullptr;
1143 void LwpDrawTextArt::CreateFWPath(XFDrawPath* pPath)
1145 sal_Int16 nX, nY;
1146 nX = (m_aTextArtRec.aPath[0].aPts[0].x + m_aTextArtRec.aPath[1].aPts[0].x) / 2;
1147 nY = (m_aTextArtRec.aPath[0].aPts[0].y + m_aTextArtRec.aPath[1].aPts[0].y) / 2;
1148 XFPoint aStart(static_cast<double>(nX)/TWIPS_PER_CM * m_pTransData->fScaleX,
1149 static_cast<double>(nY)/TWIPS_PER_CM * m_pTransData->fScaleY);
1150 pPath->MoveTo(aStart);
1152 sal_uInt8 nPtIndex = 1;
1153 for (sal_uInt16 nC = 1; nC <= m_aTextArtRec.aPath[0].n; nC++)
1155 nX = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).x + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).x) / 2;
1156 nY = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).y + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).y) / 2;
1157 XFPoint aCtrl1(static_cast<double>(nX)/TWIPS_PER_CM * m_pTransData->fScaleX,
1158 static_cast<double>(nY)/TWIPS_PER_CM * m_pTransData->fScaleY);
1160 nPtIndex++;
1161 nX = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).x + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).x) / 2;
1162 nY = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).y + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).y) / 2;
1163 XFPoint aCtrl2(static_cast<double>(nX)/TWIPS_PER_CM * m_pTransData->fScaleX,
1164 static_cast<double>(nY)/TWIPS_PER_CM * m_pTransData->fScaleY);
1166 nPtIndex++;
1167 nX = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).x + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).x) / 2;
1168 nY = (m_aTextArtRec.aPath[0].aPts.at(nPtIndex).y + m_aTextArtRec.aPath[1].aPts.at(nPtIndex).y) / 2;
1169 XFPoint aDest(static_cast<double>(nX)/TWIPS_PER_CM * m_pTransData->fScaleX,
1170 static_cast<double>(nY)/TWIPS_PER_CM * m_pTransData->fScaleY);
1172 pPath->CurveTo(aDest, aCtrl1, aCtrl2);
1176 void LwpDrawTextArt::Read()
1178 for (SdwPoint & nC : m_aVector)
1180 m_pStream->ReadInt16( nC.x );
1181 m_pStream->ReadInt16( nC.y );
1184 ReadClosedObjStyle();
1185 m_aTextArtRec.aTextColor = m_aClosedObjStyleRec.aForeColor;
1187 m_pStream->ReadUChar( m_aTextArtRec.nIndex );
1188 m_pStream->ReadInt16( m_aTextArtRec.nRotation );
1190 sal_uInt16 nPointNumber;
1191 m_pStream->ReadUInt16( nPointNumber );
1193 size_t nPoints = nPointNumber*3+1;
1194 if (!m_pStream->good() || nPoints > m_pStream->remainingSize() / 4)
1195 throw BadRead();
1197 m_aTextArtRec.aPath[0].n = nPointNumber;
1198 m_aTextArtRec.aPath[0].aPts.resize(nPoints);
1199 for (size_t nPt = 0; nPt < nPoints; ++nPt)
1201 sal_Int16 nX, nY;
1202 m_pStream->ReadInt16( nX );
1203 m_pStream->ReadInt16( nY );
1204 m_aTextArtRec.aPath[0].aPts[nPt].x = nX;
1205 m_aTextArtRec.aPath[0].aPts[nPt].y = nY;
1208 m_pStream->ReadUInt16( nPointNumber );
1210 nPoints = nPointNumber*3+1;
1211 if (!m_pStream->good() || nPoints > m_pStream->remainingSize() / 4)
1212 throw BadRead();
1214 m_aTextArtRec.aPath[1].n = nPointNumber;
1215 m_aTextArtRec.aPath[1].aPts.resize(nPoints);
1216 for (size_t nPt = 0; nPt < nPoints; ++nPt)
1218 sal_Int16 nX, nY;
1219 m_pStream->ReadInt16( nX );
1220 m_pStream->ReadInt16( nY );
1221 m_aTextArtRec.aPath[1].aPts[nPt].x = nX;
1222 m_aTextArtRec.aPath[1].aPts[nPt].y = nY;
1225 m_pStream->SeekRel(1);
1227 m_pStream->ReadBytes(m_aTextArtRec.tmpTextFaceName, DRAW_FACESIZE);
1228 m_aTextArtRec.tmpTextFaceName[DRAW_FACESIZE - 1] = 0;
1229 m_pStream->SeekRel(1);// PitchAndFamily
1231 m_pStream->ReadInt16( m_aTextArtRec.nTextSize );
1233 if (m_aTextArtRec.nTextSize < 0)
1234 m_aTextArtRec.nTextSize = -m_aTextArtRec.nTextSize;
1236 m_pStream->ReadUInt16( m_aTextArtRec.nTextAttrs );
1237 m_pStream->ReadUInt16( m_aTextArtRec.nTextCharacterSet );
1238 m_aTextArtRec.nTextRotation = 0;
1239 m_pStream->ReadInt16( m_aTextArtRec.nTextExtraSpacing );
1241 const sal_uInt16 nTextArtFixedLength = 105;
1242 m_aTextArtRec.nTextLen = m_aObjHeader.nRecLen - nTextArtFixedLength
1243 - (m_aTextArtRec.aPath[0].n*3 + 1)*4
1244 - (m_aTextArtRec.aPath[1].n*3 + 1)*4;
1247 if (!m_pStream->good())
1248 throw BadRead();
1249 if (m_aTextArtRec.nTextLen > m_pStream->remainingSize())
1250 throw BadRead();
1251 if (m_aTextArtRec.nTextLen < 1)
1252 throw BadRead();
1254 m_aTextArtRec.pTextString = new sal_uInt8 [m_aTextArtRec.nTextLen];
1255 m_pStream->ReadBytes(m_aTextArtRec.pTextString, m_aTextArtRec.nTextLen);
1256 m_aTextArtRec.pTextString[m_aTextArtRec.nTextLen-1] = 0;
1260 OUString LwpDrawTextArt::RegisterStyle()
1262 std::unique_ptr<XFParaStyle> pStyle(new XFParaStyle());
1264 // font style
1265 // the pFont need to be deleted myself?
1266 rtl::Reference<XFFont> pFont = new XFFont();
1268 OUString aFontName(reinterpret_cast<char*>(m_aTextArtRec.tmpTextFaceName),
1269 strlen(reinterpret_cast<char*>(m_aTextArtRec.tmpTextFaceName)), RTL_TEXTENCODING_MS_1252);
1270 pFont->SetFontName(aFontName);
1272 LwpDrawTextBox::SetFontStyle(pFont, &m_aTextArtRec);
1274 pStyle->SetFont(pFont);
1276 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1277 return pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName();
1280 rtl::Reference<XFFrame> LwpDrawTextArt::CreateDrawObj(const OUString& rStyleName)
1282 std::unique_ptr<XFDrawStyle> pStyle(new XFDrawStyle());
1284 rtl::Reference<XFFrame> xRetObj(new XFDrawPath());
1285 XFDrawPath* pFWPath = static_cast<XFDrawPath*>(xRetObj.get());
1286 CreateFWPath(pFWPath);
1287 pStyle->SetFontWorkStyle(enumXFFWSlantY, enumXFFWAdjustAutosize);
1289 SetPosition(xRetObj.get());
1291 rtl_TextEncoding aEncoding;
1292 if (!m_aTextArtRec.nTextCharacterSet)
1294 aEncoding = osl_getThreadTextEncoding();
1296 else
1298 // temporary code, need to create Encoding from the value of nTextCharacterSet
1299 aEncoding = LwpCharSetMgr::GetTextCharEncoding();
1302 XFParagraph* pXFPara = new XFParagraph();
1303 pXFPara->Add(OUString(reinterpret_cast<char*>(m_aTextArtRec.pTextString), (m_aTextArtRec.nTextLen-1), aEncoding));
1304 pXFPara->SetStyleName(rStyleName);
1305 xRetObj->Add(pXFPara);
1307 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1308 xRetObj->SetStyleName(pXFStyleManager->AddStyle(std::move(pStyle)).m_pStyle->GetStyleName());
1310 return xRetObj;
1313 rtl::Reference<XFFrame> LwpDrawTextArt::CreateStandardDrawObj(const OUString& rStyleName )
1315 return CreateDrawObj(rStyleName);
1319 * @descr Constructor of class LwpDrawMetafile
1320 * @param pStream The memory stream which contains the lwp-sdw draw objects
1322 LwpDrawMetafile::LwpDrawMetafile(SvStream* pStream) : LwpDrawObj(pStream)
1327 * @descr reading function of class LwpDrawMetafile
1329 void LwpDrawMetafile::Read()
1331 m_pStream->SeekRel(m_aObjHeader.nRecLen -16);
1335 * @descr Constructor of class LwpDrawBitmap
1336 * @param pStream The memory stream which contains the lwp-sdw draw objects
1338 LwpDrawBitmap::LwpDrawBitmap(SvStream* pStream) : LwpDrawObj(pStream)
1342 LwpDrawBitmap::~LwpDrawBitmap()
1346 static bool IsValid(const BmpInfoHeader2& rHeader)
1348 if (rHeader.nPlanes != 1)
1349 return false;
1351 if (rHeader.nBitCount != 0 && rHeader.nBitCount != 1 &&
1352 rHeader.nBitCount != 4 && rHeader.nBitCount != 8 &&
1353 rHeader.nBitCount != 16 && rHeader.nBitCount != 24 &&
1354 rHeader.nBitCount != 32)
1356 return false;
1359 return true;
1363 * @descr reading function of class LwpDrawBitmap
1365 void LwpDrawBitmap::Read()
1367 m_pStream->ReadUInt16( m_aBmpRec.nTranslation );
1368 m_pStream->ReadUInt16( m_aBmpRec.nRotation );
1370 // 20 == length of draw-specific fields.
1371 if (m_aObjHeader.nRecLen < 20)
1372 throw BadRead();
1374 sal_uInt64 nBmpPos = m_pStream->Tell();
1375 sal_uInt64 nBmpLen =
1376 std::min<sal_uInt64>(m_aObjHeader.nRecLen - 20, m_pStream->remainingSize());
1378 BmpInfoHeader2 aInfoHeader2;
1379 m_pStream->ReadUInt32( aInfoHeader2.nHeaderLen );
1381 if (!m_pStream->good() || nBmpLen < aInfoHeader2.nHeaderLen)
1382 throw BadRead();
1384 sal_uInt32 N;
1385 sal_uInt32 rgbTableSize;
1387 if (aInfoHeader2.nHeaderLen == sizeof(BmpInfoHeader))
1389 sal_uInt16 nTmp;
1391 m_pStream->ReadUInt16( nTmp );
1392 aInfoHeader2.nWidth = nTmp;
1393 m_pStream->ReadUInt16( nTmp );
1394 aInfoHeader2.nHeight = nTmp;
1395 m_pStream->ReadUInt16( aInfoHeader2.nPlanes );
1396 m_pStream->ReadUInt16( aInfoHeader2.nBitCount );
1398 if (!m_pStream->good() || !IsValid(aInfoHeader2))
1399 throw BadRead();
1401 N = aInfoHeader2.nPlanes * aInfoHeader2.nBitCount;
1402 if (N >= 16)
1404 rgbTableSize = 0;
1406 else
1408 rgbTableSize = 3 * (1 << N);
1411 else if (aInfoHeader2.nHeaderLen >= sizeof(BmpInfoHeader2))
1413 m_pStream->ReadUInt32( aInfoHeader2.nWidth );
1414 m_pStream->ReadUInt32( aInfoHeader2.nHeight );
1415 m_pStream->ReadUInt16( aInfoHeader2.nPlanes );
1416 m_pStream->ReadUInt16( aInfoHeader2.nBitCount );
1418 if (!m_pStream->good() || !IsValid(aInfoHeader2))
1419 throw BadRead();
1421 N = aInfoHeader2.nPlanes * aInfoHeader2.nBitCount;
1422 if (N >= 16)
1424 rgbTableSize = 0;
1426 else
1428 rgbTableSize = 4 * (1 << N);
1431 else
1433 throw BadRead();
1436 m_aBmpRec.nFileSize = static_cast<sal_uInt32>(nBmpLen + 14);
1437 m_pImageData.reset( new sal_uInt8 [m_aBmpRec.nFileSize] );
1439 sal_uInt32 nOffBits = 14 + aInfoHeader2.nHeaderLen + rgbTableSize;
1440 m_pImageData[0] = 'B';
1441 m_pImageData[1] = 'M';
1442 m_pImageData[2] = static_cast<sal_uInt8>(m_aBmpRec.nFileSize);
1443 m_pImageData[3] = static_cast<sal_uInt8>(m_aBmpRec.nFileSize >> 8);
1444 m_pImageData[4] = static_cast<sal_uInt8>(m_aBmpRec.nFileSize >> 16);
1445 m_pImageData[5] = static_cast<sal_uInt8>(m_aBmpRec.nFileSize >> 24);
1446 m_pImageData[6] = 0;
1447 m_pImageData[7] = 0;
1448 m_pImageData[8] = 0;
1449 m_pImageData[9] = 0;
1450 m_pImageData[10] = static_cast<sal_uInt8>(nOffBits);
1451 m_pImageData[11] = static_cast<sal_uInt8>(nOffBits >> 8);
1452 m_pImageData[12] = static_cast<sal_uInt8>(nOffBits >> 16);
1453 m_pImageData[13] = static_cast<sal_uInt8>(nOffBits >> 24);
1455 sal_uInt8* pPicData = m_pImageData.get();
1457 m_pStream->Seek(nBmpPos);
1458 if (nBmpLen != m_pStream->ReadBytes(pPicData + 14, nBmpLen))
1459 throw BadRead();
1462 OUString LwpDrawBitmap::RegisterStyle()
1464 std::unique_ptr<XFImageStyle> pBmpStyle(new XFImageStyle());
1465 pBmpStyle->SetYPosType(enumXFFrameYPosFromTop, enumXFFrameYRelFrame);
1466 pBmpStyle->SetXPosType(enumXFFrameXPosFromLeft, enumXFFrameXRelFrame);
1468 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1469 return pXFStyleManager->AddStyle(std::move(pBmpStyle)).m_pStyle->GetStyleName();
1472 rtl::Reference<XFFrame> LwpDrawBitmap::CreateDrawObj(const OUString& rStyleName)
1474 rtl::Reference<XFImage> xImage(new XFImage());
1475 xImage->SetImageData(m_pImageData.get(), m_aBmpRec.nFileSize);
1476 SetPosition(xImage.get());
1478 xImage->SetStyleName(rStyleName);
1480 return xImage;
1483 rtl::Reference<XFFrame> LwpDrawBitmap::CreateStandardDrawObj(const OUString& rStyleName)
1485 return CreateDrawObj(rStyleName);
1488 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */