Branch data 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 : : * Border object,now only used by paragraph object.
59 : : ************************************************************************/
60 : : #include "xfborders.hxx"
61 : :
62 : 1760 : XFBorder::XFBorder()
63 : : {
64 : 1760 : m_fOffset = 0;
65 : 1760 : m_bDouble = sal_False;
66 : 1760 : m_bSameWidth = sal_False;
67 : 1760 : m_fWidthInner = 0;
68 : 1760 : m_fWidthSpace = 0;
69 : 1760 : m_fWidthOutter = 0;
70 : 1760 : }
71 : :
72 : 1760 : void XFBorder::SetColor(XFColor& color)
73 : : {
74 : 1760 : m_aColor = color;
75 : 1760 : }
76 : :
77 : 1860 : void XFBorder::SetWidth(double width)
78 : : {
79 [ + - ]: 1860 : if( !m_bDouble )
80 : : {
81 : 1860 : m_fWidthInner = width;
82 : 1860 : m_bSameWidth = sal_True;
83 : : }
84 [ # # ][ # # ]: 0 : else if( m_bDouble && m_bSameWidth )
85 : : {
86 : 0 : m_fWidthInner = width;
87 : 0 : m_fWidthOutter = width;
88 : 0 : m_fWidthSpace = width;
89 : : }
90 : 1860 : }
91 : :
92 : 0 : void XFBorder::SetDoubleLine(sal_Bool dual,sal_Bool bSameWidth)
93 : : {
94 : 0 : m_bDouble = dual;
95 : 0 : m_bSameWidth = bSameWidth;
96 : 0 : }
97 : :
98 : 0 : void XFBorder::SetWidthInner(double inner)
99 : : {
100 : : assert(m_bDouble);
101 : 0 : m_fWidthInner = inner;
102 : 0 : }
103 : :
104 : 0 : void XFBorder::SetWidthSpace(double space)
105 : : {
106 : : assert(m_bDouble);
107 : 0 : m_fWidthSpace = space;
108 : 0 : }
109 : :
110 : 0 : void XFBorder::SetWidthOutter(double outer)
111 : : {
112 : : assert(m_bDouble);
113 : 0 : m_fWidthOutter = outer;
114 : 0 : }
115 : :
116 : 440 : rtl::OUString XFBorder::GetLineWidth()
117 : : {
118 : 440 : rtl::OUString str;
119 : :
120 [ - + ]: 440 : if( m_bDouble )
121 : : {
122 [ # # ]: 0 : str = FloatToOUString(m_fWidthInner);
123 [ # # ]: 0 : str += A2OUSTR("cm ") + DoubleToOUString(m_fWidthSpace);
124 [ # # ]: 0 : str += A2OUSTR("cm ") + DoubleToOUString(m_fWidthOutter) + A2OUSTR("cm");
125 : : }
126 : 440 : return str;
127 : : }
128 : :
129 : 820 : rtl::OUString XFBorder::ToString()
130 : : {
131 : 820 : rtl::OUString str;
132 : :
133 [ - + ]: 820 : if( m_bDouble )
134 : : {
135 : 0 : double width = m_fWidthInner + m_fWidthSpace + m_fWidthOutter;
136 [ # # ]: 0 : if( width<FLOAT_MIN )
137 : : {
138 : 0 : return str;
139 : : }
140 : :
141 [ # # ]: 0 : str = DoubleToOUString(width) + A2OUSTR("cm");
142 [ # # ]: 0 : str += A2OUSTR(" double ") + m_aColor.ToString();
143 : : }
144 : : else
145 : : {
146 : 820 : double width = m_fWidthInner;
147 [ + + ]: 820 : if( width<FLOAT_MIN )
148 : : {
149 : 60 : return str;
150 : : }
151 [ + - ]: 760 : str = DoubleToOUString(width) + A2OUSTR("cm");
152 [ + - ]: 760 : str += A2OUSTR(" solid ") + m_aColor.ToString();
153 : : }
154 : 820 : return str;
155 : : }
156 : :
157 : 515 : bool operator==(XFBorder& b1, XFBorder& b2)
158 : : {
159 [ - + ]: 515 : if( b1.m_fOffset != b2.m_fOffset )
160 : 0 : return false;
161 [ - + ]: 515 : if( b1.m_bDouble != b2.m_bDouble )
162 : 0 : return false;
163 [ + - ]: 515 : if( !b1.m_bDouble )
164 : : {
165 [ + + ]: 515 : if( b1.m_fWidthInner != b2.m_fWidthInner )
166 : 150 : return false;
167 : : }
168 : : else
169 : : {
170 [ # # ]: 0 : if( b1.m_bSameWidth != b2.m_bSameWidth )
171 : 0 : return true;
172 [ # # ][ # # ]: 0 : if( b1.m_fWidthInner != b2.m_fWidthInner ||
[ # # ]
173 : : b1.m_fWidthSpace != b2.m_fWidthSpace ||
174 : : b1.m_fWidthOutter != b2.m_fWidthOutter
175 : : )
176 : 0 : return false;
177 : : }
178 [ - + ]: 365 : if( b1.m_aColor != b2.m_aColor )
179 : 0 : return sal_False;
180 : 515 : return true;
181 : : }
182 : :
183 : 360 : bool operator!=(XFBorder& b1, XFBorder& b2)
184 : : {
185 : 360 : return !(b1 == b2);
186 : : }
187 : :
188 : : //
189 : : //XFBorders:
190 : : //
191 : 1760 : void XFBorders::SetColor(enumXFBorder side, XFColor& color)
192 : : {
193 [ + + + + : 1760 : switch(side)
- ]
194 : : {
195 : : case enumXFBorderLeft:
196 : 440 : m_aBorderLeft.SetColor(color);
197 : 440 : break;
198 : : case enumXFBorderRight:
199 : 440 : m_aBorderRight.SetColor(color);
200 : 440 : break;
201 : : case enumXFBorderTop:
202 : 440 : m_aBorderTop.SetColor(color);
203 : 440 : break;
204 : : case enumXFBorderBottom:
205 : 440 : m_aBorderBottom.SetColor(color);
206 : 440 : break;
207 : : default:
208 : 0 : break;
209 : : }
210 : 1760 : }
211 : :
212 : 1860 : void XFBorders::SetWidth(enumXFBorder side, double width)
213 : : {
214 [ + + + + : 1860 : switch(side)
- ]
215 : : {
216 : : case enumXFBorderLeft:
217 : 490 : m_aBorderLeft.SetWidth(width);
218 : 490 : break;
219 : : case enumXFBorderRight:
220 : 440 : m_aBorderRight.SetWidth(width);
221 : 440 : break;
222 : : case enumXFBorderTop:
223 : 440 : m_aBorderTop.SetWidth(width);
224 : 440 : break;
225 : : case enumXFBorderBottom:
226 : 490 : m_aBorderBottom.SetWidth(width);
227 : 490 : break;
228 : : default:
229 : 0 : break;
230 : : }
231 : 1860 : }
232 : :
233 : 0 : void XFBorders::SetDoubleLine(enumXFBorder side, sal_Bool dual,sal_Bool bSameWidth)
234 : : {
235 [ # # # # : 0 : switch(side)
# ]
236 : : {
237 : : case enumXFBorderLeft:
238 : 0 : m_aBorderLeft.SetDoubleLine(dual,bSameWidth);
239 : 0 : break;
240 : : case enumXFBorderRight:
241 : 0 : m_aBorderRight.SetDoubleLine(dual,bSameWidth);
242 : 0 : break;
243 : : case enumXFBorderTop:
244 : 0 : m_aBorderTop.SetDoubleLine(dual,bSameWidth);
245 : 0 : break;
246 : : case enumXFBorderBottom:
247 : 0 : m_aBorderBottom.SetDoubleLine(dual,bSameWidth);
248 : 0 : break;
249 : : default:
250 : 0 : break;
251 : : }
252 : 0 : }
253 : :
254 : 0 : void XFBorders::SetWidthInner(enumXFBorder side, double inner)
255 : : {
256 [ # # # # : 0 : switch(side)
# ]
257 : : {
258 : : case enumXFBorderLeft:
259 : 0 : m_aBorderLeft.SetWidthInner(inner);
260 : 0 : break;
261 : : case enumXFBorderRight:
262 : 0 : m_aBorderRight.SetWidthInner(inner);
263 : 0 : break;
264 : : case enumXFBorderTop:
265 : 0 : m_aBorderTop.SetWidthInner(inner);
266 : 0 : break;
267 : : case enumXFBorderBottom:
268 : 0 : m_aBorderBottom.SetWidthInner(inner);
269 : 0 : break;
270 : : default:
271 : 0 : break;
272 : : }
273 : 0 : }
274 : :
275 : 0 : void XFBorders::SetWidthSpace(enumXFBorder side, double space)
276 : : {
277 [ # # # # : 0 : switch(side)
# ]
278 : : {
279 : : case enumXFBorderLeft:
280 : 0 : m_aBorderLeft.SetWidthSpace(space);
281 : 0 : break;
282 : : case enumXFBorderRight:
283 : 0 : m_aBorderRight.SetWidthSpace(space);
284 : 0 : break;
285 : : case enumXFBorderTop:
286 : 0 : m_aBorderTop.SetWidthSpace(space);
287 : 0 : break;
288 : : case enumXFBorderBottom:
289 : 0 : m_aBorderBottom.SetWidthSpace(space);
290 : 0 : break;
291 : : default:
292 : 0 : break;
293 : : }
294 : 0 : }
295 : :
296 : 0 : void XFBorders::SetWidthOutter(enumXFBorder side, double outer)
297 : : {
298 [ # # # # : 0 : switch(side)
# ]
299 : : {
300 : : case enumXFBorderLeft:
301 : 0 : m_aBorderLeft.SetWidthOutter(outer);
302 : 0 : break;
303 : : case enumXFBorderRight:
304 : 0 : m_aBorderRight.SetWidthOutter(outer);
305 : 0 : break;
306 : : case enumXFBorderTop:
307 : 0 : m_aBorderTop.SetWidthOutter(outer);
308 : 0 : break;
309 : : case enumXFBorderBottom:
310 : 0 : m_aBorderBottom.SetWidthOutter(outer);
311 : 0 : break;
312 : : default:
313 : 0 : break;
314 : : }
315 : 0 : }
316 : :
317 : 165 : bool operator ==(XFBorders& b1, XFBorders& b2)
318 : : {
319 [ + + ]: 165 : if( b1.m_aBorderLeft != b2.m_aBorderLeft )
320 : 100 : return false;
321 [ - + ]: 65 : if( b1.m_aBorderRight != b2.m_aBorderRight )
322 : 0 : return false;
323 [ - + ]: 65 : if( b1.m_aBorderTop != b2.m_aBorderTop )
324 : 0 : return false;
325 [ + + ]: 65 : if( b1.m_aBorderBottom != b2.m_aBorderBottom )
326 : 50 : return false;
327 : 165 : return true;
328 : : }
329 : :
330 : 165 : bool operator!=(XFBorders& b1, XFBorders& b2)
331 : : {
332 : 165 : return !(b1 == b2);
333 : : }
334 : :
335 : 110 : void XFBorders::ToXml(IXFStream *pStrm)
336 : : {
337 : 110 : IXFAttrList *pAttrList = pStrm->GetAttrList();
338 : :
339 [ - + ]: 110 : if( !m_aBorderLeft.GetLineWidth().isEmpty() )
340 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:border-line-width-left"), m_aBorderLeft.GetLineWidth() );
341 [ - + ]: 110 : if( !m_aBorderRight.GetLineWidth().isEmpty() )
342 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:border-line-width-right"), m_aBorderRight.GetLineWidth() );
343 [ - + ]: 110 : if( !m_aBorderTop.GetLineWidth().isEmpty() )
344 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:border-line-width-top"), m_aBorderTop.GetLineWidth() );
345 [ - + ]: 110 : if( !m_aBorderBottom.GetLineWidth().isEmpty() )
346 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:border-line-width-bottom"), m_aBorderBottom.GetLineWidth() );
347 : :
348 [ + + ]: 110 : if( !m_aBorderLeft.ToString().isEmpty() )
349 [ + - ]: 80 : pAttrList->AddAttribute( A2OUSTR("fo:border-left"), m_aBorderLeft.ToString() );
350 : : else
351 [ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("fo:border-left"), A2OUSTR("none") );
352 : :
353 [ + - ]: 110 : if( !m_aBorderRight.ToString().isEmpty() )
354 [ + - ]: 110 : pAttrList->AddAttribute( A2OUSTR("fo:border-right"), m_aBorderRight.ToString() );
355 : : else
356 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("fo:border-right"), A2OUSTR("none") );
357 : :
358 [ + - ]: 110 : if( !m_aBorderTop.ToString().isEmpty() )
359 [ + - ]: 110 : pAttrList->AddAttribute( A2OUSTR("fo:border-top"), m_aBorderTop.ToString() );
360 : : else
361 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("fo:border-top"), A2OUSTR("none") );
362 : :
363 [ + + ]: 110 : if( !m_aBorderBottom.ToString().isEmpty() )
364 [ + - ]: 80 : pAttrList->AddAttribute( A2OUSTR("fo:border-bottom"), m_aBorderBottom.ToString() );
365 : : else
366 [ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("fo:border-bottom"), A2OUSTR("none") );
367 : :
368 : 110 : }
369 : :
370 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|