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 LwpDrawObjcts and associated class like LwpDrawGroup, LwpDrawRectange
61 #include <osl/thread.h>
62 #include "lwpglobalmgr.hxx"
63 #include "lwpdrawobj.hxx"
64 #include "lwptools.hxx"
65 #include <tools/stream.hxx>
67 #include "xfilter/xfframe.hxx"
69 #include "xfilter/xfstylemanager.hxx"
70 #include "xfilter/xfdrawstyle.hxx"
71 #include "xfilter/xftextstyle.hxx"
72 #include "xfilter/xfparastyle.hxx"
73 #include "xfilter/xfimagestyle.hxx"
74 #include "xfilter/xftextboxstyle.hxx"
75 #include "xfilter/xfparagraph.hxx"
76 #include "xfilter/xftextspan.hxx"
77 #include "xfilter/xffont.hxx"
79 #include "xfilter/xfdrawrect.hxx"
80 #include "xfilter/xfdrawpath.hxx"
81 #include "xfilter/xfdrawline.hxx"
82 #include "xfilter/xfdrawpolygon.hxx"
83 #include "xfilter/xfimage.hxx"
85 #include "lwpcharsetmgr.hxx"
86 #include "lwpsdwrect.hxx"
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
->Read(m_aClosedObjStyleRec
.pFillPattern
,
155 sizeof(m_aClosedObjStyleRec
.pFillPattern
));
159 * @descr set fill style of drawing objects
160 * @param pStyle pointer of the drawing xfstyle.
162 void LwpDrawObj::SetFillStyle(XFDrawStyle
* pStyle
)
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
= (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((double)m_aObjHeader
.nLeft
/TWIPS_PER_CM
* fScaleX
+ fOffsetX
,
284 (double)m_aObjHeader
.nTop
/TWIPS_PER_CM
* fScaleY
+ fOffsetY
,
285 (double)(m_aObjHeader
.nRight
-m_aObjHeader
.nLeft
)/TWIPS_PER_CM
* fScaleX
,
286 (double)(m_aObjHeader
.nBottom
-m_aObjHeader
.nTop
)/TWIPS_PER_CM
* fScaleY
);
290 * @descr set arrowhead of a xf-drawing object. only opened drawing objects can be assigned arrowheads
291 * @param pOpenedObjStyle the xf-drawing object which will be set arrowhead.
292 * @param nArrowFlag arrowhead flags of the object.
294 void LwpDrawObj::SetArrowHead(XFDrawStyle
* pOpenedObjStyle
, sal_uInt8 nArrowFlag
, sal_uInt8 nLineWidth
)
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
= (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 XFFrame
* LwpDrawObj::CreateXFDrawObject()
384 OUString aStyleName
= RegisterStyle();
387 XFFrame
* pXFObj
= nullptr;
389 && FABS(m_pTransData
->fOffsetX
- m_pTransData
->fLeftMargin
) < THRESHOLD
390 && FABS(m_pTransData
->fOffsetY
- m_pTransData
->fTopMargin
) < THRESHOLD
391 && FABS(m_pTransData
->fScaleX
- 1.0) < THRESHOLD
392 && FABS(m_pTransData
->fScaleY
- 1.0) < THRESHOLD
)
394 pXFObj
= CreateStandardDrawObj(aStyleName
);
398 pXFObj
= CreateDrawObj(aStyleName
);
404 pXFObj
->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 XFDrawStyle
* pStyle
= new XFDrawStyle();
443 SetLineStyle(pStyle
, m_aLineRec
.nLineWidth
, m_aLineRec
.nLineStyle
, m_aLineRec
.aPenColor
);
446 SetArrowHead(pStyle
, m_aLineRec
.nLineEnd
, m_aLineRec
.nLineWidth
);
448 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
449 return (pXFStyleManager
->AddStyle(pStyle
)).m_pStyle
->GetStyleName();
453 XFFrame
* LwpDrawLine::CreateDrawObj(const OUString
& rStyleName
)
455 XFDrawPath
* pLine
= new XFDrawPath();
456 pLine
->MoveTo(XFPoint((double)(m_aLineRec
.nStartX
)/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
457 (double)(m_aLineRec
.nStartY
)/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
458 pLine
->LineTo(XFPoint((double)(m_aLineRec
.nEndX
)/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
459 (double)(m_aLineRec
.nEndY
)/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
462 pLine
->SetStyleName(rStyleName
);
467 XFFrame
* LwpDrawLine::CreateStandardDrawObj(const OUString
& rStyleName
)
469 XFDrawLine
* pLine
= new XFDrawLine();
470 pLine
->SetStartPoint((double)(m_aLineRec
.nStartX
)/TWIPS_PER_CM
,(double)(m_aLineRec
.nStartY
)/TWIPS_PER_CM
);
471 pLine
->SetEndPoint((double)(m_aLineRec
.nEndX
)/TWIPS_PER_CM
,(double)(m_aLineRec
.nEndY
)/TWIPS_PER_CM
);
473 pLine
->SetStyleName(rStyleName
);
478 * @descr Constructor of class LwpDrawPolyLine
479 * @param pStream The memory stream which contains the lwp-sdw draw objects
481 LwpDrawPolyLine::LwpDrawPolyLine(SvStream
* pStream
, DrawingOffsetAndScale
* pTransData
)
482 : LwpDrawObj(pStream
, pTransData
), m_pVector(nullptr)
485 LwpDrawPolyLine::~LwpDrawPolyLine()
495 * @descr reading function of class LwpDrawPolyLine
497 void LwpDrawPolyLine::Read()
499 m_pStream
->ReadUChar( m_aPolyLineRec
.nLineWidth
);
500 m_pStream
->ReadUChar( m_aPolyLineRec
.nLineEnd
);
501 m_pStream
->ReadUChar( m_aPolyLineRec
.nLineStyle
);
502 m_pStream
->ReadUChar( m_aPolyLineRec
.aPenColor
.nR
);
503 m_pStream
->ReadUChar( m_aPolyLineRec
.aPenColor
.nG
);
504 m_pStream
->ReadUChar( m_aPolyLineRec
.aPenColor
.nB
);
505 m_pStream
->ReadUChar( m_aPolyLineRec
.aPenColor
.unused
);
506 m_pStream
->ReadUInt16( m_aPolyLineRec
.nNumPoints
);
508 if (m_aPolyLineRec
.nNumPoints
> m_pStream
->remainingSize() / 4)
511 m_pVector
= new SdwPoint
[m_aPolyLineRec
.nNumPoints
];
513 for (sal_uInt16 nC
= 0; nC
< m_aPolyLineRec
.nNumPoints
; nC
++)
515 m_pStream
->ReadInt16( m_pVector
[nC
].x
);
516 m_pStream
->ReadInt16( m_pVector
[nC
].y
);
520 OUString
LwpDrawPolyLine::RegisterStyle()
522 XFDrawStyle
* pStyle
= new XFDrawStyle();
525 SetLineStyle(pStyle
, m_aPolyLineRec
.nLineWidth
, m_aPolyLineRec
.nLineStyle
,
526 m_aPolyLineRec
.aPenColor
);
529 SetArrowHead(pStyle
, m_aPolyLineRec
.nLineEnd
, m_aPolyLineRec
.nLineWidth
);
531 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
532 return pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
535 XFFrame
* LwpDrawPolyLine::CreateDrawObj(const OUString
& rStyleName
)
537 XFDrawPath
* pPolyline
= new XFDrawPath();
538 pPolyline
->MoveTo(XFPoint((double)m_pVector
[0].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
539 (double)m_pVector
[0].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
540 for (sal_uInt16 nC
= 1; nC
< m_aPolyLineRec
.nNumPoints
; nC
++)
542 pPolyline
->LineTo(XFPoint((double)m_pVector
[nC
].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
543 (double)m_pVector
[nC
].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
545 SetPosition(pPolyline
);
547 pPolyline
->SetStyleName(rStyleName
);
552 XFFrame
* LwpDrawPolyLine::CreateStandardDrawObj(const OUString
& rStyleName
)
554 XFDrawPolyline
* pPolyline
= new XFDrawPolyline();
555 for (sal_uInt16 nC
= 0; nC
< m_aPolyLineRec
.nNumPoints
; nC
++)
557 pPolyline
->AddPoint((double)m_pVector
[nC
].x
/TWIPS_PER_CM
,
558 (double)m_pVector
[nC
].y
/TWIPS_PER_CM
);
561 pPolyline
->SetStyleName(rStyleName
);
567 * @descr Constructor of class LwpDrawPolygon
568 * @param pStream The memory stream which contains the lwp-sdw draw objects
570 LwpDrawPolygon::LwpDrawPolygon(SvStream
* pStream
, DrawingOffsetAndScale
* pTransData
)
571 : LwpDrawObj(pStream
, pTransData
)
577 LwpDrawPolygon::~LwpDrawPolygon()
587 * @descr reading function of class LwpDrawPolygon
589 void LwpDrawPolygon::Read()
591 ReadClosedObjStyle();
592 m_pStream
->ReadUInt16( m_nNumPoints
);
594 if (m_nNumPoints
> m_pStream
->remainingSize() / 4)
597 m_pVector
= new SdwPoint
[m_nNumPoints
];
599 for (sal_uInt16 nC
= 0; nC
< m_nNumPoints
; nC
++)
601 m_pStream
->ReadInt16( m_pVector
[nC
].x
);
602 m_pStream
->ReadInt16( m_pVector
[nC
].y
);
606 OUString
LwpDrawPolygon::RegisterStyle()
608 XFDrawStyle
* pStyle
= new XFDrawStyle();
611 SetLineStyle(pStyle
, m_aClosedObjStyleRec
.nLineWidth
, m_aClosedObjStyleRec
.nLineStyle
,
612 m_aClosedObjStyleRec
.aPenColor
);
615 SetFillStyle(pStyle
);
617 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
618 return pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
621 XFFrame
* LwpDrawPolygon::CreateDrawObj(const OUString
& rStyleName
)
623 XFDrawPath
* pPolygon
= new XFDrawPath();
624 pPolygon
->MoveTo(XFPoint((double)m_pVector
[0].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
625 (double)m_pVector
[0].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
626 for (sal_uInt16 nC
= 1; nC
< m_nNumPoints
; nC
++)
628 pPolygon
->LineTo(XFPoint((double)m_pVector
[nC
].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
629 (double)m_pVector
[nC
].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
631 pPolygon
->ClosePath();
632 SetPosition(pPolygon
);
633 pPolygon
->SetStyleName(rStyleName
);
638 XFFrame
* LwpDrawPolygon::CreateStandardDrawObj(const OUString
& rStyleName
)
640 XFDrawPolygon
* pPolygon
= new XFDrawPolygon();
641 for (sal_uInt16 nC
= 0; nC
< m_nNumPoints
; nC
++)
643 pPolygon
->AddPoint((double)m_pVector
[nC
].x
/TWIPS_PER_CM
,
644 (double)m_pVector
[nC
].y
/TWIPS_PER_CM
);
647 pPolygon
->SetStyleName(rStyleName
);
653 * @descr Constructor of class LwpDrawRectangle
654 * @param pStream The memory stream which contains the lwp-sdw draw objects
656 LwpDrawRectangle::LwpDrawRectangle(SvStream
* pStream
, DrawingOffsetAndScale
* pTransData
)
657 : LwpDrawObj(pStream
, pTransData
)
662 * @descr reading function of class LwpDrawRectangle
664 void LwpDrawRectangle::Read()
666 ReadClosedObjStyle();
668 sal_uInt8 nPointsCount
;
669 if (m_eType
== OT_RNDRECT
)
672 m_pStream
->SeekRel(4); // corner points
679 for (sal_uInt8 nC
= 0; nC
< nPointsCount
; nC
++)
681 m_pStream
->ReadInt16( m_aVector
[nC
].x
);
682 m_pStream
->ReadInt16( m_aVector
[nC
].y
);
686 OUString
LwpDrawRectangle::RegisterStyle()
688 XFDrawStyle
* pStyle
= new XFDrawStyle();
691 SetLineStyle(pStyle
, m_aClosedObjStyleRec
.nLineWidth
, m_aClosedObjStyleRec
.nLineStyle
,
692 m_aClosedObjStyleRec
.aPenColor
);
695 SetFillStyle(pStyle
);
697 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
698 return pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
701 XFFrame
* LwpDrawRectangle::CreateDrawObj(const OUString
& rStyleName
)
703 if (m_eType
== OT_RNDRECT
)
705 return CreateRoundedRect(rStyleName
);
709 XFDrawPath
* pRect
= new XFDrawPath();
710 pRect
->MoveTo(XFPoint((double)m_aVector
[0].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
711 (double)m_aVector
[0].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
712 for (sal_uInt8 nC
= 1; nC
< 4; nC
++)
714 pRect
->LineTo(XFPoint((double)m_aVector
[nC
].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
715 (double)m_aVector
[nC
].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
717 pRect
->LineTo(XFPoint((double)m_aVector
[0].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
718 (double)m_aVector
[0].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
722 pRect
->SetStyleName(rStyleName
);
728 XFFrame
* LwpDrawRectangle::CreateRoundedRect(const OUString
& rStyleName
)
730 XFDrawPath
* pRoundedRect
= new XFDrawPath();
731 pRoundedRect
->MoveTo(XFPoint((double)m_aVector
[0].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
732 (double)m_aVector
[0].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
734 sal_uInt8 nPtIndex
= 1;
735 for (sal_uInt8 nC
= 0; nC
< 7; nC
++)
739 XFPoint
aCtrl1((double)m_aVector
[nPtIndex
].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
740 (double)m_aVector
[nPtIndex
].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
742 XFPoint
aCtrl2((double)m_aVector
[nPtIndex
].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
743 (double)m_aVector
[nPtIndex
].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
745 XFPoint
aDest((double)m_aVector
[nPtIndex
].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
746 (double)m_aVector
[nPtIndex
].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
749 pRoundedRect
->CurveTo(aDest
, aCtrl1
, aCtrl2
);
753 XFPoint
aDest((double)m_aVector
[nPtIndex
].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
754 (double)m_aVector
[nPtIndex
].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
757 pRoundedRect
->LineTo(aDest
);
761 pRoundedRect
->LineTo(XFPoint((double)m_aVector
[0].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
762 (double)m_aVector
[0].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
763 pRoundedRect
->ClosePath();
764 SetPosition(pRoundedRect
);
766 pRoundedRect
->SetStyleName(rStyleName
);
771 XFFrame
* LwpDrawRectangle::CreateStandardDrawObj(const OUString
& rStyleName
)
773 if (m_eType
== OT_RNDRECT
)
775 return CreateRoundedRect(rStyleName
);
779 XFDrawRect
* pRect
= new XFDrawRect();
780 double fStartX
, fStartY
, fWidth
, fHeight
;
781 double fRotAngle
= 0.0;
782 SdwRectangle aSdwRect
;
783 Rectangle aOriginalRect
;
784 Point aPt0
, aPt1
, aPt2
, aPt3
;
786 aPt0
.setX(m_aVector
[0].x
); aPt0
.setY(m_aVector
[0].y
);
787 aPt1
.setX(m_aVector
[1].x
); aPt1
.setY(m_aVector
[1].y
);
788 aPt2
.setX(m_aVector
[2].x
); aPt2
.setY(m_aVector
[2].y
);
789 aPt3
.setX(m_aVector
[3].x
); aPt3
.setY(m_aVector
[3].y
);
791 aSdwRect
= SdwRectangle(aPt0
, aPt1
, aPt2
, aPt3
);
792 if (aSdwRect
.IsRectRotated())
794 aOriginalRect
= aSdwRect
.GetOriginalRect();
795 fRotAngle
= aSdwRect
.GetRotationAngle();
799 aOriginalRect
= Rectangle(aPt0
, aPt2
);
802 fStartX
= aOriginalRect
.TopLeft().X();
803 fStartY
= aOriginalRect
.TopLeft().Y();
804 fWidth
= aOriginalRect
.GetWidth();
805 fHeight
= aOriginalRect
.GetHeight();
807 pRect
->SetStartPoint(XFPoint(fStartX
/TWIPS_PER_CM
+ m_pTransData
->fOffsetX
,
808 fStartY
/TWIPS_PER_CM
+ m_pTransData
->fOffsetY
));
809 pRect
->SetSize(fWidth
/TWIPS_PER_CM
, fHeight
/TWIPS_PER_CM
);
811 if (aSdwRect
.IsRectRotated())
813 pRect
->SetRotate( fRotAngle
/ PI
* 180);// aXFCenter);
816 pRect
->SetStyleName(rStyleName
);
823 * @descr Constructor of class LwpDrawEllipse
824 * @param pStream The memory stream which contains the lwp-sdw draw objects
826 LwpDrawEllipse::LwpDrawEllipse(SvStream
* pStream
, DrawingOffsetAndScale
* pTransData
)
827 : LwpDrawObj(pStream
, pTransData
)
832 * @descr reading function of class LwpDrawEllipse
834 void LwpDrawEllipse::Read()
836 ReadClosedObjStyle();
838 for (SdwPoint
& nC
: m_aVector
)
840 m_pStream
->ReadInt16( nC
.x
);
841 m_pStream
->ReadInt16( nC
.y
);
845 OUString
LwpDrawEllipse::RegisterStyle()
847 XFDrawStyle
* pStyle
= new XFDrawStyle();
850 SetLineStyle(pStyle
, m_aClosedObjStyleRec
.nLineWidth
, m_aClosedObjStyleRec
.nLineStyle
,
851 m_aClosedObjStyleRec
.aPenColor
);
854 SetFillStyle(pStyle
);
856 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
857 return pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
860 XFFrame
* LwpDrawEllipse::CreateDrawObj(const OUString
& rStyleName
)
862 XFDrawPath
* pEllipse
= new XFDrawPath();
863 pEllipse
->MoveTo(XFPoint((double)m_aVector
[0].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
864 (double)m_aVector
[0].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
865 sal_uInt8 nPtIndex
= 1;
866 for (sal_uInt8 nC
= 0; nC
< 4; nC
++)
868 XFPoint
aCtrl1((double)m_aVector
[nPtIndex
].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
869 (double)m_aVector
[nPtIndex
].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
871 XFPoint
aCtrl2((double)m_aVector
[nPtIndex
].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
872 (double)m_aVector
[nPtIndex
].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
874 XFPoint
aDest((double)m_aVector
[nPtIndex
].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
875 (double)m_aVector
[nPtIndex
].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
878 pEllipse
->CurveTo(aDest
, aCtrl1
, aCtrl2
);
880 pEllipse
->ClosePath();
881 SetPosition(pEllipse
);
883 pEllipse
->SetStyleName(rStyleName
);
888 XFFrame
* LwpDrawEllipse::CreateStandardDrawObj(const OUString
& rStyleName
)
890 return CreateDrawObj(rStyleName
);
894 * @descr Constructor of class LwpDrawArc
895 * @param pStream The memory stream which contains the lwp-sdw draw objects
897 LwpDrawArc::LwpDrawArc(SvStream
* pStream
, DrawingOffsetAndScale
* pTransData
)
898 : LwpDrawObj(pStream
, pTransData
)
903 * @descr reading function of class LwpDrawArc
905 void LwpDrawArc::Read()
907 m_pStream
->SeekRel(16);// arcRect, startPt, endPt
909 m_pStream
->ReadUChar( m_aArcRec
.nLineWidth
);
910 m_pStream
->ReadUChar( m_aArcRec
.nLineStyle
);
911 m_pStream
->ReadUChar( m_aArcRec
.aPenColor
.nR
);
912 m_pStream
->ReadUChar( m_aArcRec
.aPenColor
.nG
);
913 m_pStream
->ReadUChar( m_aArcRec
.aPenColor
.nB
);
914 m_pStream
->ReadUChar( m_aArcRec
.aPenColor
.unused
);
915 m_pStream
->ReadUChar( m_aArcRec
.nLineEnd
);
917 for (SdwPoint
& nC
: m_aVector
)
919 m_pStream
->ReadInt16( nC
.x
);
920 m_pStream
->ReadInt16( nC
.y
);
924 OUString
LwpDrawArc::RegisterStyle()
926 XFDrawStyle
* pStyle
= new XFDrawStyle();
929 SetLineStyle(pStyle
, m_aArcRec
.nLineWidth
, m_aArcRec
.nLineStyle
,
930 m_aArcRec
.aPenColor
);
933 SetArrowHead(pStyle
, m_aArcRec
.nLineEnd
, m_aArcRec
.nLineWidth
);
935 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
936 return pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
939 XFFrame
* LwpDrawArc::CreateDrawObj(const OUString
& rStyleName
)
941 XFDrawPath
* pArc
= new XFDrawPath();
942 pArc
->MoveTo(XFPoint((double)m_aVector
[0].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
943 (double)m_aVector
[0].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
));
944 XFPoint
aDest((double)m_aVector
[3].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
945 (double)m_aVector
[3].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
946 XFPoint
aCtl1((double)m_aVector
[1].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
947 (double)m_aVector
[1].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
948 XFPoint
aCtl2((double)m_aVector
[2].x
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
949 (double)m_aVector
[2].y
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
950 pArc
->CurveTo(aDest
, aCtl1
, aCtl2
);
954 pArc
->SetStyleName(rStyleName
);
959 XFFrame
* LwpDrawArc::CreateStandardDrawObj(const OUString
& rStyleName
)
961 return CreateDrawObj(rStyleName
);
965 * @descr Constructor of class LwpDrawTextBox
966 * @param pStream The memory stream which contains the lwp-sdw draw objects
968 LwpDrawTextBox::LwpDrawTextBox(SvStream
* pStream
) : LwpDrawObj(pStream
)
972 LwpDrawTextBox::~LwpDrawTextBox()
974 if (m_aTextRec
.pTextString
)
976 delete [] m_aTextRec
.pTextString
;
977 m_aTextRec
.pTextString
= nullptr;
981 void LwpDrawTextBox::SetFontStyle(rtl::Reference
<XFFont
> const & pFont
, SdwTextBoxRecord
* pRec
)
984 XFColor
aXFColor(pRec
->aTextColor
.nR
, pRec
->aTextColor
.nG
,
985 pRec
->aTextColor
.nB
);
986 pFont
->SetColor(aXFColor
);
988 pFont
->SetFontSize(pRec
->nTextSize
/20);
990 pFont
->SetBold(((pRec
->nTextAttrs
& TA_BOLD
) != 0));
992 pFont
->SetItalic(((pRec
->nTextAttrs
& TA_ITALIC
) != 0));
994 if (pRec
->nTextAttrs
& TA_STRIKETHRU
)
996 pFont
->SetCrossout(enumXFCrossoutSignel
);
1000 pFont
->SetCrossout(enumXFCrossoutNone
);
1003 if (pRec
->nTextAttrs
& TA_UNDERLINE
)
1005 pFont
->SetUnderline(enumXFUnderlineSingle
);
1007 else if (pRec
->nTextAttrs
& TA_WORDUNDERLINE
)
1009 pFont
->SetUnderline(enumXFUnderlineSingle
, true);
1011 else if (pRec
->nTextAttrs
& TA_DOUBLEUNDER
)
1013 pFont
->SetUnderline(enumXFUnderlineDouble
);
1017 pFont
->SetUnderline(enumXFUnderlineNone
);
1020 if (pRec
->nTextAttrs
& TA_SMALLCAPS
)
1022 pFont
->SetTransform(enumXFTransformSmallCaps
);
1027 * @descr reading function of class LwpDrawTextBox
1029 void LwpDrawTextBox::Read()
1031 m_pStream
->ReadInt16( m_aVector
.x
);
1032 m_pStream
->ReadInt16( m_aVector
.y
);
1033 m_pStream
->ReadInt16( m_aTextRec
.nTextWidth
);
1035 if (m_aTextRec
.nTextWidth
== 0)
1036 m_aTextRec
.nTextWidth
= 1;
1038 m_pStream
->ReadInt16( m_aTextRec
.nTextHeight
);
1039 m_pStream
->Read(m_aTextRec
.tmpTextFaceName
, DRAW_FACESIZE
);
1040 m_pStream
->SeekRel(1);// PitchAndFamily
1042 m_pStream
->ReadInt16( m_aTextRec
.nTextSize
);
1044 if (m_aTextRec
.nTextSize
< 0)
1045 m_aTextRec
.nTextSize
= -m_aTextRec
.nTextSize
;
1048 m_pStream
->ReadUChar( m_aTextRec
.aTextColor
.nR
);
1049 m_pStream
->ReadUChar( m_aTextRec
.aTextColor
.nG
);
1050 m_pStream
->ReadUChar( m_aTextRec
.aTextColor
.nB
);
1051 m_pStream
->ReadUChar( m_aTextRec
.aTextColor
.unused
);
1053 m_pStream
->ReadUInt16( m_aTextRec
.nTextAttrs
);
1054 m_pStream
->ReadUInt16( m_aTextRec
.nTextCharacterSet
);
1055 m_pStream
->ReadInt16( m_aTextRec
.nTextRotation
);
1056 m_pStream
->ReadInt16( m_aTextRec
.nTextExtraSpacing
);
1058 // some draw files in version 1.2 have an extra byte following '\0'.
1059 // can't rely on that, so read in the whole string into memory.
1061 // the 71 is the fixed length before text content in textbox record
1062 sal_Int16 TextLength
= m_aObjHeader
.nRecLen
- 71;
1063 m_aTextRec
.pTextString
= new sal_uInt8
[TextLength
];
1065 m_pStream
->Read(m_aTextRec
.pTextString
, TextLength
);
1068 OUString
LwpDrawTextBox::RegisterStyle()
1070 XFParaStyle
* pStyle
= new XFParaStyle();
1073 // the pFont need to be deleted myself?
1074 rtl::Reference
<XFFont
> pFont
= new XFFont();
1076 rtl_TextEncoding aEncoding
= RTL_TEXTENCODING_MS_1252
;
1077 OUString aFontName
= OUString(reinterpret_cast<char*>(m_aTextRec
.tmpTextFaceName
),
1078 strlen(reinterpret_cast<char*>(m_aTextRec
.tmpTextFaceName
)), aEncoding
);
1079 pFont
->SetFontName(aFontName
);
1081 SetFontStyle(pFont
, &m_aTextRec
);
1083 pStyle
->SetFont(pFont
);
1085 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1086 return pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
1089 XFFrame
* LwpDrawTextBox::CreateDrawObj(const OUString
& rStyleName
)
1091 XFFrame
* pTextBox
= new XFFrame(true);
1093 sal_Int16 TextLength
= m_aObjHeader
.nRecLen
- 71;
1094 rtl_TextEncoding aEncoding
;
1095 if (!m_aTextRec
.nTextCharacterSet
)
1097 aEncoding
= osl_getThreadTextEncoding();
1101 // temporary code, need to create Encoding from the value of nTextCharacterSet
1102 aEncoding
= LwpCharSetMgr::GetTextCharEncoding();
1105 XFParagraph
* pXFPara
= new XFParagraph();
1106 pXFPara
->Add(OUString(reinterpret_cast<char*>(m_aTextRec
.pTextString
), (TextLength
-2), aEncoding
));
1107 pXFPara
->SetStyleName(rStyleName
);
1109 pTextBox
->Add(pXFPara
);
1110 SetPosition(pTextBox
);
1112 XFTextBoxStyle
* pBoxStyle
= new XFTextBoxStyle();
1114 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1115 OUString sName
= pXFStyleManager
->AddStyle(pBoxStyle
).m_pStyle
->GetStyleName();
1116 pTextBox
->SetStyleName(sName
);
1118 //todo: add the interface for rotating textbox
1119 // if (m_aTextRec.nTextRotation)
1121 // double fAngle = double(3600-m_aTextRec.nTextRotation)/10;
1122 // pTextBox->SetRotate(fAngle);
1128 XFFrame
* LwpDrawTextBox::CreateStandardDrawObj(const OUString
& rStyleName
)
1130 return CreateDrawObj(rStyleName
);
1134 * @descr Constructor of class LwpDrawTextBox
1135 * @param pStream The memory stream which contains the lwp-sdw draw objects
1137 LwpDrawTextArt::LwpDrawTextArt(SvStream
* pStream
, DrawingOffsetAndScale
* pTransData
)
1138 : LwpDrawObj(pStream
, pTransData
)
1142 LwpDrawTextArt::~LwpDrawTextArt()
1144 if (m_aTextArtRec
.aPath
[0].pPts
)
1146 delete [] m_aTextArtRec
.aPath
[0].pPts
;
1147 m_aTextArtRec
.aPath
[0].pPts
= nullptr;
1149 if (m_aTextArtRec
.aPath
[1].pPts
)
1151 delete [] m_aTextArtRec
.aPath
[1].pPts
;
1152 m_aTextArtRec
.aPath
[1].pPts
= nullptr;
1154 if (m_aTextArtRec
.pTextString
)
1156 delete [] m_aTextArtRec
.pTextString
;
1157 m_aTextArtRec
.pTextString
= nullptr;
1162 void LwpDrawTextArt::CreateFWPath(XFDrawPath
* pPath
)
1165 nX
= (m_aTextArtRec
.aPath
[0].pPts
[0].x
+ m_aTextArtRec
.aPath
[1].pPts
[0].x
) / 2;
1166 nY
= (m_aTextArtRec
.aPath
[0].pPts
[0].y
+ m_aTextArtRec
.aPath
[1].pPts
[0].y
) / 2;
1167 XFPoint
aStart((double)nX
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
1168 (double)nY
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
1169 pPath
->MoveTo(aStart
);
1171 sal_uInt8 nPtIndex
= 1;
1172 for (sal_uInt16 nC
= 1; nC
<= m_aTextArtRec
.aPath
[0].n
; nC
++)
1174 nX
= (m_aTextArtRec
.aPath
[0].pPts
[nPtIndex
].x
+ m_aTextArtRec
.aPath
[1].pPts
[nPtIndex
].x
) / 2;
1175 nY
= (m_aTextArtRec
.aPath
[0].pPts
[nPtIndex
].y
+ m_aTextArtRec
.aPath
[1].pPts
[nPtIndex
].y
) / 2;
1176 XFPoint
aCtrl1((double)nX
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
1177 (double)nY
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
1180 nX
= (m_aTextArtRec
.aPath
[0].pPts
[nPtIndex
].x
+ m_aTextArtRec
.aPath
[1].pPts
[nPtIndex
].x
) / 2;
1181 nY
= (m_aTextArtRec
.aPath
[0].pPts
[nPtIndex
].y
+ m_aTextArtRec
.aPath
[1].pPts
[nPtIndex
].y
) / 2;
1182 XFPoint
aCtrl2((double)nX
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
1183 (double)nY
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
1186 nX
= (m_aTextArtRec
.aPath
[0].pPts
[nPtIndex
].x
+ m_aTextArtRec
.aPath
[1].pPts
[nPtIndex
].x
) / 2;
1187 nY
= (m_aTextArtRec
.aPath
[0].pPts
[nPtIndex
].y
+ m_aTextArtRec
.aPath
[1].pPts
[nPtIndex
].y
) / 2;
1188 XFPoint
aDest((double)nX
/TWIPS_PER_CM
* m_pTransData
->fScaleX
,
1189 (double)nY
/TWIPS_PER_CM
* m_pTransData
->fScaleY
);
1191 pPath
->CurveTo(aDest
, aCtrl1
, aCtrl2
);
1195 void LwpDrawTextArt::Read()
1197 for (SdwPoint
& nC
: m_aVector
)
1199 m_pStream
->ReadInt16( nC
.x
);
1200 m_pStream
->ReadInt16( nC
.y
);
1203 ReadClosedObjStyle();
1204 m_aTextArtRec
.aTextColor
= m_aClosedObjStyleRec
.aForeColor
;
1206 m_pStream
->ReadUChar( m_aTextArtRec
.nIndex
);
1207 m_pStream
->ReadInt16( m_aTextArtRec
.nRotation
);
1209 sal_uInt16 nPointNumber
;
1211 m_pStream
->ReadUInt16( nPointNumber
);
1213 size_t nPoints
= nPointNumber
*3+1;
1214 if (nPoints
> m_pStream
->remainingSize() / 4)
1217 m_aTextArtRec
.aPath
[0].n
= nPointNumber
;
1218 m_aTextArtRec
.aPath
[0].pPts
= new SdwPoint
[nPoints
];
1219 for (size_t nPt
= 0; nPt
< nPoints
; ++nPt
)
1221 m_pStream
->ReadInt16( nX
);
1222 m_pStream
->ReadInt16( nY
);
1223 m_aTextArtRec
.aPath
[0].pPts
[nPt
].x
= nX
;
1224 m_aTextArtRec
.aPath
[0].pPts
[nPt
].y
= nY
;
1227 m_pStream
->ReadUInt16( nPointNumber
);
1229 nPoints
= nPointNumber
*3+1;
1230 if (nPoints
> m_pStream
->remainingSize() / 4)
1233 m_aTextArtRec
.aPath
[1].n
= nPointNumber
;
1234 m_aTextArtRec
.aPath
[1].pPts
= new SdwPoint
[nPoints
];
1235 for (size_t nPt
= 0; nPt
< nPoints
; ++nPt
)
1237 m_pStream
->ReadInt16( nX
);
1238 m_pStream
->ReadInt16( nY
);
1239 m_aTextArtRec
.aPath
[1].pPts
[nPt
].x
= nX
;
1240 m_aTextArtRec
.aPath
[1].pPts
[nPt
].y
= nY
;
1243 m_pStream
->SeekRel(1);
1245 m_pStream
->Read(m_aTextArtRec
.tmpTextFaceName
, DRAW_FACESIZE
);
1246 m_pStream
->SeekRel(1);// PitchAndFamily
1248 m_pStream
->ReadInt16( m_aTextArtRec
.nTextSize
);
1250 if (m_aTextArtRec
.nTextSize
< 0)
1251 m_aTextArtRec
.nTextSize
= -m_aTextArtRec
.nTextSize
;
1253 m_pStream
->ReadUInt16( m_aTextArtRec
.nTextAttrs
);
1254 m_pStream
->ReadUInt16( m_aTextArtRec
.nTextCharacterSet
);
1255 m_aTextArtRec
.nTextRotation
= 0;
1256 m_pStream
->ReadInt16( m_aTextArtRec
.nTextExtraSpacing
);
1258 const sal_uInt16 nTextArtFixedLength
= 105;
1259 m_aTextArtRec
.nTextLen
= m_aObjHeader
.nRecLen
- nTextArtFixedLength
1260 - (m_aTextArtRec
.aPath
[0].n
*3 + 1)*4
1261 - (m_aTextArtRec
.aPath
[1].n
*3 + 1)*4;
1264 if (m_aTextArtRec
.nTextLen
> m_pStream
->remainingSize())
1267 m_aTextArtRec
.pTextString
= new sal_uInt8
[m_aTextArtRec
.nTextLen
];
1268 m_pStream
->Read(m_aTextArtRec
.pTextString
, m_aTextArtRec
.nTextLen
);
1269 m_aTextArtRec
.pTextString
[m_aTextArtRec
.nTextLen
-1] = 0;
1273 OUString
LwpDrawTextArt::RegisterStyle()
1275 XFParaStyle
* pStyle
= new XFParaStyle();
1278 // the pFont need to be deleted myself?
1279 rtl::Reference
<XFFont
> pFont
= new XFFont();
1281 rtl_TextEncoding aEncoding
= RTL_TEXTENCODING_MS_1252
;
1282 OUString aFontName
= OUString(reinterpret_cast<char*>(m_aTextArtRec
.tmpTextFaceName
),
1283 strlen(reinterpret_cast<char*>(m_aTextArtRec
.tmpTextFaceName
)), aEncoding
);
1284 pFont
->SetFontName(aFontName
);
1286 LwpDrawTextBox::SetFontStyle(pFont
, &m_aTextArtRec
);
1288 pStyle
->SetFont(pFont
);
1290 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1291 return pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
1294 XFFrame
* LwpDrawTextArt::CreateDrawObj(const OUString
& rStyleName
)
1296 XFFrame
* pRetObj
= nullptr;
1297 XFDrawStyle
* pStyle
= new XFDrawStyle();
1299 pRetObj
= new XFDrawPath();
1300 XFDrawPath
* pFWPath
= static_cast<XFDrawPath
*>(pRetObj
);
1301 CreateFWPath(pFWPath
);
1302 pStyle
->SetFontWorkStyle(enumXFFWSlantY
, enumXFFWAdjustAutosize
);
1304 SetPosition(pRetObj
);
1306 rtl_TextEncoding aEncoding
;
1307 if (!m_aTextArtRec
.nTextCharacterSet
)
1309 aEncoding
= osl_getThreadTextEncoding();
1313 // temporary code, need to create Encoding from the value of nTextCharacterSet
1314 aEncoding
= LwpCharSetMgr::GetTextCharEncoding();
1317 XFParagraph
* pXFPara
= new XFParagraph();
1318 pXFPara
->Add(OUString(reinterpret_cast<char*>(m_aTextArtRec
.pTextString
), (m_aTextArtRec
.nTextLen
-1), aEncoding
));
1319 pXFPara
->SetStyleName(rStyleName
);
1320 pRetObj
->Add(pXFPara
);
1322 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1323 pRetObj
->SetStyleName(pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName());
1328 XFFrame
* LwpDrawTextArt::CreateStandardDrawObj(const OUString
& rStyleName
)
1330 return CreateDrawObj(rStyleName
);
1334 * @descr Constructor of class LwpDrawMetafile
1335 * @param pStream The memory stream which contains the lwp-sdw draw objects
1337 LwpDrawMetafile::LwpDrawMetafile(SvStream
* pStream
) : LwpDrawObj(pStream
)
1342 * @descr reading function of class LwpDrawMetafile
1344 void LwpDrawMetafile::Read()
1346 m_pStream
->SeekRel(m_aObjHeader
.nRecLen
-16);
1350 * @descr Constructor of class LwpDrawBitmap
1351 * @param pStream The memory stream which contains the lwp-sdw draw objects
1353 LwpDrawBitmap::LwpDrawBitmap(SvStream
* pStream
) : LwpDrawObj(pStream
), m_pImageData(nullptr)
1357 LwpDrawBitmap::~LwpDrawBitmap()
1361 delete [] m_pImageData
;
1362 m_pImageData
= nullptr;
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 // 14 == length of bmp file header.
1376 m_aBmpRec
.nFileSize
= m_aObjHeader
.nRecLen
- 20 + 14;
1377 m_pImageData
= new sal_uInt8
[m_aBmpRec
.nFileSize
];
1379 BmpInfoHeader2 aInfoHeader2
;
1380 m_pStream
->ReadUInt32( aInfoHeader2
.nHeaderLen
);
1383 sal_uInt32 rgbTableSize
;
1385 if (aInfoHeader2
.nHeaderLen
== sizeof(BmpInfoHeader
))
1387 m_pStream
->ReadUInt32( aInfoHeader2
.nWidth
);
1388 m_pStream
->ReadUInt32( aInfoHeader2
.nHeight
);
1389 m_pStream
->ReadUInt16( aInfoHeader2
.nPlanes
);
1390 m_pStream
->ReadUInt16( aInfoHeader2
.nBitCount
);
1392 N
= aInfoHeader2
.nPlanes
* aInfoHeader2
.nBitCount
;
1399 rgbTableSize
= 3 * (1 << N
);
1404 m_pStream
->ReadUInt32( aInfoHeader2
.nWidth
);
1405 m_pStream
->ReadUInt32( aInfoHeader2
.nHeight
);
1406 m_pStream
->ReadUInt16( aInfoHeader2
.nPlanes
);
1407 m_pStream
->ReadUInt16( aInfoHeader2
.nBitCount
);
1408 N
= aInfoHeader2
.nPlanes
* aInfoHeader2
.nBitCount
;
1415 rgbTableSize
= 4 * (1 << N
);
1420 sal_uInt32 nOffBits
= 14 + aInfoHeader2
.nHeaderLen
+ rgbTableSize
;
1421 m_pImageData
[0] = 'B';
1422 m_pImageData
[1] = 'M';
1423 m_pImageData
[2] = (sal_uInt8
)m_aBmpRec
.nFileSize
;
1424 m_pImageData
[3] = (sal_uInt8
)(m_aBmpRec
.nFileSize
>> 8);
1425 m_pImageData
[4] = (sal_uInt8
)(m_aBmpRec
.nFileSize
>> 16);
1426 m_pImageData
[5] = (sal_uInt8
)(m_aBmpRec
.nFileSize
>> 24);
1427 m_pImageData
[6] = 0;
1428 m_pImageData
[7] = 0;
1429 m_pImageData
[8] = 0;
1430 m_pImageData
[9] = 0;
1431 m_pImageData
[10] = (sal_uInt8
)nOffBits
;
1432 m_pImageData
[11] = (sal_uInt8
)(nOffBits
>> 8);
1433 m_pImageData
[12] = (sal_uInt8
)(nOffBits
>> 16);
1434 m_pImageData
[13] = (sal_uInt8
)(nOffBits
>> 24);
1436 sal_uInt32 nDIBRemaining
;
1437 sal_uInt8
* pPicData
= m_pImageData
;
1438 if (aInfoHeader2
.nHeaderLen
== sizeof(BmpInfoHeader
))
1440 m_pImageData
[14] = (sal_uInt8
)aInfoHeader2
.nHeaderLen
;
1441 m_pImageData
[15] = (sal_uInt8
)(aInfoHeader2
.nHeaderLen
>> 8);
1442 m_pImageData
[16] = (sal_uInt8
)(aInfoHeader2
.nHeaderLen
>> 16);
1443 m_pImageData
[17] = (sal_uInt8
)(aInfoHeader2
.nHeaderLen
>> 24);
1444 m_pImageData
[18] = (sal_uInt8
)aInfoHeader2
.nWidth
;
1445 m_pImageData
[19] = (sal_uInt8
)(aInfoHeader2
.nWidth
>> 8);
1446 m_pImageData
[20] = (sal_uInt8
)aInfoHeader2
.nHeight
;
1447 m_pImageData
[21] = (sal_uInt8
)(aInfoHeader2
.nHeight
>> 8);
1448 m_pImageData
[22] = (sal_uInt8
)aInfoHeader2
.nPlanes
;
1449 m_pImageData
[23] = (sal_uInt8
)(aInfoHeader2
.nPlanes
>> 8);
1450 m_pImageData
[24] = (sal_uInt8
)aInfoHeader2
.nBitCount
;
1451 m_pImageData
[25] = (sal_uInt8
)(aInfoHeader2
.nBitCount
>> 8);
1453 nDIBRemaining
= m_aBmpRec
.nFileSize
- 26;
1454 pPicData
+= 26*sizeof(sal_uInt8
);
1458 m_pImageData
[14] = (sal_uInt8
)aInfoHeader2
.nHeaderLen
;
1459 m_pImageData
[15] = (sal_uInt8
)(aInfoHeader2
.nHeaderLen
>> 8);
1460 m_pImageData
[16] = (sal_uInt8
)(aInfoHeader2
.nHeaderLen
>> 16);
1461 m_pImageData
[17] = (sal_uInt8
)(aInfoHeader2
.nHeaderLen
>> 24);
1462 m_pImageData
[18] = (sal_uInt8
)aInfoHeader2
.nWidth
;
1463 m_pImageData
[19] = (sal_uInt8
)(aInfoHeader2
.nWidth
>> 8);
1464 m_pImageData
[20] = (sal_uInt8
)(aInfoHeader2
.nWidth
>> 16);
1465 m_pImageData
[21] = (sal_uInt8
)(aInfoHeader2
.nWidth
>> 24);
1466 m_pImageData
[22] = (sal_uInt8
)aInfoHeader2
.nHeight
;
1467 m_pImageData
[23] = (sal_uInt8
)(aInfoHeader2
.nHeight
>> 8);
1468 m_pImageData
[24] = (sal_uInt8
)(aInfoHeader2
.nHeight
>> 16);
1469 m_pImageData
[25] = (sal_uInt8
)(aInfoHeader2
.nHeight
>> 24);
1470 m_pImageData
[26] = (sal_uInt8
)aInfoHeader2
.nPlanes
;
1471 m_pImageData
[27] = (sal_uInt8
)(aInfoHeader2
.nPlanes
>> 8);
1472 m_pImageData
[28] = (sal_uInt8
)aInfoHeader2
.nBitCount
;
1473 m_pImageData
[29] = (sal_uInt8
)(aInfoHeader2
.nBitCount
>> 8);
1475 nDIBRemaining
= m_aBmpRec
.nFileSize
- 30;
1476 pPicData
+= 30*sizeof(sal_uInt8
);
1479 m_pStream
->Read(pPicData
, nDIBRemaining
);
1482 OUString
LwpDrawBitmap::RegisterStyle()
1484 XFImageStyle
* pBmpStyle
= new XFImageStyle();
1485 pBmpStyle
->SetYPosType(enumXFFrameYPosFromTop
, enumXFFrameYRelFrame
);
1486 pBmpStyle
->SetXPosType(enumXFFrameXPosFromLeft
, enumXFFrameXRelFrame
);
1488 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1489 return pXFStyleManager
->AddStyle(pBmpStyle
).m_pStyle
->GetStyleName();
1492 XFFrame
* LwpDrawBitmap::CreateDrawObj(const OUString
& rStyleName
)
1494 XFImage
* pImage
= new XFImage();
1495 pImage
->SetImageData(m_pImageData
, m_aBmpRec
.nFileSize
);
1496 SetPosition(pImage
);
1498 pImage
->SetStyleName(rStyleName
);
1503 XFFrame
* LwpDrawBitmap::CreateStandardDrawObj(const OUString
& rStyleName
)
1505 return CreateDrawObj(rStyleName
);
1508 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */