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_fWidthOuter = 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_fWidthOuter = 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::SetWidthOuter(double outer)
111 : {
112 : assert(m_bDouble);
113 0 : m_fWidthOuter = outer;
114 0 : }
115 :
116 88 : OUString XFBorder::GetLineWidth()
117 : {
118 88 : OUString str;
119 :
120 88 : if( m_bDouble )
121 : {
122 0 : str = OUString::number(m_fWidthInner) + "cm " +
123 0 : OUString::number(m_fWidthSpace) + "cm " +
124 0 : OUString::number(m_fWidthOuter) + "cm";
125 : }
126 88 : return str;
127 : }
128 :
129 164 : OUString XFBorder::ToString()
130 : {
131 164 : OUString str;
132 :
133 164 : if( m_bDouble )
134 : {
135 0 : double width = m_fWidthInner + m_fWidthSpace + m_fWidthOuter;
136 0 : if( width<FLOAT_MIN )
137 : {
138 0 : return str;
139 : }
140 :
141 0 : str = OUString::number(width) + "cm double " + m_aColor.ToString();
142 : }
143 : else
144 : {
145 164 : double width = m_fWidthInner;
146 164 : if( width<FLOAT_MIN )
147 : {
148 12 : return str;
149 : }
150 152 : str = OUString::number(width) + "cm solid " + m_aColor.ToString();
151 : }
152 152 : return str;
153 : }
154 :
155 103 : bool operator==(XFBorder& b1, XFBorder& b2)
156 : {
157 103 : if( b1.m_fOffset != b2.m_fOffset )
158 0 : return false;
159 103 : if( b1.m_bDouble != b2.m_bDouble )
160 0 : return false;
161 103 : if( !b1.m_bDouble )
162 : {
163 103 : if( b1.m_fWidthInner != b2.m_fWidthInner )
164 30 : return false;
165 : }
166 : else
167 : {
168 0 : if( b1.m_bSameWidth != b2.m_bSameWidth )
169 0 : return true;
170 0 : if( b1.m_fWidthInner != b2.m_fWidthInner ||
171 0 : b1.m_fWidthSpace != b2.m_fWidthSpace ||
172 0 : b1.m_fWidthOuter != b2.m_fWidthOuter
173 : )
174 0 : return false;
175 : }
176 73 : if( b1.m_aColor != b2.m_aColor )
177 0 : return false;
178 73 : return true;
179 : }
180 :
181 72 : bool operator!=(XFBorder& b1, XFBorder& b2)
182 : {
183 72 : return !(b1 == b2);
184 : }
185 :
186 : //XFBorders:
187 :
188 352 : void XFBorders::SetColor(enumXFBorder side, XFColor& color)
189 : {
190 352 : switch(side)
191 : {
192 : case enumXFBorderLeft:
193 88 : m_aBorderLeft.SetColor(color);
194 88 : break;
195 : case enumXFBorderRight:
196 88 : m_aBorderRight.SetColor(color);
197 88 : break;
198 : case enumXFBorderTop:
199 88 : m_aBorderTop.SetColor(color);
200 88 : break;
201 : case enumXFBorderBottom:
202 88 : m_aBorderBottom.SetColor(color);
203 88 : break;
204 : default:
205 0 : break;
206 : }
207 352 : }
208 :
209 372 : void XFBorders::SetWidth(enumXFBorder side, double width)
210 : {
211 372 : switch(side)
212 : {
213 : case enumXFBorderLeft:
214 98 : m_aBorderLeft.SetWidth(width);
215 98 : break;
216 : case enumXFBorderRight:
217 88 : m_aBorderRight.SetWidth(width);
218 88 : break;
219 : case enumXFBorderTop:
220 88 : m_aBorderTop.SetWidth(width);
221 88 : break;
222 : case enumXFBorderBottom:
223 98 : m_aBorderBottom.SetWidth(width);
224 98 : break;
225 : default:
226 0 : break;
227 : }
228 372 : }
229 :
230 0 : void XFBorders::SetDoubleLine(enumXFBorder side, sal_Bool dual,sal_Bool bSameWidth)
231 : {
232 0 : switch(side)
233 : {
234 : case enumXFBorderLeft:
235 0 : m_aBorderLeft.SetDoubleLine(dual,bSameWidth);
236 0 : break;
237 : case enumXFBorderRight:
238 0 : m_aBorderRight.SetDoubleLine(dual,bSameWidth);
239 0 : break;
240 : case enumXFBorderTop:
241 0 : m_aBorderTop.SetDoubleLine(dual,bSameWidth);
242 0 : break;
243 : case enumXFBorderBottom:
244 0 : m_aBorderBottom.SetDoubleLine(dual,bSameWidth);
245 0 : break;
246 : default:
247 0 : break;
248 : }
249 0 : }
250 :
251 0 : void XFBorders::SetWidthInner(enumXFBorder side, double inner)
252 : {
253 0 : switch(side)
254 : {
255 : case enumXFBorderLeft:
256 0 : m_aBorderLeft.SetWidthInner(inner);
257 0 : break;
258 : case enumXFBorderRight:
259 0 : m_aBorderRight.SetWidthInner(inner);
260 0 : break;
261 : case enumXFBorderTop:
262 0 : m_aBorderTop.SetWidthInner(inner);
263 0 : break;
264 : case enumXFBorderBottom:
265 0 : m_aBorderBottom.SetWidthInner(inner);
266 0 : break;
267 : default:
268 0 : break;
269 : }
270 0 : }
271 :
272 0 : void XFBorders::SetWidthSpace(enumXFBorder side, double space)
273 : {
274 0 : switch(side)
275 : {
276 : case enumXFBorderLeft:
277 0 : m_aBorderLeft.SetWidthSpace(space);
278 0 : break;
279 : case enumXFBorderRight:
280 0 : m_aBorderRight.SetWidthSpace(space);
281 0 : break;
282 : case enumXFBorderTop:
283 0 : m_aBorderTop.SetWidthSpace(space);
284 0 : break;
285 : case enumXFBorderBottom:
286 0 : m_aBorderBottom.SetWidthSpace(space);
287 0 : break;
288 : default:
289 0 : break;
290 : }
291 0 : }
292 :
293 0 : void XFBorders::SetWidthOuter(enumXFBorder side, double outer)
294 : {
295 0 : switch(side)
296 : {
297 : case enumXFBorderLeft:
298 0 : m_aBorderLeft.SetWidthOuter(outer);
299 0 : break;
300 : case enumXFBorderRight:
301 0 : m_aBorderRight.SetWidthOuter(outer);
302 0 : break;
303 : case enumXFBorderTop:
304 0 : m_aBorderTop.SetWidthOuter(outer);
305 0 : break;
306 : case enumXFBorderBottom:
307 0 : m_aBorderBottom.SetWidthOuter(outer);
308 0 : break;
309 : default:
310 0 : break;
311 : }
312 0 : }
313 :
314 33 : bool operator ==(XFBorders& b1, XFBorders& b2)
315 : {
316 33 : if( b1.m_aBorderLeft != b2.m_aBorderLeft )
317 20 : return false;
318 13 : if( b1.m_aBorderRight != b2.m_aBorderRight )
319 0 : return false;
320 13 : if( b1.m_aBorderTop != b2.m_aBorderTop )
321 0 : return false;
322 13 : if( b1.m_aBorderBottom != b2.m_aBorderBottom )
323 10 : return false;
324 3 : return true;
325 : }
326 :
327 33 : bool operator!=(XFBorders& b1, XFBorders& b2)
328 : {
329 33 : return !(b1 == b2);
330 : }
331 :
332 22 : void XFBorders::ToXml(IXFStream *pStrm)
333 : {
334 22 : IXFAttrList *pAttrList = pStrm->GetAttrList();
335 :
336 22 : if( !m_aBorderLeft.GetLineWidth().isEmpty() )
337 0 : pAttrList->AddAttribute( "style:border-line-width-left", m_aBorderLeft.GetLineWidth() );
338 22 : if( !m_aBorderRight.GetLineWidth().isEmpty() )
339 0 : pAttrList->AddAttribute( "style:border-line-width-right", m_aBorderRight.GetLineWidth() );
340 22 : if( !m_aBorderTop.GetLineWidth().isEmpty() )
341 0 : pAttrList->AddAttribute( "style:border-line-width-top", m_aBorderTop.GetLineWidth() );
342 22 : if( !m_aBorderBottom.GetLineWidth().isEmpty() )
343 0 : pAttrList->AddAttribute( "style:border-line-width-bottom", m_aBorderBottom.GetLineWidth() );
344 :
345 22 : if( !m_aBorderLeft.ToString().isEmpty() )
346 16 : pAttrList->AddAttribute( "fo:border-left", m_aBorderLeft.ToString() );
347 : else
348 6 : pAttrList->AddAttribute( "fo:border-left", "none" );
349 :
350 22 : if( !m_aBorderRight.ToString().isEmpty() )
351 22 : pAttrList->AddAttribute( "fo:border-right", m_aBorderRight.ToString() );
352 : else
353 0 : pAttrList->AddAttribute( "fo:border-right", "none" );
354 :
355 22 : if( !m_aBorderTop.ToString().isEmpty() )
356 22 : pAttrList->AddAttribute( "fo:border-top", m_aBorderTop.ToString() );
357 : else
358 0 : pAttrList->AddAttribute( "fo:border-top", "none" );
359 :
360 22 : if( !m_aBorderBottom.ToString().isEmpty() )
361 16 : pAttrList->AddAttribute( "fo:border-bottom", m_aBorderBottom.ToString() );
362 : else
363 6 : pAttrList->AddAttribute( "fo:border-bottom", "none" );
364 :
365 22 : }
366 :
367 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|