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 : : * Style for all draw object.
59 : : ************************************************************************/
60 : : #include "xfdrawstyle.hxx"
61 : : #include "xfdrawlinestyle.hxx"
62 : : #include "xfdrawareastyle.hxx"
63 : : #include "xfstylemanager.hxx"
64 : : #include "xffontworkstyle.hxx"
65 : : #include "../lwpglobalmgr.hxx"
66 : 0 : XFDrawStyle::XFDrawStyle()
67 : : {
68 : 0 : m_eWrap = enumXFWrapNone;
69 : 0 : m_nWrapLines = 0; //not limited.
70 : :
71 : 0 : m_pLineStyle = NULL;
72 : 0 : m_pAreaStyle = NULL;
73 : :
74 : 0 : m_pFontWorkStyle = NULL;
75 : :
76 : 0 : m_fArrowStartSize = 0.3;
77 : 0 : m_fArrowEndSize = 0.3;
78 : 0 : m_bArrowStartCenter = sal_False;
79 : 0 : m_bArrowStartCenter = sal_False;
80 : 0 : }
81 : :
82 : 0 : XFDrawStyle::~XFDrawStyle()
83 : : {
84 : : //don't delete m_pLineStyle, it was managed by XFStyleManager.
85 [ # # ]: 0 : if (m_pFontWorkStyle)
86 : : {
87 [ # # ]: 0 : delete m_pFontWorkStyle;
88 : 0 : m_pFontWorkStyle = NULL;
89 : : }
90 [ # # ]: 0 : }
91 : :
92 : 0 : void XFDrawStyle::SetLineStyle(double width, XFColor color, sal_Int32 transparency)
93 : : {
94 [ # # ]: 0 : if( !m_pLineStyle )
95 : : {
96 [ # # ]: 0 : m_pLineStyle = new XFDrawLineStyle();
97 [ # # ]: 0 : m_pLineStyle->SetStyleName( XFGlobal::GenStrokeDashName());
98 : : }
99 : 0 : m_pLineStyle->SetWidth(width);
100 : 0 : m_pLineStyle->SetColor(color);
101 : 0 : m_pLineStyle->SetTransparency(transparency);
102 : 0 : }
103 : :
104 : 0 : void XFDrawStyle::SetLineDashStyle(enumXFLineStyle style, int num1, int num2, double len1, double len2, double space )
105 : : {
106 [ # # ]: 0 : if( !m_pLineStyle )
107 : : {
108 [ # # ]: 0 : m_pLineStyle = new XFDrawLineStyle();
109 [ # # ]: 0 : m_pLineStyle->SetStyleName( XFGlobal::GenStrokeDashName());
110 : : }
111 : 0 : m_pLineStyle->SetLineStyle(style);
112 : 0 : m_pLineStyle->SetDot1Number(num1);
113 : 0 : m_pLineStyle->SetDot1Length(len1);
114 : 0 : m_pLineStyle->SetDot2Number(num2);
115 : 0 : m_pLineStyle->SetDot2Length(len2);
116 : 0 : m_pLineStyle->SetSpace(space);
117 : 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
118 : 0 : pXFStyleManager->AddStyle(m_pLineStyle);
119 : 0 : }
120 : :
121 : 0 : void XFDrawStyle::SetFontWorkStyle(sal_Int8 nForm, enumXFFWStyle eStyle, enumXFFWAdjust eAdjust)
122 : : {
123 [ # # ]: 0 : if (!m_pFontWorkStyle)
124 : : {
125 : 0 : m_pFontWorkStyle = new XFFontWorkStyle();
126 : : }
127 : :
128 : 0 : m_pFontWorkStyle->SetButtonForm(nForm);
129 : 0 : m_pFontWorkStyle->SetFWStyleType(eStyle);
130 : 0 : m_pFontWorkStyle->SetFWAdjustType(eAdjust);
131 : 0 : }
132 : :
133 : 0 : void XFDrawStyle::SetAreaColor(XFColor& color)
134 : : {
135 [ # # ]: 0 : if( !m_pAreaStyle )
136 : : {
137 [ # # ]: 0 : m_pAreaStyle = new XFDrawAreaStyle();
138 [ # # ]: 0 : m_pAreaStyle->SetStyleName( XFGlobal::GenAreaName());
139 : : }
140 : 0 : m_pAreaStyle->SetBackColor(color);
141 : 0 : }
142 : :
143 : 0 : void XFDrawStyle::SetAreaLineStyle(enumXFAreaLineStyle style, sal_Int32 angle, double space, XFColor lineColor)
144 : : {
145 [ # # ]: 0 : if( !m_pAreaStyle )
146 : : {
147 [ # # ]: 0 : m_pAreaStyle = new XFDrawAreaStyle();
148 [ # # ]: 0 : m_pAreaStyle->SetStyleName( XFGlobal::GenAreaName());
149 : : }
150 : 0 : m_pAreaStyle->SetAreaStyle(enumXFAreaHatch);
151 : :
152 : 0 : m_pAreaStyle->SetLineStyle(style);
153 : 0 : m_pAreaStyle->SetLineAngle(angle);
154 : 0 : m_pAreaStyle->SetLineSpace(space);
155 : 0 : m_pAreaStyle->SetLineColor(lineColor);
156 : 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
157 : 0 : pXFStyleManager->AddStyle(m_pAreaStyle);
158 : 0 : }
159 : :
160 : 0 : enumXFStyle XFDrawStyle::GetStyleFamily()
161 : : {
162 : 0 : return enumXFStyleGraphics;
163 : : }
164 : :
165 : : /**************************************************************************
166 : : *************************************************************************/
167 : 0 : void XFDrawStyle::ToXml(IXFStream *pStrm)
168 : : {
169 : 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
170 : :
171 : 0 : pAttrList->Clear();
172 : :
173 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:name"), GetStyleName() );
174 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:family"), A2OUSTR("graphics") );
175 [ # # ]: 0 : pStrm->StartElement( A2OUSTR("style:style") );
176 : :
177 : 0 : pAttrList->Clear();
178 : :
179 [ # # ]: 0 : if( m_eWrap == enumXFWrapBackground )
180 : : {
181 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:run-through"), A2OUSTR("background") );
182 : : }
183 : : else
184 : : {
185 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:run-through"), A2OUSTR("foreground") );
186 : :
187 [ # # ]: 0 : if( m_eWrap == enumXFWrapNone )
188 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:wrap"), A2OUSTR("none") );
189 [ # # ]: 0 : else if( m_eWrap == enumXFWrapLeft )
190 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:wrap"), A2OUSTR("left") );
191 [ # # ]: 0 : else if( m_eWrap == enumXFWrapRight )
192 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:wrap"), A2OUSTR("right") );
193 [ # # ]: 0 : else if( m_eWrap == enumXFWrapParallel )
194 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:wrap"), A2OUSTR("parallel") );
195 [ # # ]: 0 : else if( m_eWrap == enumXFWrapRunThrough )
196 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:wrap"), A2OUSTR("run-through") );
197 [ # # ]: 0 : else if( m_eWrap == enumXFWrapBest )
198 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:wrap"), A2OUSTR("dynamic") );
199 : : }
200 : :
201 : : //line style:
202 [ # # ]: 0 : if( m_pLineStyle )
203 : : {
204 : : //1. if is a dash style, register the stroke-dash style first.
205 [ # # ]: 0 : if( !m_pLineStyle->IsSolid() )
206 : : {
207 : : // pAttrList->Clear();
208 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:stroke"), A2OUSTR("dash") );
209 [ # # ][ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:stroke-dash"), m_pLineStyle->GetStyleName() );
210 : : }
211 : : else
212 : : {
213 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:stroke"), A2OUSTR("solid") );
214 : : }
215 : :
216 [ # # ]: 0 : if( m_pLineStyle->GetWidth() > 0 )
217 [ # # ][ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("svg:stroke-width"), DoubleToOUString(m_pLineStyle->GetWidth()) + A2OUSTR("cm") );
218 : :
219 : 0 : XFColor color = m_pLineStyle->GetColor();
220 [ # # ]: 0 : if( color.IsValid() )
221 [ # # ][ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("svg:stroke-color"), color.ToString() );
222 : :
223 [ # # ]: 0 : if( m_pLineStyle->GetTransparency()>0 )
224 [ # # ][ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("svg:stroke-opacity"), Int32ToOUString(m_pLineStyle->GetTransparency()) + A2OUSTR("%") );
225 : : }
226 : : else
227 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:stroke"), A2OUSTR("none") );
228 : : //area style:
229 [ # # ]: 0 : if( m_pAreaStyle )
230 : : {
231 [ # # ]: 0 : if( enumXFAreaSolid == m_pAreaStyle->GetAreaStyle() )
232 : : {
233 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:fill"), A2OUSTR("solid") );
234 : 0 : XFColor color = m_pAreaStyle->GetBackColor();
235 [ # # ]: 0 : if( color.IsValid() )
236 [ # # ][ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:fill-color"), color.ToString() );
237 : : }
238 [ # # ]: 0 : else if( enumXFAreaHatch == m_pAreaStyle->GetAreaStyle() )
239 : : {
240 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:fill"), A2OUSTR("hatch") );
241 [ # # ][ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:fill-hatch-name"), m_pAreaStyle->GetStyleName() );
242 : 0 : XFColor color = m_pAreaStyle->GetBackColor();
243 [ # # ]: 0 : if( color.IsValid() )
244 : : {
245 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:fill-hatch-solid"), A2OUSTR("true") );
246 [ # # ][ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:fill-color"), color.ToString() );
247 : : }
248 : : }
249 : : }
250 : : else
251 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:fill"), A2OUSTR("none") );
252 : :
253 [ # # ]: 0 : if( !m_strArrowStart.isEmpty() )
254 : : {
255 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:marker-start"), m_strArrowStart );
256 [ # # ][ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:marker-start-width"), DoubleToOUString(m_fArrowStartSize)+A2OUSTR("cm") );
257 [ # # ]: 0 : if( m_bArrowStartCenter )
258 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:draw:marker-start-center"), A2OUSTR("true") );
259 : : }
260 [ # # ]: 0 : if( !m_strArrowEnd.isEmpty() )
261 : : {
262 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:marker-end"), m_strArrowEnd );
263 [ # # ][ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:marker-end-width"), DoubleToOUString(m_fArrowEndSize)+A2OUSTR("cm") );
264 [ # # ]: 0 : if( m_bArrowEndCenter )
265 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("draw:draw:marker-end-center"), A2OUSTR("true") );
266 : : }
267 [ # # ]: 0 : if (m_pFontWorkStyle)
268 : : {
269 : : // style
270 : 0 : rtl::OUString aStr = A2OUSTR("");
271 [ # # # # : 0 : switch (m_pFontWorkStyle->GetStyleType())
# ]
272 : : {
273 : : default: // fall through!
274 : : case enumXFFWOff:
275 : 0 : break;
276 : : case enumXFFWRotate:
277 : 0 : aStr = A2OUSTR("rotate");
278 : 0 : break;
279 : : case enumXFFWUpright:
280 : 0 : aStr = A2OUSTR("upright");
281 : 0 : break;
282 : : case enumXFFWSlantX:
283 : 0 : aStr = A2OUSTR("slant-x");
284 : 0 : break;
285 : : case enumXFFWSlantY:
286 : 0 : aStr = A2OUSTR("slant-y");
287 : 0 : break;
288 : : }
289 [ # # ]: 0 : if (!aStr.isEmpty())
290 : : {
291 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("draw:fontwork-style"), aStr);
292 : : }
293 : :
294 : : //adjust
295 : 0 : aStr = A2OUSTR("");
296 [ # # # # ]: 0 : switch (m_pFontWorkStyle->GetAdjustType())
297 : : {
298 : : default: // fall througth
299 : : case enumXFFWAdjustAutosize:
300 : 0 : aStr = A2OUSTR("autosize");
301 : 0 : break;
302 : : case enumXFFWAdjustLeft:
303 : 0 : aStr = A2OUSTR("left");
304 : 0 : break;
305 : : case enumXFFWAdjustCenter:
306 : 0 : aStr = A2OUSTR("center");
307 : 0 : break;
308 : : case enumXFFWAdustRight:
309 : 0 : aStr = A2OUSTR("right");
310 : 0 : break;
311 : : }
312 [ # # ]: 0 : if (!aStr.isEmpty())
313 : : {
314 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("draw:fontwork-adjust"), aStr);
315 : : }
316 : :
317 : : //form
318 : 0 : aStr = A2OUSTR("");
319 [ # # # ]: 0 : switch (m_pFontWorkStyle->GetButtonForm())
320 : : {
321 : : default: // fall through!
322 : : case -1:
323 : 0 : break;
324 : : case 4:
325 : 0 : aStr = A2OUSTR("top-arc");
326 : 0 : break;
327 : : case 5:
328 : 0 : aStr = A2OUSTR("bottom-arc");
329 : 0 : break;
330 : : }
331 [ # # ]: 0 : if (!aStr.isEmpty())
332 : : {
333 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("draw:fontwork-form"), aStr);
334 : 0 : }
335 : :
336 : : // distance
337 : : //pAttrList->AddAttribute(A2OUSTR("draw:fontwork-distance"),
338 : : // DoubleToOUString(m_pFontWorkStyle->GetFWDistance())+A2OUSTR("cm"));
339 : : }
340 : :
341 [ # # ]: 0 : pStrm->StartElement( A2OUSTR("style:properties") );
342 : :
343 [ # # ]: 0 : pStrm->EndElement( A2OUSTR("style:properties") );
344 : :
345 [ # # ]: 0 : pStrm->EndElement( A2OUSTR("style:style") );
346 : 0 : }
347 : :
348 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|