Debian Codegraph @

src/lib/RVNGSVGPresentationGenerator.cpp

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* librevenge
3 * Version: MPL 2.0 / LGPLv2.1+
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * Alternatively, the contents of this file may be used under the terms
10 * of the GNU Lesser General Public License Version 2.1 or later
11 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
12 * applicable instead of those above.
13 */
14
15 #include <librevenge-generators/librevenge-generators.h>
16
17 #include <locale.h>
18
19 #include <iostream>
20 #include <map>
21 #include <memory>
22 #include <sstream>
23 #include <string>
24 #include <vector>
25
26 #include "librevenge_internal.h"
27
28 namespace librevenge
29 {
30
31 namespace PresentationSVG
32 {
33
34 static double getInchValue(librevenge::RVNGProperty const &prop)
35 {
36 double value=prop.getDouble();
37 switch (prop.getUnit())
38 {
39 case librevenge::RVNG_GENERIC: // assume inch
40 case librevenge::RVNG_INCH:
41 return value;
42 case librevenge::RVNG_POINT:
43 value /= 72.;
44 return value;
45 case librevenge::RVNG_TWIP:
46 value /= 1440.;
47 return value;
48 case librevenge::RVNG_PERCENT:
49 case librevenge::RVNG_UNIT_ERROR:
50 default:
51 {
52 static bool first=true;
53 if (first)
54 {
55 RVNG_DEBUG_MSG(("librevenge::getInchValue: call with no double value\n"));
56 first=false;
57 }
58 break;
59 }
60 }
61 return value;
62 }
63
64 static std::string doubleToString(const double value)
65 {
66 std::unique_ptr<RVNGProperty> prop{RVNGPropertyFactory::newDoubleProp(value)};
67 std::string retVal = prop->getStr().cstr();
68 return retVal;
69 }
70
71 static unsigned stringToColour(const RVNGString &s)
72 {
73 std::string str(s.cstr());
74 if (str[0] == '#')
75 {
76 if (str.length() != 7)
77 return 0;
78 else
79 str.erase(str.begin());
80 }
81 else
82 return 0;
83
84 std::istringstream istr(str);
85 unsigned val = 0;
86 istr >> std::hex >> val;
87 return val;
88 }
89
90 //! basic class used to store table information
91 struct Table
92 {
93 //! constructor
94 Table(const RVNGPropertyList &propList) : m_column(0), m_row(0), m_x(0), m_y(0), m_columnsDistanceFromOrigin(), m_rowsDistanceFromOrigin()
95 {
96 if (propList["svg:x"])
97 m_x=getInchValue(*propList["svg:x"]);
98 if (propList["svg:y"])
99 m_y=getInchValue(*propList["svg:y"]);
100 // we do not actually use height/width, so...
101
102 m_columnsDistanceFromOrigin.push_back(0);
103 m_rowsDistanceFromOrigin.push_back(0);
104
105 const librevenge::RVNGPropertyListVector *columns = propList.child("librevenge:table-columns");
106 if (columns)
107 {
108 double actDist=0;
109 for (unsigned long i=0; i<columns->count(); ++i)
110 {
111 if ((*columns)[i]["style:column-width"])
112 actDist+=getInchValue(*(*columns)[i]["style:column-width"]);
113 m_columnsDistanceFromOrigin.push_back(actDist);
114 }
115 }
116 else
117 {
118 RVNG_DEBUG_MSG(("librevenge::DrawingSVG::Table::Table: can not find any columns\n"));
119 }
120 }
121 //! calls to open a row
122 void openRow(const RVNGPropertyList &propList)
123 {
124 double height=0;
125 if (propList["style:row-height"])
126 height=getInchValue(*propList["style:row-height"]);
127 // changeme
128 else if (propList["style:min-row-height"])
129 height=getInchValue(*propList["style:min-row-height"]);
130 else
131 {
132 RVNG_DEBUG_MSG(("librevenge::DrawingSVG::Table::openRow: can not determine row height\n"));
133 }
134 m_rowsDistanceFromOrigin.push_back(m_rowsDistanceFromOrigin.back()+height);
135 }
136 //! call to close a row
137 void closeRow()
138 {
139 ++m_row;
140 }
141 //! returns the position of a cellule
142 bool getPosition(int column, int row, double &x, double &y) const
143 {
144 bool ok=true;
145 if (column>=0 && column <int(m_columnsDistanceFromOrigin.size()))
146 x=m_x+m_columnsDistanceFromOrigin[size_t(column)];
147 else
148 {
149 ok=false;
150 RVNG_DEBUG_MSG(("librevenge::DrawingSVG::Table::getPosition: the column %d seems bad\n", column));
151 x=(column<0 || m_columnsDistanceFromOrigin.empty()) ? m_x : m_x + m_columnsDistanceFromOrigin.back();
152 }
153 if (row>=0 && row <int(m_rowsDistanceFromOrigin.size()))
154 y=m_y+m_rowsDistanceFromOrigin[size_t(row)];
155 else
156 {
157 ok=false;
158 RVNG_DEBUG_MSG(("librevenge::DrawingSVG::Table::getPosition: the row %d seems bad\n", row));
159 y=(row<0 || m_rowsDistanceFromOrigin.empty()) ? m_y : m_y + m_rowsDistanceFromOrigin.back();
160 }
161 return ok;
162 }
163 //! the actual column
164 int m_column;
165 //! the actual row
166 int m_row;
167 //! the origin table position in inches
168 double m_x, m_y;
169 //! the distance of each begin column in inches from origin
170 std::vector<double> m_columnsDistanceFromOrigin;
171 //! the distance of each begin row in inches from origin
172 std::vector<double> m_rowsDistanceFromOrigin;
173 };
174
175 } // PresentationSVG namespace
176
177 using namespace PresentationSVG;
178
179 struct RVNGSVGPresentationGeneratorImpl
180 {
181 RVNGSVGPresentationGeneratorImpl(RVNGStringVector &m_vec);
182
183 std::map<int, RVNGPropertyList> m_idSpanMap;
184
185 RVNGPropertyListVector m_gradient;
186 RVNGPropertyList m_style;
187 int m_gradientIndex;
188 int m_patternIndex;
189 int m_arrowStartIndex /** start arrow index*/, m_arrowEndIndex /** end arrow index */;
190 //! layerId used if svg:id is not defined when calling startLayer
191 int m_layerId;
192 int m_shadowIndex;
193
194 void writeStyle(bool isClosed=true);
195 void drawPolySomething(const RVNGPropertyListVector &vertices, bool isClosed);
196
197 std::ostringstream m_outputSink;
198 RVNGStringVector &m_vec;
199 //! the actual master name
200 RVNGString m_masterName;
201 //! a map master name to master content
202 std::map<RVNGString, std::string> m_masterNameToContentMap;
203 //! the actual opened table
204 std::shared_ptr<Table> m_table;
205 };
206
207 RVNGSVGPresentationGeneratorImpl::RVNGSVGPresentationGeneratorImpl(RVNGStringVector &vec)
208 : m_idSpanMap()
209 , m_gradient()
210 , m_style()
211 , m_gradientIndex(1)
212 , m_patternIndex(1)
213 , m_arrowStartIndex(1)
214 , m_arrowEndIndex(1)
215 , m_layerId(1000)
216 , m_shadowIndex(1)
217 , m_outputSink()
218 , m_vec(vec)
219 , m_masterName(), m_masterNameToContentMap()
220 , m_table()
221 {
222 }
223
224 RVNGSVGPresentationGenerator::RVNGSVGPresentationGenerator(RVNGStringVector &vec)
225 : m_impl(new RVNGSVGPresentationGeneratorImpl(vec))
226 {
227 }
228
229 RVNGSVGPresentationGenerator::~RVNGSVGPresentationGenerator()
230 {
231 delete m_impl;
232 }
233
234 void RVNGSVGPresentationGenerator::startDocument(const RVNGPropertyList &)
235 {
236 }
237
238 void RVNGSVGPresentationGenerator::endDocument()
239 {
240 }
241
242 void RVNGSVGPresentationGenerator::setDocumentMetaData(const RVNGPropertyList &)
243 {
244 }
245
246 void RVNGSVGPresentationGenerator::defineEmbeddedFont(const RVNGPropertyList &)
247 {
248 }
249
250 void RVNGSVGPresentationGenerator::startSlide(const RVNGPropertyList &propList)
251 {
252 if (propList["librevenge:master-page-name"])
253 {
254 if (m_impl->m_masterNameToContentMap.find(propList["librevenge:master-page-name"]->getStr())!=
255 m_impl->m_masterNameToContentMap.end())
256 {
257 m_impl->m_outputSink << m_impl->m_masterNameToContentMap.find(propList["librevenge:master-page-name"]->getStr())->second;
258 return;
259 }
260 RVNG_DEBUG_MSG(("RVNGSVGPresentationGenerator::startSlide: can not find master slide with given master name\n"));
261 }
262
263 m_impl->m_outputSink << "<svg:svg version=\"1.1\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" ";
264 if (propList["svg:width"])
265 m_impl->m_outputSink << "width=\"" << doubleToString(72*getInchValue(*propList["svg:width"])) << "\" ";
266 if (propList["svg:height"])
267 m_impl->m_outputSink << "height=\"" << doubleToString(72*getInchValue(*propList["svg:height"])) << "\"";
268 m_impl->m_outputSink << " >\n";
269 }
270
271 void RVNGSVGPresentationGenerator::endSlide()
272 {
273 m_impl->m_outputSink << "</svg:svg>\n";
274 m_impl->m_vec.append(m_impl->m_outputSink.str().c_str());
275 m_impl->m_outputSink.str("");
276 }
277
278 void RVNGSVGPresentationGenerator::startMasterSlide(const RVNGPropertyList &propList)
279 {
280 if (!m_impl->m_masterName.empty())
281 {
282 RVNG_DEBUG_MSG(("RVNGSVGPresentationGenerator::startMasterSlide: a master slide is already opened\n"));
283 }
284 else if (propList["librevenge:master-page-name"])
285 {
286 m_impl->m_masterName=propList["librevenge:master-page-name"]->getStr();
287 RVNGPropertyList pList(propList);
288 pList.remove("librevenge:master-page-name");
289 startSlide(pList);
290 }
291 else
292 {
293 RVNG_DEBUG_MSG(("RVNGSVGPresentationGenerator::startMasterSlide: can not find the master name\n"));
294 }
295 }
296
297 void RVNGSVGPresentationGenerator::endMasterSlide()
298 {
299 if (m_impl->m_masterName.empty())
300 {
301 RVNG_DEBUG_MSG(("RVNGSVGPresentationGenerator::endMasterSlide: no master slides are opened\n"));
302 }
303 else
304 {
305 if (m_impl->m_masterNameToContentMap.find(m_impl->m_masterName)!=m_impl->m_masterNameToContentMap.end())
306 {
307 RVNG_DEBUG_MSG(("RVNGSVGPresentationGenerator::endMasterSlide: a master slide with name %s already exists\n",
308 m_impl->m_masterName.cstr()));
309 }
310 // no need to close the page, this will be done when the master page will be used
311 m_impl->m_masterNameToContentMap[m_impl->m_masterName]=m_impl->m_outputSink.str();
312 m_impl->m_masterName.clear();
313 }
314 // reset the content
315 m_impl->m_outputSink.str("");
316 }
317
318 void RVNGSVGPresentationGenerator::setSlideTransition(const RVNGPropertyList &)
319 {
320 }
321
322 void RVNGSVGPresentationGenerator::setStyle(const RVNGPropertyList &propList)
323 {
324 m_impl->m_style.clear();
325 m_impl->m_style = propList;
326
327 const librevenge::RVNGPropertyListVector *gradient = propList.child("svg:linearGradient");
328 if (!gradient)
329 gradient = propList.child("svg:radialGradient");
330 m_impl->m_gradient = gradient ? *gradient : librevenge::RVNGPropertyListVector();
331 if (m_impl->m_style["draw:shadow"] && m_impl->m_style["draw:shadow"]->getStr() == "visible")
332 {
333 double shadowRed = 0.0;
334 double shadowGreen = 0.0;
335 double shadowBlue = 0.0;
336 if (m_impl->m_style["draw:shadow-color"])
337 {
338 const unsigned shadowColour = stringToColour(m_impl->m_style["draw:shadow-color"]->getStr());
339 shadowRed = (double)((shadowColour & 0x00ff0000) >> 16)/255.0;
340 shadowGreen = (double)((shadowColour & 0x0000ff00) >> 8)/255.0;
341 shadowBlue = (double)(shadowColour & 0x000000ff)/255.0;
342 }
343 m_impl->m_outputSink << "<svg:defs>\n";
344 m_impl->m_outputSink << "<svg:filter filterUnits=\"userSpaceOnUse\" id=\"shadow" << m_impl->m_shadowIndex++ << "\">";
345 m_impl->m_outputSink << "<svg:feOffset in=\"SourceGraphic\" result=\"offset\" ";
346 if (m_impl->m_style["draw:shadow-offset-x"])
347 m_impl->m_outputSink << "dx=\"" << doubleToString(72*getInchValue(*m_impl->m_style["draw:shadow-offset-x"])) << "\" ";
348 if (m_impl->m_style["draw:shadow-offset-y"])
349 m_impl->m_outputSink << "dy=\"" << doubleToString(72*getInchValue(*m_impl->m_style["draw:shadow-offset-y"])) << "\" ";
350 m_impl->m_outputSink << "/>";
351 m_impl->m_outputSink << "<svg:feColorMatrix in=\"offset\" result=\"offset-color\" type=\"matrix\" values=\"";
352 m_impl->m_outputSink << "0 0 0 0 " << doubleToString(shadowRed) ;
353 m_impl->m_outputSink << " 0 0 0 0 " << doubleToString(shadowGreen);
354 m_impl->m_outputSink << " 0 0 0 0 " << doubleToString(shadowBlue);
355 if (m_impl->m_style["draw:opacity"] && m_impl->m_style["draw:opacity"]->getDouble() < 1)
356 m_impl->m_outputSink << " 0 0 0 " << doubleToString(m_impl->m_style["draw:shadow-opacity"]->getDouble()/m_impl->m_style["draw:opacity"]->getDouble()) << " 0\"/>";
357 else
358 m_impl->m_outputSink << " 0 0 0 " << doubleToString(m_impl->m_style["draw:shadow-opacity"]->getDouble()) << " 0\"/>";
359 m_impl->m_outputSink << "<svg:feMerge><svg:feMergeNode in=\"offset-color\" /><svg:feMergeNode in=\"SourceGraphic\" /></svg:feMerge></svg:filter></svg:defs>";
360 }
361
362 if (m_impl->m_style["draw:fill"] && m_impl->m_style["draw:fill"]->getStr() == "gradient")
363 {
364 double angle = (m_impl->m_style["draw:angle"] ? m_impl->m_style["draw:angle"]->getDouble() : 0.0);
365 angle *= -1.0;
366 while (angle < 0)
367 angle += 360;
368 while (angle > 360)
369 angle -= 360;
370
371 if (!m_impl->m_gradient.count())
372 {
373 if (m_impl->m_style["draw:style"] &&
374 (m_impl->m_style["draw:style"]->getStr() == "radial" ||
375 m_impl->m_style["draw:style"]->getStr() == "rectangular" ||
376 m_impl->m_style["draw:style"]->getStr() == "square" ||
377 m_impl->m_style["draw:style"]->getStr() == "ellipsoid"))
378 {
379 m_impl->m_outputSink << "<svg:defs>\n";
380 m_impl->m_outputSink << " <svg:radialGradient id=\"grad" << m_impl->m_gradientIndex++ << "\"";
381
382 if (m_impl->m_style["svg:cx"])
383 m_impl->m_outputSink << " cx=\"" << m_impl->m_style["svg:cx"]->getStr().cstr() << "\"";
384 else if (m_impl->m_style["draw:cx"])
385 m_impl->m_outputSink << " cx=\"" << m_impl->m_style["draw:cx"]->getStr().cstr() << "\"";
386
387 if (m_impl->m_style["svg:cy"])
388 m_impl->m_outputSink << " cy=\"" << m_impl->m_style["svg:cy"]->getStr().cstr() << "\"";
389 else if (m_impl->m_style["draw:cy"])
390 m_impl->m_outputSink << " cy=\"" << m_impl->m_style["draw:cy"]->getStr().cstr() << "\"";
391 m_impl->m_outputSink << " r=\"" << (1 - (m_impl->m_style["draw:border"] ? m_impl->m_style["draw:border"]->getDouble() : 0))*100.0 << "%\" >\n";
392 m_impl->m_outputSink << " >\n";
393
394 if (m_impl->m_style["draw:start-color"] && m_impl->m_style["draw:end-color"])
395 {
396 m_impl->m_outputSink << " <svg:stop offset=\"0%\"";
397 m_impl->m_outputSink << " stop-color=\"" << m_impl->m_style["draw:end-color"]->getStr().cstr() << "\"";
398 m_impl->m_outputSink << " stop-opacity=\"" << (m_impl->m_style["librevenge:end-opacity"] ? m_impl->m_style["librevenge:end-opacity"]->getDouble() : 1) << "\" />" << std::endl;
399
400 m_impl->m_outputSink << " <svg:stop offset=\"100%\"";
401 m_impl->m_outputSink << " stop-color=\"" << m_impl->m_style["draw:start-color"]->getStr().cstr() << "\"";
402 m_impl->m_outputSink << " stop-opacity=\"" << (m_impl->m_style["librevenge:start-opacity"] ? m_impl->m_style["librevenge:start-opacity"]->getDouble() : 1) << "\" />" << std::endl;
403 }
404 m_impl->m_outputSink << " </svg:radialGradient>\n";
405 m_impl->m_outputSink << "</svg:defs>\n";
406 }
407 else if (m_impl->m_style["draw:style"] && m_impl->m_style["draw:style"]->getStr() == "linear")
408 {
409 m_impl->m_outputSink << "<svg:defs>\n";
410 m_impl->m_outputSink << " <svg:linearGradient id=\"grad" << m_impl->m_gradientIndex++ << "\" >\n";
411
412 if (m_impl->m_style["draw:start-color"] && m_impl->m_style["draw:end-color"])
413 {
414 m_impl->m_outputSink << " <svg:stop offset=\"0%\"";
415 m_impl->m_outputSink << " stop-color=\"" << m_impl->m_style["draw:start-color"]->getStr().cstr() << "\"";
416 m_impl->m_outputSink << " stop-opacity=\"" << (m_impl->m_style["librevenge:start-opacity"] ? m_impl->m_style["librevenge:start-opacity"]->getDouble() : 1) << "\" />" << std::endl;
417
418 m_impl->m_outputSink << " <svg:stop offset=\"100%\"";
419 m_impl->m_outputSink << " stop-color=\"" << m_impl->m_style["draw:end-color"]->getStr().cstr() << "\"";
420 m_impl->m_outputSink << " stop-opacity=\"" << (m_impl->m_style["librevenge:end-opacity"] ? m_impl->m_style["librevenge:end-opacity"]->getDouble() : 1) << "\" />" << std::endl;
421 }
422 m_impl->m_outputSink << " </svg:linearGradient>\n";
423
424 // not a simple horizontal gradient
425 if (angle < 270 || angle > 270)
426 {
427 m_impl->m_outputSink << " <svg:linearGradient xlink:href=\"#grad" << m_impl->m_gradientIndex-1 << "\"";
428 m_impl->m_outputSink << " id=\"grad" << m_impl->m_gradientIndex++ << "\" ";
429 m_impl->m_outputSink << "x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\" ";
430 m_impl->m_outputSink << "gradientTransform=\"rotate(" << angle << " .5 .5)\" ";
431 m_impl->m_outputSink << "gradientUnits=\"objectBoundingBox\" >\n";
432 m_impl->m_outputSink << " </svg:linearGradient>\n";
433 }
434
435 m_impl->m_outputSink << "</svg:defs>\n";
436 }
437 else if (m_impl->m_style["draw:style"] && m_impl->m_style["draw:style"]->getStr() == "axial")
438 {
439 m_impl->m_outputSink << "<svg:defs>\n";
440 m_impl->m_outputSink << " <svg:linearGradient id=\"grad" << m_impl->m_gradientIndex++ << "\" >\n";
441
442 if (m_impl->m_style["draw:start-color"] && m_impl->m_style["draw:end-color"])
443 {
444 m_impl->m_outputSink << " <svg:stop offset=\"0%\"";
445 m_impl->m_outputSink << " stop-color=\"" << m_impl->m_style["draw:end-color"]->getStr().cstr() << "\"";
446 m_impl->m_outputSink << " stop-opacity=\"" << (m_impl->m_style["librevenge:end-opacity"] ? m_impl->m_style["librevenge:end-opacity"]->getDouble() : 1) << "\" />" << std::endl;
447
448 m_impl->m_outputSink << " <svg:stop offset=\"50%\"";
449 m_impl->m_outputSink << " stop-color=\"" << m_impl->m_style["draw:start-color"]->getStr().cstr() << "\"";
450 m_impl->m_outputSink << " stop-opacity=\"" << (m_impl->m_style["librevenge:start-opacity"] ? m_impl->m_style["librevenge:start-opacity"]->getDouble() : 1) << "\" />" << std::endl;
451
452 m_impl->m_outputSink << " <svg:stop offset=\"100%\"";
453 m_impl->m_outputSink << " stop-color=\"" << m_impl->m_style["draw:end-color"]->getStr().cstr() << "\"";
454 m_impl->m_outputSink << " stop-opacity=\"" << (m_impl->m_style["librevenge:end-opacity"] ? m_impl->m_style["librevenge:end-opacity"]->getDouble() : 1) << "\" />" << std::endl;
455 }
456 m_impl->m_outputSink << " </svg:linearGradient>\n";
457
458 // not a simple horizontal gradient
459 if (angle < 270 || angle > 270)
460 {
461 m_impl->m_outputSink << " <svg:linearGradient xlink:href=\"#grad" << m_impl->m_gradientIndex-1 << "\"";
462 m_impl->m_outputSink << " id=\"grad" << m_impl->m_gradientIndex++ << "\" ";
463 m_impl->m_outputSink << "x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\" ";
464 m_impl->m_outputSink << "gradientTransform=\"rotate(" << angle << " .5 .5)\" ";
465 m_impl->m_outputSink << "gradientUnits=\"objectBoundingBox\" >\n";
466 m_impl->m_outputSink << " </svg:linearGradient>\n";
467 }
468
469 m_impl->m_outputSink << "</svg:defs>\n";
470 }
471 }
472 else
473 {
474 if (m_impl->m_style["draw:style"] && m_impl->m_style["draw:style"]->getStr() == "radial")
475 {
476 m_impl->m_outputSink << "<svg:defs>\n";
477 m_impl->m_outputSink << " <svg:radialGradient id=\"grad" << m_impl->m_gradientIndex++ << "\" cx=\"" << m_impl->m_style["svg:cx"]->getStr().cstr() << "\" cy=\"" << m_impl->m_style["svg:cy"]->getStr().cstr() << "\" r=\"" << m_impl->m_style["svg:r"]->getStr().cstr() << "\" >\n";
478 for (unsigned long c = 0; c < m_impl->m_gradient.count(); c++)
479 {
480 m_impl->m_outputSink << " <svg:stop offset=\"" << m_impl->m_gradient[c]["svg:offset"]->getStr().cstr() << "\"";
481
482 m_impl->m_outputSink << " stop-color=\"" << m_impl->m_gradient[c]["svg:stop-color"]->getStr().cstr() << "\"";
483 m_impl->m_outputSink << " stop-opacity=\"" << m_impl->m_gradient[c]["svg:stop-opacity"]->getDouble() << "\" />" << std::endl;
484
485 }
486 m_impl->m_outputSink << " </svg:radialGradient>\n";
487 m_impl->m_outputSink << "</svg:defs>\n";
488 }
489 else
490 {
491 m_impl->m_outputSink << "<svg:defs>\n";
492 m_impl->m_outputSink << " <svg:linearGradient id=\"grad" << m_impl->m_gradientIndex++ << "\" >\n";
493 for (unsigned long c = 0; c < m_impl->m_gradient.count(); c++)
494 {
495 m_impl->m_outputSink << " <svg:stop offset=\"" << m_impl->m_gradient[c]["svg:offset"]->getStr().cstr() << "\"";
496
497 m_impl->m_outputSink << " stop-color=\"" << m_impl->m_gradient[c]["svg:stop-color"]->getStr().cstr() << "\"";
498 m_impl->m_outputSink << " stop-opacity=\"" << m_impl->m_gradient[c]["svg:stop-opacity"]->getDouble() << "\" />" << std::endl;
499
500 }
501 m_impl->m_outputSink << " </svg:linearGradient>\n";
502
503 // not a simple horizontal gradient
504 if (angle < 270 || angle > 270)
505 {
506 m_impl->m_outputSink << " <svg:linearGradient xlink:href=\"#grad" << m_impl->m_gradientIndex-1 << "\"";
507 m_impl->m_outputSink << " id=\"grad" << m_impl->m_gradientIndex++ << "\" ";
508 m_impl->m_outputSink << "x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\" ";
509 m_impl->m_outputSink << "gradientTransform=\"rotate(" << angle << " .5 .5)\" ";
510 m_impl->m_outputSink << "gradientUnits=\"objectBoundingBox\" >\n";
511 m_impl->m_outputSink << " </svg:linearGradient>\n";
512 }
513
514 m_impl->m_outputSink << "</svg:defs>\n";
515 }
516 }
517 }
518 else if (m_impl->m_style["draw:fill"] && m_impl->m_style["draw:fill"]->getStr() == "bitmap")
519 {
520 if (m_impl->m_style["draw:fill-image"] && m_impl->m_style["librevenge:mime-type"])
521 {
522 m_impl->m_outputSink << "<svg:defs>\n";
523 m_impl->m_outputSink << " <svg:pattern id=\"img" << m_impl->m_patternIndex++ << "\" patternUnits=\"userSpaceOnUse\" ";
524 if (m_impl->m_style["svg:width"])
525 m_impl->m_outputSink << "width=\"" << doubleToString(72*getInchValue(*m_impl->m_style["svg:width"])) << "\" ";
526 else
527 m_impl->m_outputSink << "width=\"100\" ";
528
529 if (m_impl->m_style["svg:height"])
530 m_impl->m_outputSink << "height=\"" << doubleToString(72*getInchValue(*m_impl->m_style["svg:height"])) << "\">" << std::endl;
531 else
532 m_impl->m_outputSink << "height=\"100\">" << std::endl;
533 m_impl->m_outputSink << "<svg:image ";
534
535 if (m_impl->m_style["svg:x"])
536 m_impl->m_outputSink << "x=\"" << doubleToString(72*getInchValue(*m_impl->m_style["svg:x"])) << "\" ";
537 else
538 m_impl->m_outputSink << "x=\"0\" ";
539
540 if (m_impl->m_style["svg:y"])
541 m_impl->m_outputSink << "y=\"" << doubleToString(72*getInchValue(*m_impl->m_style["svg:y"])) << "\" ";
542 else
543 m_impl->m_outputSink << "y=\"0\" ";
544
545 if (m_impl->m_style["svg:width"])
546 m_impl->m_outputSink << "width=\"" << doubleToString(72*getInchValue(*m_impl->m_style["svg:width"])) << "\" ";
547 else
548 m_impl->m_outputSink << "width=\"100\" ";
549
550 if (m_impl->m_style["svg:height"])
551 m_impl->m_outputSink << "height=\"" << doubleToString(72*getInchValue(*m_impl->m_style["svg:height"])) << "\" ";
552 else
553 m_impl->m_outputSink << "height=\"100\" ";
554
555 m_impl->m_outputSink << "xlink:href=\"data:" << m_impl->m_style["librevenge:mime-type"]->getStr().cstr() << ";base64,";
556 m_impl->m_outputSink << m_impl->m_style["draw:fill-image"]->getStr().cstr();
557 m_impl->m_outputSink << "\" />\n";
558 m_impl->m_outputSink << " </svg:pattern>\n";
559 m_impl->m_outputSink << "</svg:defs>\n";
560 }
561 }
562 }
563
564 void RVNGSVGPresentationGenerator::startLayer(const RVNGPropertyList &propList)
565 {
566 m_impl->m_outputSink << "<svg:g";
567 librevenge::RVNGString layer("Layer");
568 if (propList["draw:layer"])
569 layer.append(propList["draw:layer"]->getStr());
570 else if (propList["svg:id"])
571 layer.append(propList["svg:id"]->getStr());
572 else
573 layer.sprintf("Layer%d", m_impl->m_layerId++);
574 librevenge::RVNGString finalName("");
575 finalName.appendEscapedXML(layer);
576 m_impl->m_outputSink << " id=\"" << finalName.cstr() << "\"";
577 if (propList["svg:fill-rule"])
578 m_impl->m_outputSink << " fill-rule=\"" << propList["svg:fill-rule"]->getStr().cstr() << "\"";
579 m_impl->m_outputSink << " >\n";
580 }
581
582 void RVNGSVGPresentationGenerator::endLayer()
583 {
584 m_impl->m_outputSink << "</svg:g>\n";
585 }
586
587 void RVNGSVGPresentationGenerator::startEmbeddedGraphics(const RVNGPropertyList & /*propList*/)
588 {
589 }
590
591 void RVNGSVGPresentationGenerator::endEmbeddedGraphics()
592 {
593 }
594
595 void RVNGSVGPresentationGenerator::openGroup(const RVNGPropertyList &/*propList*/)
596 {
597 // TODO: handle svg:id
598 m_impl->m_outputSink << "<svg:g>\n";
599 }
600
601 void RVNGSVGPresentationGenerator::closeGroup()
602 {
603 m_impl->m_outputSink << "</svg:g>\n";
604 }
605
606 void RVNGSVGPresentationGenerator::drawRectangle(const RVNGPropertyList &propList)
607 {
608 if (!propList["svg:x"] || !propList["svg:y"] || !propList["svg:width"] || !propList["svg:height"])
609 return;
610 m_impl->m_outputSink << "<svg:rect ";
611 m_impl->m_outputSink << "x=\"" << doubleToString(72*getInchValue(*propList["svg:x"])) << "\" y=\"" << doubleToString(72*getInchValue(*propList["svg:y"])) << "\" ";
612 m_impl->m_outputSink << "width=\"" << doubleToString(72*getInchValue(*propList["svg:width"])) << "\" height=\"" << doubleToString(72*getInchValue(*propList["svg:height"])) << "\" ";
613 if ((propList["svg:rx"] && propList["svg:rx"]->getInt() !=0) || (propList["svg:ry"] && propList["svg:ry"]->getInt() !=0))
614 m_impl->m_outputSink << "rx=\"" << doubleToString(72*getInchValue(*propList["svg:rx"])) << "\" ry=\"" << doubleToString(72*getInchValue(*propList["svg:ry"])) << "\" ";
615 m_impl->writeStyle();
616 m_impl->m_outputSink << "/>\n";
617 }
618
619 void RVNGSVGPresentationGenerator::drawEllipse(const RVNGPropertyList &propList)
620 {
621 if (!propList["svg:cx"] || !propList["svg:cy"] || !propList["svg:rx"] || !propList["svg:ry"])
622 return;
623 m_impl->m_outputSink << "<svg:ellipse ";
624 m_impl->m_outputSink << "cx=\"" << doubleToString(72*getInchValue(*propList["svg:cx"])) << "\" cy=\"" << doubleToString(72*getInchValue(*propList["svg:cy"])) << "\" ";
625 m_impl->m_outputSink << "rx=\"" << doubleToString(72*getInchValue(*propList["svg:rx"])) << "\" ry=\"" << doubleToString(72*getInchValue(*propList["svg:ry"])) << "\" ";
626 m_impl->writeStyle();
627 if (propList["librevenge:rotate"] && (propList["librevenge:rotate"]->getDouble()<0||propList["librevenge:rotate"]->getDouble()>0))
628 m_impl->m_outputSink << " transform=\" rotate(" << doubleToString(-propList["librevenge:rotate"]->getDouble())
629 << ", " << doubleToString(72*getInchValue(*propList["svg:cx"]))
630 << ", " << doubleToString(72*getInchValue(*propList["svg:cy"]))
631 << ")\" ";
632 m_impl->m_outputSink << "/>\n";
633 }
634
635 void RVNGSVGPresentationGenerator::drawPolyline(const RVNGPropertyList &propList)
636 {
637 const RVNGPropertyListVector *vertices = propList.child("svg:points");
638 if (vertices && vertices->count())
639 m_impl->drawPolySomething(*vertices, false);
640 }
641
642 void RVNGSVGPresentationGenerator::drawPolygon(const RVNGPropertyList &propList)
643 {
644 const RVNGPropertyListVector *vertices = propList.child("svg:points");
645 if (vertices && vertices->count())
646 m_impl->drawPolySomething(*vertices, true);
647 }
648
649 void RVNGSVGPresentationGeneratorImpl::drawPolySomething(const RVNGPropertyListVector &vertices, bool isClosed)
650 {
651 if (vertices.count() < 2)
652 return;
653
654 if (vertices.count() == 2)
655 {
656 if (!vertices[0]["svg:x"]||!vertices[0]["svg:y"]||!vertices[1]["svg:x"]||!vertices[1]["svg:y"])
657 return;
658 m_outputSink << "<svg:line ";
659 m_outputSink << "x1=\"" << doubleToString(72*getInchValue(*vertices[0]["svg:x"])) << "\" y1=\"" << doubleToString(72*getInchValue(*vertices[0]["svg:y"])) << "\" ";
660 m_outputSink << "x2=\"" << doubleToString(72*getInchValue(*vertices[1]["svg:x"])) << "\" y2=\"" << doubleToString(72*getInchValue(*vertices[1]["svg:y"])) << "\"\n";
661 writeStyle();
662 m_outputSink << "/>\n";
663 }
664 else
665 {
666 if (isClosed)
667 m_outputSink << "<svg:polygon ";
668 else
669 m_outputSink << "<svg:polyline ";
670
671 m_outputSink << "points=\"";
672 for (unsigned long i = 0; i < vertices.count(); i++)
673 {
674 if (!vertices[i]["svg:x"]||!vertices[i]["svg:y"])
675 continue;
676 m_outputSink << doubleToString(72*getInchValue(*vertices[i]["svg:x"])) << " " << doubleToString(72*getInchValue(*vertices[i]["svg:y"]));
677 if (i < vertices.count()-1)
678 m_outputSink << ", ";
679 }
680 m_outputSink << "\"\n";
681 writeStyle(isClosed);
682 m_outputSink << "/>\n";
683 }
684 }
685
686 void RVNGSVGPresentationGenerator::drawPath(const RVNGPropertyList &propList)
687 {
688 const RVNGPropertyListVector *path = propList.child("svg:d");
689 if (!path)
690 return;
691 m_impl->m_outputSink << "<svg:path d=\" ";
692 bool isClosed = false;
693 unsigned long i=0;
694 for (i=0; i < path->count(); i++)
695 {
696 RVNGPropertyList pList((*path)[i]);
697 if (!pList["librevenge:path-action"]) continue;
698 std::string action=pList["librevenge:path-action"]->getStr().cstr();
699 if (action.length()!=1) continue;
700 bool coordOk=pList["svg:x"]&&pList["svg:y"];
701 bool coord1Ok=coordOk && pList["svg:x1"]&&pList["svg:y1"];
702 bool coord2Ok=coord1Ok && pList["svg:x2"]&&pList["svg:y2"];
703 if (pList["svg:x"] && action[0] == 'H')
704 m_impl->m_outputSink << "\nH" << doubleToString(72*getInchValue(*pList["svg:x"]));
705 else if (pList["svg:y"] && action[0] == 'V')
706 m_impl->m_outputSink << "\nV" << doubleToString(72*getInchValue(*pList["svg:y"]));
707 else if (coordOk && (action[0] == 'M' || action[0] == 'L' || action[0] == 'T'))
708 {
709 m_impl->m_outputSink << "\n" << action;
710 m_impl->m_outputSink << doubleToString(72*getInchValue(*pList["svg:x"])) << "," << doubleToString(72*getInchValue(*pList["svg:y"]));
711 }
712 else if (coord1Ok && (action[0] == 'Q' || action[0] == 'S'))
713 {
714 m_impl->m_outputSink << "\n" << action;
715 m_impl->m_outputSink << doubleToString(72*getInchValue(*pList["svg:x1"])) << "," << doubleToString(72*getInchValue(*pList["svg:y1"])) << " ";
716 m_impl->m_outputSink << doubleToString(72*getInchValue(*pList["svg:x"])) << "," << doubleToString(72*getInchValue(*pList["svg:y"]));
717 }
718 else if (coord2Ok && action[0] == 'C')
719 {
720 m_impl->m_outputSink << "\nC";
721 m_impl->m_outputSink << doubleToString(72*getInchValue(*pList["svg:x1"])) << "," << doubleToString(72*getInchValue(*pList["svg:y1"])) << " ";
722 m_impl->m_outputSink << doubleToString(72*getInchValue(*pList["svg:x2"])) << "," << doubleToString(72*getInchValue(*pList["svg:y2"])) << " ";
723 m_impl->m_outputSink << doubleToString(72*getInchValue(*pList["svg:x"])) << "," << doubleToString(72*getInchValue(*pList["svg:y"]));
724 }
725 else if (coordOk && pList["svg:rx"] && pList["svg:ry"] && action[0] == 'A')
726 {
727 m_impl->m_outputSink << "\nA";
728 m_impl->m_outputSink << doubleToString(72*getInchValue(*pList["svg:rx"])) << "," << doubleToString(72*getInchValue(*pList["svg:ry"])) << " ";
729 m_impl->m_outputSink << doubleToString(pList["librevenge:rotate"] ? pList["librevenge:rotate"]->getDouble() : 0) << " ";
730 m_impl->m_outputSink << (pList["librevenge:large-arc"] ? pList["librevenge:large-arc"]->getInt() : 1) << ",";
731 m_impl->m_outputSink << (pList["librevenge:sweep"] ? pList["librevenge:sweep"]->getInt() : 1) << " ";
732 m_impl->m_outputSink << doubleToString(72*getInchValue(*pList["svg:x"])) << "," << doubleToString(72*getInchValue(*pList["svg:y"]));
733 }
734 else if (action[0] == 'Z')
735 {
736 isClosed = true;
737 m_impl->m_outputSink << "\nZ";
738 }
739 }
740
741 m_impl->m_outputSink << "\" \n";
742 m_impl->writeStyle(isClosed);
743 m_impl->m_outputSink << "/>\n";
744 }
745
746 void RVNGSVGPresentationGenerator::drawGraphicObject(const RVNGPropertyList &propList)
747 {
748 if (!propList["librevenge:mime-type"] || propList["librevenge:mime-type"]->getStr().len() <= 0)
749 return;
750 if (!propList["office:binary-data"])
751 return;
752 m_impl->m_outputSink << "<svg:image ";
753 if (propList["svg:x"] && propList["svg:y"] && propList["svg:width"] && propList["svg:height"])
754 {
755 double x=getInchValue(*propList["svg:x"]);
756 double y=getInchValue(*propList["svg:y"]);
757 double width=getInchValue(*propList["svg:width"]);
758 double height=getInchValue(*propList["svg:height"]);
759 bool flipX(propList["draw:mirror-horizontal"] && propList["draw:mirror-horizontal"]->getInt());
760 bool flipY(propList["draw:mirror-vertical"] && propList["draw:mirror-vertical"]->getInt());
761
762 m_impl->m_outputSink << "x=\"" << doubleToString(72*x) << "\" y=\"" << doubleToString(72*y) << "\" ";
763 m_impl->m_outputSink << "width=\"" << doubleToString(72*width) << "\" height=\"" << doubleToString(72*height) << "\" ";
764 if (flipX || flipY || propList["librevenge:rotate"])
765 {
766 double xmiddle = x + width / 2.0;
767 double ymiddle = y + height / 2.0;
768 m_impl->m_outputSink << "transform=\"";
769 m_impl->m_outputSink << " translate(" << doubleToString(72*xmiddle) << ", " << doubleToString(72*ymiddle) << ") ";
770 m_impl->m_outputSink << " scale(" << (flipX ? "-1" : "1") << ", " << (flipY ? "-1" : "1") << ") ";
771 // rotation is around the center of the object's bounding box
772 if (propList["librevenge:rotate"])
773 {
774 double angle(propList["librevenge:rotate"]->getDouble());
775 while (angle > 180.0)
776 angle -= 360.0;
777 while (angle < -180.0)
778 angle += 360.0;
779 m_impl->m_outputSink << " rotate(" << doubleToString(angle) << ") ";
780 }
781 m_impl->m_outputSink << " translate(" << doubleToString(-72*xmiddle) << ", " << doubleToString(-72*ymiddle) << ") ";
782 m_impl->m_outputSink << "\" ";
783 }
784 }
785 m_impl->m_outputSink << "xlink:href=\"data:" << propList["librevenge:mime-type"]->getStr().cstr() << ";base64,";
786 m_impl->m_outputSink << propList["office:binary-data"]->getStr().cstr();
787 m_impl->m_outputSink << "\" />\n";
788 }
789
790 void RVNGSVGPresentationGenerator::drawConnector(const RVNGPropertyList &/*propList*/)
791 {
792 // TODO: implement me
793 }
794
795 void RVNGSVGPresentationGenerator::startTextObject(const RVNGPropertyList &propList)
796 {
797 double x = 0.0;
798 double y = 0.0;
799 double height = 0.0;
800 m_impl->m_outputSink << "<svg:text ";
801 if (propList["svg:x"] && propList["svg:y"])
802 {
803 x = getInchValue(*propList["svg:x"]);
804 y = getInchValue(*propList["svg:y"]);
805 }
806
807 double xmiddle = x;
808 double ymiddle = y;
809
810 if (propList["svg:width"])
811 {
812 double width = getInchValue(*propList["svg:width"]);
813 xmiddle += width / 2.0;
814 }
815
816 if (propList["svg:height"])
817 {
818 height = getInchValue(*propList["svg:height"]);
819 ymiddle += height / 2.0;
820 }
821
822 if (propList["draw:textarea-vertical-align"])
823 {
824 if (propList["draw:textarea-vertical-align"]->getStr() == "middle")
825 y = ymiddle;
826 if (propList["draw:textarea-vertical-align"]->getStr() == "bottom")
827 {
828 y += height;
829 if (propList["fo:padding-bottom"])
830 y -= propList["fo:padding-bottom"]->getDouble();
831 }
832 }
833 else
834 y += height;
835
836 if (propList["fo:padding-left"])
837 x += propList["fo:padding-left"]->getDouble();
838
839 m_impl->m_outputSink << "x=\"" << doubleToString(72*x) << "\" y=\"" << doubleToString(72*y) << "\"";
840
841 // rotation is around the center of the object's bounding box
842 if (propList["librevenge:rotate"] && (propList["librevenge:rotate"]->getDouble()<0||propList["librevenge:rotate"]->getDouble()>0))
843 {
844 double angle(propList["librevenge:rotate"]->getDouble());
845 while (angle > 180.0)
846 angle -= 360.0;
847 while (angle < -180.0)
848 angle += 360.0;
849 m_impl->m_outputSink << " transform=\"rotate(" << doubleToString(angle) << ", " << doubleToString(72*xmiddle) << ", " << doubleToString(72*ymiddle) << ")\" ";
850 }
851 m_impl->m_outputSink << ">\n";
852 }
853
854 void RVNGSVGPresentationGenerator::endTextObject()
855 {
856 m_impl->m_outputSink << "</svg:text>\n";
857 }
858
859 void RVNGSVGPresentationGenerator::defineCharacterStyle(const RVNGPropertyList &propList)
860 {
861 if (!propList["librevenge:span-id"])
862 {
863 RVNG_DEBUG_MSG(("RVNGSVGPresentationGenerator::defineCharacterStyle: can not find the span-id\n"));
864 return;
865 }
866 m_impl->m_idSpanMap[propList["librevenge:span-id"]->getInt()]=propList;
867 }
868
869 void RVNGSVGPresentationGenerator::openSpan(const RVNGPropertyList &propList)
870 {
871 RVNGPropertyList pList(propList);
872 if (propList["librevenge:span-id"] &&
873 m_impl->m_idSpanMap.find(propList["librevenge:span-id"]->getInt())!=m_impl->m_idSpanMap.end())
874 pList=m_impl->m_idSpanMap.find(propList["librevenge:span-id"]->getInt())->second;
875
876 m_impl->m_outputSink << "<svg:tspan ";
877 if (pList["style:font-name"])
878 m_impl->m_outputSink << "font-family=\"" << pList["style:font-name"]->getStr().cstr() << "\" ";
879 if (pList["fo:font-style"])
880 m_impl->m_outputSink << "font-style=\"" << pList["fo:font-style"]->getStr().cstr() << "\" ";
881 if (pList["fo:font-weight"])
882 m_impl->m_outputSink << "font-weight=\"" << pList["fo:font-weight"]->getStr().cstr() << "\" ";
883 if (pList["fo:font-variant"])
884 m_impl->m_outputSink << "font-variant=\"" << pList["fo:font-variant"]->getStr().cstr() << "\" ";
885 if (pList["fo:font-size"])
886 m_impl->m_outputSink << "font-size=\"" << doubleToString(pList["fo:font-size"]->getDouble()) << "\" ";
887 if (pList["fo:color"])
888 m_impl->m_outputSink << "fill=\"" << pList["fo:color"]->getStr().cstr() << "\" ";
889 if (pList["fo:text-transform"])
890 m_impl->m_outputSink << "text-transform=\"" << pList["fo:text-transform"]->getStr().cstr() << "\" ";
891 if (pList["svg:fill-opacity"])
892 m_impl->m_outputSink << "fill-opacity=\"" << doubleToString(pList["svg:fill-opacity"]->getDouble()) << "\" ";
893 if (pList["svg:stroke-opacity"])
894 m_impl->m_outputSink << "stroke-opacity=\"" << doubleToString(pList["svg:stroke-opacity"]->getDouble()) << "\" ";
895 m_impl->m_outputSink << ">\n";
896 }
897
898 void RVNGSVGPresentationGenerator::closeSpan()
899 {
900 m_impl->m_outputSink << "</svg:tspan>\n";
901 }
902
903 void RVNGSVGPresentationGenerator::openLink(const RVNGPropertyList & /* propList */)
904 {
905 }
906
907 void RVNGSVGPresentationGenerator::closeLink()
908 {
909 }
910
911 void RVNGSVGPresentationGenerator::insertTab()
912 {
913 m_impl->m_outputSink << '\t';
914 }
915
916 void RVNGSVGPresentationGenerator::insertSpace()
917 {
918 m_impl->m_outputSink << ' ';
919 }
920
921 void RVNGSVGPresentationGenerator::insertText(const RVNGString &str)
922 {
923 m_impl->m_outputSink << RVNGString::escapeXML(str).cstr() << "\n";
924 }
925
926 void RVNGSVGPresentationGenerator::insertLineBreak()
927 {
928 m_impl->m_outputSink << '\n';
929 }
930
931 void RVNGSVGPresentationGenerator::insertField(const RVNGPropertyList &/*propList*/)
932 {
933 // TODO: implement me
934 }
935
936 void RVNGSVGPresentationGenerator::openOrderedListLevel(const RVNGPropertyList &)
937 {
938 }
939
940 void RVNGSVGPresentationGenerator::openUnorderedListLevel(const RVNGPropertyList &)
941 {
942 }
943
944 void RVNGSVGPresentationGenerator::closeOrderedListLevel()
945 {
946 }
947
948 void RVNGSVGPresentationGenerator::closeUnorderedListLevel()
949 {
950 }
951
952 void RVNGSVGPresentationGenerator::openListElement(const RVNGPropertyList &propList)
953 {
954 openParagraph(propList);
955 }
956
957 void RVNGSVGPresentationGenerator::closeListElement()
958 {
959 closeParagraph();
960 }
961
962 void RVNGSVGPresentationGenerator::defineParagraphStyle(const RVNGPropertyList &)
963 {
964 }
965
966 void RVNGSVGPresentationGenerator::openParagraph(const RVNGPropertyList &)
967 {
968 }
969
970 void RVNGSVGPresentationGenerator::closeParagraph()
971 {
972 m_impl->m_outputSink << '\n';
973 }
974
975 void RVNGSVGPresentationGenerator::startTableObject(const RVNGPropertyList &propList)
976 {
977 if (m_impl->m_table)
978 {
979 RVNG_DEBUG_MSG(("RVNGSVGPresentationGenerator::startTableObject: a table is already opened\n"));
980 return;
981 }
982 m_impl->m_table.reset(new Table(propList));
983 }
984
985 void RVNGSVGPresentationGenerator::openTableRow(const RVNGPropertyList &propList)
986 {
987 if (!m_impl->m_table) return;
988 m_impl->m_table->openRow(propList);
989 }
990
991 void RVNGSVGPresentationGenerator::closeTableRow()
992 {
993 if (!m_impl->m_table) return;
994 m_impl->m_table->closeRow();
995 }
996
997 void RVNGSVGPresentationGenerator::openTableCell(const RVNGPropertyList &propList)
998 {
999 if (!m_impl->m_table) return;
1000
1001 if (propList["librevenge:column"])
1002 m_impl->m_table->m_column=propList["librevenge:column"]->getInt();
1003 if (propList["librevenge:row"])
1004 m_impl->m_table->m_row=propList["librevenge:row"]->getInt();
1005
1006 double x = 0, y=0;
1007 m_impl->m_table->getPosition(m_impl->m_table->m_column, m_impl->m_table->m_row, x, y);
1008 m_impl->m_outputSink << "<svg:text ";
1009 m_impl->m_outputSink << "x=\"" << doubleToString(72*x) << "\" y=\"" << doubleToString(72*y) << "\" ";
1010 m_impl->m_outputSink << ">\n";
1011
1012 // time to update the next cell's column
1013 if (propList["table:number-columns-spanned"])
1014 m_impl->m_table->m_column += propList["librevenge:column"]->getInt();
1015 else
1016 ++m_impl->m_table->m_column;
1017 }
1018
1019 void RVNGSVGPresentationGenerator::closeTableCell()
1020 {
1021 if (!m_impl->m_table) return;
1022 m_impl->m_outputSink << "</svg:text>\n";
1023 }
1024
1025 void RVNGSVGPresentationGenerator::insertCoveredTableCell(const RVNGPropertyList &/*propList*/)
1026 {
1027 if (!m_impl->m_table) return;
1028 // TODO: implement me
1029 }
1030
1031 void RVNGSVGPresentationGenerator::endTableObject()
1032 {
1033 if (!m_impl->m_table)
1034 {
1035 RVNG_DEBUG_MSG(("RVNGSVGDrawingGenerator::endTableObject: no table is already opened\n"));
1036 return;
1037 }
1038 m_impl->m_table.reset();
1039 }
1040
1041 void RVNGSVGPresentationGenerator::startComment(const RVNGPropertyList &/*propList*/)
1042 {
1043 // TODO: implement me
1044 }
1045
1046 void RVNGSVGPresentationGenerator::endComment()
1047 {
1048 // TODO: implement me
1049 }
1050
1051
1052 void RVNGSVGPresentationGenerator::startNotes(const RVNGPropertyList &/*propList*/)
1053 {
1054 // TODO: implement me
1055 }
1056
1057 void RVNGSVGPresentationGenerator::endNotes()
1058 {
1059 // TODO: implement me
1060 }
1061
1062 void RVNGSVGPresentationGenerator::defineChartStyle(const RVNGPropertyList &)
1063 {
1064 }
1065
1066 void RVNGSVGPresentationGenerator::openChart(const RVNGPropertyList &)
1067 {
1068 }
1069
1070 void RVNGSVGPresentationGenerator::closeChart()
1071 {
1072 }
1073
1074 void RVNGSVGPresentationGenerator::openChartTextObject(const RVNGPropertyList &)
1075 {
1076 }
1077
1078 void RVNGSVGPresentationGenerator::closeChartTextObject()
1079 {
1080 }
1081
1082 void RVNGSVGPresentationGenerator::openChartPlotArea(const RVNGPropertyList &)
1083 {
1084 }
1085
1086 void RVNGSVGPresentationGenerator::closeChartPlotArea()
1087 {
1088 }
1089
1090 void RVNGSVGPresentationGenerator::insertChartAxis(const RVNGPropertyList &)
1091 {
1092 }
1093
1094 void RVNGSVGPresentationGenerator::openChartSeries(const librevenge::RVNGPropertyList &)
1095 {
1096 }
1097
1098 void RVNGSVGPresentationGenerator::closeChartSeries()
1099 {
1100 }
1101
1102 // create "style" attribute based on current pen and brush
1103 void RVNGSVGPresentationGeneratorImpl::writeStyle(bool /* isClosed */)
1104 {
1105 m_outputSink << "style=\"";
1106
1107 double width = 1.0 / 72.0;
1108 if (m_style["svg:stroke-width"])
1109 {
1110 width = getInchValue(*m_style["svg:stroke-width"]);
1111 if (width <= 0.0 && m_style["draw:stroke"] && m_style["draw:stroke"]->getStr() != "none")
1112 width = 0.2 / 72.0; // reasonable hairline
1113 m_outputSink << "stroke-width: " << doubleToString(72*width) << "; ";
1114 }
1115
1116 if (m_style["draw:stroke"] && m_style["draw:stroke"]->getStr() != "none")
1117 {
1118 if (m_style["svg:stroke-color"])
1119 m_outputSink << "stroke: " << m_style["svg:stroke-color"]->getStr().cstr() << "; ";
1120 if (m_style["svg:stroke-opacity"] && m_style["svg:stroke-opacity"]->getInt()!= 1)
1121 m_outputSink << "stroke-opacity: " << doubleToString(m_style["svg:stroke-opacity"]->getDouble()) << "; ";
1122 }
1123
1124 if (m_style["draw:stroke"] && m_style["draw:stroke"]->getStr() == "solid")
1125 m_outputSink << "stroke-dasharray: none; ";
1126 else if (m_style["draw:stroke"] && m_style["draw:stroke"]->getStr() == "dash")
1127 {
1128 int dots1 = m_style["draw:dots1"] ? m_style["draw:dots1"]->getInt() : 0;
1129 int dots2 = m_style["draw:dots2"] ? m_style["draw:dots2"]->getInt() : 0;
1130 double dots1len = 72.*width, dots2len = 72.*width, gap = 72.*width;
1131 if (m_style["draw:dots1-length"])
1132 {
1133 if (m_style["draw:dots1-length"]->getUnit()==librevenge::RVNG_PERCENT)
1134 dots1len=72*m_style["draw:dots1-length"]->getDouble()*width;
1135 else
1136 dots1len=72*getInchValue(*m_style["draw:dots1-length"]);
1137 }
1138 if (m_style["draw:dots2-length"])
1139 {
1140 if (m_style["draw:dots2-length"]->getUnit()==librevenge::RVNG_PERCENT)
1141 dots2len=72*m_style["draw:dots2-length"]->getDouble()*width;
1142 else
1143 dots2len=72*getInchValue(*m_style["draw:dots2-length"]);
1144 }
1145 if (m_style["draw:distance"])
1146 {
1147 if (m_style["draw:distance"]->getUnit()==librevenge::RVNG_PERCENT)
1148 gap=72*m_style["draw:distance"]->getDouble()*width;
1149 else
1150 gap=72*getInchValue(*m_style["draw:distance"]);
1151 }
1152 m_outputSink << "stroke-dasharray: ";
1153 for (int i = 0; i < dots1; i++)
1154 {
1155 if (i)
1156 m_outputSink << ", ";
1157 m_outputSink << doubleToString(dots1len);
1158 m_outputSink << ", ";
1159 m_outputSink << doubleToString(gap);
1160 }
1161 for (int j = 0; j < dots2; j++)
1162 {
1163 m_outputSink << ", ";
1164 m_outputSink << doubleToString(dots2len);
1165 m_outputSink << ", ";
1166 m_outputSink << doubleToString(gap);
1167 }
1168 m_outputSink << "; ";
1169 }
1170
1171 if (m_style["svg:stroke-linecap"])
1172 m_outputSink << "stroke-linecap: " << m_style["svg:stroke-linecap"]->getStr().cstr() << "; ";
1173
1174 if (m_style["svg:stroke-linejoin"])
1175 m_outputSink << "stroke-linejoin: " << m_style["svg:stroke-linejoin"]->getStr().cstr() << "; ";
1176
1177 if (m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "none")
1178 m_outputSink << "fill: none; ";
1179 else if (m_style["svg:fill-rule"])
1180 m_outputSink << "fill-rule: " << m_style["svg:fill-rule"]->getStr().cstr() << "; ";
1181
1182 if (m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "gradient")
1183 m_outputSink << "fill: url(#grad" << m_gradientIndex-1 << "); ";
1184 else if (m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "bitmap")
1185 m_outputSink << "fill: url(#img" << m_patternIndex-1 << "); ";
1186
1187 if (m_style["draw:shadow"] && m_style["draw:shadow"]->getStr() == "visible")
1188 m_outputSink << "filter:url(#shadow" << m_shadowIndex-1 << "); ";
1189
1190 if (m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "solid")
1191 if (m_style["draw:fill-color"])
1192 m_outputSink << "fill: " << m_style["draw:fill-color"]->getStr().cstr() << "; ";
1193 if (m_style["draw:opacity"] && m_style["draw:opacity"]->getDouble() < 1)
1194 m_outputSink << "fill-opacity: " << doubleToString(m_style["draw:opacity"]->getDouble()) << "; ";
1195
1196 if (m_style["draw:marker-start-path"])
1197 m_outputSink << "marker-start: url(#startMarker" << m_arrowStartIndex-1 << "); ";
1198 if (m_style["draw:marker-end-path"])
1199 m_outputSink << "marker-end: url(#endMarker" << m_arrowEndIndex-1 << "); ";
1200
1201 m_outputSink << "\""; // style
1202 }
1203
1204 void RVNGSVGPresentationGenerator::openAnimationSequence(const RVNGPropertyList &)
1205 {
1206 }
1207
1208 void RVNGSVGPresentationGenerator::closeAnimationSequence()
1209 {
1210 }
1211
1212 void RVNGSVGPresentationGenerator::openAnimationGroup(const RVNGPropertyList &)
1213 {
1214 }
1215
1216 void RVNGSVGPresentationGenerator::closeAnimationGroup()
1217 {
1218 }
1219
1220 void RVNGSVGPresentationGenerator::openAnimationIteration(const RVNGPropertyList &)
1221 {
1222 }
1223
1224 void RVNGSVGPresentationGenerator::closeAnimationIteration()
1225 {
1226 }
1227
1228 void RVNGSVGPresentationGenerator::insertMotionAnimation(const RVNGPropertyList &)
1229 {
1230 }
1231
1232 void RVNGSVGPresentationGenerator::insertColorAnimation(const RVNGPropertyList &)
1233 {
1234 }
1235
1236 void RVNGSVGPresentationGenerator::insertAnimation(const RVNGPropertyList &)
1237 {
1238 }
1239
1240 void RVNGSVGPresentationGenerator::insertEffect(const RVNGPropertyList &)
1241 {
1242 }
1243
1244 }
1245
1246 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */