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