OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1364 lines
56 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../koffice/0001-koffice-2.3.1-fix-wpg-import.patch
  5. # Copyright (C) 2011 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. From: Jan Hambrecht <jaham@gmx.net>
  17. Date: Thu, 30 Dec 2010 14:28:26 +0000
  18. Subject: make wpg import compile again, simplified code by using high level libwpg function to convert to svg,
  19. X-Git-Tag: v2.3.70~681^2
  20. X-Git-Url: http://quickgit.kde.org/?p=calligra.git&amp;a=commitdiff&amp;h=9cda7aed2ea103750172e61f5c800a474913fa59
  21. ---
  22. make wpg import compile again, simplified code by using high level libwpg function to convert to svg,
  23. this makes us less dependent on libwpg API changes, code works with old an new libwpg versions
  24. ---
  25. Note: This patch is a backport done by people from Fedora!
  26. http://pkgs.fedoraproject.org/gitweb/?p=koffice.git;a=blob;f=koffice-2.3.1-libwpg02.patch;h=1e7761bc17dcf67dcb4cb99454a9f90cb1829f4b;hb=HEAD
  27. diff -Nur koffice-2.3.1/filters/karbon/wpg/import/CMakeLists.txt koffice-2.3.1-libwpg02/filters/karbon/wpg/import/CMakeLists.txt
  28. --- koffice-2.3.1/filters/karbon/wpg/import/CMakeLists.txt 2011-01-15 21:05:35.000000000 +0100
  29. +++ koffice-2.3.1-libwpg02/filters/karbon/wpg/import/CMakeLists.txt 2011-01-18 07:40:25.000000000 +0100
  30. @@ -1,16 +1,11 @@
  31. -
  32. include_directories(${CMAKE_BINARY_DIR}/filters/ ${WPD_INCLUDE_DIR} ${LIBWPG_INCLUDE_DIR}/)
  33. -set(wpgimport_PART_SRCS
  34. -WPGImport.cpp
  35. -OdgExporter.cxx
  36. -FileOutputHandler.cxx
  37. -GraphicsElement.cxx)
  38. +set(wpgimport_PART_SRCS WPGImport.cpp)
  39. kde4_add_plugin(wpgimport ${wpgimport_PART_SRCS})
  40. -target_link_libraries(wpgimport komain ${LIBWPG_LIBRARIES} ${LIBWPG_STREAM_LIBRARIES})
  41. +target_link_libraries(wpgimport komain ${LIBWPG_LIBRARIES} ${LIBWPG_STREAM_LIBRARIES} ${WPD_LIBRARIES})
  42. install(TARGETS wpgimport DESTINATION ${PLUGIN_INSTALL_DIR})
  43. install(FILES karbon_wpg_import.desktop DESTINATION ${SERVICES_INSTALL_DIR})
  44. diff -Nur koffice-2.3.1/filters/karbon/wpg/import/FileOutputHandler.cxx koffice-2.3.1-libwpg02/filters/karbon/wpg/import/FileOutputHandler.cxx
  45. --- koffice-2.3.1/filters/karbon/wpg/import/FileOutputHandler.cxx 2011-01-15 21:05:35.000000000 +0100
  46. +++ koffice-2.3.1-libwpg02/filters/karbon/wpg/import/FileOutputHandler.cxx 1970-01-01 01:00:00.000000000 +0100
  47. @@ -1,95 +0,0 @@
  48. -/* libwpg
  49. - * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
  50. - *
  51. - * This library is free software; you can redistribute it and/or
  52. - * modify it under the terms of the GNU Library General Public
  53. - * License as published by the Free Software Foundation; either
  54. - * version 2 of the License, or (at your option) any later version.
  55. - *
  56. - * This library is distributed in the hope that it will be useful,
  57. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  58. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  59. - * Library General Public License for more details.
  60. - *
  61. - * You should have received a copy of the GNU Library General Public
  62. - * License along with this library; if not, write to the
  63. - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  64. - * Boston, MA 02111-1301 USA
  65. - *
  66. - * For further information visit http://libwpg.sourceforge.net
  67. - */
  68. -
  69. -/* "This product is not manufactured, approved, or supported by
  70. - * Corel Corporation or Corel Corporation Limited."
  71. - */
  72. -
  73. -#include "FileOutputHandler.hxx"
  74. -
  75. -FileOutputHandler::FileOutputHandler(std::ostringstream &contentStream) :
  76. - mbIsTagOpened(false),
  77. - mContentStream(contentStream)
  78. -{
  79. -}
  80. -
  81. -void FileOutputHandler::startDocument()
  82. -{
  83. -}
  84. -
  85. -void FileOutputHandler::startElement(const char *psName, const std::vector<std::pair<std::string, std::string> > &xPropList)
  86. -{
  87. - if (mbIsTagOpened)
  88. - {
  89. - mContentStream << ">";
  90. - mbIsTagOpened = false;
  91. - }
  92. - mContentStream << "<" << psName;
  93. -
  94. - for (std::vector<std::pair<std::string, std::string> >::const_iterator i = xPropList.begin(); i != xPropList.end(); i++)
  95. - {
  96. - mContentStream << " " << (*i).first.c_str() << "=\"" << (*i).second.c_str() << "\"";
  97. - }
  98. - mbIsTagOpened = true;
  99. - msOpenedTagName = psName;
  100. -}
  101. -
  102. -void FileOutputHandler::endElement(const char *psName)
  103. -{
  104. - if (mbIsTagOpened)
  105. - {
  106. - if( msOpenedTagName == psName )
  107. - {
  108. - mContentStream << "/>";
  109. - mbIsTagOpened = false;
  110. - }
  111. - else // should not happen, but handle it
  112. - {
  113. - mContentStream << ">";
  114. - mContentStream << "</" << psName << ">";
  115. - mbIsTagOpened = false;
  116. - }
  117. - }
  118. - else
  119. - {
  120. - mContentStream << "</" << psName << ">";
  121. - mbIsTagOpened = false;
  122. - }
  123. -}
  124. -
  125. -void FileOutputHandler::characters(const std::string &sCharacters)
  126. -{
  127. - if (mbIsTagOpened)
  128. - {
  129. - mContentStream << ">";
  130. - mbIsTagOpened = false;
  131. - }
  132. - mContentStream << sCharacters.c_str();
  133. -}
  134. -
  135. -void FileOutputHandler::endDocument()
  136. -{
  137. - if (mbIsTagOpened)
  138. - {
  139. - mContentStream << ">";
  140. - mbIsTagOpened = false;
  141. - }
  142. -}
  143. diff -Nur koffice-2.3.1/filters/karbon/wpg/import/FileOutputHandler.hxx koffice-2.3.1-libwpg02/filters/karbon/wpg/import/FileOutputHandler.hxx
  144. --- koffice-2.3.1/filters/karbon/wpg/import/FileOutputHandler.hxx 2011-01-15 21:05:35.000000000 +0100
  145. +++ koffice-2.3.1-libwpg02/filters/karbon/wpg/import/FileOutputHandler.hxx 1970-01-01 01:00:00.000000000 +0100
  146. @@ -1,49 +0,0 @@
  147. -/* libwpg
  148. - * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
  149. - *
  150. - * This library is free software; you can redistribute it and/or
  151. - * modify it under the terms of the GNU Library General Public
  152. - * License as published by the Free Software Foundation; either
  153. - * version 2 of the License, or (at your option) any later version.
  154. - *
  155. - * This library is distributed in the hope that it will be useful,
  156. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  157. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  158. - * Library General Public License for more details.
  159. - *
  160. - * You should have received a copy of the GNU Library General Public
  161. - * License along with this library; if not, write to the
  162. - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  163. - * Boston, MA 02111-1301 USA
  164. - *
  165. - * For further information visit http://libwpg.sourceforge.net
  166. - */
  167. -
  168. -/* "This product is not manufactured, approved, or supported by
  169. - * Corel Corporation or Corel Corporation Limited."
  170. - */
  171. -
  172. -#ifndef FILEOUTPUTHANDLER_H
  173. -#define FILEOUTPUTHANDLER_H
  174. -
  175. -#include <iostream>
  176. -#include <sstream>
  177. -#include <string>
  178. -#include "GraphicsHandler.hxx"
  179. -
  180. -class FileOutputHandler : public GraphicsHandler
  181. -{
  182. - public:
  183. - explicit FileOutputHandler(std::ostringstream &contentStream);
  184. - virtual void startDocument();
  185. - virtual void endDocument();
  186. - virtual void startElement(const char *psName, const std::vector<std::pair<std::string, std::string> > &xPropList);
  187. - virtual void endElement(const char *psName);
  188. - virtual void characters(const std::string &sCharacters);
  189. -
  190. - private:
  191. - bool mbIsTagOpened;
  192. - std::string msOpenedTagName;
  193. - std::ostringstream &mContentStream;
  194. -};
  195. -#endif
  196. diff -Nur koffice-2.3.1/filters/karbon/wpg/import/GraphicsElement.cxx koffice-2.3.1-libwpg02/filters/karbon/wpg/import/GraphicsElement.cxx
  197. --- koffice-2.3.1/filters/karbon/wpg/import/GraphicsElement.cxx 2011-01-15 21:05:35.000000000 +0100
  198. +++ koffice-2.3.1-libwpg02/filters/karbon/wpg/import/GraphicsElement.cxx 1970-01-01 01:00:00.000000000 +0100
  199. @@ -1,66 +0,0 @@
  200. -/* GraphicsElement: The items we are collecting to be put into the Writer
  201. - * document: paragraph and spans of text, as well as section breaks.
  202. - *
  203. - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca)
  204. - *
  205. - * This program is free software; you can redistribute it and/or
  206. - * modify it under the terms of the GNU Lesser General Public
  207. - * License as published by the Free Software Foundation; either
  208. - * version 2 of the License, or (at your option) any later version.
  209. - *
  210. - * This program is distributed in the hope that it will be useful,
  211. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  212. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  213. - * Library General Public License for more details.
  214. - *
  215. - * You should have received a copy of the GNU Library General Public
  216. - * License along with this library; if not, write to the
  217. - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  218. - * Boston, MA 02111-1301 USA
  219. - *
  220. - * For further information visit http://libwpg.sourceforge.net
  221. - *
  222. - */
  223. -
  224. -/* "This product is not manufactured, approved, or supported by
  225. - * Corel Corporation or Corel Corporation Limited."
  226. - */
  227. -
  228. -#include "GraphicsElement.hxx"
  229. -#include "GraphicsHandler.hxx"
  230. -#include <string.h>
  231. -
  232. -#define ASCII_SPACE 0x0020
  233. -
  234. -void TagGraphicsElement::print() const
  235. -{
  236. -}
  237. -
  238. -void OpenTagGraphicsElement::write(GraphicsHandler *pHandler) const
  239. -{
  240. - pHandler->startElement(getTagName().c_str(), maAttrList);
  241. -}
  242. -
  243. -void OpenTagGraphicsElement::print() const
  244. -{
  245. - TagGraphicsElement::print();
  246. -}
  247. -
  248. -void OpenTagGraphicsElement::addAttribute(const std::string &szAttributeName, const std::string &sAttributeValue)
  249. -{
  250. - std::pair<std::string, std::string> tmpAttribute;
  251. - tmpAttribute.first = szAttributeName;
  252. - tmpAttribute.second = sAttributeValue;
  253. - maAttrList.push_back(tmpAttribute);
  254. -}
  255. -
  256. -void CloseTagGraphicsElement::write(GraphicsHandler *pHandler) const
  257. -{
  258. -
  259. - pHandler->endElement(getTagName().c_str());
  260. -}
  261. -
  262. -void CharDataGraphicsElement::write(GraphicsHandler *pHandler) const
  263. -{
  264. - pHandler->characters(msData);
  265. -}
  266. diff -Nur koffice-2.3.1/filters/karbon/wpg/import/GraphicsElement.hxx koffice-2.3.1-libwpg02/filters/karbon/wpg/import/GraphicsElement.hxx
  267. --- koffice-2.3.1/filters/karbon/wpg/import/GraphicsElement.hxx 2011-01-15 21:05:35.000000000 +0100
  268. +++ koffice-2.3.1-libwpg02/filters/karbon/wpg/import/GraphicsElement.hxx 1970-01-01 01:00:00.000000000 +0100
  269. @@ -1,84 +0,0 @@
  270. -/* GraphicsElement: The items we are collecting to be put into the Writer
  271. - * document: paragraph and spans of text, as well as section breaks.
  272. - *
  273. - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca)
  274. - *
  275. - * This program is free software; you can redistribute it and/or
  276. - * modify it under the terms of the GNU Lesser General Public
  277. - * License as published by the Free Software Foundation; either
  278. - * version 2 of the License, or (at your option) any later version.
  279. - *
  280. - * This program is distributed in the hope that it will be useful,
  281. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  282. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  283. - * Library General Public License for more details.
  284. - *
  285. - * You should have received a copy of the GNU Library General Public
  286. - * License along with this library; if not, write to the
  287. - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  288. - * Boston, MA 02111-1301 USA
  289. - *
  290. - * For further information visit http://libwpd.sourceforge.net
  291. - *
  292. - */
  293. -
  294. -/* "This product is not manufactured, approved, or supported by
  295. - * Corel Corporation or Corel Corporation Limited."
  296. - */
  297. -
  298. -#ifndef _GRAPHICSELEMENT_H
  299. -#define _GRAPHICSELEMENT_H
  300. -#include <string>
  301. -#include <map>
  302. -#include <vector>
  303. -
  304. -#include "GraphicsHandler.hxx"
  305. -
  306. -class GraphicsElement
  307. -{
  308. -public:
  309. - virtual ~GraphicsElement() {}
  310. - virtual void write(GraphicsHandler *pHandler) const = 0;
  311. - virtual void print() const {}
  312. -};
  313. -
  314. -class TagGraphicsElement : public GraphicsElement
  315. -{
  316. -public:
  317. - explicit TagGraphicsElement(const char *szTagName) : msTagName(szTagName) {}
  318. - const std::string &getTagName() const { return msTagName; }
  319. - virtual void print() const;
  320. -private:
  321. - const std::string msTagName;
  322. -};
  323. -
  324. -class OpenTagGraphicsElement : public TagGraphicsElement
  325. -{
  326. -public:
  327. - explicit OpenTagGraphicsElement(const char *szTagName) : TagGraphicsElement(szTagName) {}
  328. - ~OpenTagGraphicsElement() {}
  329. - void addAttribute(const std::string &szAttributeName, const std::string &sAttributeValue);
  330. - virtual void write(GraphicsHandler *pHandler) const;
  331. - virtual void print () const;
  332. -private:
  333. - std::vector<std::pair<std::string, std::string> > maAttrList;
  334. -};
  335. -
  336. -class CloseTagGraphicsElement : public TagGraphicsElement
  337. -{
  338. -public:
  339. - explicit CloseTagGraphicsElement(const char *szTagName) : TagGraphicsElement(szTagName) {}
  340. - virtual void write(GraphicsHandler *pHandler) const;
  341. -};
  342. -
  343. -class CharDataGraphicsElement : public GraphicsElement
  344. -{
  345. -public:
  346. - CharDataGraphicsElement(const char *sData) : GraphicsElement(), msData(sData) {}
  347. - virtual void write(GraphicsHandler *pHandler) const;
  348. -private:
  349. - std::string msData;
  350. -};
  351. -
  352. -
  353. -#endif
  354. diff -Nur koffice-2.3.1/filters/karbon/wpg/import/GraphicsHandler.hxx koffice-2.3.1-libwpg02/filters/karbon/wpg/import/GraphicsHandler.hxx
  355. --- koffice-2.3.1/filters/karbon/wpg/import/GraphicsHandler.hxx 2011-01-15 21:05:35.000000000 +0100
  356. +++ koffice-2.3.1-libwpg02/filters/karbon/wpg/import/GraphicsHandler.hxx 1970-01-01 01:00:00.000000000 +0100
  357. @@ -1,43 +0,0 @@
  358. -/*
  359. - * Copyright (C) 2004 William Lachance (wlach@interlog.com)
  360. - * Copyright (C) 2004 Net Integration Technologies (http://www.net-itech.com)
  361. - *
  362. - * This program is free software; you can redistribute it and/or
  363. - * modify it under the terms of the GNU General Public License
  364. - * as published by the Free Software Foundation; either version 2
  365. - * of the License, or (at your option) any later version.
  366. - *
  367. - * This program is distributed in the hope that it will be useful,
  368. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  369. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  370. - * GNU General Public License for more details.
  371. - *
  372. - * You should have received a copy of the GNU Library General Public
  373. - * License along with this library; if not, write to the
  374. - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  375. - * Boston, MA 02111-1301 USA
  376. - *
  377. - * Contributor(s): Martin Gallwey (gallwey@sun.com)
  378. - *
  379. - */
  380. -
  381. -/* "This product is not manufactured, approved, or supported by
  382. - * Corel Corporation or Corel Corporation Limited."
  383. - */
  384. -#ifndef _GRAPHICSHANDLER_H
  385. -#define _GRAPHICSHANDLER_H
  386. -#include <string>
  387. -#include <map>
  388. -#include <vector>
  389. -
  390. -class GraphicsHandler
  391. -{
  392. -public:
  393. - virtual ~GraphicsHandler() {}
  394. - virtual void startDocument() = 0;
  395. - virtual void endDocument() = 0;
  396. - virtual void startElement(const char *psName, const std::vector< std::pair <std::string, std::string> > &xPropList) = 0;
  397. - virtual void endElement(const char *psName) = 0;
  398. - virtual void characters(const std::string &sCharacters) = 0;
  399. -};
  400. -#endif
  401. diff -Nur koffice-2.3.1/filters/karbon/wpg/import/karbon_wpg_import.desktop koffice-2.3.1-libwpg02/filters/karbon/wpg/import/karbon_wpg_import.desktop
  402. --- koffice-2.3.1/filters/karbon/wpg/import/karbon_wpg_import.desktop 2011-01-15 21:05:35.000000000 +0100
  403. +++ koffice-2.3.1-libwpg02/filters/karbon/wpg/import/karbon_wpg_import.desktop 2011-01-18 07:41:33.000000000 +0100
  404. @@ -42,7 +42,7 @@
  405. Name[x-test]=xxKarbon WPG Import Filterxx
  406. Name[zh_CN]=Karbon WPG 导入过滤器
  407. Name[zh_TW]=Karbon WPG 匯入過濾程式
  408. -X-KDE-Export=application/vnd.oasis.opendocument.graphics
  409. +X-KDE-Export=image/svg+xml
  410. X-KDE-Import=application/x-wpg
  411. X-KDE-Weight=1
  412. X-KDE-Library=wpgimport
  413. diff -Nur koffice-2.3.1/filters/karbon/wpg/import/OdgExporter.cxx koffice-2.3.1-libwpg02/filters/karbon/wpg/import/OdgExporter.cxx
  414. --- koffice-2.3.1/filters/karbon/wpg/import/OdgExporter.cxx 2011-01-15 21:05:35.000000000 +0100
  415. +++ koffice-2.3.1-libwpg02/filters/karbon/wpg/import/OdgExporter.cxx 1970-01-01 01:00:00.000000000 +0100
  416. @@ -1,662 +0,0 @@
  417. -/* libwpg
  418. - * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
  419. - * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
  420. - *
  421. - * This library is free software; you can redistribute it and/or
  422. - * modify it under the terms of the GNU Library General Public
  423. - * License as published by the Free Software Foundation; either
  424. - * version 2 of the License, or (at your option) any later version.
  425. - *
  426. - * This library is distributed in the hope that it will be useful,
  427. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  428. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  429. - * Library General Public License for more details.
  430. - *
  431. - * You should have received a copy of the GNU Library General Public
  432. - * License along with this library; if not, write to the
  433. - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  434. - * Boston, MA 02111-1301 USA
  435. - *
  436. - * For further information visit http://libwpg.sourceforge.net
  437. - */
  438. -
  439. -/* "This product is not manufactured, approved, or supported by
  440. - * Corel Corporation or Corel Corporation Limited."
  441. - */
  442. -
  443. -#include "OdgExporter.hxx"
  444. -#include "GraphicsElement.hxx"
  445. -#include "GraphicsHandler.hxx"
  446. -#include <locale.h>
  447. -
  448. -static std::string doubleToString(const double value)
  449. -{
  450. - std::ostringstream tempStream;
  451. - tempStream << value;
  452. - std::string decimalPoint(localeconv()->decimal_point);
  453. - if ((decimalPoint.size() == 0) || (decimalPoint == "."))
  454. - return tempStream.str();
  455. - std::string stringValue(tempStream.str());
  456. - if (!stringValue.empty())
  457. - {
  458. - std::string::size_type pos;
  459. - while ((pos = stringValue.find(decimalPoint)) != std::string::npos)
  460. - stringValue.replace(pos,decimalPoint.size(),".");
  461. - }
  462. - return stringValue;
  463. -}
  464. -
  465. -
  466. -OdgExporter::OdgExporter(GraphicsHandler *pHandler, const bool isFlatXML):
  467. - mpHandler(pHandler),
  468. - m_fillRule(AlternatingFill),
  469. - m_gradientIndex(1),
  470. - m_dashIndex(1),
  471. - m_styleIndex(1),
  472. - m_width(0.0f),
  473. - m_height(0.0f),
  474. - m_isFlatXML(isFlatXML)
  475. -{
  476. -}
  477. -
  478. -OdgExporter::~OdgExporter()
  479. -{
  480. - for (std::vector <GraphicsElement *>::iterator iterStroke = mStrokeDashElements.begin();
  481. - iterStroke != mStrokeDashElements.end(); iterStroke++)
  482. - delete (*iterStroke);
  483. -
  484. - for (std::vector <GraphicsElement *>::iterator iterGradient = mGradientElements.begin();
  485. - iterGradient != mGradientElements.end(); iterGradient++)
  486. - delete (*iterGradient);
  487. -
  488. - for (std::vector <GraphicsElement *>::iterator iterAutomaticStyles = mAutomaticStylesElements.begin();
  489. - iterAutomaticStyles != mAutomaticStylesElements.end(); iterAutomaticStyles++)
  490. - delete (*iterAutomaticStyles);
  491. -
  492. - for (std::vector<GraphicsElement *>::iterator bodyIter = mBodyElements.begin();
  493. - bodyIter != mBodyElements.end(); bodyIter++)
  494. - delete (*bodyIter);
  495. -}
  496. -
  497. -void OdgExporter::startGraphics(double width, double height)
  498. -{
  499. - m_gradientIndex = 1;
  500. - m_dashIndex = 1;
  501. - m_styleIndex = 1;
  502. - m_width = width;
  503. - m_height = height;
  504. -
  505. -
  506. - mpHandler->startDocument();
  507. - OpenTagGraphicsElement tmpOfficeDocumentContent("office:document");
  508. - tmpOfficeDocumentContent.addAttribute("xmlns:office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
  509. - tmpOfficeDocumentContent.addAttribute("xmlns:style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
  510. - tmpOfficeDocumentContent.addAttribute("xmlns:text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
  511. - tmpOfficeDocumentContent.addAttribute("xmlns:draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0");
  512. - tmpOfficeDocumentContent.addAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
  513. - tmpOfficeDocumentContent.addAttribute("xmlns:svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0");
  514. - tmpOfficeDocumentContent.addAttribute("xmlns:fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
  515. - tmpOfficeDocumentContent.addAttribute("xmlns:config", "urn:oasis:names:tc:opendocument:xmlns:config:1.0");
  516. - tmpOfficeDocumentContent.addAttribute("xmlns:ooo", "http://openoffice.org/2004/office");
  517. - tmpOfficeDocumentContent.addAttribute("office:version", "1.0");
  518. - if (m_isFlatXML)
  519. - tmpOfficeDocumentContent.addAttribute("office:mimetype", "application/x-vnd.oasis.openoffice.drawing");
  520. - tmpOfficeDocumentContent.write(mpHandler);
  521. -
  522. - OpenTagGraphicsElement("office:settings").write(mpHandler);
  523. -
  524. - OpenTagGraphicsElement configItemSetOpenElement("config:config-item-set");
  525. - configItemSetOpenElement.addAttribute("config:name", "ooo:view-settings");
  526. - configItemSetOpenElement.write(mpHandler);
  527. -
  528. - OpenTagGraphicsElement configItemOpenElement1("config:config-item");
  529. - configItemOpenElement1.addAttribute("config:name", "VisibleAreaTop");
  530. - configItemOpenElement1.addAttribute("config:type", "int");
  531. - configItemOpenElement1.write(mpHandler);
  532. - mpHandler->characters("0");
  533. - mpHandler->endElement("config:config-item");
  534. -
  535. - OpenTagGraphicsElement configItemOpenElement2("config:config-item");
  536. - configItemOpenElement2.addAttribute("config:name", "VisibleAreaLeft");
  537. - configItemOpenElement2.addAttribute("config:type", "int");
  538. - configItemOpenElement2.write(mpHandler);
  539. - mpHandler->characters("0");
  540. - mpHandler->endElement("config:config-item");
  541. -
  542. - OpenTagGraphicsElement configItemOpenElement3("config:config-item");
  543. - configItemOpenElement3.addAttribute("config:name", "VisibleAreaWidth");
  544. - configItemOpenElement3.addAttribute("config:type", "int");
  545. - configItemOpenElement3.write(mpHandler);
  546. - m_value.str("");
  547. - m_value << (unsigned)(2540 * width);
  548. - mpHandler->characters(m_value.str());
  549. - mpHandler->endElement("config:config-item");
  550. -
  551. - OpenTagGraphicsElement configItemOpenElement4("config:config-item");
  552. - configItemOpenElement4.addAttribute("config:name", "VisibleAreaHeight");
  553. - configItemOpenElement4.addAttribute("config:type", "int");
  554. - configItemOpenElement4.write(mpHandler);
  555. - m_value.str("");
  556. - m_value << (unsigned)(2540 * height);
  557. - mpHandler->characters(m_value.str());
  558. - mpHandler->endElement("config:config-item");
  559. -
  560. - mpHandler->endElement("config:config-item-set");
  561. -
  562. - mpHandler->endElement("office:settings");
  563. -
  564. -}
  565. -
  566. -void OdgExporter::endGraphics()
  567. -{
  568. - OpenTagGraphicsElement("office:styles").write(mpHandler);
  569. -
  570. - for (std::vector <GraphicsElement *>::const_iterator iterStroke = mStrokeDashElements.begin();
  571. - iterStroke != mStrokeDashElements.end(); iterStroke++)
  572. - (*iterStroke)->write(mpHandler);
  573. -
  574. - for (std::vector <GraphicsElement *>::const_iterator iterGradient = mGradientElements.begin();
  575. - iterGradient != mGradientElements.end(); iterGradient++)
  576. - (*iterGradient)->write(mpHandler);
  577. -
  578. - mpHandler->endElement("office:styles");
  579. -
  580. - OpenTagGraphicsElement("office:automatic-styles").write(mpHandler);
  581. -
  582. - for (std::vector <GraphicsElement *>::const_iterator iterAutomaticStyles = mAutomaticStylesElements.begin();
  583. - iterAutomaticStyles != mAutomaticStylesElements.end(); iterAutomaticStyles++)
  584. - (*iterAutomaticStyles)->write(mpHandler);
  585. -
  586. - OpenTagGraphicsElement tmpStylePageLayoutOpenElement("style:page-layout");
  587. - tmpStylePageLayoutOpenElement.addAttribute("style:name", "PM0");
  588. - tmpStylePageLayoutOpenElement.write(mpHandler);
  589. -
  590. - OpenTagGraphicsElement tmpStylePageLayoutPropertiesOpenElement("style:page-layout-properties");
  591. - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-top", "0in");
  592. - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-bottom", "0in");
  593. - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-left", "0in");
  594. - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-right", "0in");
  595. - m_value.str("");
  596. - m_value << doubleToString(m_width) << "in";
  597. - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-width", m_value.str());
  598. - m_value.str("");
  599. - m_value << doubleToString(m_height) << "in";
  600. - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-height", m_value.str());
  601. - m_value.str("");
  602. - tmpStylePageLayoutPropertiesOpenElement.addAttribute("style:print-orientation", "portrait");
  603. - tmpStylePageLayoutPropertiesOpenElement.write(mpHandler);
  604. -
  605. - mpHandler->endElement("style:page-layout-properties");
  606. -
  607. - mpHandler->endElement("style:page-layout");
  608. -
  609. - OpenTagGraphicsElement tmpStyleStyleOpenElement("style:style");
  610. - tmpStyleStyleOpenElement.addAttribute("style:name", "dp1");
  611. - tmpStyleStyleOpenElement.addAttribute("style:family", "drawing-page");
  612. - tmpStyleStyleOpenElement.write(mpHandler);
  613. -
  614. - OpenTagGraphicsElement tmpStyleDrawingPagePropertiesOpenElement("style:drawing-page-properties");
  615. - // tmpStyleDrawingPagePropertiesOpenElement.addAttribute("draw:background-size", "border");
  616. - tmpStyleDrawingPagePropertiesOpenElement.addAttribute("draw:fill", "none");
  617. - tmpStyleDrawingPagePropertiesOpenElement.write(mpHandler);
  618. -
  619. - mpHandler->endElement("style:drawing-page-properties");
  620. -
  621. - mpHandler->endElement("style:style");
  622. -
  623. - mpHandler->endElement("office:automatic-styles");
  624. -
  625. - OpenTagGraphicsElement("office:master-styles").write(mpHandler);
  626. -
  627. - OpenTagGraphicsElement tmpStyleMasterPageOpenElement("style:master-page");
  628. - tmpStyleMasterPageOpenElement.addAttribute("style:name", "Default");
  629. - tmpStyleMasterPageOpenElement.addAttribute("style:page-layout-name", "PM0");
  630. - tmpStyleMasterPageOpenElement.addAttribute("draw:style-name", "dp1");
  631. - tmpStyleMasterPageOpenElement.write(mpHandler);
  632. -
  633. - mpHandler->endElement("style:master-page");
  634. -
  635. - mpHandler->endElement("office:master-styles");
  636. -
  637. - OpenTagGraphicsElement("office:body").write(mpHandler);
  638. -
  639. - OpenTagGraphicsElement("office:drawing").write(mpHandler);
  640. -
  641. - OpenTagGraphicsElement tmpDrawPageOpenElement("draw:page");
  642. - tmpDrawPageOpenElement.addAttribute("draw:name", "page1");
  643. - tmpDrawPageOpenElement.addAttribute("draw:style-name", "dp1");
  644. - tmpDrawPageOpenElement.addAttribute("draw:master-page-name", "Default");
  645. - tmpDrawPageOpenElement.write(mpHandler);
  646. -
  647. - for (std::vector<GraphicsElement *>::const_iterator bodyIter = mBodyElements.begin();
  648. - bodyIter != mBodyElements.end(); bodyIter++)
  649. - {
  650. - (*bodyIter)->write(mpHandler);
  651. - }
  652. -
  653. - mpHandler->endElement("draw:page");
  654. - mpHandler->endElement("office:drawing");
  655. - mpHandler->endElement("office:body");
  656. - mpHandler->endElement("office:document");
  657. -
  658. - mpHandler->endDocument();
  659. -}
  660. -
  661. -void OdgExporter::setPen(const libwpg::WPGPen& pen)
  662. -{
  663. - m_pen = pen;
  664. -}
  665. -
  666. -void OdgExporter::setBrush(const libwpg::WPGBrush& brush)
  667. -{
  668. - m_brush = brush;
  669. -}
  670. -
  671. -void OdgExporter::setFillRule(FillRule rule)
  672. -{
  673. - m_fillRule = rule;
  674. -}
  675. -
  676. -void OdgExporter::startLayer(unsigned int)
  677. -{
  678. -}
  679. -
  680. -void OdgExporter::endLayer(unsigned int)
  681. -{
  682. -}
  683. -
  684. -void OdgExporter::drawRectangle(const libwpg::WPGRect& rect, double rx, double )
  685. -{
  686. - writeStyle();
  687. - OpenTagGraphicsElement *pDrawRectElement = new OpenTagGraphicsElement("draw:rect");
  688. - m_value.str("");
  689. - m_value << "gr" << m_styleIndex-1;
  690. - pDrawRectElement->addAttribute("draw:style-name", m_value.str());
  691. - m_value.str("");
  692. - m_value << doubleToString(rect.x1) << "in";
  693. - pDrawRectElement->addAttribute("svg:x", m_value.str());
  694. - m_value.str("");
  695. - m_value << doubleToString(rect.y1) << "in";
  696. - pDrawRectElement->addAttribute("svg:y", m_value.str());
  697. - m_value.str("");
  698. - m_value << doubleToString(rect.x2-rect.x1) << "in";
  699. - pDrawRectElement->addAttribute("svg:width", m_value.str());
  700. - m_value.str("");
  701. - m_value << doubleToString(rect.y2-rect.y1) << "in";
  702. - pDrawRectElement->addAttribute("svg:height", m_value.str());
  703. - m_value.str("");
  704. - m_value << doubleToString(rx) << "in";
  705. - // FIXME: what to do when rx != ry ?
  706. - pDrawRectElement->addAttribute("draw:corner-radius", m_value.str());
  707. - m_value.str("");
  708. - mBodyElements.push_back(static_cast<GraphicsElement *>(pDrawRectElement));
  709. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("draw:rect")));
  710. -}
  711. -
  712. -void OdgExporter::drawEllipse(const libwpg::WPGPoint& center, double rx, double ry)
  713. -{
  714. - writeStyle();
  715. - OpenTagGraphicsElement *pDrawEllipseElement = new OpenTagGraphicsElement("draw:ellipse");
  716. - m_value.str("");
  717. - m_value << "gr" << m_styleIndex-1;
  718. - pDrawEllipseElement->addAttribute("draw:style-name", m_value.str());
  719. - m_value.str("");
  720. - m_value << doubleToString(center.x - rx) << "in";
  721. - pDrawEllipseElement->addAttribute("svg:x", m_value.str());
  722. - m_value.str("");
  723. - m_value << doubleToString(center.y - ry) << "in";
  724. - pDrawEllipseElement->addAttribute("svg:y", m_value.str());
  725. - m_value.str("");
  726. - m_value << doubleToString(2 * rx) << "in";
  727. - pDrawEllipseElement->addAttribute("svg:width", m_value.str());
  728. - m_value.str("");
  729. - m_value << doubleToString(2 * ry) << "in";
  730. - pDrawEllipseElement->addAttribute("svg:height", m_value.str());
  731. - m_value.str("");
  732. - mBodyElements.push_back(static_cast<GraphicsElement *>(pDrawEllipseElement));
  733. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("draw:ellipse")));
  734. -}
  735. -
  736. -void OdgExporter::drawPolygon(const libwpg::WPGPointArray& vertices)
  737. -{
  738. - if(vertices.count() < 2)
  739. - return;
  740. -
  741. - if(vertices.count() == 2)
  742. - {
  743. - const libwpg::WPGPoint& p1 = vertices[0];
  744. - const libwpg::WPGPoint& p2 = vertices[1];
  745. -
  746. - writeStyle();
  747. - OpenTagGraphicsElement *pDrawLineElement = new OpenTagGraphicsElement("draw:line");
  748. - m_value.str("");
  749. - m_value << "gr" << m_styleIndex-1;
  750. - pDrawLineElement->addAttribute("draw:style-name", m_value.str());
  751. - m_value.str("");
  752. - pDrawLineElement->addAttribute("draw:text-style-name", "P1");
  753. - pDrawLineElement->addAttribute("draw:layer", "layout");
  754. - m_value << doubleToString(p1.x) << "in";
  755. - pDrawLineElement->addAttribute("svg:x1", m_value.str());
  756. - m_value.str("");
  757. - m_value << doubleToString(p1.y) << "in";
  758. - pDrawLineElement->addAttribute("svg:y1", m_value.str());
  759. - m_value.str("");
  760. - m_value << doubleToString(p2.x) << "in";
  761. - pDrawLineElement->addAttribute("svg:x2", m_value.str());
  762. - m_value.str("");
  763. - m_value << doubleToString(p2.y) << "in";
  764. - pDrawLineElement->addAttribute("svg:y2", m_value.str());
  765. - m_value.str("");
  766. - mBodyElements.push_back(static_cast<GraphicsElement *>(pDrawLineElement));
  767. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("draw:line")));
  768. - }
  769. - else
  770. - {
  771. - // draw as path
  772. - libwpg::WPGPath path;
  773. - path.moveTo(vertices[0]);
  774. - for(unsigned long ii = 1; ii < vertices.count(); ii++)
  775. - path.lineTo(vertices[ii]);
  776. - path.closed = true;
  777. - drawPath(path);
  778. - }
  779. -}
  780. -
  781. -void OdgExporter::drawPath(const libwpg::WPGPath& path)
  782. -{
  783. - if(path.count() == 0)
  784. - return;
  785. -
  786. - // try to find the bounding box
  787. - // this is simple convex hull technique, the bounding box might not be
  788. - // accurate but that should be enough for this purpose
  789. - libwpg::WPGPoint p = path.element(0).point;
  790. - libwpg::WPGPoint q = path.element(0).point;
  791. - for(unsigned k = 0; k < path.count(); k++)
  792. - {
  793. - libwpg::WPGPathElement element = path.element(k);
  794. - p.x = (p.x > element.point.x) ? element.point.x : p.x;
  795. - p.y = (p.y > element.point.y) ? element.point.y : p.y;
  796. - q.x = (q.x < element.point.x) ? element.point.x : q.x;
  797. - q.y = (q.y < element.point.y) ? element.point.y : q.y;
  798. - if(element.type == libwpg::WPGPathElement::CurveToElement)
  799. - {
  800. - p.x = (p.x > element.extra1.x) ? element.extra1.x : p.x;
  801. - p.y = (p.y > element.extra1.y) ? element.extra1.y : p.y;
  802. - q.x = (q.x < element.extra1.x) ? element.extra1.x : q.x;
  803. - q.y = (q.y < element.extra1.y) ? element.extra1.y : q.y;
  804. - p.x = (p.x > element.extra2.x) ? element.extra2.x : p.x;
  805. - p.y = (p.y > element.extra2.y) ? element.extra2.y : p.y;
  806. - q.x = (q.x < element.extra2.x) ? element.extra2.x : q.x;
  807. - q.y = (q.y < element.extra2.y) ? element.extra2.y : q.y;
  808. - }
  809. - }
  810. - double vw = q.x - p.x;
  811. - double vh = q.y - p.y;
  812. -
  813. - writeStyle();
  814. -
  815. - OpenTagGraphicsElement *pDrawPathElement = new OpenTagGraphicsElement("draw:path");
  816. - m_value.str("");
  817. - m_value << "gr" << m_styleIndex-1;
  818. - pDrawPathElement->addAttribute("draw:style-name", m_value.str());
  819. - m_value.str("");
  820. - pDrawPathElement->addAttribute("draw:text-style-name", "P1");
  821. - pDrawPathElement->addAttribute("draw:layer", "layout");
  822. - m_value << doubleToString(p.x) << "in";
  823. - pDrawPathElement->addAttribute("svg:x", m_value.str());
  824. - m_value.str("");
  825. - m_value << doubleToString(p.y) << "in";
  826. - pDrawPathElement->addAttribute("svg:y", m_value.str());
  827. - m_value.str("");
  828. - m_value << doubleToString(vw) << "in";
  829. - pDrawPathElement->addAttribute("svg:width", m_value.str());
  830. - m_value.str("");
  831. - m_value << doubleToString(vh) << "in";
  832. - pDrawPathElement->addAttribute("svg:height", m_value.str());
  833. - m_value.str("");
  834. - m_value << "0 0 " << (int)(vw*2540) << " " << (int)(vh*2540);
  835. - pDrawPathElement->addAttribute("svg:viewBox", m_value.str());
  836. - m_value.str("");
  837. -
  838. - for(unsigned i = 0; i < path.count(); i++)
  839. - {
  840. - libwpg::WPGPathElement element = path.element(i);
  841. - libwpg::WPGPoint point = element.point;
  842. - switch(element.type)
  843. - {
  844. - // 2540 is 2.54*1000, 2.54 in = 1 in
  845. - case libwpg::WPGPathElement::MoveToElement:
  846. - m_value << "M" << (int)((point.x-p.x)*2540) << " ";
  847. - m_value << (int)((point.y-p.y)*2540);
  848. - break;
  849. -
  850. - case libwpg::WPGPathElement::LineToElement:
  851. - m_value << "L" << (int)((point.x-p.x)*2540) << " ";
  852. - m_value << (int)((point.y-p.y)*2540);
  853. - break;
  854. -
  855. - case libwpg::WPGPathElement::CurveToElement:
  856. - m_value << "C" << (int)((element.extra1.x-p.x)*2540) << " ";
  857. - m_value << (int)((element.extra1.y-p.y)*2540) << " ";
  858. - m_value << (int)((element.extra2.x-p.x)*2540) << " ";
  859. - m_value << (int)((element.extra2.y-p.y)*2540) << " ";
  860. - m_value << (int)((point.x-p.x)*2540) << " ";
  861. - m_value << (int)((point.y-p.y)*2540);
  862. - break;
  863. -
  864. - default:
  865. - break;
  866. - }
  867. - }
  868. - if(path.closed)
  869. - m_value << " Z";
  870. - pDrawPathElement->addAttribute("svg:d", m_value.str());
  871. - m_value.str("");
  872. - mBodyElements.push_back(static_cast<GraphicsElement *>(pDrawPathElement));
  873. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("draw:path")));
  874. -}
  875. -
  876. -
  877. -void OdgExporter::drawBitmap(const libwpg::WPGBitmap& bitmap)
  878. -{
  879. - OpenTagGraphicsElement *pDrawFrameElement = new OpenTagGraphicsElement("draw:frame");
  880. - m_value.str("");
  881. - m_value << doubleToString(bitmap.rect.x1) << "in";
  882. - pDrawFrameElement->addAttribute("svg:x", m_value.str());
  883. - m_value.str("");
  884. - m_value << doubleToString(bitmap.rect.y1) << "in";
  885. - pDrawFrameElement->addAttribute("svg:y", m_value.str());
  886. - m_value.str("");
  887. - m_value << doubleToString(bitmap.rect.height()) << "in";
  888. - pDrawFrameElement->addAttribute("svg:height", m_value.str());
  889. - m_value.str("");
  890. - m_value << doubleToString(bitmap.rect.width()) << "in";
  891. - pDrawFrameElement->addAttribute("svg:width", m_value.str());
  892. - mBodyElements.push_back(static_cast<GraphicsElement *>(pDrawFrameElement));
  893. -
  894. - mBodyElements.push_back(static_cast<GraphicsElement *>(new OpenTagGraphicsElement("draw:image")));
  895. -
  896. - mBodyElements.push_back(static_cast<GraphicsElement *>(new OpenTagGraphicsElement("office:binary-data")));
  897. -
  898. - libwpg::WPGString base64Binary;
  899. - bitmap.generateBase64DIB(base64Binary);
  900. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CharDataGraphicsElement(base64Binary.cstr())));
  901. -
  902. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("office:binary-data")));
  903. -
  904. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("draw:image")));
  905. -
  906. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("draw:frame")));
  907. -}
  908. -
  909. -void OdgExporter::drawImageObject(const libwpg::WPGBinaryData& binaryData)
  910. -{
  911. - if (binaryData.mimeType.length() <= 0)
  912. - return;
  913. - OpenTagGraphicsElement *pDrawFrameElement = new OpenTagGraphicsElement("draw:frame");
  914. - m_value.str("");
  915. - m_value << doubleToString(binaryData.rect.x1) << "in";
  916. - pDrawFrameElement->addAttribute("svg:x", m_value.str());
  917. - m_value.str("");
  918. - m_value << doubleToString(binaryData.rect.y1) << "in";
  919. - pDrawFrameElement->addAttribute("svg:y", m_value.str());
  920. - m_value.str("");
  921. - m_value << doubleToString(binaryData.rect.height()) << "in";
  922. - pDrawFrameElement->addAttribute("svg:height", m_value.str());
  923. - m_value.str("");
  924. - m_value << doubleToString(binaryData.rect.width()) << "in";
  925. - pDrawFrameElement->addAttribute("svg:width", m_value.str());
  926. - mBodyElements.push_back(static_cast<GraphicsElement *>(pDrawFrameElement));
  927. -
  928. - mBodyElements.push_back(static_cast<GraphicsElement *>(new OpenTagGraphicsElement("draw:image")));
  929. -
  930. - mBodyElements.push_back(static_cast<GraphicsElement *>(new OpenTagGraphicsElement("office:binary-data")));
  931. -
  932. - libwpg::WPGString base64Binary = binaryData.getBase64Data();
  933. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CharDataGraphicsElement(base64Binary.cstr())));
  934. -
  935. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("office:binary-data")));
  936. -
  937. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("draw:image")));
  938. -
  939. - mBodyElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("draw:frame")));
  940. -}
  941. -
  942. -
  943. -static std::string colorToHex(const libwpg::WPGColor& color)
  944. -{
  945. - char hexdigits[] = "0123456789abcdef";
  946. - char buffer[] = "123456";
  947. - buffer[0] = hexdigits[(color.red >> 4) & 15];
  948. - buffer[1] = hexdigits[color.red & 15];
  949. - buffer[2] = hexdigits[(color.green >> 4) & 15];
  950. - buffer[3] = hexdigits[color.green & 15];
  951. - buffer[4] = hexdigits[(color.blue >> 4) & 15];
  952. - buffer[5] = hexdigits[color.blue & 15];
  953. - return std::string(buffer);
  954. -}
  955. -
  956. -void OdgExporter::writeStyle()
  957. -{
  958. - m_value.str("");
  959. - m_name.str("");
  960. -
  961. - if(!m_pen.solid && (m_pen.dashArray.count() >=2 ) )
  962. - {
  963. - // ODG only supports dashes with the same length of spaces inbetween
  964. - // here we take the first space and assume everything else the same
  965. - // note that dash length is written in percentage
  966. - double distance = m_pen.dashArray.at(1);
  967. - OpenTagGraphicsElement *tmpDrawStrokeDashElement = new OpenTagGraphicsElement("draw:stroke-dash");
  968. - tmpDrawStrokeDashElement->addAttribute("draw:style", "rect");
  969. - m_value << "Dash_" << m_dashIndex++;
  970. - tmpDrawStrokeDashElement->addAttribute("draw:name", m_value.str());
  971. - m_value.str("");
  972. - m_value << doubleToString(distance*100) << "%";
  973. - tmpDrawStrokeDashElement->addAttribute("draw:distance", m_value.str());
  974. - m_value.str("");
  975. - for(unsigned i = 0; i < m_pen.dashArray.count()/2; i++)
  976. - {
  977. - m_name << "draw:dots" << i+1;
  978. - tmpDrawStrokeDashElement->addAttribute(m_name.str(), "1");
  979. - m_name.str("");
  980. - m_name << "draw:dots" << i+1 << "-length";
  981. - m_value << doubleToString(100*m_pen.dashArray.at(i*2)) << "%";
  982. - tmpDrawStrokeDashElement->addAttribute(m_name.str(), m_value.str());
  983. - m_name.str("");
  984. - m_value.str("");
  985. - }
  986. - mStrokeDashElements.push_back(static_cast<GraphicsElement *>(tmpDrawStrokeDashElement));
  987. - mStrokeDashElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("draw:stroke-dash")));
  988. - }
  989. -
  990. - if(m_brush.style == libwpg::WPGBrush::Gradient)
  991. - {
  992. - OpenTagGraphicsElement *tmpDrawGradientElement = new OpenTagGraphicsElement("draw:gradient");
  993. - tmpDrawGradientElement->addAttribute("draw:style", "linear");
  994. - m_value << "Gradient_" << m_gradientIndex++;
  995. - tmpDrawGradientElement->addAttribute("draw:name", m_value.str());
  996. - m_value.str("");
  997. -
  998. - // ODG angle unit is 0.1 degree
  999. - double angle = -m_brush.gradient.angle();
  1000. - while(angle < 0)
  1001. - angle += 360;
  1002. - while(angle > 360)
  1003. - angle -= 360;
  1004. -
  1005. - m_value << (unsigned)(angle*10);
  1006. - tmpDrawGradientElement->addAttribute("draw:angle", m_value.str());
  1007. - m_value.str("");
  1008. -
  1009. - libwpg::WPGColor startColor = m_brush.gradient.stopColor(0);
  1010. - libwpg::WPGColor stopColor = m_brush.gradient.stopColor(1);
  1011. - m_value << "#" << colorToHex(startColor);
  1012. - tmpDrawGradientElement->addAttribute("draw:start-color", m_value.str());
  1013. - m_value.str("");
  1014. - m_value << "#" << colorToHex(stopColor);
  1015. - tmpDrawGradientElement->addAttribute("draw:end-color", m_value.str());
  1016. - m_value.str("");
  1017. - tmpDrawGradientElement->addAttribute("draw:start-intensity", "100%");
  1018. - tmpDrawGradientElement->addAttribute("draw:end-intensity", "100%");
  1019. - tmpDrawGradientElement->addAttribute("draw:border", "0%");
  1020. - mGradientElements.push_back(static_cast<GraphicsElement *>(tmpDrawGradientElement));
  1021. - mGradientElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("draw:gradient")));
  1022. - }
  1023. -
  1024. - OpenTagGraphicsElement *tmpStyleStyleElement = new OpenTagGraphicsElement("style:style");
  1025. - m_value << "gr" << m_styleIndex;
  1026. - tmpStyleStyleElement->addAttribute("style:name", m_value.str());
  1027. - m_value.str("");
  1028. - tmpStyleStyleElement->addAttribute("style:family", "graphic");
  1029. - tmpStyleStyleElement->addAttribute("style:parent-style-name", "standard");
  1030. - mAutomaticStylesElements.push_back(static_cast<GraphicsElement *>(tmpStyleStyleElement));
  1031. -
  1032. - OpenTagGraphicsElement *tmpStyleGraphicPropertiesElement = new OpenTagGraphicsElement("style:graphic-properties");
  1033. -
  1034. - if(m_pen.width > 0.0)
  1035. - {
  1036. - m_value << doubleToString(m_pen.width) << "in";
  1037. - tmpStyleGraphicPropertiesElement->addAttribute("svg:stroke-width", m_value.str());
  1038. - m_value.str("");
  1039. - m_value << "#" << colorToHex(m_pen.foreColor);
  1040. - tmpStyleGraphicPropertiesElement->addAttribute("svg:stroke-color", m_value.str());
  1041. - m_value.str("");
  1042. -
  1043. - if(!m_pen.solid)
  1044. - {
  1045. - tmpStyleGraphicPropertiesElement->addAttribute("draw:stroke", "dash");
  1046. - m_value << "Dash_" << m_dashIndex-1;
  1047. - tmpStyleGraphicPropertiesElement->addAttribute("draw:stroke-dash", m_value.str());
  1048. - m_value.str("");
  1049. - }
  1050. - }
  1051. - else
  1052. - tmpStyleGraphicPropertiesElement->addAttribute("draw:stroke", "none");
  1053. -
  1054. - if(m_brush.style == libwpg::WPGBrush::NoBrush)
  1055. - tmpStyleGraphicPropertiesElement->addAttribute("draw:fill", "none");
  1056. -
  1057. - if(m_brush.style == libwpg::WPGBrush::Solid)
  1058. - {
  1059. - tmpStyleGraphicPropertiesElement->addAttribute("draw:fill", "solid");
  1060. - m_value << "#" << colorToHex(m_brush.foreColor);
  1061. - tmpStyleGraphicPropertiesElement->addAttribute("draw:fill-color", m_value.str());
  1062. - m_value.str("");
  1063. - }
  1064. -
  1065. - if(m_brush.style == libwpg::WPGBrush::Gradient)
  1066. - {
  1067. - tmpStyleGraphicPropertiesElement->addAttribute("draw:fill", "gradient");
  1068. - m_value << "Gradient_" << m_gradientIndex-1;
  1069. - tmpStyleGraphicPropertiesElement->addAttribute("draw:fill-gradient-name", m_value.str());
  1070. - m_value.str("");
  1071. - }
  1072. -
  1073. - mAutomaticStylesElements.push_back(static_cast<GraphicsElement *>(tmpStyleGraphicPropertiesElement));
  1074. - mAutomaticStylesElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("style:graphic-properties")));
  1075. -
  1076. - mAutomaticStylesElements.push_back(static_cast<GraphicsElement *>(new CloseTagGraphicsElement("style:style")));
  1077. - m_styleIndex++;
  1078. -}
  1079. diff -Nur koffice-2.3.1/filters/karbon/wpg/import/OdgExporter.hxx koffice-2.3.1-libwpg02/filters/karbon/wpg/import/OdgExporter.hxx
  1080. --- koffice-2.3.1/filters/karbon/wpg/import/OdgExporter.hxx 2011-01-15 21:05:35.000000000 +0100
  1081. +++ koffice-2.3.1-libwpg02/filters/karbon/wpg/import/OdgExporter.hxx 1970-01-01 01:00:00.000000000 +0100
  1082. @@ -1,116 +0,0 @@
  1083. -/* libwpg
  1084. - * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
  1085. - *
  1086. - * This library is free software; you can redistribute it and/or
  1087. - * modify it under the terms of the GNU Library General Public
  1088. - * License as published by the Free Software Foundation; either
  1089. - * version 2 of the License, or (at your option) any later version.
  1090. - *
  1091. - * This library is distributed in the hope that it will be useful,
  1092. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1093. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1094. - * Library General Public License for more details.
  1095. - *
  1096. - * You should have received a copy of the GNU Library General Public
  1097. - * License along with this library; if not, write to the
  1098. - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  1099. - * Boston, MA 02111-1301 USA
  1100. - *
  1101. - * For further information visit http://libwpg.sourceforge.net
  1102. - */
  1103. -
  1104. -/* "This product is not manufactured, approved, or supported by
  1105. - * Corel Corporation or Corel Corporation Limited."
  1106. - */
  1107. -
  1108. -#ifndef __ODGEXPORTER_H__
  1109. -#define __ODGEXPORTER_H__
  1110. -
  1111. -#include <iostream>
  1112. -#include <sstream>
  1113. -#include <string>
  1114. -
  1115. -#include <libwpg/libwpg.h>
  1116. -#include "GraphicsElement.hxx"
  1117. -
  1118. -class OdgExporter : public libwpg::WPGPaintInterface {
  1119. -public:
  1120. - explicit OdgExporter(GraphicsHandler *pHandler,
  1121. - const bool isFlatXML = false);
  1122. - ~OdgExporter();
  1123. -
  1124. -#if LIBWPG_VERSION_MINOR<2
  1125. - void startGraphics(double imageWidth, double imageHeight);
  1126. - void endGraphics();
  1127. - void startLayer(unsigned int id);
  1128. - void endLayer(unsigned int id);
  1129. -
  1130. - void setPen(const libwpg::WPGPen& pen);
  1131. - void setBrush(const libwpg::WPGBrush& brush);
  1132. - void setFillRule(FillRule rule);
  1133. -
  1134. - void drawRectangle(const libwpg::WPGRect& rect, double rx, double ry);
  1135. - void drawEllipse(const libwpg::WPGPoint& center, double rx, double ry);
  1136. - void drawPolygon(const libwpg::WPGPointArray& vertices);
  1137. - void drawPath(const libwpg::WPGPath& path);
  1138. - void drawBitmap(const libwpg::WPGBitmap& bitmap);
  1139. - void drawImageObject(const libwpg::WPGBinaryData& binaryData);
  1140. -
  1141. -private:
  1142. - std::vector <GraphicsElement *> mBodyElements;
  1143. - std::vector <GraphicsElement *> mAutomaticStylesElements;
  1144. - std::vector <GraphicsElement *> mStrokeDashElements;
  1145. - std::vector <GraphicsElement *> mGradientElements;
  1146. - GraphicsHandler *mpHandler;
  1147. -
  1148. - libwpg::WPGPen m_pen;
  1149. - libwpg::WPGBrush m_brush;
  1150. - FillRule m_fillRule;
  1151. - int m_gradientIndex;
  1152. - int m_dashIndex;
  1153. - int m_styleIndex;
  1154. - void writeStyle();
  1155. - std::ostringstream m_value, m_name;
  1156. - double m_width, m_height;
  1157. - const bool m_isFlatXML;
  1158. -#else
  1159. - virtual void startGraphics(const ::WPXPropertyList &propList);
  1160. - virtual void endGraphics();
  1161. - virtual void setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &gradient);
  1162. - virtual void startLayer(const ::WPXPropertyList &propList);
  1163. - virtual void endLayer();
  1164. - virtual void drawRectangle(const ::WPXPropertyList& propList);
  1165. - virtual void drawEllipse(const ::WPXPropertyList& propList);
  1166. - virtual void drawPolygon(const ::WPXPropertyListVector &vertices);
  1167. - virtual void drawPath(const ::WPXPropertyListVector &path);
  1168. - virtual void drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData &binaryData);
  1169. - virtual void startEmbeddedGraphics(const ::WPXPropertyList &propList);
  1170. - virtual void endEmbeddedGraphics();
  1171. - virtual void drawPolyline(const ::WPXPropertyListVector &vertices);
  1172. - virtual void startTextObject(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &path);
  1173. - virtual void endTextObject();
  1174. - virtual void startTextLine(const ::WPXPropertyList &propList);
  1175. - virtual void endTextLine();
  1176. - virtual void startTextSpan(const ::WPXPropertyList &propList);
  1177. - virtual void endTextSpan();
  1178. - virtual void insertText(const ::WPXString &str);
  1179. -
  1180. -
  1181. -private:
  1182. - std::vector <GraphicsElement *> mBodyElements;
  1183. - std::vector <GraphicsElement *> mAutomaticStylesElements;
  1184. - std::vector <GraphicsElement *> mStrokeDashElements;
  1185. - std::vector <GraphicsElement *> mGradientElements;
  1186. - GraphicsHandler *mpHandler;
  1187. -
  1188. - int m_gradientIndex;
  1189. - int m_dashIndex;
  1190. - int m_styleIndex;
  1191. - void writeStyle();
  1192. - std::ostringstream m_value, m_name;
  1193. - double m_width, m_height;
  1194. - const bool m_isFlatXML;
  1195. -#endif
  1196. -};
  1197. -
  1198. -#endif // __ODGEXPORTER_H__
  1199. diff -Nur koffice-2.3.1/filters/karbon/wpg/import/WPGImport.cpp koffice-2.3.1-libwpg02/filters/karbon/wpg/import/WPGImport.cpp
  1200. --- koffice-2.3.1/filters/karbon/wpg/import/WPGImport.cpp 2011-01-15 21:05:35.000000000 +0100
  1201. +++ koffice-2.3.1-libwpg02/filters/karbon/wpg/import/WPGImport.cpp 2011-01-02 17:46:15.000000000 +0100
  1202. @@ -20,28 +20,26 @@
  1203. #include <WPGImport.h>
  1204. #include <WPGImport.moc>
  1205. -#include <QBuffer>
  1206. -#include <QByteArray>
  1207. -#include <QString>
  1208. -
  1209. -#include <kdebug.h>
  1210. #include <KoFilterChain.h>
  1211. #include <KoGlobal.h>
  1212. #include <KoUnit.h>
  1213. +#include <KoXmlWriter.h>
  1214. +
  1215. #include <kpluginfactory.h>
  1216. +#include <KDebug>
  1217. -#include <KoXmlWriter.h>
  1218. +
  1219. +#include <QtCore/QString>
  1220. +#include <QtCore/QFile>
  1221. #include <libwpg/libwpg.h>
  1222. #if LIBWPG_VERSION_MINOR<2
  1223. #include <libwpg/WPGStreamImplementation.h>
  1224. #else
  1225. #include <libwpd-stream/libwpd-stream.h>
  1226. +#include <libwpd/libwpd.h>
  1227. #endif
  1228. -#include "FileOutputHandler.hxx"
  1229. -#include "OdgExporter.hxx"
  1230. -
  1231. #include <iostream>
  1232. K_PLUGIN_FACTORY(WPGImportFactory, registerPlugin<WPGImport>();)
  1233. @@ -56,35 +54,13 @@
  1234. {
  1235. }
  1236. -static QByteArray createManifest()
  1237. -{
  1238. - KoXmlWriter* manifestWriter;
  1239. - QByteArray manifestData;
  1240. - QBuffer manifestBuffer(&manifestData);
  1241. -
  1242. - manifestBuffer.open(QIODevice::WriteOnly);
  1243. - manifestWriter = new KoXmlWriter(&manifestBuffer);
  1244. -
  1245. - manifestWriter->startDocument("manifest:manifest");
  1246. - manifestWriter->startElement("manifest:manifest");
  1247. - manifestWriter->addAttribute("xmlns:manifest", "urn:oasis:names:tc:openoffice:xmlns:manifest:1.0");
  1248. - manifestWriter->addManifestEntry("/", "application/vnd.oasis.opendocument.graphics");
  1249. - //manifestWriter->addManifestEntry( "styles.xml", "text/xml" );
  1250. - manifestWriter->addManifestEntry("content.xml", "text/xml");
  1251. - manifestWriter->endElement();
  1252. - manifestWriter->endDocument();
  1253. - delete manifestWriter;
  1254. -
  1255. - return manifestData;
  1256. -}
  1257. -
  1258. KoFilter::ConversionStatus WPGImport::convert(const QByteArray& from, const QByteArray& to)
  1259. {
  1260. if (from != "application/x-wpg")
  1261. return KoFilter::NotImplemented;
  1262. - if (to != "application/vnd.oasis.opendocument.graphics")
  1263. + if (to != "image/svg+xml")
  1264. return KoFilter::NotImplemented;
  1265. #if LIBWPG_VERSION_MINOR<2
  1266. @@ -96,6 +72,7 @@
  1267. input = olestream;
  1268. }
  1269. }
  1270. + libwpg::WPGString output;
  1271. #else
  1272. WPXInputStream* input = new WPXFileStream(m_chain->inputFile().toLocal8Bit());
  1273. if (input->isOLEStream()) {
  1274. @@ -105,59 +82,31 @@
  1275. input = olestream;
  1276. }
  1277. }
  1278. + ::WPXString output;
  1279. #endif
  1280. if (!libwpg::WPGraphics::isSupported(input)) {
  1281. - std::cerr << "ERROR: Unsupported file format (unsupported version) or file is encrypted!" << std::endl;
  1282. + kWarning() << "ERROR: Unsupported file format (unsupported version) or file is encrypted!";
  1283. delete input;
  1284. return KoFilter::NotImplemented;
  1285. }
  1286. - // do the conversion
  1287. - std::ostringstream tmpStringStream;
  1288. - FileOutputHandler tmpHandler(tmpStringStream);
  1289. - OdgExporter exporter(&tmpHandler);
  1290. - libwpg::WPGraphics::parse(input, &exporter);
  1291. - delete input;
  1292. -
  1293. -
  1294. - // create output store
  1295. - KoStore* storeout;
  1296. - storeout = KoStore::createStore(m_chain->outputFile(), KoStore::Write,
  1297. - "application/vnd.oasis.opendocument.graphics", KoStore::Zip);
  1298. -
  1299. - if (!storeout) {
  1300. - kWarning() << "Couldn't open the requested file.";
  1301. - return KoFilter::FileNotFound;
  1302. - }
  1303. -
  1304. -#if 0
  1305. - if (!storeout->open("styles.xml")) {
  1306. - kWarning() << "Couldn't open the file 'styles.xml'.";
  1307. - return KoFilter::CreationError;
  1308. + if (!libwpg::WPGraphics::generateSVG(input, output)) {
  1309. + kWarning() << "ERROR: SVG Generation failed!";
  1310. + delete input;
  1311. + return KoFilter::ParsingError;
  1312. }
  1313. - //storeout->write( createStyles() );
  1314. - storeout->close();
  1315. -#endif
  1316. - if (!storeout->open("content.xml")) {
  1317. - kWarning() << "Couldn't open the file 'content.xml'.";
  1318. - return KoFilter::CreationError;
  1319. - }
  1320. - storeout->write(tmpStringStream.str().c_str());
  1321. - storeout->close();
  1322. + delete input;
  1323. - // store document manifest
  1324. - storeout->enterDirectory("META-INF");
  1325. - if (!storeout->open("manifest.xml")) {
  1326. - kWarning() << "Couldn't open the file 'META-INF/manifest.xml'.";
  1327. - return KoFilter::CreationError;
  1328. + QFile outputFile(m_chain->outputFile());
  1329. + if(!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
  1330. + kWarning() << "ERROR: Could not open output file" << m_chain->outputFile();
  1331. + return KoFilter::InternalError;
  1332. }
  1333. - storeout->write(createManifest());
  1334. - storeout->close();
  1335. - // we are done!
  1336. - delete storeout;
  1337. + outputFile.write(output.cstr());
  1338. + outputFile.close();
  1339. return KoFilter::OK;
  1340. }