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,
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 ************************************************************************/
58 * Implementation file of LwpDrawObjects and associated class like LwpDrawGroup, LwpDrawRectangle
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"
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
)
95 , m_pTransData(pTransData
)
97 ReadObjHeaderRecord();
101 * @descr read the header record data of lwp-sdw-object
103 void LwpDrawObj::ReadObjHeaderRecord()
106 m_pStream
->SeekRel(1);
109 m_pStream
->ReadUInt16( m_aObjHeader
.nRecLen
);
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
);
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
);
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
);
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
);
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
);
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
)
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!
180 // set fill style : none
185 pStyle
->SetAreaColor(aForeColor
);
190 pStyle
->SetAreaColor(aBackColor
);
191 pStyle
->SetAreaLineStyle(enumXFAreaLineSingle
, 0, 0.12, aForeColor
);
196 pStyle
->SetAreaColor(aBackColor
);
197 pStyle
->SetAreaLineStyle(enumXFAreaLineSingle
, 90, 0.12, aForeColor
);
202 pStyle
->SetAreaColor(aBackColor
);
203 pStyle
->SetAreaLineStyle(enumXFAreaLineSingle
, 135, 0.09, aForeColor
);
208 pStyle
->SetAreaColor(aBackColor
);
209 pStyle
->SetAreaLineStyle(enumXFAreaLineSingle
, 45, 0.09, aForeColor
);
214 pStyle
->SetAreaColor(aBackColor
);
215 pStyle
->SetAreaLineStyle(enumXFAreaLineCrossed
, 0, 0.12, aForeColor
);
218 case FT_DIAGCROSSHATCH
:
220 pStyle
->SetAreaColor(aBackColor
);
221 pStyle
->SetAreaLineStyle(enumXFAreaLineCrossed
, 45, 0.095, aForeColor
);
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
)
244 nLineStyle
= LS_NULL
;
247 if (nLineStyle
== LS_NULL
)
253 if (nLineStyle
== LS_DOT
)
255 pStyle
->SetLineDashStyle(enumXFLineDash
, 0.05, 0.05, 0.05);
259 double fWidth
= static_cast<double>(nWidth
)/TWIPS_PER_CM
;
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;
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
)
302 if (!pOpenedObjStyle
)
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
;
320 pOpenedObjStyle
->SetArrowStart( GetArrowName(nLeftArrow
), fArrowSize
);
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
342 case AH_ARROW_FULLARROW
:
343 aArrowName
= "Symmetric arrow";
345 case AH_ARROW_HALFARROW
:
346 aArrowName
= "Arrow concave";
348 case AH_ARROW_LINEARROW
:
349 aArrowName
= "arrow100";
351 case AH_ARROW_INVFULLARROW
:
352 aArrowName
= "reverse arrow";
354 case AH_ARROW_INVHALFARROW
:
355 aArrowName
= "reverse concave arrow";
357 case AH_ARROW_INVLINEARROW
:
358 aArrowName
= "reverse line arrow";
361 aArrowName
= "Dimension lines";
363 case AH_ARROW_SQUARE
:
364 aArrowName
= "Square";
366 case AH_ARROW_CIRCLE
:
367 aArrowName
= "Circle";
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()
384 OUString aStyleName
= RegisterStyle();
387 rtl::Reference
<XFFrame
> xXFObj
;
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
);
398 xXFObj
= CreateDrawObj(aStyleName
);
404 xXFObj
->SetAnchorType(enumXFAnchorFrame
);
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() );
443 SetLineStyle(pStyle
.get(), m_aLineRec
.nLineWidth
, m_aLineRec
.nLineStyle
, m_aLineRec
.aPenColor
);
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
);
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
);
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)
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());
519 SetLineStyle(pStyle
.get(), m_aPolyLineRec
.nLineWidth
, m_aPolyLineRec
.nLineStyle
,
520 m_aPolyLineRec
.aPenColor
);
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
);
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
);
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
)
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)
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());
599 SetLineStyle(pStyle
.get(), m_aClosedObjStyleRec
.nLineWidth
, m_aClosedObjStyleRec
.nLineStyle
,
600 m_aClosedObjStyleRec
.aPenColor
);
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
);
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
);
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
)
660 m_pStream
->SeekRel(4); // corner points
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());
679 SetLineStyle(pStyle
.get(), m_aClosedObjStyleRec
.nLineWidth
, m_aClosedObjStyleRec
.nLineStyle
,
680 m_aClosedObjStyleRec
.aPenColor
);
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
);
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
));
708 SetPosition(xRect
.get());
710 xRect
->SetStyleName(rStyleName
);
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
++)
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
);
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
);
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
);
737 pRoundedRect
->CurveTo(aDest
, aCtrl1
, aCtrl2
);
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
);
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
);
759 rtl::Reference
<XFFrame
> LwpDrawRectangle::CreateStandardDrawObj(const OUString
& rStyleName
)
761 if (m_eType
== OT_RNDRECT
)
763 return CreateRoundedRect(rStyleName
);
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();
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
);
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());
838 SetLineStyle(pStyle
.get(), m_aClosedObjStyleRec
.nLineWidth
, m_aClosedObjStyleRec
.nLineStyle
,
839 m_aClosedObjStyleRec
.aPenColor
);
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
);
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
);
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
);
866 xEllipse
->CurveTo(aDest
, aCtrl1
, aCtrl2
);
868 xEllipse
->ClosePath();
869 SetPosition(xEllipse
.get());
871 xEllipse
->SetStyleName(rStyleName
);
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());
917 SetLineStyle(pStyle
.get(), m_aArcRec
.nLineWidth
, m_aArcRec
.nLineStyle
,
918 m_aArcRec
.aPenColor
);
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
);
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
)
972 XFColor
aXFColor(pRec
->aTextColor
.nR
, pRec
->aTextColor
.nG
,
973 pRec
->aTextColor
.nB
);
974 pFont
->SetColor(aXFColor
);
976 pFont
->SetFontSize(pRec
->nTextSize
/20);
978 pFont
->SetBold((pRec
->nTextAttrs
& TA_BOLD
) != 0);
980 pFont
->SetItalic((pRec
->nTextAttrs
& TA_ITALIC
) != 0);
982 if (pRec
->nTextAttrs
& TA_STRIKETHRU
)
984 pFont
->SetCrossout(enumXFCrossoutSignel
);
988 pFont
->SetCrossout(enumXFCrossoutNone
);
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
);
1005 pFont
->SetUnderline(enumXFUnderlineNone
);
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
;
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())
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;
1057 m_aTextRec
.pTextString
= new sal_uInt8
[TextLength
];
1058 if (m_pStream
->ReadBytes(m_aTextRec
.pTextString
, TextLength
) != o3tl::make_unsigned(TextLength
))
1062 OUString
LwpDrawTextBox::RegisterStyle()
1064 std::unique_ptr
<XFParaStyle
> pStyle(new XFParaStyle());
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();
1094 // temporary code, need to create Encoding from the value of nTextCharacterSet
1095 aEncoding
= LwpCharSetMgr::GetTextCharEncoding();
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
);
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
)
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
);
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
);
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)
1197 m_aTextArtRec
.aPath
[0].n
= nPointNumber
;
1198 m_aTextArtRec
.aPath
[0].aPts
.resize(nPoints
);
1199 for (size_t nPt
= 0; nPt
< nPoints
; ++nPt
)
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)
1214 m_aTextArtRec
.aPath
[1].n
= nPointNumber
;
1215 m_aTextArtRec
.aPath
[1].aPts
.resize(nPoints
);
1216 for (size_t nPt
= 0; nPt
< nPoints
; ++nPt
)
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())
1249 if (m_aTextArtRec
.nTextLen
> m_pStream
->remainingSize())
1251 if (m_aTextArtRec
.nTextLen
< 1)
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());
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();
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());
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)
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)
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)
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
)
1385 sal_uInt32 rgbTableSize
;
1387 if (aInfoHeader2
.nHeaderLen
== sizeof(BmpInfoHeader
))
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
))
1401 N
= aInfoHeader2
.nPlanes
* aInfoHeader2
.nBitCount
;
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
))
1421 N
= aInfoHeader2
.nPlanes
* aInfoHeader2
.nBitCount
;
1428 rgbTableSize
= 4 * (1 << N
);
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
))
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
);
1483 rtl::Reference
<XFFrame
> LwpDrawBitmap::CreateStandardDrawObj(const OUString
& rStyleName
)
1485 return CreateDrawObj(rStyleName
);
1488 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */