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 352 : XFBorder::XFBorder()
63 : {
64 352 : m_fOffset = 0;
65 352 : m_bDouble = sal_False;
66 352 : m_bSameWidth = sal_False;
67 352 : m_fWidthInner = 0;
68 352 : m_fWidthSpace = 0;
69 352 : m_fWidthOutter = 0;
70 352 : }
71 :
72 352 : void XFBorder::SetColor(XFColor& color)
73 : {
74 352 : m_aColor = color;
75 352 : }
76 :
77 372 : void XFBorder::SetWidth(double width)
78 : {
79 372 : if( !m_bDouble )
80 : {
81 372 : m_fWidthInner = width;
82 372 : 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 372 : }
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 88 : rtl::OUString XFBorder::GetLineWidth()
117 : {
118 88 : rtl::OUString str;
119 :
120 88 : 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 88 : return str;
127 : }
128 :
129 164 : rtl::OUString XFBorder::ToString()
130 : {
131 164 : rtl::OUString str;
132 :
133 164 : 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 164 : double width = m_fWidthInner;
147 164 : if( width<FLOAT_MIN )
148 : {
149 12 : return str;
150 : }
151 152 : str = DoubleToOUString(width) + A2OUSTR("cm");
152 152 : str += A2OUSTR(" solid ") + m_aColor.ToString();
153 : }
154 152 : return str;
155 : }
156 :
157 103 : bool operator==(XFBorder& b1, XFBorder& b2)
158 : {
159 103 : if( b1.m_fOffset != b2.m_fOffset )
160 0 : return false;
161 103 : if( b1.m_bDouble != b2.m_bDouble )
162 0 : return false;
163 103 : if( !b1.m_bDouble )
164 : {
165 103 : if( b1.m_fWidthInner != b2.m_fWidthInner )
166 30 : 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 73 : if( b1.m_aColor != b2.m_aColor )
179 0 : return sal_False;
180 73 : return true;
181 : }
182 :
183 72 : bool operator!=(XFBorder& b1, XFBorder& b2)
184 : {
185 72 : return !(b1 == b2);
186 : }
187 :
188 : //
189 : //XFBorders:
190 : //
191 352 : void XFBorders::SetColor(enumXFBorder side, XFColor& color)
192 : {
193 352 : switch(side)
194 : {
195 : case enumXFBorderLeft:
196 88 : m_aBorderLeft.SetColor(color);
197 88 : break;
198 : case enumXFBorderRight:
199 88 : m_aBorderRight.SetColor(color);
200 88 : break;
201 : case enumXFBorderTop:
202 88 : m_aBorderTop.SetColor(color);
203 88 : break;
204 : case enumXFBorderBottom:
205 88 : m_aBorderBottom.SetColor(color);
206 88 : break;
207 : default:
208 0 : break;
209 : }
210 352 : }
211 :
212 372 : void XFBorders::SetWidth(enumXFBorder side, double width)
213 : {
214 372 : switch(side)
215 : {
216 : case enumXFBorderLeft:
217 98 : m_aBorderLeft.SetWidth(width);
218 98 : break;
219 : case enumXFBorderRight:
220 88 : m_aBorderRight.SetWidth(width);
221 88 : break;
222 : case enumXFBorderTop:
223 88 : m_aBorderTop.SetWidth(width);
224 88 : break;
225 : case enumXFBorderBottom:
226 98 : m_aBorderBottom.SetWidth(width);
227 98 : break;
228 : default:
229 0 : break;
230 : }
231 372 : }
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 33 : bool operator ==(XFBorders& b1, XFBorders& b2)
318 : {
319 33 : if( b1.m_aBorderLeft != b2.m_aBorderLeft )
320 20 : return false;
321 13 : if( b1.m_aBorderRight != b2.m_aBorderRight )
322 0 : return false;
323 13 : if( b1.m_aBorderTop != b2.m_aBorderTop )
324 0 : return false;
325 13 : if( b1.m_aBorderBottom != b2.m_aBorderBottom )
326 10 : return false;
327 3 : return true;
328 : }
329 :
330 33 : bool operator!=(XFBorders& b1, XFBorders& b2)
331 : {
332 33 : return !(b1 == b2);
333 : }
334 :
335 22 : void XFBorders::ToXml(IXFStream *pStrm)
336 : {
337 22 : IXFAttrList *pAttrList = pStrm->GetAttrList();
338 :
339 22 : if( !m_aBorderLeft.GetLineWidth().isEmpty() )
340 0 : pAttrList->AddAttribute( A2OUSTR("style:border-line-width-left"), m_aBorderLeft.GetLineWidth() );
341 22 : if( !m_aBorderRight.GetLineWidth().isEmpty() )
342 0 : pAttrList->AddAttribute( A2OUSTR("style:border-line-width-right"), m_aBorderRight.GetLineWidth() );
343 22 : if( !m_aBorderTop.GetLineWidth().isEmpty() )
344 0 : pAttrList->AddAttribute( A2OUSTR("style:border-line-width-top"), m_aBorderTop.GetLineWidth() );
345 22 : if( !m_aBorderBottom.GetLineWidth().isEmpty() )
346 0 : pAttrList->AddAttribute( A2OUSTR("style:border-line-width-bottom"), m_aBorderBottom.GetLineWidth() );
347 :
348 22 : if( !m_aBorderLeft.ToString().isEmpty() )
349 16 : pAttrList->AddAttribute( A2OUSTR("fo:border-left"), m_aBorderLeft.ToString() );
350 : else
351 6 : pAttrList->AddAttribute( A2OUSTR("fo:border-left"), A2OUSTR("none") );
352 :
353 22 : if( !m_aBorderRight.ToString().isEmpty() )
354 22 : pAttrList->AddAttribute( A2OUSTR("fo:border-right"), m_aBorderRight.ToString() );
355 : else
356 0 : pAttrList->AddAttribute( A2OUSTR("fo:border-right"), A2OUSTR("none") );
357 :
358 22 : if( !m_aBorderTop.ToString().isEmpty() )
359 22 : pAttrList->AddAttribute( A2OUSTR("fo:border-top"), m_aBorderTop.ToString() );
360 : else
361 0 : pAttrList->AddAttribute( A2OUSTR("fo:border-top"), A2OUSTR("none") );
362 :
363 22 : if( !m_aBorderBottom.ToString().isEmpty() )
364 16 : pAttrList->AddAttribute( A2OUSTR("fo:border-bottom"), m_aBorderBottom.ToString() );
365 : else
366 6 : pAttrList->AddAttribute( A2OUSTR("fo:border-bottom"), A2OUSTR("none") );
367 :
368 22 : }
369 :
370 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|