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 : * Styles for paragraph.
59 : * Styles for paragraph may include many style,include font,indent,margin,
60 : * shadow,line height,and so on.
61 : ************************************************************************/
62 : #include "xfparastyle.hxx"
63 : #include "xffont.hxx"
64 : #include "xfborders.hxx"
65 : #include "xftabstyle.hxx"
66 : #include "xfbgimage.hxx"
67 :
68 520 : XFParaStyle::XFParaStyle()
69 : {
70 : //init member variables:
71 520 : m_nFlag = 0;
72 520 : m_eAlignType = enumXFAlignNone;
73 520 : m_eLastLineAlign = enumXFAlignNone;
74 520 : m_bJustSingleWord = sal_False;
75 520 : m_bKeepWithNext = sal_False;
76 520 : m_nPageNumber = 0;
77 520 : m_fTextIndent = 0;
78 :
79 520 : m_pFont = NULL;
80 520 : m_pBorders = NULL;
81 520 : m_pBGImage = NULL;
82 :
83 520 : m_nLineNumberRestart = 0;
84 520 : m_bNumberLines = sal_True;
85 520 : m_bNumberRight = sal_False;
86 520 : }
87 :
88 0 : XFParaStyle::XFParaStyle(const XFParaStyle& other) : XFStyle(other)
89 : {
90 0 : m_strParentStyleName = other.m_strParentStyleName;
91 0 : m_nFlag = other.m_nFlag;
92 0 : m_eAlignType = other.m_eAlignType;
93 0 : m_fTextIndent = other.m_fTextIndent;
94 0 : m_bNumberLines = other.m_bNumberLines;
95 0 : m_nLineNumberRestart = other.m_nLineNumberRestart;
96 0 : m_bNumberRight = other.m_bNumberRight;
97 :
98 0 : if( other.m_pFont )
99 0 : m_pFont = other.m_pFont;
100 : else
101 0 : m_pFont = NULL;
102 :
103 0 : if( other.m_pBorders )
104 0 : m_pBorders = new XFBorders(*other.m_pBorders);
105 : else
106 0 : m_pBorders = NULL;
107 0 : m_aBackColor = other.m_aBackColor;
108 0 : if( other.m_pBGImage )
109 0 : m_pBGImage = new XFBGImage(*other.m_pBGImage);
110 : else
111 0 : m_pBGImage = NULL;
112 :
113 0 : m_aShadow = other.m_aShadow;
114 0 : m_aMargin = other.m_aMargin;
115 0 : m_aDropcap = other.m_aDropcap;
116 0 : m_aLineHeight = other.m_aLineHeight;
117 0 : m_aPadding = other.m_aPadding;
118 0 : m_aBreaks = other.m_aBreaks;
119 :
120 0 : for (size_t i=0; i<other.m_aTabs.GetCount(); ++i)
121 : {
122 0 : const IXFStyle *pStyle = other.m_aTabs.Item(i);
123 0 : if( pStyle )
124 : {
125 0 : const XFTabStyle *pTabStyle = dynamic_cast<const XFTabStyle*>(pStyle);
126 0 : if( pTabStyle )
127 : {
128 0 : XFTabStyle *pCopyStyle = new XFTabStyle(*pTabStyle);
129 0 : m_aTabs.AddStyle(pCopyStyle);
130 : }
131 : }
132 : }
133 0 : }
134 :
135 384 : XFParaStyle& XFParaStyle::operator=(const XFParaStyle& other)
136 : {
137 : // Check for self-assignment
138 384 : if (this != &other)
139 : {
140 : // first , clean member
141 384 : delete(m_pBGImage);
142 384 : m_aTabs.Reset();
143 :
144 384 : m_strParentStyleName = other.m_strParentStyleName;
145 384 : m_nFlag = other.m_nFlag;
146 384 : m_eAlignType = other.m_eAlignType;
147 384 : m_fTextIndent = other.m_fTextIndent;
148 384 : m_bNumberLines = other.m_bNumberLines;
149 384 : m_nLineNumberRestart = other.m_nLineNumberRestart;
150 384 : m_bNumberRight = other.m_bNumberRight;
151 :
152 384 : if( other.m_pFont )
153 384 : m_pFont = other.m_pFont;
154 : else
155 0 : m_pFont = NULL;
156 :
157 384 : if( other.m_pBorders )
158 0 : m_pBorders = new XFBorders(*other.m_pBorders);
159 : else
160 384 : m_pBorders = NULL;
161 384 : m_aBackColor = other.m_aBackColor;
162 384 : if( other.m_pBGImage )
163 0 : m_pBGImage = new XFBGImage(*other.m_pBGImage);
164 : else
165 384 : m_pBGImage = NULL;
166 :
167 384 : m_aShadow = other.m_aShadow;
168 384 : m_aMargin = other.m_aMargin;
169 384 : m_aDropcap = other.m_aDropcap;
170 384 : m_aLineHeight = other.m_aLineHeight;
171 384 : m_aPadding = other.m_aPadding;
172 384 : m_aBreaks = other.m_aBreaks;
173 :
174 384 : for (size_t i=0; i<other.m_aTabs.GetCount(); ++i)
175 : {
176 0 : const IXFStyle *pStyle = other.m_aTabs.Item(i);
177 0 : if( pStyle )
178 : {
179 0 : const XFTabStyle *pTabStyle = dynamic_cast<const XFTabStyle*>(pStyle);
180 0 : if( pTabStyle )
181 : {
182 0 : XFTabStyle *pCopyStyle = new XFTabStyle(*pTabStyle);
183 0 : m_aTabs.AddStyle(pCopyStyle);
184 : }
185 : }
186 : }
187 : }
188 384 : return *this;
189 : }
190 :
191 1560 : XFParaStyle::~XFParaStyle()
192 : {
193 520 : if( m_pBorders )
194 4 : delete m_pBorders;
195 520 : if( m_pBGImage )
196 0 : delete m_pBGImage;
197 1040 : }
198 :
199 3722 : enumXFStyle XFParaStyle::GetStyleFamily()
200 : {
201 3722 : return enumXFStylePara;
202 : }
203 :
204 592 : void XFParaStyle::SetFont(XFFont *pFont)
205 : {
206 592 : m_pFont = pFont;
207 592 : }
208 :
209 350 : void XFParaStyle::SetIndent(double indent )
210 : {
211 350 : m_fTextIndent = indent;
212 350 : }
213 :
214 636 : void XFParaStyle::SetMargins(double left, double right, double top, double bottom)
215 : {
216 636 : if( left != -1 )
217 358 : m_aMargin.SetLeft(left);
218 636 : if( right != -1 )
219 358 : m_aMargin.SetRight(right);
220 636 : if( top != -1 )
221 208 : m_aMargin.SetTop(top);
222 636 : if( bottom != -1 )
223 208 : m_aMargin.SetBottom( bottom );
224 636 : }
225 :
226 2 : void XFParaStyle::SetShadow(enumXFShadowPos pos, double offset, XFColor& color)
227 : {
228 2 : m_aShadow.SetPosition(pos);
229 2 : m_aShadow.SetOffset(offset);
230 2 : m_aShadow.SetColor(color);
231 2 : }
232 :
233 4 : void XFParaStyle::SetBackColor(XFColor& color)
234 : {
235 4 : m_aBackColor = color;
236 4 : m_nFlag |= XFPARA_FLAG_BACKCOLOR;
237 4 : }
238 :
239 0 : void XFParaStyle::SetBackImage(XFBGImage *image)
240 : {
241 0 : if( m_pBGImage )
242 0 : delete m_pBGImage;
243 0 : m_pBGImage = image;
244 0 : }
245 :
246 4 : void XFParaStyle::SetBorders(XFBorders *pBorders)
247 : {
248 4 : if( m_pBorders )
249 0 : delete m_pBorders;
250 4 : m_pBorders = pBorders;
251 4 : }
252 :
253 0 : void XFParaStyle::SetDropCap(sal_Int16 nLength,
254 : sal_Int16 nLines,
255 : double fDistance
256 : )
257 : {
258 : assert(nLength>=1);
259 : assert(nLines>=2);
260 : assert(fDistance>=0);
261 :
262 0 : m_aDropcap.SetCharCount(nLength);
263 0 : m_aDropcap.SetLines(nLines);
264 0 : m_aDropcap.SetDistance(fDistance);
265 0 : }
266 :
267 234 : void XFParaStyle::SetLineHeight(enumLHType type, double value)
268 : {
269 234 : if( type == enumLHNone )
270 : {
271 234 : return;
272 : }
273 234 : switch(type)
274 : {
275 : case enumLHHeight:
276 0 : m_aLineHeight.SetHeight(value) ;
277 0 : break;
278 : case enumLHLeast:
279 0 : m_aLineHeight.SetLeastHeight(value);
280 0 : break;
281 : case enumLHPercent: //perhaps i should redesign the interface here,ohm..
282 234 : m_aLineHeight.SetPercent((sal_Int32)value);
283 234 : break;
284 : case enumLHSpace:
285 0 : m_aLineHeight.SetSpace(value*0.5666); //don't known why,just suspect.
286 0 : break;
287 : default:
288 0 : break;
289 : }
290 : }
291 :
292 20 : void XFParaStyle::AddTabStyle(enumXFTab type, double len, sal_Unicode leader, sal_Unicode delimiter)
293 : {
294 20 : XFTabStyle *tab = new XFTabStyle();
295 20 : tab->SetTabType(type);
296 20 : tab->SetLength(len);
297 20 : tab->SetLeaderChar(leader);
298 20 : tab->SetDelimiter(delimiter);
299 20 : m_aTabs.AddStyle(tab);
300 20 : }
301 :
302 : /**
303 : *Affirm whether two XFParaStyle objects are equal.
304 : */
305 1642 : sal_Bool XFParaStyle::Equal(IXFStyle *pStyle)
306 : {
307 1642 : if( this == pStyle )
308 0 : return sal_True;
309 1642 : if( !pStyle || pStyle->GetStyleFamily() != enumXFStylePara )
310 0 : return sal_False;
311 :
312 1642 : XFParaStyle *pOther = (XFParaStyle*)(pStyle);
313 1642 : if( !pOther )
314 0 : return sal_False;
315 :
316 1642 : if( m_nFlag != pOther->m_nFlag )
317 44 : return sal_False;
318 1598 : if( m_strParentStyleName != pOther->m_strParentStyleName )
319 406 : return sal_False;
320 1192 : if( m_strMasterPage != pOther->m_strMasterPage )
321 262 : return sal_False;
322 930 : if( m_fTextIndent != pOther->m_fTextIndent )
323 0 : return sal_False;
324 930 : if( m_bJustSingleWord != pOther->m_bJustSingleWord )
325 0 : return sal_False;
326 930 : if( m_bKeepWithNext != pOther->m_bKeepWithNext )
327 0 : return sal_False;
328 : //line number:
329 930 : if( m_bNumberLines != pOther->m_bNumberLines )
330 0 : return sal_False;
331 930 : if( m_nLineNumberRestart != pOther->m_nLineNumberRestart )
332 0 : return sal_False;
333 : //align:
334 930 : if( m_eAlignType != pOther->m_eAlignType )
335 56 : return sal_False;
336 : //last line align:
337 874 : if( m_eLastLineAlign != pOther->m_eLastLineAlign )
338 0 : return sal_False;
339 :
340 : //shadow:
341 874 : if( m_aShadow != pOther->m_aShadow )
342 2 : return sal_False;
343 : //margin:
344 872 : if( m_aMargin != pOther->m_aMargin )
345 536 : return sal_False;
346 :
347 336 : if( m_aPadding != pOther->m_aPadding )
348 0 : return sal_False;
349 :
350 : //dropcap:
351 336 : if( m_aDropcap != pOther->m_aDropcap )
352 0 : return sal_False;
353 : //line height:
354 336 : if( m_aLineHeight != pOther->m_aLineHeight )
355 0 : return sal_False;
356 : //breaks:
357 336 : if( m_aBreaks != pOther->m_aBreaks )
358 18 : return sal_False;
359 318 : if( m_nPageNumber != pOther->m_nPageNumber )
360 0 : return sal_False;
361 318 : if( m_aTabs != pOther->m_aTabs )
362 14 : return sal_False;
363 :
364 : //font:
365 304 : if( m_pFont )
366 : {
367 304 : if( !pOther->m_pFont )
368 0 : return sal_False;
369 304 : if(*m_pFont != *pOther->m_pFont )
370 0 : return sal_False;
371 : }
372 0 : else if( pOther->m_pFont )
373 0 : return sal_False;
374 :
375 : //border:
376 304 : if( m_pBorders )
377 : {
378 0 : if( !pOther->m_pBorders )
379 0 : return sal_False;
380 0 : if( *m_pBorders != *pOther->m_pBorders )
381 0 : return sal_False;
382 : }
383 304 : else if( pOther->m_pBorders )
384 0 : return sal_False;
385 :
386 304 : if( m_pBGImage )
387 : {
388 0 : if( !pOther->m_pBGImage )
389 0 : return sal_False;
390 0 : if( *m_pBGImage != *pOther->m_pBGImage )
391 0 : return sal_False;
392 : }
393 304 : else if( pOther->m_pBGImage )
394 0 : return sal_False;//add end
395 :
396 : //number right
397 304 : if ( m_bNumberRight != pOther->m_bNumberRight)
398 0 : return sal_False;
399 :
400 304 : return sal_True;
401 : }
402 :
403 156 : void XFParaStyle::ToXml(IXFStream *pStrm)
404 : {
405 156 : IXFAttrList *pAttrList = pStrm->GetAttrList();
406 156 : rtl::OUString style = GetStyleName();
407 :
408 156 : pAttrList->Clear();
409 156 : if( !style.isEmpty() )
410 156 : pAttrList->AddAttribute(A2OUSTR("style:name"),GetStyleName());
411 156 : pAttrList->AddAttribute(A2OUSTR("style:family"), A2OUSTR("paragraph"));
412 156 : if( !GetParentStyleName().isEmpty() )
413 54 : pAttrList->AddAttribute(A2OUSTR("style:parent-style-name"),GetParentStyleName());
414 :
415 156 : if( !m_strMasterPage.isEmpty() )
416 6 : pAttrList->AddAttribute(A2OUSTR("style:master-page-name"),m_strMasterPage);
417 156 : pStrm->StartElement(A2OUSTR("style:style"));
418 :
419 : //Paragraph properties:
420 156 : pAttrList->Clear();
421 :
422 : //text indent:
423 156 : if( m_fTextIndent )
424 : {
425 6 : pAttrList->AddAttribute(A2OUSTR("fo:text-indent"), DoubleToOUString(m_fTextIndent) + A2OUSTR("cm") );
426 : }
427 : //padding:
428 156 : m_aPadding.ToXml(pStrm);
429 : //margin:
430 156 : m_aMargin.ToXml(pStrm);
431 :
432 : //text align:
433 156 : if( m_eAlignType != enumXFAlignNone )
434 : {
435 78 : pAttrList->AddAttribute(A2OUSTR("fo:text-align"), GetAlignName(m_eAlignType) );
436 : }
437 : //last line align:
438 156 : if( m_eLastLineAlign != enumXFAlignNone )
439 : {
440 0 : pAttrList->AddAttribute(A2OUSTR("fo:fo:text-align-last"), GetAlignName(m_eLastLineAlign) );
441 0 : if( m_bJustSingleWord )
442 0 : pAttrList->AddAttribute(A2OUSTR("style:justify-single-word"), A2OUSTR("true") );
443 : }
444 : //line number:
445 156 : if( m_bNumberLines )
446 : {
447 156 : pAttrList->AddAttribute( A2OUSTR("text:number-lines"), A2OUSTR("true") );
448 156 : pAttrList->AddAttribute( A2OUSTR("text:line-number"), Int32ToOUString(m_nLineNumberRestart) );
449 : }
450 : else
451 : {
452 0 : pAttrList->AddAttribute( A2OUSTR("text:number-lines"), A2OUSTR("false") );
453 : assert(m_nLineNumberRestart>0);
454 0 : pAttrList->AddAttribute( A2OUSTR("text:line-number"), A2OUSTR("0") );
455 : }
456 :
457 : //shadow:
458 156 : m_aShadow.ToXml(pStrm);
459 : //borders:
460 156 : if( m_pBorders )
461 4 : m_pBorders->ToXml(pStrm);
462 : //line height:
463 156 : m_aLineHeight.ToXml(pStrm);
464 :
465 : //background color:
466 156 : if( m_nFlag&XFPARA_FLAG_BACKCOLOR && m_aBackColor.IsValid() )
467 : {
468 4 : pAttrList->AddAttribute(A2OUSTR("fo:background-color"), m_aBackColor.ToString() );
469 : }
470 : //Font properties:
471 156 : if( m_pFont )
472 156 : m_pFont->ToXml(pStrm);
473 :
474 : //page number:
475 156 : if( m_nPageNumber )
476 0 : pAttrList->AddAttribute(A2OUSTR("fo:page-number"), Int32ToOUString(m_nPageNumber) );
477 : //page breaks:
478 156 : m_aBreaks.ToXml(pStrm);
479 :
480 156 : if( m_bKeepWithNext )
481 0 : pAttrList->AddAttribute(A2OUSTR("fo:fo:keep-with-next"), A2OUSTR("true") );
482 :
483 156 : pStrm->StartElement(A2OUSTR("style:properties"));
484 :
485 : //dropcap:
486 156 : m_aDropcap.ToXml(pStrm);
487 :
488 : //tabs:
489 156 : if( m_aTabs.GetCount() > 0 )
490 : {
491 8 : pAttrList->Clear();
492 8 : pStrm->StartElement( A2OUSTR("style:tab-stops") );
493 8 : m_aTabs.ToXml(pStrm);
494 8 : pStrm->EndElement( A2OUSTR("style:tab-stops") );
495 : }
496 :
497 : //background color:
498 156 : if( m_pBGImage )
499 0 : m_pBGImage->ToXml(pStrm);
500 :
501 156 : pStrm->EndElement(A2OUSTR("style:properties"));
502 :
503 156 : pStrm->EndElement(A2OUSTR("style:style"));
504 156 : }
505 :
506 8 : XFDefaultParaStyle::XFDefaultParaStyle()
507 : {
508 8 : m_fTabDistance = 1.28;
509 8 : }
510 :
511 40 : enumXFStyle XFDefaultParaStyle::GetStyleFamily()
512 : {
513 40 : return enumXFStyleDefaultPara;
514 : }
515 :
516 :
517 6 : void XFDefaultParaStyle::ToXml(IXFStream * pStrm)
518 : {
519 6 : IXFAttrList *pAttrList = pStrm->GetAttrList();
520 6 : pAttrList->Clear();
521 6 : pAttrList->AddAttribute(A2OUSTR("style:family"), A2OUSTR("paragraph"));
522 6 : pStrm->StartElement(A2OUSTR("style:default-style"));
523 :
524 : //Paragraph properties:
525 6 : pAttrList->Clear();
526 :
527 6 : pAttrList->AddAttribute(A2OUSTR("style:tab-stop-distance"), DoubleToOUString(m_fTabDistance) + A2OUSTR("cm") );
528 :
529 6 : pStrm->StartElement(A2OUSTR("style:properties"));
530 6 : pStrm->EndElement(A2OUSTR("style:properties"));
531 6 : pStrm->EndElement(A2OUSTR("style:default-style"));
532 6 : }
533 :
534 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|