LibreOffice Module lotuswordpro (master) 1
xfparastyle.cxx
Go to the documentation of this file.
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 ************************************************************************/
63#include <xfilter/xffont.hxx>
64#include <xfilter/xfborders.hxx>
65#include "xftabstyle.hxx"
66#include <xfilter/xfbgimage.hxx>
67#include <xfilter/xfutil.hxx>
68
70 : m_eAlignType(enumXFAlignNone)
71 , m_fTextIndent(0)
72 , m_nFlag(0)
73 , m_bNumberRight(false)
74{
75}
76
77
79 : XFStyle(other)
80 , m_eAlignType(other.m_eAlignType)
81 , m_fTextIndent(other.m_fTextIndent)
82 , m_aBackColor(other.m_aBackColor)
83 , m_aMargin(other.m_aMargin)
84 , m_aPadding(other.m_aPadding)
85 , m_pFont(other.m_pFont)
86 , m_aShadow(other.m_aShadow)
87 , m_aDropcap(other.m_aDropcap)
88 , m_aLineHeight(other.m_aLineHeight)
89 , m_aBreaks(other.m_aBreaks)
90 , m_nFlag(other.m_nFlag)
91 , m_bNumberRight(other.m_bNumberRight)
92{
93 if( other.m_pBorders )
94 m_pBorders.reset( new XFBorders(*other.m_pBorders) );
95
96 if( other.m_pBGImage )
97 m_pBGImage.reset( new XFBGImage(*other.m_pBGImage) );
98
99 for (size_t i = 0; i < other.m_aTabs.GetCount(); ++i)
100 {
101 const IXFStyle* pStyle = other.m_aTabs.Item(i);
102 if( pStyle )
103 {
104 const XFTabStyle* pTabStyle = dynamic_cast<const XFTabStyle*>(pStyle);
105 if( pTabStyle )
106 {
107 std::unique_ptr<XFTabStyle> pCopyStyle(new XFTabStyle(*pTabStyle));
108 m_aTabs.AddStyle(std::move(pCopyStyle));
109 }
110 }
111 }
112}
113
115{
116 // Check for self-assignment
117 if (this != &other)
118 {
119 // first , clean member
120 m_pBGImage.reset();
121 m_aTabs.Reset();
122
124 m_nFlag = other.m_nFlag;
128
129 m_pFont = other.m_pFont;
130
131 if( other.m_pBorders )
132 m_pBorders.reset( new XFBorders(*other.m_pBorders) );
133 else
134 m_pBorders.reset();
136 if( other.m_pBGImage )
137 m_pBGImage.reset( new XFBGImage(*other.m_pBGImage) );
138 else
139 m_pBGImage.reset();
140
141 m_aShadow = other.m_aShadow;
142 m_aMargin = other.m_aMargin;
143 m_aDropcap = other.m_aDropcap;
145 m_aPadding = other.m_aPadding;
146 m_aBreaks = other.m_aBreaks;
147
148 for (size_t i=0; i<other.m_aTabs.GetCount(); ++i)
149 {
150 const IXFStyle *pStyle = other.m_aTabs.Item(i);
151 if( pStyle )
152 {
153 const XFTabStyle *pTabStyle = dynamic_cast<const XFTabStyle*>(pStyle);
154 if( pTabStyle )
155 {
156 std::unique_ptr<XFTabStyle> pCopyStyle(new XFTabStyle(*pTabStyle));
157 m_aTabs.AddStyle(std::move(pCopyStyle));
158 }
159 }
160 }
161 }
162 return *this;
163}
164
166{
167}
168
170{
171 return enumXFStylePara;
172}
173
175{
176 m_pFont = pFont;
177}
178
179void XFParaStyle::SetIndent(double indent )
180{
181 m_fTextIndent = indent;
182}
183
184void XFParaStyle::SetMargins(double left, double right, double top, double bottom)
185{
186 if( left != -1 )
188 if( right != -1 )
190 if( top != -1 )
192 if( bottom != -1 )
194}
195
196void XFParaStyle::SetShadow(enumXFShadowPos pos, double offset, XFColor const & color)
197{
199 m_aShadow.SetOffset(offset);
201}
202
204{
207}
208
209void XFParaStyle::SetBackImage(std::unique_ptr<XFBGImage>& rImage)
210{
211 m_pBGImage = std::move(rImage);
212}
213
215{
216 m_pBorders.reset( pBorders );
217}
218
219void XFParaStyle::SetDropCap(sal_Int16 nLength,
220 sal_Int16 nLines,
221 double fDistance
222 )
223{
224 assert(nLength>=1);
225 assert(nLines>=2);
226 assert(fDistance>=0);
227
229 m_aDropcap.SetLines(nLines);
230 m_aDropcap.SetDistance(fDistance);
231}
232
234{
235 if( type == enumLHNone )
236 {
237 return;
238 }
239 switch(type)
240 {
241 case enumLHHeight:
243 break;
244 case enumLHLeast:
246 break;
247 case enumLHPercent: //perhaps i should redesign the interface here,ohm...
248 m_aLineHeight.SetPercent(static_cast<sal_Int32>(value));
249 break;
250 case enumLHSpace:
251 m_aLineHeight.SetSpace(value*0.5666); //don't known why,just suspect.
252 break;
253 default:
254 break;
255 }
256}
257
258void XFParaStyle::AddTabStyle(enumXFTab type, double len, sal_Unicode leader, sal_Unicode delimiter)
259{
260 std::unique_ptr<XFTabStyle> tab(new XFTabStyle());
261 tab->SetTabType(type);
262 tab->SetLength(len);
263 tab->SetLeaderChar(leader);
264 tab->SetDelimiter(delimiter);
265 m_aTabs.AddStyle(std::move(tab));
266}
267
272{
273 if( this == pStyle )
274 return true;
275 if( !pStyle || pStyle->GetStyleFamily() != enumXFStylePara )
276 return false;
277
278 XFParaStyle *pOther = static_cast<XFParaStyle*>(pStyle);
279
280 if( m_nFlag != pOther->m_nFlag )
281 return false;
283 return false;
284 if( m_strMasterPage != pOther->m_strMasterPage )
285 return false;
286 if( m_fTextIndent != pOther->m_fTextIndent )
287 return false;
288 //align:
289 if( m_eAlignType != pOther->m_eAlignType )
290 return false;
291
292 //shadow:
293 if( m_aShadow != pOther->m_aShadow )
294 return false;
295 //margin:
296 if( m_aMargin != pOther->m_aMargin )
297 return false;
298
299 if( m_aPadding != pOther->m_aPadding )
300 return false;
301
302 //dropcap:
303 if( m_aDropcap != pOther->m_aDropcap )
304 return false;
305 //line height:
306 if( m_aLineHeight != pOther->m_aLineHeight )
307 return false;
308 //breaks:
309 if( m_aBreaks != pOther->m_aBreaks )
310 return false;
311 if( m_aTabs != pOther->m_aTabs )
312 return false;
313
314 //font:
315 if( m_pFont.is() )
316 {
317 if( !pOther->m_pFont.is() )
318 return false;
319 if(*m_pFont != *pOther->m_pFont )
320 return false;
321 }
322 else if( pOther->m_pFont.is() )
323 return false;
324
325 //border:
326 if( m_pBorders )
327 {
328 if( !pOther->m_pBorders )
329 return false;
330 if( *m_pBorders != *pOther->m_pBorders )
331 return false;
332 }
333 else if( pOther->m_pBorders )
334 return false;
335
336 if( m_pBGImage )
337 {
338 if( !pOther->m_pBGImage )
339 return false;
340 if( *m_pBGImage != *pOther->m_pBGImage )
341 return false;
342 }
343 else if( pOther->m_pBGImage )
344 return false;//add end
345
346 //number right
347 if ( m_bNumberRight != pOther->m_bNumberRight)
348 return false;
349
350 return true;
351}
352
354{
355 IXFAttrList *pAttrList = pStrm->GetAttrList();
356 OUString style = GetStyleName();
357
358 pAttrList->Clear();
359 if( !style.isEmpty() )
360 pAttrList->AddAttribute("style:name",GetStyleName());
361 pAttrList->AddAttribute("style:family", "paragraph");
362 if( !GetParentStyleName().isEmpty() )
363 pAttrList->AddAttribute("style:parent-style-name",GetParentStyleName());
364
365 if( !m_strMasterPage.isEmpty() )
366 pAttrList->AddAttribute("style:master-page-name",m_strMasterPage);
367 pStrm->StartElement("style:style");
368
369 //Paragraph properties:
370 pAttrList->Clear();
371
372 //text indent:
373 if( m_fTextIndent )
374 {
375 pAttrList->AddAttribute("fo:text-indent", OUString::number(m_fTextIndent) + "cm" );
376 }
377 //padding:
378 m_aPadding.ToXml(pStrm);
379 //margin:
380 m_aMargin.ToXml(pStrm);
381
382 //text align:
384 {
385 pAttrList->AddAttribute("fo:text-align", GetAlignName(m_eAlignType) );
386 }
387 //line number:
388 pAttrList->AddAttribute( "text:number-lines", "true" );
389 pAttrList->AddAttribute( "text:line-number", OUString::number(0) );
390
391 //shadow:
392 m_aShadow.ToXml(pStrm);
393 //borders:
394 if( m_pBorders )
395 m_pBorders->ToXml(pStrm);
396 //line height:
397 m_aLineHeight.ToXml(pStrm);
398
399 //background color:
401 {
402 pAttrList->AddAttribute("fo:background-color", m_aBackColor.ToString() );
403 }
404 //Font properties:
405 if( m_pFont.is() )
406 m_pFont->ToXml(pStrm);
407
408 //page breaks:
409 m_aBreaks.ToXml(pStrm);
410
411 pStrm->StartElement("style:properties");
412
413 //dropcap:
414 m_aDropcap.ToXml(pStrm);
415
416 //tabs:
417 if( m_aTabs.GetCount() > 0 )
418 {
419 pAttrList->Clear();
420 pStrm->StartElement( "style:tab-stops" );
421 m_aTabs.ToXml(pStrm);
422 pStrm->EndElement( "style:tab-stops" );
423 }
424
425 //background color:
426 if( m_pBGImage )
427 m_pBGImage->ToXml(pStrm);
428
429 pStrm->EndElement("style:properties");
430
431 pStrm->EndElement("style:style");
432}
433
435{
436 m_fTabDistance = 1.28;
437}
438
440{
442}
443
445{
446 IXFAttrList *pAttrList = pStrm->GetAttrList();
447 pAttrList->Clear();
448 pAttrList->AddAttribute("style:family", "paragraph");
449 pStrm->StartElement("style:default-style");
450
451 //Paragraph properties:
452 pAttrList->Clear();
453
454 pAttrList->AddAttribute("style:tab-stop-distance", OUString::number(m_fTabDistance) + "cm" );
455
456 pStrm->StartElement("style:properties");
457 pStrm->EndElement("style:properties");
458 pStrm->EndElement("style:default-style");
459}
460
461/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Attribute list interface for sax writer.
Definition: ixfattrlist.hxx:72
virtual void Clear()=0
@descr: Clear all the attributes in the attribute list.
virtual void AddAttribute(const OUString &name, const OUString &value)=0
@descr: Add an attribute to the attribute list.
Stream wrapper for sax writer.
Definition: ixfstream.hxx:72
virtual IXFAttrList * GetAttrList()=0
@descr return the Attribute list interface.
virtual void StartElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::startElement()
virtual void EndElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::endElement()
@descr Interface for all style object.
Definition: ixfstyle.hxx:71
virtual enumXFStyle GetStyleFamily()=0
@descr: return the style family.
Background image object.
Definition: xfbgimage.hxx:70
Borders for object with borders.
Definition: xfborders.hxx:134
void ToXml(IXFStream *pStrm)
@descr Output breaks object.
Definition: xfbreaks.hxx:100
Color object.
Definition: xfcolor.hxx:70
bool IsValid() const
@descr helper function to assert whether a color is valid.
Definition: xfcolor.hxx:99
OUString ToString() const
Definition: xfcolor.cxx:63
enumXFStyle GetStyleFamily() override
@descr get style family.
virtual void ToXml(IXFStream *pStrm) override
void ToXml(IXFStream *pStrm)
Definition: xfdropcap.hxx:117
void SetDistance(double distance)
Definition: xfdropcap.hxx:104
void SetLines(sal_Int32 lines)
Definition: xfdropcap.hxx:99
void SetCharCount(sal_Int32 count)
Definition: xfdropcap.hxx:94
void ToXml(IXFStream *pStrm)
void SetLeastHeight(double value)
void SetPercent(sal_Int32 value)
void SetSpace(double value)
void SetHeight(double value)
void SetLeft(double left)
Definition: xfmargins.hxx:96
void SetRight(double right)
Definition: xfmargins.hxx:102
void SetBottom(double bottom)
Definition: xfmargins.hxx:114
void SetTop(double top)
Definition: xfmargins.hxx:108
void ToXml(IXFStream *pStrm)
Definition: xfmargins.cxx:78
void ToXml(IXFStream *pStrm)
@descr Output padding properties.
Definition: xfpadding.hxx:159
Style object for aragraph.
Definition: xfparastyle.hxx:93
OUString m_strMasterPage
virtual void ToXml(IXFStream *strm) override
bool m_bNumberRight
void SetIndent(double indent)
@descr Set the indent of the paragraph.
XFMargins m_aMargin
void SetDropCap(sal_Int16 nLength, sal_Int16 nLines, double fDistance=0)
@descr Set drop caption of the paragraph.
XFBreaks m_aBreaks
std::unique_ptr< XFBGImage > m_pBGImage
void SetMargins(double left, double right, double top=-1, double bottom=-1)
@descr Set the Margins of the paragraph.
enumXFAlignType m_eAlignType
void SetLineHeight(enumLHType type, double value)
@descr Set line height of the paragraph.
XFStyleContainer m_aTabs
XFShadow m_aShadow
virtual ~XFParaStyle() override
sal_uInt32 m_nFlag
std::unique_ptr< XFBorders > m_pBorders
XFParaStyle & operator=(const XFParaStyle &other)
virtual enumXFStyle GetStyleFamily() override
@descr get style family.
XFDropcap m_aDropcap
void SetShadow(enumXFShadowPos pos, double offset, XFColor const &color)
@descr Set the shadow of the paragraph.
double m_fTextIndent
rtl::Reference< XFFont > m_pFont
virtual bool Equal(IXFStyle *pStyle) override
Affirm whether two XFParaStyle objects are equal.
XFColor m_aBackColor
void SetFont(rtl::Reference< XFFont > const &font)
@descr set the paragraph default font.
void SetBackImage(std::unique_ptr< XFBGImage > &rImage)
@descr Set background image of the paragraph.
void AddTabStyle(enumXFTab type, double len, sal_Unicode leader, sal_Unicode delimiter)
@descr Add a tab style.
void SetBorders(XFBorders *pBorders)
@descr The borders is complex, so you have to create one before use.
XFLineHeight m_aLineHeight
XFPadding m_aPadding
void SetBackColor(XFColor const &color)
@descr Set background color of the paragraph.
void SetPosition(enumXFShadowPos pos)
@descr set shadow position.
Definition: xfshadow.hxx:119
void SetOffset(double offset)
@descr Set shadow offset from owner object.
Definition: xfshadow.hxx:129
void ToXml(IXFStream *pStrm)
Definition: xfshadow.cxx:96
void SetColor(const XFColor &color)
@descr Set shadow color.
Definition: xfshadow.hxx:139
IXFStyleRet AddStyle(std::unique_ptr< IXFStyle > pStyle)
@descr Add style to container.
Definition: xfstylecont.cxx:83
size_t GetCount() const
@descr get count of styles in the container.
void Reset()
@descr clear container.
Definition: xfstylecont.cxx:78
virtual void ToXml(IXFStream *pStrm)
@descr Output all style.
const IXFStyle * Item(size_t index) const
@descr get style by index.
implements ixfstyle interface.
Definition: xfstyle.hxx:70
virtual OUString GetStyleName() override
@descr get style name.
Definition: xfstyle.cxx:70
OUString m_strParentStyleName
Definition: xfstyle.hxx:114
virtual OUString GetParentStyleName() override
@descr set parent style name.
Definition: xfstyle.cxx:80
Any value
OString right
OString top
OString bottom
int i
sal_uInt16 sal_Unicode
ResultType type
sal_uInt64 left
size_t pos
enumXFShadowPos
Definition: xfdefs.hxx:185
enumXFStyle
Definition: xfdefs.hxx:80
@ enumXFStyleDefaultPara
Definition: xfdefs.hxx:103
@ enumXFStylePara
Definition: xfdefs.hxx:83
enumLHType
Definition: xfdefs.hxx:211
@ enumLHNone
Definition: xfdefs.hxx:212
@ enumLHHeight
Definition: xfdefs.hxx:213
@ enumLHSpace
Definition: xfdefs.hxx:216
@ enumLHLeast
Definition: xfdefs.hxx:214
@ enumLHPercent
Definition: xfdefs.hxx:215
@ enumXFAlignNone
Definition: xfdefs.hxx:173
enumXFTab
Definition: xfdefs.hxx:230
#define XFPARA_FLAG_BACKCOLOR
Definition: xfparastyle.hxx:83
OUString GetAlignName(enumXFAlignType align)
Definition: xfutil.cxx:296
sal_Int32 nLength