Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
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
16 : *
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.
20 : *
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.
25 : *
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
30 : *
31 : *
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.
38 : *
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.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : /**
57 : * @file
58 : * Implementation file of LwpDrawObjcts and associated class like LwpDrawGroup, LwpDrawRectange
59 : * and so on.
60 : */
61 : #include <osl/thread.h>
62 : #include "lwpglobalmgr.hxx"
63 : #include "lwpdrawobj.hxx"
64 : #include "lwptools.hxx"
65 : #include <tools/stream.hxx>
66 :
67 : #include "xfilter/xfframe.hxx"
68 :
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"
78 :
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"
84 :
85 : #include "lwpcharsetmgr.hxx"
86 : #include "lwpsdwrect.hxx"
87 :
88 : /**
89 : * @descr Constructor of class LwpDrawObj
90 : * @param pStream The memory stream which contains the lwp-sdw draw objects
91 : */
92 0 : LwpDrawObj::LwpDrawObj(SvStream * pStream, DrawingOffsetAndScale* pTransData)
93 : : m_eType(OT_UNDEFINED)
94 : , m_pStream(pStream)
95 0 : , m_pTransData(pTransData)
96 : {
97 0 : this->ReadObjHeaderRecord();
98 0 : }
99 :
100 : /**
101 : * @descr read the header record data of lwp-sdw-object
102 : */
103 0 : void LwpDrawObj::ReadObjHeaderRecord()
104 : {
105 : //flags
106 0 : m_pStream->SeekRel(1);
107 :
108 : //record Length
109 0 : *m_pStream >> m_aObjHeader.nRecLen;
110 :
111 : //boundrect
112 0 : *m_pStream >> m_aObjHeader.nLeft;
113 0 : *m_pStream >> m_aObjHeader.nTop;
114 0 : *m_pStream >> m_aObjHeader.nRight;
115 0 : *m_pStream >> m_aObjHeader.nBottom;
116 :
117 : //nextObj, prevObj
118 0 : m_pStream->SeekRel(4);
119 0 : }
120 :
121 : /**
122 : * @descr read the style of closed lwp-sdw-object like: rectangle, ellipse and so on.
123 : */
124 0 : void LwpDrawObj::ReadClosedObjStyle()
125 : {
126 0 : if ((m_eType != OT_POLYGON) && (m_eType != OT_TEXTART))
127 : {
128 0 : m_pStream->SeekRel(8);
129 : }
130 :
131 0 : *m_pStream >> m_aClosedObjStyleRec.nLineWidth;
132 0 : *m_pStream >> m_aClosedObjStyleRec.nLineStyle;
133 :
134 : // pen color
135 0 : *m_pStream >> m_aClosedObjStyleRec.aPenColor.nR;
136 0 : *m_pStream >> m_aClosedObjStyleRec.aPenColor.nG;
137 0 : *m_pStream >> m_aClosedObjStyleRec.aPenColor.nB;
138 0 : *m_pStream >> m_aClosedObjStyleRec.aPenColor.unused;
139 :
140 : // foreground color
141 0 : *m_pStream >> m_aClosedObjStyleRec.aForeColor.nR;
142 0 : *m_pStream >> m_aClosedObjStyleRec.aForeColor.nG;
143 0 : *m_pStream >> m_aClosedObjStyleRec.aForeColor.nB;
144 0 : *m_pStream >> m_aClosedObjStyleRec.aForeColor.unused;
145 :
146 : // background color
147 0 : *m_pStream >> m_aClosedObjStyleRec.aBackColor.nR;
148 0 : *m_pStream >> m_aClosedObjStyleRec.aBackColor.nG;
149 0 : *m_pStream >> m_aClosedObjStyleRec.aBackColor.nB;
150 0 : *m_pStream >> m_aClosedObjStyleRec.aBackColor.unused;
151 :
152 : // fill style
153 0 : *m_pStream >> m_aClosedObjStyleRec.nFillType;
154 : m_pStream->Read(m_aClosedObjStyleRec.pFillPattern,
155 0 : sizeof(m_aClosedObjStyleRec.pFillPattern));
156 0 : }
157 :
158 : /**
159 : * @descr set fill style of drawing objects
160 : * @param pStyle pointer of the drawing xfstyle.
161 : */
162 0 : void LwpDrawObj::SetFillStyle(XFDrawStyle* pStyle)
163 : {
164 0 : if (!pStyle)
165 : {
166 : assert(false);
167 0 : return;
168 : }
169 :
170 : XFColor aForeColor(m_aClosedObjStyleRec.aForeColor.nR,
171 0 : m_aClosedObjStyleRec.aForeColor.nG, m_aClosedObjStyleRec.aForeColor.nB);
172 : XFColor aBackColor(m_aClosedObjStyleRec.aBackColor.nR,
173 0 : m_aClosedObjStyleRec.aBackColor.nG, m_aClosedObjStyleRec.aBackColor.nB);
174 :
175 0 : switch (m_aClosedObjStyleRec.nFillType)
176 : {
177 : default: //fall through!
178 : case FT_TRANSPARENT:
179 : {
180 : // set fill style : none
181 0 : break;
182 : }
183 : case FT_SOLID:
184 : {
185 0 : pStyle->SetAreaColor(aForeColor);
186 0 : break;
187 : }
188 : case FT_HORZHATCH:
189 : {
190 0 : pStyle->SetAreaColor(aBackColor);
191 0 : pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 0, 0.12, aForeColor);
192 0 : break;
193 : }
194 : case FT_VERTHATCH:
195 : {
196 0 : pStyle->SetAreaColor(aBackColor);
197 0 : pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 90, 0.12, aForeColor);
198 0 : break;
199 : }
200 : case FT_FDIAGHATCH:
201 : {
202 0 : pStyle->SetAreaColor(aBackColor);
203 0 : pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 135, 0.09, aForeColor);
204 0 : break;
205 : }
206 : case FT_BDIAGHATCH:
207 : {
208 0 : pStyle->SetAreaColor(aBackColor);
209 0 : pStyle->SetAreaLineStyle(enumXFAreaLineSingle, 45, 0.09, aForeColor);
210 0 : break;
211 : }
212 : case FT_CROSSHATCH:
213 : {
214 0 : pStyle->SetAreaColor(aBackColor);
215 0 : pStyle->SetAreaLineStyle(enumXFAreaLineCrossed, 0, 0.12, aForeColor);
216 0 : break;
217 : }
218 : case FT_DIAGCROSSHATCH:
219 : {
220 0 : pStyle->SetAreaColor(aBackColor);
221 0 : pStyle->SetAreaLineStyle(enumXFAreaLineCrossed, 45, 0.095, aForeColor);
222 0 : break;
223 : }
224 : }
225 : }
226 :
227 : /**
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.
233 : */
234 0 : void LwpDrawObj::SetLineStyle(XFDrawStyle* pStyle, sal_uInt8 nWidth, sal_uInt8 nLineStyle,
235 : const SdwColor& rColor)
236 : {
237 0 : if (!pStyle)
238 : {
239 : assert(false);
240 0 : return;
241 : }
242 0 : if (nWidth == 0)
243 : {
244 0 : nLineStyle = LS_NULL;
245 : }
246 :
247 0 : if (nLineStyle == LS_NULL)
248 : {
249 : // set stroke:none
250 0 : return;
251 : }
252 :
253 0 : if (nLineStyle == LS_DOT)
254 : {
255 0 : pStyle->SetLineDashStyle(enumXFLineDash, 1, 1, 0.05, 0.05, 0.05);
256 : }
257 :
258 : // line width
259 0 : double fWidth = (double)nWidth/TWIPS_PER_CM;
260 :
261 : // line color
262 0 : XFColor aXFColor(rColor.nR, rColor.nG, rColor.nB);
263 :
264 0 : pStyle->SetLineStyle(fWidth, aXFColor);
265 : }
266 :
267 : /**
268 : * @descr set position of a drawing object in the frame.
269 : * @param pObj pointer of the xf-drawing object
270 : */
271 0 : void LwpDrawObj::SetPosition(XFFrame* pObj)
272 : {
273 0 : double fOffsetX = 0.00, fOffsetY = 0.00;
274 0 : double fScaleX = 1.00, fScaleY = 1.00;
275 0 : if (m_pTransData)
276 : {
277 0 : fOffsetX = m_pTransData->fOffsetX;
278 0 : fOffsetY = m_pTransData->fOffsetY;
279 0 : fScaleX = m_pTransData->fScaleX;
280 0 : fScaleY = m_pTransData->fScaleY;
281 : }
282 :
283 0 : pObj->SetPosition((double)m_aObjHeader.nLeft/TWIPS_PER_CM * fScaleX+ fOffsetX,
284 0 : (double)m_aObjHeader.nTop/TWIPS_PER_CM * fScaleY + fOffsetY,
285 0 : (double)(m_aObjHeader.nRight-m_aObjHeader.nLeft)/TWIPS_PER_CM * fScaleX,
286 0 : (double)(m_aObjHeader.nBottom-m_aObjHeader.nTop)/TWIPS_PER_CM * fScaleY);
287 0 : }
288 :
289 : /**
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.
293 : */
294 0 : void LwpDrawObj::SetArrowHead(XFDrawStyle* pOpenedObjStyle, sal_uInt8 nArrowFlag, sal_uInt8 nLineWidth)
295 : {
296 : // no arrowhead
297 0 : if (!nArrowFlag)
298 : {
299 0 : return;
300 : }
301 :
302 0 : if (!pOpenedObjStyle)
303 : {
304 : assert(false);
305 0 : return;
306 : }
307 :
308 : // arrowhead flag of an object's start side
309 0 : sal_uInt8 nLeftArrow = nArrowFlag & 0x0F;
310 :
311 : // arrowhead flag of an object's end side
312 0 : sal_uInt8 nRightArrow = (nArrowFlag & 0xF0) >> 4;
313 :
314 0 : double fWidth_inch = (double)nLineWidth/TWIPS_PER_CM;
315 0 : double fArrowSize_inch = fWidth_inch + 0.08;
316 0 : double fArrowSize = fArrowSize_inch * CM_PER_INCH;
317 :
318 0 : if (nLeftArrow)
319 : {
320 0 : pOpenedObjStyle->SetArrowStart( this->GetArrowName(nLeftArrow), fArrowSize, sal_True);
321 : }
322 0 : if (nRightArrow)
323 : {
324 0 : pOpenedObjStyle->SetArrowEnd( this->GetArrowName(nRightArrow), fArrowSize, sal_True);
325 : }
326 :
327 : }
328 :
329 : /**
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.
333 : */
334 0 : OUString LwpDrawObj::GetArrowName(sal_uInt8 nArrowStyle)
335 : {
336 : // style name of arrowhead
337 0 : OUString aArrowName;
338 :
339 0 : switch(nArrowStyle)
340 : {
341 : default:
342 : case AH_ARROW_FULLARROW:
343 0 : aArrowName = OUString("Symmetric arrow");
344 0 : break;
345 : case AH_ARROW_HALFARROW:
346 0 : aArrowName = OUString("Arrow concave");
347 0 : break;
348 : case AH_ARROW_LINEARROW:
349 0 : aArrowName = OUString("arrow100");
350 0 : break;
351 : case AH_ARROW_INVFULLARROW:
352 0 : aArrowName = OUString("reverse arrow");
353 0 : break;
354 : case AH_ARROW_INVHALFARROW:
355 0 : aArrowName = OUString("reverse concave arrow");
356 0 : break;
357 : case AH_ARROW_INVLINEARROW:
358 0 : aArrowName = OUString("reverse line arrow");
359 0 : break;
360 : case AH_ARROW_TEE:
361 0 : aArrowName = OUString("Dimension lines");
362 0 : break;
363 : case AH_ARROW_SQUARE:
364 0 : aArrowName = OUString("Square");
365 0 : break;
366 : case AH_ARROW_CIRCLE:
367 0 : aArrowName = OUString("Circle");
368 0 : break;
369 : }
370 :
371 0 : return aArrowName;
372 : }
373 :
374 : /**
375 : * @descr template method of creating drawing object from Lwp-Model to XF-Model
376 : * @return pointer of the drawing object of XF-Model.
377 : */
378 0 : XFFrame* LwpDrawObj::CreateXFDrawObject()
379 : {
380 : // read records
381 0 : this->Read();
382 :
383 : // register style
384 0 : OUString aStyleName = this->RegisterStyle();
385 :
386 : // create XF-Objects
387 0 : XFFrame* pXFObj = NULL;
388 0 : if (m_pTransData
389 0 : && FABS(m_pTransData->fOffsetX - m_pTransData->fLeftMargin) < THRESHOLD
390 0 : && FABS(m_pTransData->fOffsetY - m_pTransData->fTopMargin) < THRESHOLD
391 0 : && FABS(m_pTransData->fScaleX - 1.0) < THRESHOLD
392 0 : && FABS(m_pTransData->fScaleY - 1.0) < THRESHOLD)
393 : {
394 0 : pXFObj = this->CreateStandardDrawObj(aStyleName);
395 : }
396 : else
397 : {
398 0 : pXFObj = this->CreateDrawObj(aStyleName);
399 : }
400 :
401 : // set anchor type
402 0 : if (pXFObj)
403 : {
404 0 : pXFObj->SetAnchorType(enumXFAnchorFrame);
405 : }
406 :
407 0 : return pXFObj;
408 : }
409 :
410 : /**
411 : * @descr Constructor of class LwpDrawLine
412 : * @param pStream The memory stream which contains the lwp-sdw draw objects
413 : */
414 0 : LwpDrawLine::LwpDrawLine(SvStream * pStream, DrawingOffsetAndScale* pTransData)
415 0 : : LwpDrawObj(pStream, pTransData)
416 : {
417 0 : }
418 :
419 : /**
420 : * @descr reading function of class LwpDrawLine
421 : */
422 0 : void LwpDrawLine::Read()
423 : {
424 0 : *m_pStream >> m_aLineRec.nStartX;
425 0 : *m_pStream >> m_aLineRec.nStartY;
426 0 : *m_pStream >> m_aLineRec.nEndX;
427 0 : *m_pStream >> m_aLineRec.nEndY;
428 0 : *m_pStream >> m_aLineRec.nLineWidth;
429 0 : *m_pStream >> m_aLineRec.nLineEnd;
430 0 : *m_pStream >> m_aLineRec.nLineStyle;
431 :
432 0 : *m_pStream >> m_aLineRec.aPenColor.nR;
433 0 : *m_pStream >> m_aLineRec.aPenColor.nG;
434 0 : *m_pStream >> m_aLineRec.aPenColor.nB;
435 0 : *m_pStream >> m_aLineRec.aPenColor.unused;
436 0 : }
437 :
438 0 : OUString LwpDrawLine::RegisterStyle()
439 : {
440 0 : XFDrawStyle* pStyle = new XFDrawStyle();
441 :
442 : // set line style
443 0 : this->SetLineStyle(pStyle, m_aLineRec.nLineWidth, m_aLineRec.nLineStyle, m_aLineRec.aPenColor);
444 :
445 : // set arrow head
446 0 : this->SetArrowHead(pStyle, m_aLineRec.nLineEnd, m_aLineRec.nLineWidth);
447 :
448 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
449 0 : return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
450 :
451 : }
452 :
453 0 : XFFrame* LwpDrawLine::CreateDrawObj(const OUString& rStyleName )
454 : {
455 0 : XFDrawPath* pLine = new XFDrawPath();
456 0 : pLine->MoveTo(XFPoint((double)(m_aLineRec.nStartX)/TWIPS_PER_CM * m_pTransData->fScaleX,
457 0 : (double)(m_aLineRec.nStartY)/TWIPS_PER_CM * m_pTransData->fScaleY));
458 0 : pLine->LineTo(XFPoint((double)(m_aLineRec.nEndX)/TWIPS_PER_CM * m_pTransData->fScaleX,
459 0 : (double)(m_aLineRec.nEndY)/TWIPS_PER_CM * m_pTransData->fScaleY));
460 0 : this->SetPosition(pLine);
461 :
462 0 : pLine->SetStyleName(rStyleName);
463 :
464 0 : return pLine;
465 : }
466 :
467 0 : XFFrame* LwpDrawLine::CreateStandardDrawObj(const OUString& rStyleName)
468 : {
469 0 : XFDrawLine* pLine = new XFDrawLine();
470 0 : pLine->SetStartPoint((double)(m_aLineRec.nStartX)/TWIPS_PER_CM,(double)(m_aLineRec.nStartY)/TWIPS_PER_CM);
471 0 : pLine->SetEndPoint((double)(m_aLineRec.nEndX)/TWIPS_PER_CM,(double)(m_aLineRec.nEndY)/TWIPS_PER_CM);
472 :
473 0 : pLine->SetStyleName(rStyleName);
474 0 : return pLine;
475 : }
476 :
477 : /**
478 : * @descr Constructor of class LwpDrawPolyLine
479 : * @param pStream The memory stream which contains the lwp-sdw draw objects
480 : */
481 0 : LwpDrawPolyLine::LwpDrawPolyLine(SvStream * pStream, DrawingOffsetAndScale* pTransData)
482 0 : : LwpDrawObj(pStream, pTransData), m_pVector(NULL)
483 : {
484 0 : }
485 0 : LwpDrawPolyLine::~LwpDrawPolyLine()
486 : {
487 0 : if (m_pVector)
488 : {
489 0 : delete [] m_pVector;
490 0 : m_pVector = NULL;
491 : }
492 0 : }
493 :
494 : /**
495 : * @descr reading function of class LwpDrawPolyLine
496 : */
497 0 : void LwpDrawPolyLine::Read()
498 : {
499 0 : *m_pStream >> m_aPolyLineRec.nLineWidth;
500 0 : *m_pStream >> m_aPolyLineRec.nLineEnd;
501 0 : *m_pStream >> m_aPolyLineRec.nLineStyle;
502 0 : *m_pStream >> m_aPolyLineRec.aPenColor.nR;
503 0 : *m_pStream >> m_aPolyLineRec.aPenColor.nG;
504 0 : *m_pStream >> m_aPolyLineRec.aPenColor.nB;
505 0 : *m_pStream >> m_aPolyLineRec.aPenColor.unused;
506 0 : *m_pStream >> m_aPolyLineRec.nNumPoints;
507 :
508 0 : m_pVector= new SdwPoint [m_aPolyLineRec.nNumPoints];
509 :
510 0 : for (sal_uInt16 nC = 0; nC < m_aPolyLineRec.nNumPoints; nC++)
511 : {
512 0 : *m_pStream >> m_pVector[nC].x;
513 0 : *m_pStream >> m_pVector[nC].y;
514 : }
515 0 : }
516 :
517 0 : OUString LwpDrawPolyLine::RegisterStyle()
518 : {
519 0 : XFDrawStyle* pStyle = new XFDrawStyle();
520 :
521 : // set line style
522 : this->SetLineStyle(pStyle, m_aPolyLineRec.nLineWidth, m_aPolyLineRec.nLineStyle,
523 0 : m_aPolyLineRec.aPenColor);
524 :
525 : // set arrow head
526 0 : this->SetArrowHead(pStyle, m_aPolyLineRec.nLineEnd, m_aPolyLineRec.nLineWidth);
527 :
528 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
529 0 : return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
530 : }
531 :
532 0 : XFFrame* LwpDrawPolyLine::CreateDrawObj(const OUString& rStyleName )
533 : {
534 0 : XFDrawPath* pPolyline = new XFDrawPath();
535 0 : pPolyline->MoveTo(XFPoint((double)m_pVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
536 0 : (double)m_pVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
537 0 : for (sal_uInt8 nC = 1; nC < m_aPolyLineRec.nNumPoints; nC++)
538 : {
539 0 : pPolyline->LineTo(XFPoint((double)m_pVector[nC].x/TWIPS_PER_CM * m_pTransData->fScaleX,
540 0 : (double)m_pVector[nC].y/TWIPS_PER_CM * m_pTransData->fScaleY));
541 : }
542 0 : this->SetPosition(pPolyline);
543 :
544 0 : pPolyline->SetStyleName(rStyleName);
545 :
546 0 : return pPolyline;
547 : }
548 :
549 0 : XFFrame* LwpDrawPolyLine::CreateStandardDrawObj(const OUString& rStyleName)
550 : {
551 0 : XFDrawPolyline* pPolyline = new XFDrawPolyline();
552 0 : for (sal_uInt8 nC = 0; nC < m_aPolyLineRec.nNumPoints; nC++)
553 : {
554 0 : pPolyline->AddPoint((double)m_pVector[nC].x/TWIPS_PER_CM,
555 0 : (double)m_pVector[nC].y/TWIPS_PER_CM);
556 : }
557 :
558 0 : pPolyline->SetStyleName(rStyleName);
559 :
560 0 : return pPolyline;
561 : }
562 :
563 : /**
564 : * @descr Constructor of class LwpDrawPolygon
565 : * @param pStream The memory stream which contains the lwp-sdw draw objects
566 : */
567 0 : LwpDrawPolygon::LwpDrawPolygon(SvStream * pStream, DrawingOffsetAndScale* pTransData)
568 0 : : LwpDrawObj(pStream, pTransData)
569 : {
570 0 : }
571 0 : LwpDrawPolygon::~LwpDrawPolygon()
572 : {
573 0 : if (m_pVector)
574 : {
575 0 : delete [] m_pVector;
576 0 : m_pVector = NULL;
577 : }
578 0 : }
579 :
580 : /**
581 : * @descr reading function of class LwpDrawPolygon
582 : */
583 0 : void LwpDrawPolygon::Read()
584 : {
585 0 : this->ReadClosedObjStyle();
586 0 : *m_pStream >> m_nNumPoints;
587 :
588 0 : m_pVector = new SdwPoint [m_nNumPoints];
589 :
590 0 : for (sal_uInt16 nC = 0; nC < m_nNumPoints; nC++)
591 : {
592 0 : *m_pStream >> m_pVector[nC].x;
593 0 : *m_pStream >> m_pVector[nC].y;
594 : }
595 0 : }
596 :
597 0 : OUString LwpDrawPolygon::RegisterStyle()
598 : {
599 0 : XFDrawStyle* pStyle = new XFDrawStyle();
600 :
601 : // set line style
602 : this->SetLineStyle(pStyle, m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
603 0 : m_aClosedObjStyleRec.aPenColor);
604 :
605 : // set fill style
606 0 : this->SetFillStyle(pStyle);
607 :
608 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
609 0 : return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
610 : }
611 :
612 0 : XFFrame* LwpDrawPolygon::CreateDrawObj(const OUString& rStyleName)
613 : {
614 0 : XFDrawPath* pPolygon = new XFDrawPath();
615 0 : pPolygon->MoveTo(XFPoint((double)m_pVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
616 0 : (double)m_pVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
617 0 : for (sal_uInt16 nC = 1; nC < m_nNumPoints; nC++)
618 : {
619 0 : pPolygon->LineTo(XFPoint((double)m_pVector[nC].x/TWIPS_PER_CM * m_pTransData->fScaleX,
620 0 : (double)m_pVector[nC].y/TWIPS_PER_CM * m_pTransData->fScaleY));
621 : }
622 0 : pPolygon->ClosePath();
623 0 : this->SetPosition(pPolygon);
624 0 : pPolygon->SetStyleName(rStyleName);
625 :
626 0 : return pPolygon;
627 : }
628 :
629 0 : XFFrame* LwpDrawPolygon::CreateStandardDrawObj(const OUString& rStyleName)
630 : {
631 0 : XFDrawPolygon* pPolygon = new XFDrawPolygon();
632 0 : for (sal_uInt16 nC = 0; nC < m_nNumPoints; nC++)
633 : {
634 0 : pPolygon->AddPoint((double)m_pVector[nC].x/TWIPS_PER_CM,
635 0 : (double)m_pVector[nC].y/TWIPS_PER_CM);
636 : }
637 :
638 0 : pPolygon->SetStyleName(rStyleName);
639 :
640 0 : return pPolygon;
641 : }
642 :
643 : /**
644 : * @descr Constructor of class LwpDrawRectangle
645 : * @param pStream The memory stream which contains the lwp-sdw draw objects
646 : */
647 0 : LwpDrawRectangle::LwpDrawRectangle(SvStream * pStream, DrawingOffsetAndScale* pTransData)
648 0 : : LwpDrawObj(pStream, pTransData)
649 : {
650 0 : }
651 :
652 : /**
653 : * @descr reading function of class LwpDrawRectangle
654 : */
655 0 : void LwpDrawRectangle::Read()
656 : {
657 0 : this->ReadClosedObjStyle();
658 :
659 : sal_uInt8 nPointsCount;
660 0 : if (m_eType == OT_RNDRECT)
661 : {
662 0 : nPointsCount = 16;
663 0 : m_pStream->SeekRel(4); // corner points
664 : }
665 : else
666 : {
667 0 : nPointsCount = 4;
668 : }
669 :
670 0 : for (sal_uInt8 nC = 0; nC < nPointsCount; nC++)
671 : {
672 0 : *m_pStream >> m_aVector[nC].x;
673 0 : *m_pStream >> m_aVector[nC].y;
674 : }
675 0 : }
676 :
677 0 : OUString LwpDrawRectangle::RegisterStyle()
678 : {
679 0 : XFDrawStyle* pStyle = new XFDrawStyle();
680 :
681 : // set line style
682 : this->SetLineStyle(pStyle, m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
683 0 : m_aClosedObjStyleRec.aPenColor);
684 :
685 : // set fill style
686 0 : this->SetFillStyle(pStyle);
687 :
688 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
689 0 : return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
690 : }
691 :
692 0 : XFFrame* LwpDrawRectangle::CreateDrawObj(const OUString& rStyleName)
693 : {
694 0 : if (m_eType == OT_RNDRECT)
695 : {
696 0 : return this->CreateRoundedRect(rStyleName);
697 : }
698 : else
699 : {
700 0 : XFDrawPath* pRect = new XFDrawPath();
701 0 : pRect->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
702 0 : (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
703 0 : for (sal_uInt8 nC = 1; nC < 4; nC++)
704 : {
705 0 : pRect->LineTo(XFPoint((double)m_aVector[nC].x/TWIPS_PER_CM * m_pTransData->fScaleX,
706 0 : (double)m_aVector[nC].y/TWIPS_PER_CM * m_pTransData->fScaleY));
707 : }
708 0 : pRect->LineTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
709 0 : (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
710 0 : pRect->ClosePath(sal_True);
711 0 : this->SetPosition(pRect);
712 :
713 0 : pRect->SetStyleName(rStyleName);
714 :
715 0 : return pRect;
716 : }
717 : }
718 :
719 0 : XFFrame* LwpDrawRectangle::CreateRoundedRect(const OUString& rStyleName)
720 : {
721 0 : XFDrawPath* pRoundedRect = new XFDrawPath();
722 0 : pRoundedRect->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
723 0 : (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
724 :
725 0 : sal_uInt8 nPtIndex = 1;
726 0 : for (sal_uInt8 nC = 0; nC < 7; nC++)
727 : {
728 0 : if (nC%2 == 0)
729 : {
730 0 : XFPoint aCtrl1((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
731 0 : (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
732 0 : nPtIndex++;
733 0 : XFPoint aCtrl2((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
734 0 : (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
735 0 : nPtIndex++;
736 0 : XFPoint aDest((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
737 0 : (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
738 0 : nPtIndex++;
739 :
740 0 : pRoundedRect->CurveTo(aDest, aCtrl1, aCtrl2);
741 : }
742 : else
743 : {
744 0 : XFPoint aDest((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
745 0 : (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
746 0 : nPtIndex++;
747 :
748 0 : pRoundedRect->LineTo(aDest);
749 : }
750 : }
751 :
752 0 : pRoundedRect->LineTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
753 0 : (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
754 0 : pRoundedRect->ClosePath(sal_True);
755 0 : this->SetPosition(pRoundedRect);
756 :
757 0 : pRoundedRect->SetStyleName(rStyleName);
758 :
759 0 : return pRoundedRect;
760 : }
761 :
762 0 : XFFrame* LwpDrawRectangle::CreateStandardDrawObj(const OUString& rStyleName)
763 : {
764 0 : if (m_eType == OT_RNDRECT)
765 : {
766 0 : return this->CreateRoundedRect(rStyleName);
767 : }
768 : else
769 : {
770 0 : XFDrawRect* pRect = new XFDrawRect();
771 : double fStartX, fStartY, fWidth, fHeight;
772 0 : double fRotAngle = 0.0;
773 0 : SdwRectangle aSdwRect;
774 0 : Rectangle aOriginalRect;
775 0 : Point aPt0, aPt1, aPt2, aPt3;
776 :
777 0 : aPt0.setX(m_aVector[0].x); aPt0.setY(m_aVector[0].y);
778 0 : aPt1.setX(m_aVector[1].x); aPt1.setY(m_aVector[1].y);
779 0 : aPt2.setX(m_aVector[2].x); aPt2.setY(m_aVector[2].y);
780 0 : aPt3.setX(m_aVector[3].x); aPt3.setY(m_aVector[3].y);
781 :
782 0 : aSdwRect = SdwRectangle(aPt0, aPt1, aPt2, aPt3);
783 0 : if (aSdwRect.IsRectRotated())
784 : {
785 0 : aOriginalRect = aSdwRect.GetOriginalRect();
786 0 : fRotAngle = aSdwRect.GetRotationAngle();
787 : }
788 : else
789 : {
790 0 : aOriginalRect = Rectangle(aPt0, aPt2);
791 : }
792 :
793 0 : fStartX = aOriginalRect.TopLeft().X();
794 0 : fStartY = aOriginalRect.TopLeft().Y();
795 0 : fWidth = aOriginalRect.GetWidth();
796 0 : fHeight = aOriginalRect.GetHeight();
797 :
798 0 : pRect->SetStartPoint(XFPoint(fStartX/TWIPS_PER_CM + m_pTransData->fOffsetX,
799 0 : fStartY/TWIPS_PER_CM + m_pTransData->fOffsetY));
800 0 : pRect->SetSize(fWidth/TWIPS_PER_CM, fHeight/TWIPS_PER_CM);
801 :
802 0 : if (aSdwRect.IsRectRotated())
803 : {
804 0 : pRect->SetRotate( fRotAngle / PI * 180);// aXFCenter);
805 : }
806 :
807 0 : pRect->SetStyleName(rStyleName);
808 :
809 0 : return pRect;
810 : }
811 : }
812 :
813 : /**
814 : * @descr Constructor of class LwpDrawEllipse
815 : * @param pStream The memory stream which contains the lwp-sdw draw objects
816 : */
817 0 : LwpDrawEllipse::LwpDrawEllipse(SvStream * pStream, DrawingOffsetAndScale* pTransData)
818 0 : : LwpDrawObj(pStream, pTransData)
819 : {
820 0 : }
821 :
822 : /**
823 : * @descr reading function of class LwpDrawEllipse
824 : */
825 0 : void LwpDrawEllipse::Read()
826 : {
827 0 : this->ReadClosedObjStyle();
828 :
829 0 : for (sal_uInt8 nC = 0; nC < 13; nC++)
830 : {
831 0 : *m_pStream >> m_aVector[nC].x;
832 0 : *m_pStream >> m_aVector[nC].y;
833 : }
834 0 : }
835 :
836 0 : OUString LwpDrawEllipse::RegisterStyle()
837 : {
838 0 : XFDrawStyle* pStyle = new XFDrawStyle();
839 :
840 : // set line style
841 : this->SetLineStyle(pStyle, m_aClosedObjStyleRec.nLineWidth, m_aClosedObjStyleRec.nLineStyle,
842 0 : m_aClosedObjStyleRec.aPenColor);
843 :
844 : // set fill style
845 0 : this->SetFillStyle(pStyle);
846 :
847 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
848 0 : return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
849 : }
850 :
851 0 : XFFrame* LwpDrawEllipse::CreateDrawObj(const OUString& rStyleName )
852 : {
853 0 : XFDrawPath* pEllipse = new XFDrawPath();
854 0 : pEllipse->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
855 0 : (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
856 0 : sal_uInt8 nPtIndex = 1;
857 0 : for (sal_uInt8 nC = 0; nC < 4; nC++)
858 : {
859 0 : XFPoint aCtrl1((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
860 0 : (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
861 0 : nPtIndex++;
862 0 : XFPoint aCtrl2((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
863 0 : (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
864 0 : nPtIndex++;
865 0 : XFPoint aDest((double)m_aVector[nPtIndex].x/TWIPS_PER_CM * m_pTransData->fScaleX,
866 0 : (double)m_aVector[nPtIndex].y/TWIPS_PER_CM * m_pTransData->fScaleY);
867 0 : nPtIndex++;
868 :
869 0 : pEllipse->CurveTo(aDest, aCtrl1, aCtrl2);
870 : }
871 0 : pEllipse->ClosePath(sal_True);
872 0 : this->SetPosition(pEllipse);
873 :
874 0 : pEllipse->SetStyleName(rStyleName);
875 :
876 0 : return pEllipse;
877 : }
878 :
879 0 : XFFrame* LwpDrawEllipse::CreateStandardDrawObj(const OUString& rStyleName)
880 : {
881 0 : return this->CreateDrawObj(rStyleName);
882 : }
883 :
884 : /**
885 : * @descr Constructor of class LwpDrawArc
886 : * @param pStream The memory stream which contains the lwp-sdw draw objects
887 : */
888 0 : LwpDrawArc::LwpDrawArc(SvStream * pStream, DrawingOffsetAndScale* pTransData)
889 0 : : LwpDrawObj(pStream, pTransData)
890 : {
891 0 : }
892 :
893 : /**
894 : * @descr reading function of class LwpDrawArc
895 : */
896 0 : void LwpDrawArc::Read()
897 : {
898 0 : m_pStream->SeekRel(16);// arcRect, startPt, endPt
899 :
900 0 : *m_pStream >> m_aArcRec.nLineWidth;
901 0 : *m_pStream >> m_aArcRec.nLineStyle;
902 0 : *m_pStream >> m_aArcRec.aPenColor.nR;
903 0 : *m_pStream >> m_aArcRec.aPenColor.nG;
904 0 : *m_pStream >> m_aArcRec.aPenColor.nB;
905 0 : *m_pStream >> m_aArcRec.aPenColor.unused;
906 0 : *m_pStream >> m_aArcRec.nLineEnd;
907 :
908 0 : for (sal_uInt8 nC = 0; nC < 4; nC++)
909 : {
910 0 : *m_pStream >> m_aVector[nC].x;
911 0 : *m_pStream >> m_aVector[nC].y;
912 : }
913 0 : }
914 :
915 0 : OUString LwpDrawArc::RegisterStyle()
916 : {
917 0 : XFDrawStyle* pStyle = new XFDrawStyle();
918 :
919 : // set line style
920 : this->SetLineStyle(pStyle, m_aArcRec.nLineWidth, m_aArcRec.nLineStyle,
921 0 : m_aArcRec.aPenColor);
922 :
923 : // set arrow head
924 0 : this->SetArrowHead(pStyle, m_aArcRec.nLineEnd, m_aArcRec.nLineWidth);
925 :
926 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
927 0 : return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
928 : }
929 :
930 0 : XFFrame* LwpDrawArc::CreateDrawObj(const OUString& rStyleName )
931 : {
932 0 : XFDrawPath* pArc = new XFDrawPath();
933 0 : pArc->MoveTo(XFPoint((double)m_aVector[0].x/TWIPS_PER_CM * m_pTransData->fScaleX,
934 0 : (double)m_aVector[0].y/TWIPS_PER_CM * m_pTransData->fScaleY));
935 0 : XFPoint aDest((double)m_aVector[3].x/TWIPS_PER_CM * m_pTransData->fScaleX,
936 0 : (double)m_aVector[3].y/TWIPS_PER_CM * m_pTransData->fScaleY);
937 0 : XFPoint aCtl1((double)m_aVector[1].x/TWIPS_PER_CM * m_pTransData->fScaleX,
938 0 : (double)m_aVector[1].y/TWIPS_PER_CM * m_pTransData->fScaleY);
939 0 : XFPoint aCtl2((double)m_aVector[2].x/TWIPS_PER_CM* m_pTransData->fScaleX,
940 0 : (double)m_aVector[2].y/TWIPS_PER_CM * m_pTransData->fScaleY);
941 0 : pArc->CurveTo(aDest, aCtl1, aCtl2);
942 :
943 0 : this->SetPosition(pArc);
944 :
945 0 : pArc->SetStyleName(rStyleName);
946 :
947 0 : return pArc;
948 : }
949 :
950 0 : XFFrame* LwpDrawArc::CreateStandardDrawObj(const OUString& rStyleName)
951 : {
952 0 : return this->CreateDrawObj(rStyleName);
953 : }
954 :
955 : /**
956 : * @descr Constructor of class LwpDrawTextBox
957 : * @param pStream The memory stream which contains the lwp-sdw draw objects
958 : */
959 0 : LwpDrawTextBox::LwpDrawTextBox(SvStream* pStream) : LwpDrawObj(pStream)
960 : {
961 0 : }
962 :
963 0 : LwpDrawTextBox::~LwpDrawTextBox()
964 : {
965 0 : if (m_aTextRec.pTextString)
966 : {
967 0 : delete [] m_aTextRec.pTextString;
968 0 : m_aTextRec.pTextString = NULL;
969 : }
970 0 : }
971 :
972 0 : void LwpDrawTextBox::SetFontStyle(XFFont* pFont, SdwTextBoxRecord* pRec)
973 : {
974 : // color
975 : XFColor aXFColor(pRec->aTextColor.nR, pRec->aTextColor.nG,
976 0 : pRec->aTextColor.nB);
977 0 : pFont->SetColor(aXFColor);
978 : //size
979 0 : pFont->SetFontSize(pRec->nTextSize/20);
980 : // bold
981 0 : pFont->SetBold((sal_Bool)((pRec->nTextAttrs & TA_BOLD) != 0));
982 : // italic
983 0 : pFont->SetItalic((sal_Bool)((pRec->nTextAttrs & TA_ITALIC) != 0));
984 : // strike-through
985 0 : if (pRec->nTextAttrs & TA_STRIKETHRU)
986 : {
987 0 : pFont->SetCrossout(enumXFCrossoutSignel);
988 : }
989 : else
990 : {
991 0 : pFont->SetCrossout(enumXFCrossoutNone);
992 : }
993 : // underline
994 0 : if (pRec->nTextAttrs & TA_UNDERLINE)
995 : {
996 0 : pFont->SetUnderline(enumXFUnderlineSingle);
997 : }
998 0 : else if (pRec->nTextAttrs & TA_WORDUNDERLINE)
999 : {
1000 0 : pFont->SetUnderline(enumXFUnderlineSingle, sal_True);
1001 : }
1002 0 : else if (pRec->nTextAttrs & TA_DOUBLEUNDER)
1003 : {
1004 0 : pFont->SetUnderline(enumXFUnderlineDouble);
1005 : }
1006 : else
1007 : {
1008 0 : pFont->SetUnderline(enumXFUnderlineNone);
1009 : }
1010 : // small-caps
1011 0 : if (pRec->nTextAttrs & TA_SMALLCAPS)
1012 : {
1013 0 : pFont->SetTransform(enumXFTransformSmallCaps);
1014 : }
1015 0 : }
1016 :
1017 : /**
1018 : * @descr reading function of class LwpDrawTextBox
1019 : */
1020 0 : void LwpDrawTextBox::Read()
1021 : {
1022 0 : *m_pStream >> m_aVector.x;
1023 0 : *m_pStream >> m_aVector.y;
1024 0 : *m_pStream >> m_aTextRec.nTextWidth;
1025 :
1026 0 : if (m_aTextRec.nTextWidth == 0)
1027 0 : m_aTextRec.nTextWidth = 1;
1028 :
1029 0 : *m_pStream >> m_aTextRec.nTextHeight;
1030 0 : m_pStream->Read(m_aTextRec.tmpTextFaceName, DRAW_FACESIZE);
1031 0 : m_pStream->SeekRel(1);// PitchAndFamily
1032 :
1033 0 : *m_pStream >> m_aTextRec.nTextSize;
1034 :
1035 0 : if (m_aTextRec.nTextSize < 0)
1036 0 : m_aTextRec.nTextSize = -m_aTextRec.nTextSize;
1037 :
1038 : //color
1039 0 : *m_pStream >> m_aTextRec.aTextColor.nR;
1040 0 : *m_pStream >> m_aTextRec.aTextColor.nG;
1041 0 : *m_pStream >> m_aTextRec.aTextColor.nB;
1042 0 : *m_pStream >> m_aTextRec.aTextColor.unused;
1043 :
1044 0 : *m_pStream >> m_aTextRec.nTextAttrs;
1045 0 : *m_pStream >> m_aTextRec.nTextCharacterSet;
1046 0 : *m_pStream >> m_aTextRec.nTextRotation;
1047 0 : *m_pStream >> m_aTextRec.nTextExtraSpacing;
1048 :
1049 : // some draw files in version 1.2 have an extra byte following '\0'.
1050 : // can't rely on that, so read in the whole string into memory.
1051 :
1052 : // the 71 is the fixed length before text content in textbox record
1053 0 : sal_Int16 TextLength = m_aObjHeader.nRecLen - 71;
1054 0 : m_aTextRec.pTextString = new sal_uInt8 [TextLength];
1055 :
1056 0 : m_pStream->Read(m_aTextRec.pTextString, TextLength);
1057 0 : }
1058 :
1059 0 : OUString LwpDrawTextBox::RegisterStyle()
1060 : {
1061 0 : XFParaStyle* pStyle = new XFParaStyle();
1062 :
1063 : // font style
1064 : // the pFont need to be deleted myself?
1065 0 : XFFont* pFont = new XFFont();
1066 :
1067 0 : rtl_TextEncoding aEncoding = RTL_TEXTENCODING_MS_1252;
1068 : OUString aFontName = OUString((sal_Char*)m_aTextRec.tmpTextFaceName,
1069 0 : strlen((char*)m_aTextRec.tmpTextFaceName), aEncoding);
1070 0 : pFont->SetFontName(aFontName);
1071 :
1072 0 : this->SetFontStyle(pFont, &m_aTextRec);
1073 :
1074 0 : pStyle->SetFont(pFont);
1075 :
1076 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1077 0 : return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
1078 : }
1079 :
1080 0 : XFFrame* LwpDrawTextBox::CreateDrawObj(const OUString& rStyleName )
1081 : {
1082 0 : XFFrame* pTextBox = new XFFrame(sal_True);
1083 :
1084 0 : sal_Int16 TextLength = m_aObjHeader.nRecLen - 71;
1085 : rtl_TextEncoding aEncoding;
1086 0 : if (!m_aTextRec.nTextCharacterSet)
1087 : {
1088 0 : aEncoding = osl_getThreadTextEncoding();
1089 : }
1090 : else
1091 : {
1092 : // temporary code, need to create Encoding from the value of nTextCharacterSet
1093 0 : aEncoding = LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
1094 : }
1095 :
1096 0 : XFParagraph* pXFPara = new XFParagraph();
1097 0 : pXFPara->Add(OUString((sal_Char*)m_aTextRec.pTextString, (TextLength-2), aEncoding));
1098 0 : pXFPara->SetStyleName(rStyleName);
1099 :
1100 0 : pTextBox->Add(pXFPara);
1101 0 : this->SetPosition(pTextBox);
1102 :
1103 0 : XFTextBoxStyle* pBoxStyle = new XFTextBoxStyle();
1104 :
1105 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1106 0 : OUString sName = pXFStyleManager->AddStyle(pBoxStyle)->GetStyleName();
1107 0 : pTextBox->SetStyleName(sName);
1108 :
1109 : //todo: add the interface for rotating textbox
1110 : // if (m_aTextRec.nTextRotation)
1111 : // {
1112 : // double fAngle = double(3600-m_aTextRec.nTextRotation)/10;
1113 : // pTextBox->SetRotate(fAngle);
1114 : // }
1115 :
1116 0 : return pTextBox;
1117 : }
1118 :
1119 0 : XFFrame* LwpDrawTextBox::CreateStandardDrawObj(const OUString& rStyleName)
1120 : {
1121 0 : return this->CreateDrawObj(rStyleName);
1122 : }
1123 :
1124 : /**
1125 : * @descr Constructor of class LwpDrawTextBox
1126 : * @param pStream The memory stream which contains the lwp-sdw draw objects
1127 : */
1128 0 : LwpDrawTextArt::LwpDrawTextArt(SvStream* pStream, DrawingOffsetAndScale* pTransData)
1129 0 : : LwpDrawObj(pStream, pTransData)
1130 : {
1131 0 : }
1132 :
1133 0 : LwpDrawTextArt::~LwpDrawTextArt()
1134 : {
1135 0 : if (m_aTextArtRec.aPath[0].pPts)
1136 : {
1137 0 : delete [] m_aTextArtRec.aPath[0].pPts;
1138 0 : m_aTextArtRec.aPath[0].pPts = NULL;
1139 : }
1140 0 : if (m_aTextArtRec.aPath[1].pPts)
1141 : {
1142 0 : delete [] m_aTextArtRec.aPath[1].pPts;
1143 0 : m_aTextArtRec.aPath[1].pPts = NULL;
1144 : }
1145 0 : if (m_aTextArtRec.pTextString)
1146 : {
1147 0 : delete [] m_aTextArtRec.pTextString;
1148 0 : m_aTextArtRec.pTextString = NULL;
1149 : }
1150 :
1151 0 : }
1152 :
1153 0 : void LwpDrawTextArt::CreateFWPath(XFDrawPath* pPath)
1154 : {
1155 : sal_Int16 nX, nY;
1156 0 : nX = (m_aTextArtRec.aPath[0].pPts[0].x + m_aTextArtRec.aPath[1].pPts[0].x) / 2;
1157 0 : nY = (m_aTextArtRec.aPath[0].pPts[0].y + m_aTextArtRec.aPath[1].pPts[0].y) / 2;
1158 0 : XFPoint aStart((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1159 0 : (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1160 0 : pPath->MoveTo(aStart);
1161 :
1162 0 : sal_uInt8 nPtIndex = 1;
1163 0 : for (sal_uInt8 nC = 1; nC <= m_aTextArtRec.aPath[0].n; nC++)
1164 : {
1165 0 : nX = (m_aTextArtRec.aPath[0].pPts[nPtIndex].x + m_aTextArtRec.aPath[1].pPts[nPtIndex].x) / 2;
1166 0 : nY = (m_aTextArtRec.aPath[0].pPts[nPtIndex].y + m_aTextArtRec.aPath[1].pPts[nPtIndex].y) / 2;
1167 0 : XFPoint aCtrl1((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1168 0 : (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1169 :
1170 0 : nPtIndex++;
1171 0 : nX = (m_aTextArtRec.aPath[0].pPts[nPtIndex].x + m_aTextArtRec.aPath[1].pPts[nPtIndex].x) / 2;
1172 0 : nY = (m_aTextArtRec.aPath[0].pPts[nPtIndex].y + m_aTextArtRec.aPath[1].pPts[nPtIndex].y) / 2;
1173 0 : XFPoint aCtrl2((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1174 0 : (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1175 :
1176 0 : nPtIndex++;
1177 0 : nX = (m_aTextArtRec.aPath[0].pPts[nPtIndex].x + m_aTextArtRec.aPath[1].pPts[nPtIndex].x) / 2;
1178 0 : nY = (m_aTextArtRec.aPath[0].pPts[nPtIndex].y + m_aTextArtRec.aPath[1].pPts[nPtIndex].y) / 2;
1179 0 : XFPoint aDest((double)nX/TWIPS_PER_CM * m_pTransData->fScaleX,
1180 0 : (double)nY/TWIPS_PER_CM * m_pTransData->fScaleY);
1181 :
1182 0 : pPath->CurveTo(aDest, aCtrl1, aCtrl2);
1183 : }
1184 0 : }
1185 :
1186 0 : void LwpDrawTextArt::Read()
1187 : {
1188 0 : for (sal_uInt8 nC = 0; nC < 4; nC++)
1189 : {
1190 0 : *m_pStream >> m_aVector[nC].x;
1191 0 : *m_pStream >> m_aVector[nC].y;
1192 : }
1193 :
1194 0 : this->ReadClosedObjStyle();
1195 0 : m_aTextArtRec.aTextColor = m_aClosedObjStyleRec.aForeColor;
1196 :
1197 0 : *m_pStream >> m_aTextArtRec.nIndex;
1198 0 : *m_pStream >> m_aTextArtRec.nRotation;
1199 :
1200 : sal_uInt16 nPointNumber;
1201 : sal_Int16 nX, nY;
1202 0 : *m_pStream >> nPointNumber;
1203 0 : m_aTextArtRec.aPath[0].n = nPointNumber;
1204 0 : m_aTextArtRec.aPath[0].pPts = new SdwPoint [nPointNumber*3+1];
1205 0 : sal_uInt16 nPt = 0;
1206 0 : for ( nPt = 0; nPt <= nPointNumber*3; nPt++)
1207 : {
1208 0 : *m_pStream >> nX;
1209 0 : *m_pStream >> nY;
1210 0 : m_aTextArtRec.aPath[0].pPts[nPt].x = nX;
1211 0 : m_aTextArtRec.aPath[0].pPts[nPt].y = nY;
1212 : }
1213 :
1214 0 : *m_pStream >> nPointNumber;
1215 0 : m_aTextArtRec.aPath[1].n = nPointNumber;
1216 0 : m_aTextArtRec.aPath[1].pPts = new SdwPoint [nPointNumber*3+1];
1217 0 : for (nPt = 0; nPt <= nPointNumber*3; nPt++)
1218 : {
1219 0 : *m_pStream >> nX;
1220 0 : *m_pStream >> nY;
1221 0 : m_aTextArtRec.aPath[1].pPts[nPt].x = nX;
1222 0 : m_aTextArtRec.aPath[1].pPts[nPt].y = nY;
1223 : }
1224 :
1225 0 : m_pStream->SeekRel(1);
1226 :
1227 0 : m_pStream->Read(m_aTextArtRec.tmpTextFaceName, DRAW_FACESIZE);
1228 0 : m_pStream->SeekRel(1);// PitchAndFamily
1229 :
1230 0 : *m_pStream >> m_aTextArtRec.nTextSize;
1231 :
1232 0 : if (m_aTextArtRec.nTextSize < 0)
1233 0 : m_aTextArtRec.nTextSize = -m_aTextArtRec.nTextSize;
1234 :
1235 0 : *m_pStream >> m_aTextArtRec.nTextAttrs;
1236 0 : *m_pStream >> m_aTextArtRec.nTextCharacterSet;
1237 0 : m_aTextArtRec.nTextRotation = 0;
1238 0 : *m_pStream >> m_aTextArtRec.nTextExtraSpacing;
1239 :
1240 0 : const sal_uInt16 nTextArtFixedLength = 105;
1241 : m_aTextArtRec.nTextLen = m_aObjHeader.nRecLen - nTextArtFixedLength
1242 : - (m_aTextArtRec.aPath[0].n*3 + 1)*4
1243 0 : - (m_aTextArtRec.aPath[1].n*3 + 1)*4;
1244 :
1245 0 : m_aTextArtRec.pTextString = new sal_uInt8 [m_aTextArtRec.nTextLen];
1246 0 : m_pStream->Read(m_aTextArtRec.pTextString, m_aTextArtRec.nTextLen);
1247 0 : m_aTextArtRec.pTextString[m_aTextArtRec.nTextLen-1] = 0;
1248 :
1249 0 : }
1250 :
1251 0 : OUString LwpDrawTextArt::RegisterStyle()
1252 : {
1253 0 : XFParaStyle* pStyle = new XFParaStyle();
1254 :
1255 : // font style
1256 : // the pFont need to be deleted myself?
1257 0 : XFFont* pFont = new XFFont();
1258 :
1259 0 : rtl_TextEncoding aEncoding = RTL_TEXTENCODING_MS_1252;
1260 : OUString aFontName = OUString((sal_Char*)m_aTextArtRec.tmpTextFaceName,
1261 0 : strlen((char*)m_aTextArtRec.tmpTextFaceName), aEncoding);
1262 0 : pFont->SetFontName(aFontName);
1263 :
1264 0 : LwpDrawTextBox::SetFontStyle(pFont, &m_aTextArtRec);
1265 :
1266 0 : pStyle->SetFont(pFont);
1267 :
1268 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1269 0 : return pXFStyleManager->AddStyle(pStyle)->GetStyleName();
1270 : }
1271 :
1272 0 : XFFrame* LwpDrawTextArt::CreateDrawObj(const OUString& rStyleName)
1273 : {
1274 0 : XFFrame* pRetObj = NULL;
1275 0 : XFDrawStyle* pStyle = new XFDrawStyle();
1276 :
1277 0 : pRetObj = new XFDrawPath();
1278 0 : XFDrawPath* pFWPath = static_cast<XFDrawPath*>(pRetObj);
1279 0 : this->CreateFWPath(pFWPath);
1280 0 : pStyle->SetFontWorkStyle(0, enumXFFWSlantY, enumXFFWAdjustAutosize);
1281 :
1282 0 : this->SetPosition(pRetObj);
1283 :
1284 : rtl_TextEncoding aEncoding;
1285 0 : if (!m_aTextArtRec.nTextCharacterSet)
1286 : {
1287 0 : aEncoding = osl_getThreadTextEncoding();
1288 : }
1289 : else
1290 : {
1291 : // temporary code, need to create Encoding from the value of nTextCharacterSet
1292 0 : aEncoding = LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
1293 : }
1294 :
1295 0 : XFParagraph* pXFPara = new XFParagraph();
1296 0 : pXFPara->Add(OUString((sal_Char*)m_aTextArtRec.pTextString, (m_aTextArtRec.nTextLen-1), aEncoding));
1297 0 : pXFPara->SetStyleName(rStyleName);
1298 0 : pRetObj->Add(pXFPara);
1299 :
1300 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1301 0 : pRetObj->SetStyleName(pXFStyleManager->AddStyle(pStyle)->GetStyleName());
1302 :
1303 0 : return pRetObj;
1304 : }
1305 :
1306 0 : XFFrame* LwpDrawTextArt::CreateStandardDrawObj(const OUString& rStyleName )
1307 : {
1308 0 : return this->CreateDrawObj(rStyleName);
1309 : }
1310 :
1311 :
1312 : /**
1313 : * @descr Constructor of class LwpDrawMetafile
1314 : * @param pStream The memory stream which contains the lwp-sdw draw objects
1315 : */
1316 0 : LwpDrawMetafile::LwpDrawMetafile(SvStream* pStream) : LwpDrawObj(pStream)
1317 : {
1318 0 : }
1319 :
1320 : /**
1321 : * @descr reading function of class LwpDrawMetafile
1322 : */
1323 0 : void LwpDrawMetafile::Read()
1324 : {
1325 0 : m_pStream->SeekRel(m_aObjHeader.nRecLen -16);
1326 0 : }
1327 :
1328 : /**
1329 : * @descr Constructor of class LwpDrawBitmap
1330 : * @param pStream The memory stream which contains the lwp-sdw draw objects
1331 : */
1332 0 : LwpDrawBitmap::LwpDrawBitmap(SvStream* pStream) : LwpDrawObj(pStream), m_pImageData(NULL)
1333 : {
1334 0 : }
1335 :
1336 0 : LwpDrawBitmap::~LwpDrawBitmap()
1337 : {
1338 0 : if (m_pImageData)
1339 : {
1340 0 : delete [] m_pImageData;
1341 0 : m_pImageData = NULL;
1342 : }
1343 0 : }
1344 :
1345 : /**
1346 : * @descr reading function of class LwpDrawBitmap
1347 : */
1348 0 : void LwpDrawBitmap::Read()
1349 : {
1350 0 : *m_pStream >> m_aBmpRec.nTranslation;
1351 0 : *m_pStream >> m_aBmpRec.nRotation;
1352 :
1353 : // 20 == length of draw-specific fields.
1354 : // 14 == length of bmp file header.
1355 0 : m_aBmpRec.nFileSize = m_aObjHeader.nRecLen - 20 + 14;
1356 0 : m_pImageData = new sal_uInt8 [m_aBmpRec.nFileSize];
1357 :
1358 : BmpInfoHeader2 aInfoHeader2;
1359 0 : *m_pStream >> aInfoHeader2.nHeaderLen;
1360 :
1361 : sal_uInt32 N;
1362 : sal_uInt32 rgbTableSize;
1363 :
1364 0 : if (aInfoHeader2.nHeaderLen == sizeof(BmpInfoHeader))
1365 : {
1366 0 : *m_pStream >> aInfoHeader2.nWidth;
1367 0 : *m_pStream >> aInfoHeader2.nHeight;
1368 0 : *m_pStream >> aInfoHeader2.nPlanes;
1369 0 : *m_pStream >> aInfoHeader2.nBitCount;
1370 :
1371 0 : N = aInfoHeader2.nPlanes * aInfoHeader2.nBitCount;
1372 0 : if (N == 24)
1373 : {
1374 0 : rgbTableSize = 0;
1375 : }
1376 : else
1377 : {
1378 0 : rgbTableSize = 3 * (1 << N);
1379 : }
1380 : }
1381 : else
1382 : {
1383 0 : *m_pStream >> aInfoHeader2.nWidth;
1384 0 : *m_pStream >> aInfoHeader2.nHeight;
1385 0 : *m_pStream >> aInfoHeader2.nPlanes;
1386 0 : *m_pStream >> aInfoHeader2.nBitCount;
1387 0 : N = aInfoHeader2.nPlanes * aInfoHeader2.nBitCount;
1388 0 : if (N == 24)
1389 : {
1390 0 : rgbTableSize = 0;
1391 : }
1392 : else
1393 : {
1394 0 : rgbTableSize = 4 * (1 << N);
1395 : }
1396 :
1397 : }
1398 :
1399 0 : sal_uInt32 nOffBits = 14 + aInfoHeader2.nHeaderLen + rgbTableSize;
1400 0 : m_pImageData[0] = 'B';
1401 0 : m_pImageData[1] = 'M';
1402 0 : m_pImageData[2] = (sal_uInt8)m_aBmpRec.nFileSize;
1403 0 : m_pImageData[3] = (sal_uInt8)(m_aBmpRec.nFileSize >> 8);
1404 0 : m_pImageData[4] = (sal_uInt8)(m_aBmpRec.nFileSize >> 16);
1405 0 : m_pImageData[5] = (sal_uInt8)(m_aBmpRec.nFileSize >> 24);
1406 0 : m_pImageData[6] = 0;
1407 0 : m_pImageData[7] = 0;
1408 0 : m_pImageData[8] = 0;
1409 0 : m_pImageData[9] = 0;
1410 0 : m_pImageData[10] = (sal_uInt8)nOffBits;
1411 0 : m_pImageData[11] = (sal_uInt8)(nOffBits >> 8);
1412 0 : m_pImageData[12] = (sal_uInt8)(nOffBits >> 16);
1413 0 : m_pImageData[13] = (sal_uInt8)(nOffBits >> 24);
1414 :
1415 : sal_uInt32 nDIBRemaining;
1416 0 : sal_uInt8* pPicData = m_pImageData;
1417 0 : if (aInfoHeader2.nHeaderLen== sizeof(BmpInfoHeader))
1418 : {
1419 0 : m_pImageData[14] = (sal_uInt8)aInfoHeader2.nHeaderLen;
1420 0 : m_pImageData[15] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 8);
1421 0 : m_pImageData[16] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 16);
1422 0 : m_pImageData[17] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 24);
1423 0 : m_pImageData[18] = (sal_uInt8)aInfoHeader2.nWidth;
1424 0 : m_pImageData[19] = (sal_uInt8)(aInfoHeader2.nWidth >> 8);
1425 0 : m_pImageData[20] = (sal_uInt8)aInfoHeader2.nHeight;
1426 0 : m_pImageData[21] = (sal_uInt8)(aInfoHeader2.nHeight >> 8);
1427 0 : m_pImageData[22] = (sal_uInt8)aInfoHeader2.nPlanes;
1428 0 : m_pImageData[23] = (sal_uInt8)(aInfoHeader2.nPlanes >> 8);
1429 0 : m_pImageData[24] = (sal_uInt8)aInfoHeader2.nBitCount;
1430 0 : m_pImageData[25] = (sal_uInt8)(aInfoHeader2.nBitCount >> 8);
1431 :
1432 0 : nDIBRemaining = m_aBmpRec.nFileSize - 26;
1433 0 : pPicData += 26*sizeof(sal_uInt8);
1434 : }
1435 : else
1436 : {
1437 0 : m_pImageData[14] = (sal_uInt8)aInfoHeader2.nHeaderLen;
1438 0 : m_pImageData[15] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 8);
1439 0 : m_pImageData[16] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 16);
1440 0 : m_pImageData[17] = (sal_uInt8)(aInfoHeader2.nHeaderLen >> 24);
1441 0 : m_pImageData[18] = (sal_uInt8)aInfoHeader2.nWidth;
1442 0 : m_pImageData[19] = (sal_uInt8)(aInfoHeader2.nWidth >> 8);
1443 0 : m_pImageData[20] = (sal_uInt8)(aInfoHeader2.nWidth >> 16);
1444 0 : m_pImageData[21] = (sal_uInt8)(aInfoHeader2.nWidth >> 24);
1445 0 : m_pImageData[22] = (sal_uInt8)aInfoHeader2.nHeight;
1446 0 : m_pImageData[23] = (sal_uInt8)(aInfoHeader2.nHeight >> 8);
1447 0 : m_pImageData[24] = (sal_uInt8)(aInfoHeader2.nHeight >> 16);
1448 0 : m_pImageData[25] = (sal_uInt8)(aInfoHeader2.nHeight >> 24);
1449 0 : m_pImageData[26] = (sal_uInt8)aInfoHeader2.nPlanes;
1450 0 : m_pImageData[27] = (sal_uInt8)(aInfoHeader2.nPlanes >> 8);
1451 0 : m_pImageData[28] = (sal_uInt8)aInfoHeader2.nBitCount;
1452 0 : m_pImageData[29] = (sal_uInt8)(aInfoHeader2.nBitCount >> 8);
1453 :
1454 0 : nDIBRemaining = m_aBmpRec.nFileSize - 30;
1455 0 : pPicData += 30*sizeof(sal_uInt8);
1456 : }
1457 :
1458 0 : m_pStream->Read(pPicData, nDIBRemaining);
1459 0 : }
1460 :
1461 0 : OUString LwpDrawBitmap::RegisterStyle()
1462 : {
1463 0 : XFImageStyle* pBmpStyle = new XFImageStyle();
1464 0 : pBmpStyle->SetYPosType(enumXFFrameYPosFromTop, enumXFFrameYRelFrame);
1465 0 : pBmpStyle->SetXPosType(enumXFFrameXPosFromLeft, enumXFFrameXRelFrame);
1466 :
1467 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1468 0 : return pXFStyleManager->AddStyle(pBmpStyle)->GetStyleName();
1469 : }
1470 :
1471 0 : XFFrame* LwpDrawBitmap::CreateDrawObj(const OUString& rStyleName)
1472 : {
1473 0 : XFImage* pImage = new XFImage();
1474 0 : pImage->SetImageData(m_pImageData, m_aBmpRec.nFileSize);
1475 0 : this->SetPosition(pImage);
1476 :
1477 0 : pImage->SetStyleName(rStyleName);
1478 :
1479 0 : return pImage;
1480 : }
1481 :
1482 0 : XFFrame* LwpDrawBitmap::CreateStandardDrawObj(const OUString& rStyleName)
1483 : {
1484 0 : return this->CreateDrawObj(rStyleName);
1485 : }
1486 :
1487 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|