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 : * Line height for paragraph.
59 : ************************************************************************/
60 : #ifndef _XFLINEHEIGHT_HXX
61 : #define _XFLINEHEIGHT_HXX
62 :
63 : #include <string.h>
64 :
65 : class XFLineHeight
66 : {
67 : public:
68 260 : XFLineHeight()
69 : {
70 260 : Reset();
71 260 : }
72 : public:
73 : void SetHeight(double value);
74 :
75 : void SetLeastHeight(double value);
76 :
77 : void SetPercent(sal_Int32 value);
78 :
79 : void SetSpace(double value);
80 :
81 : void Reset();
82 :
83 : void ToXml(IXFStream *pStrm);
84 :
85 : enumLHType GetType();
86 :
87 : friend bool operator==(XFLineHeight& indent1, XFLineHeight& indent2);
88 : friend bool operator!=(XFLineHeight& indent1, XFLineHeight& indent2);
89 : private:
90 : union{
91 : sal_Int32 m_nValue;
92 : double m_fValue;
93 : }m_Value;
94 : enumLHType m_eType;
95 : };
96 :
97 0 : inline void XFLineHeight::SetHeight(double value)
98 : {
99 0 : m_Value.m_fValue = value;
100 0 : m_eType = enumLHHeight;
101 0 : }
102 :
103 0 : inline void XFLineHeight::SetLeastHeight(double value)
104 : {
105 0 : m_Value.m_fValue = value;
106 0 : m_eType = enumLHLeast;
107 0 : }
108 :
109 117 : inline void XFLineHeight::SetPercent(sal_Int32 value)
110 : {
111 117 : m_Value.m_nValue = value;
112 117 : m_eType = enumLHPercent;
113 117 : }
114 0 : inline void XFLineHeight::SetSpace(double value)
115 : {
116 0 : m_Value.m_fValue = value;
117 0 : m_eType = enumLHSpace;
118 0 : }
119 260 : inline void XFLineHeight::Reset()
120 : {
121 260 : m_eType = enumLHNone;
122 260 : memset(&m_Value, 0, sizeof(m_Value));
123 260 : }
124 :
125 : inline enumLHType XFLineHeight::GetType()
126 : {
127 : return m_eType;
128 : }
129 :
130 78 : inline void XFLineHeight::ToXml(IXFStream *pStrm)
131 : {
132 78 : IXFAttrList *pAttrList = pStrm->GetAttrList();
133 :
134 78 : switch(m_eType)
135 : {
136 : case enumLHNone:
137 118 : return;
138 : case enumLHHeight:
139 0 : pAttrList->AddAttribute( A2OUSTR("fo:line-height"),DoubleToOUString(m_Value.m_fValue) + A2OUSTR("cm") );
140 0 : break;
141 : case enumLHLeast:
142 0 : pAttrList->AddAttribute( A2OUSTR("style:line-height-at-least"),DoubleToOUString(m_Value.m_fValue) + A2OUSTR("cm") );
143 0 : break;
144 : case enumLHPercent:
145 38 : pAttrList->AddAttribute( A2OUSTR("fo:line-height"), DoubleToOUString(m_Value.m_nValue) + A2OUSTR("%") );
146 38 : break;
147 : case enumLHSpace:
148 0 : pAttrList->AddAttribute( A2OUSTR("style:line-spacing"), DoubleToOUString(m_Value.m_fValue) + A2OUSTR("cm") );
149 0 : break;
150 : }
151 : }
152 :
153 168 : inline bool operator==(XFLineHeight& lh1, XFLineHeight& lh2)
154 : {
155 168 : if( lh1.m_eType != lh2.m_eType )
156 0 : return false;
157 168 : if( lh1.m_eType == enumLHPercent )
158 : {
159 137 : if( lh1.m_Value.m_nValue != lh2.m_Value.m_nValue )
160 0 : return false;
161 : }
162 : else
163 : {
164 31 : if( lh1.m_Value.m_fValue != lh2.m_Value.m_fValue )
165 0 : return false;
166 : }
167 168 : return true;
168 : }
169 :
170 168 : inline bool operator!=(XFLineHeight& lh1, XFLineHeight& lh2)
171 : {
172 168 : return !(lh1==lh2);
173 : }
174 :
175 : #endif
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|