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 260 : XFParaStyle::XFParaStyle()
69 : : m_eAlignType(enumXFAlignNone)
70 : , m_eLastLineAlign(enumXFAlignNone)
71 : , m_bJustSingleWord(sal_False)
72 : , m_bKeepWithNext(sal_False)
73 : , m_fTextIndent(0)
74 : , m_pFont(NULL)
75 : , m_pBorders(NULL)
76 : , m_pBGImage(NULL)
77 : , m_nPageNumber(0)
78 : , m_bNumberLines(sal_True)
79 : , m_nLineNumberRestart(0)
80 : , m_nFlag(0)
81 260 : , m_bNumberRight(sal_False)
82 : {
83 260 : }
84 :
85 :
86 0 : XFParaStyle::XFParaStyle(const XFParaStyle& other)
87 : : XFStyle(other)
88 : , m_eAlignType(other.m_eAlignType)
89 : , m_eLastLineAlign(other.m_eLastLineAlign)
90 : , m_bJustSingleWord(other.m_bJustSingleWord)
91 : , m_bKeepWithNext(other.m_bKeepWithNext)
92 : , m_fTextIndent(other.m_fTextIndent)
93 : , m_aBackColor(other.m_aBackColor)
94 : , m_aMargin(other.m_aMargin)
95 : , m_aPadding(other.m_aPadding)
96 : , m_pFont(other.m_pFont)
97 : , m_aShadow(other.m_aShadow)
98 : , m_aDropcap(other.m_aDropcap)
99 : , m_aLineHeight(other.m_aLineHeight)
100 : , m_aBreaks(other.m_aBreaks)
101 : , m_nPageNumber(other.m_nPageNumber)
102 : , m_bNumberLines(other.m_bNumberLines)
103 : , m_nLineNumberRestart(other.m_nLineNumberRestart)
104 : , m_nFlag(other.m_nFlag)
105 0 : , m_bNumberRight(other.m_bNumberRight)
106 : {
107 0 : m_strParentStyleName = other.m_strParentStyleName;
108 :
109 0 : if( other.m_pBorders )
110 0 : m_pBorders = new XFBorders(*other.m_pBorders);
111 : else
112 0 : m_pBorders = NULL;
113 :
114 0 : if( other.m_pBGImage )
115 0 : m_pBGImage = new XFBGImage(*other.m_pBGImage);
116 : else
117 0 : m_pBGImage = NULL;
118 :
119 0 : for (size_t i = 0; i < other.m_aTabs.GetCount(); ++i)
120 : {
121 0 : const IXFStyle* pStyle = other.m_aTabs.Item(i);
122 0 : if( pStyle )
123 : {
124 0 : const XFTabStyle* pTabStyle = dynamic_cast<const XFTabStyle*>(pStyle);
125 0 : if( pTabStyle )
126 : {
127 0 : XFTabStyle *pCopyStyle = new XFTabStyle(*pTabStyle);
128 0 : m_aTabs.AddStyle(pCopyStyle);
129 : }
130 : }
131 : }
132 0 : }
133 :
134 192 : XFParaStyle& XFParaStyle::operator=(const XFParaStyle& other)
135 : {
136 : // Check for self-assignment
137 192 : if (this != &other)
138 : {
139 : // first , clean member
140 192 : delete(m_pBGImage);
141 192 : m_aTabs.Reset();
142 :
143 192 : m_strParentStyleName = other.m_strParentStyleName;
144 192 : m_nFlag = other.m_nFlag;
145 192 : m_eAlignType = other.m_eAlignType;
146 192 : m_eLastLineAlign = other.m_eLastLineAlign;
147 192 : m_fTextIndent = other.m_fTextIndent;
148 192 : m_bNumberLines = other.m_bNumberLines;
149 192 : m_nLineNumberRestart = other.m_nLineNumberRestart;
150 192 : m_bNumberRight = other.m_bNumberRight;
151 :
152 192 : if( other.m_pFont )
153 192 : m_pFont = other.m_pFont;
154 : else
155 0 : m_pFont = NULL;
156 :
157 192 : if( other.m_pBorders )
158 0 : m_pBorders = new XFBorders(*other.m_pBorders);
159 : else
160 192 : m_pBorders = NULL;
161 192 : m_aBackColor = other.m_aBackColor;
162 192 : if( other.m_pBGImage )
163 0 : m_pBGImage = new XFBGImage(*other.m_pBGImage);
164 : else
165 192 : m_pBGImage = NULL;
166 :
167 192 : m_aShadow = other.m_aShadow;
168 192 : m_aMargin = other.m_aMargin;
169 192 : m_aDropcap = other.m_aDropcap;
170 192 : m_aLineHeight = other.m_aLineHeight;
171 192 : m_aPadding = other.m_aPadding;
172 192 : m_aBreaks = other.m_aBreaks;
173 :
174 192 : 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 192 : return *this;
189 : }
190 :
191 780 : XFParaStyle::~XFParaStyle()
192 : {
193 260 : if( m_pBorders )
194 2 : delete m_pBorders;
195 260 : if( m_pBGImage )
196 0 : delete m_pBGImage;
197 520 : }
198 :
199 1861 : enumXFStyle XFParaStyle::GetStyleFamily()
200 : {
201 1861 : return enumXFStylePara;
202 : }
203 :
204 296 : void XFParaStyle::SetFont(XFFont *pFont)
205 : {
206 296 : m_pFont = pFont;
207 296 : }
208 :
209 175 : void XFParaStyle::SetIndent(double indent )
210 : {
211 175 : m_fTextIndent = indent;
212 175 : }
213 :
214 318 : void XFParaStyle::SetMargins(double left, double right, double top, double bottom)
215 : {
216 318 : if( left != -1 )
217 179 : m_aMargin.SetLeft(left);
218 318 : if( right != -1 )
219 179 : m_aMargin.SetRight(right);
220 318 : if( top != -1 )
221 104 : m_aMargin.SetTop(top);
222 318 : if( bottom != -1 )
223 104 : m_aMargin.SetBottom( bottom );
224 318 : }
225 :
226 1 : void XFParaStyle::SetShadow(enumXFShadowPos pos, double offset, XFColor& color)
227 : {
228 1 : m_aShadow.SetPosition(pos);
229 1 : m_aShadow.SetOffset(offset);
230 1 : m_aShadow.SetColor(color);
231 1 : }
232 :
233 2 : void XFParaStyle::SetBackColor(XFColor& color)
234 : {
235 2 : m_aBackColor = color;
236 2 : m_nFlag |= XFPARA_FLAG_BACKCOLOR;
237 2 : }
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 2 : void XFParaStyle::SetBorders(XFBorders *pBorders)
247 : {
248 2 : if( m_pBorders )
249 0 : delete m_pBorders;
250 2 : m_pBorders = pBorders;
251 2 : }
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 117 : void XFParaStyle::SetLineHeight(enumLHType type, double value)
268 : {
269 117 : if( type == enumLHNone )
270 : {
271 117 : return;
272 : }
273 117 : 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 117 : m_aLineHeight.SetPercent((sal_Int32)value);
283 117 : 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 10 : void XFParaStyle::AddTabStyle(enumXFTab type, double len, sal_Unicode leader, sal_Unicode delimiter)
293 : {
294 10 : XFTabStyle *tab = new XFTabStyle();
295 10 : tab->SetTabType(type);
296 10 : tab->SetLength(len);
297 10 : tab->SetLeaderChar(leader);
298 10 : tab->SetDelimiter(delimiter);
299 10 : m_aTabs.AddStyle(tab);
300 10 : }
301 :
302 : /**
303 : *Affirm whether two XFParaStyle objects are equal.
304 : */
305 821 : sal_Bool XFParaStyle::Equal(IXFStyle *pStyle)
306 : {
307 821 : if( this == pStyle )
308 0 : return sal_True;
309 821 : if( !pStyle || pStyle->GetStyleFamily() != enumXFStylePara )
310 0 : return sal_False;
311 :
312 821 : XFParaStyle *pOther = (XFParaStyle*)(pStyle);
313 821 : if( !pOther )
314 0 : return sal_False;
315 :
316 821 : if( m_nFlag != pOther->m_nFlag )
317 22 : return sal_False;
318 799 : if( m_strParentStyleName != pOther->m_strParentStyleName )
319 203 : return sal_False;
320 596 : if( m_strMasterPage != pOther->m_strMasterPage )
321 131 : return sal_False;
322 465 : if( m_fTextIndent != pOther->m_fTextIndent )
323 0 : return sal_False;
324 465 : if( m_bJustSingleWord != pOther->m_bJustSingleWord )
325 0 : return sal_False;
326 465 : if( m_bKeepWithNext != pOther->m_bKeepWithNext )
327 0 : return sal_False;
328 : //line number:
329 465 : if( m_bNumberLines != pOther->m_bNumberLines )
330 0 : return sal_False;
331 465 : if( m_nLineNumberRestart != pOther->m_nLineNumberRestart )
332 0 : return sal_False;
333 : //align:
334 465 : if( m_eAlignType != pOther->m_eAlignType )
335 28 : return sal_False;
336 : //last line align:
337 437 : if( m_eLastLineAlign != pOther->m_eLastLineAlign )
338 0 : return sal_False;
339 :
340 : //shadow:
341 437 : if( m_aShadow != pOther->m_aShadow )
342 1 : return sal_False;
343 : //margin:
344 436 : if( m_aMargin != pOther->m_aMargin )
345 268 : return sal_False;
346 :
347 168 : if( m_aPadding != pOther->m_aPadding )
348 0 : return sal_False;
349 :
350 : //dropcap:
351 168 : if( m_aDropcap != pOther->m_aDropcap )
352 0 : return sal_False;
353 : //line height:
354 168 : if( m_aLineHeight != pOther->m_aLineHeight )
355 0 : return sal_False;
356 : //breaks:
357 168 : if( m_aBreaks != pOther->m_aBreaks )
358 9 : return sal_False;
359 159 : if( m_nPageNumber != pOther->m_nPageNumber )
360 0 : return sal_False;
361 159 : if( m_aTabs != pOther->m_aTabs )
362 7 : return sal_False;
363 :
364 : //font:
365 152 : if( m_pFont )
366 : {
367 152 : if( !pOther->m_pFont )
368 0 : return sal_False;
369 152 : 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 152 : 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 152 : else if( pOther->m_pBorders )
384 0 : return sal_False;
385 :
386 152 : 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 152 : else if( pOther->m_pBGImage )
394 0 : return sal_False;//add end
395 :
396 : //number right
397 152 : if ( m_bNumberRight != pOther->m_bNumberRight)
398 0 : return sal_False;
399 :
400 152 : return sal_True;
401 : }
402 :
403 78 : void XFParaStyle::ToXml(IXFStream *pStrm)
404 : {
405 78 : IXFAttrList *pAttrList = pStrm->GetAttrList();
406 78 : OUString style = GetStyleName();
407 :
408 78 : pAttrList->Clear();
409 78 : if( !style.isEmpty() )
410 78 : pAttrList->AddAttribute("style:name",GetStyleName());
411 78 : pAttrList->AddAttribute("style:family", "paragraph");
412 78 : if( !GetParentStyleName().isEmpty() )
413 27 : pAttrList->AddAttribute("style:parent-style-name",GetParentStyleName());
414 :
415 78 : if( !m_strMasterPage.isEmpty() )
416 3 : pAttrList->AddAttribute("style:master-page-name",m_strMasterPage);
417 78 : pStrm->StartElement("style:style");
418 :
419 : //Paragraph properties:
420 78 : pAttrList->Clear();
421 :
422 : //text indent:
423 78 : if( m_fTextIndent )
424 : {
425 3 : pAttrList->AddAttribute("fo:text-indent", OUString::number(m_fTextIndent) + "cm" );
426 : }
427 : //padding:
428 78 : m_aPadding.ToXml(pStrm);
429 : //margin:
430 78 : m_aMargin.ToXml(pStrm);
431 :
432 : //text align:
433 78 : if( m_eAlignType != enumXFAlignNone )
434 : {
435 39 : pAttrList->AddAttribute("fo:text-align", GetAlignName(m_eAlignType) );
436 : }
437 : //last line align:
438 78 : if( m_eLastLineAlign != enumXFAlignNone )
439 : {
440 0 : pAttrList->AddAttribute("fo:fo:text-align-last", GetAlignName(m_eLastLineAlign) );
441 0 : if( m_bJustSingleWord )
442 0 : pAttrList->AddAttribute("style:justify-single-word", "true" );
443 : }
444 : //line number:
445 78 : if( m_bNumberLines )
446 : {
447 78 : pAttrList->AddAttribute( "text:number-lines", "true" );
448 78 : pAttrList->AddAttribute( "text:line-number", OUString::number(m_nLineNumberRestart) );
449 : }
450 : else
451 : {
452 0 : pAttrList->AddAttribute( "text:number-lines", "false" );
453 : assert(m_nLineNumberRestart>0);
454 0 : pAttrList->AddAttribute( "text:line-number", "0" );
455 : }
456 :
457 : //shadow:
458 78 : m_aShadow.ToXml(pStrm);
459 : //borders:
460 78 : if( m_pBorders )
461 2 : m_pBorders->ToXml(pStrm);
462 : //line height:
463 78 : m_aLineHeight.ToXml(pStrm);
464 :
465 : //background color:
466 78 : if( m_nFlag&XFPARA_FLAG_BACKCOLOR && m_aBackColor.IsValid() )
467 : {
468 2 : pAttrList->AddAttribute("fo:background-color", m_aBackColor.ToString() );
469 : }
470 : //Font properties:
471 78 : if( m_pFont )
472 78 : m_pFont->ToXml(pStrm);
473 :
474 : //page number:
475 78 : if( m_nPageNumber )
476 0 : pAttrList->AddAttribute("fo:page-number", OUString::number(m_nPageNumber) );
477 : //page breaks:
478 78 : m_aBreaks.ToXml(pStrm);
479 :
480 78 : if( m_bKeepWithNext )
481 0 : pAttrList->AddAttribute("fo:fo:keep-with-next", "true" );
482 :
483 78 : pStrm->StartElement("style:properties");
484 :
485 : //dropcap:
486 78 : m_aDropcap.ToXml(pStrm);
487 :
488 : //tabs:
489 78 : if( m_aTabs.GetCount() > 0 )
490 : {
491 4 : pAttrList->Clear();
492 4 : pStrm->StartElement( "style:tab-stops" );
493 4 : m_aTabs.ToXml(pStrm);
494 4 : pStrm->EndElement( "style:tab-stops" );
495 : }
496 :
497 : //background color:
498 78 : if( m_pBGImage )
499 0 : m_pBGImage->ToXml(pStrm);
500 :
501 78 : pStrm->EndElement("style:properties");
502 :
503 78 : pStrm->EndElement("style:style");
504 78 : }
505 :
506 4 : XFDefaultParaStyle::XFDefaultParaStyle()
507 : {
508 4 : m_fTabDistance = 1.28;
509 4 : }
510 :
511 20 : enumXFStyle XFDefaultParaStyle::GetStyleFamily()
512 : {
513 20 : return enumXFStyleDefaultPara;
514 : }
515 :
516 3 : void XFDefaultParaStyle::ToXml(IXFStream * pStrm)
517 : {
518 3 : IXFAttrList *pAttrList = pStrm->GetAttrList();
519 3 : pAttrList->Clear();
520 3 : pAttrList->AddAttribute("style:family", "paragraph");
521 3 : pStrm->StartElement("style:default-style");
522 :
523 : //Paragraph properties:
524 3 : pAttrList->Clear();
525 :
526 3 : pAttrList->AddAttribute("style:tab-stop-distance", OUString::number(m_fTabDistance) + "cm" );
527 :
528 3 : pStrm->StartElement("style:properties");
529 3 : pStrm->EndElement("style:properties");
530 3 : pStrm->EndElement("style:default-style");
531 3 : }
532 :
533 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|