KOffice – TDE office suite
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.

175 lines
7.9KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2001, 2002, 2003, 2004 Nicolas GOUTTE <goutte@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. * Boston, MA 02110-1301, USA.
  15. */
  16. /*
  17. This file is based on the old file:
  18. /home/kde/koffice/filters/kword/ascii/asciiexport.cc
  19. The old file was copyrighted by
  20. Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
  21. Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved.
  22. Contact: Wolf-Michael Bolle <Bolle@ID-PRO.de>
  23. The old file was licensed under the terms of the GNU Library General Public
  24. License version 2.
  25. */
  26. #ifndef _EXPORTFILTER_H
  27. #define _EXPORTFILTER_H
  28. #include <KWEFStructures.h>
  29. #include <KWEFUtil.h>
  30. #include <KWEFBaseWorker.h>
  31. #include <KWEFKWordLeader.h>
  32. #define STRICT_OOWRITER_VERSION_1
  33. class KZip;
  34. class StyleMap : public TQMap<TQString,LayoutData>
  35. {
  36. public:
  37. StyleMap(void) {}
  38. ~StyleMap(void) {}
  39. };
  40. class OOWriterWorker : public KWEFBaseWorker
  41. {
  42. public:
  43. OOWriterWorker(void);
  44. virtual ~OOWriterWorker(void) { delete m_streamOut; }
  45. public:
  46. /// What is the type of the frameset anchor
  47. enum AnchorType
  48. {
  49. AnchorUnknown = 0, // ### TODO: is this really needed?
  50. AnchorInlined, ///< The frameset is inlined
  51. AnchorNonInlined, ///< the frameset is not inlined
  52. AnchorTextImage ///< This is a text image (KWord 0.8; inlined; only for pictures)
  53. };
  54. public:
  55. virtual bool doOpenFile(const TQString& filenameOut, const TQString& to);
  56. virtual bool doCloseFile(void); ///< Close file in normal conditions
  57. virtual bool doOpenDocument(void);
  58. virtual bool doCloseDocument(void);
  59. virtual bool doFullParagraph(const TQString& paraText, const LayoutData& layout,
  60. const ValueListFormatData& paraFormatDataList);
  61. virtual bool doFullPaperFormat(const int format,
  62. const double width, const double height, const int orientation);
  63. virtual bool doFullPaperBorders (const double top, const double left,
  64. const double bottom, const double right);
  65. /**
  66. * Other data of KWord's \<PAPER\> which are not in @see doFullPaperFormat
  67. * @since 1.4
  68. */
  69. virtual bool doFullPaperFormatOther ( const int columns, const double columnspacing, const int numPages );
  70. virtual bool doOpenStyles(void);
  71. virtual bool doCloseStyles(void);
  72. virtual bool doFullDefineStyle(LayoutData& layout);
  73. virtual bool doFullDocumentInfo(const KWEFDocumentInfo& docInfo);
  74. virtual bool doVariableSettings(const VariableSettingsData& vs);
  75. virtual bool doOpenBody (void);
  76. virtual bool doDeclareNonInlinedFramesets( TQValueList<FrameAnchor>& pictureAnchors, TQValueList<FrameAnchor>& tableAnchors ); ///< @since 1.4
  77. private:
  78. void processParagraphData (const TQString& paraText,
  79. const TextFormatting& formatLayout,
  80. const ValueListFormatData& paraFormatDataList);
  81. void processNormalText ( const TQString& paraText,
  82. const TextFormatting& formatLayout,
  83. const FormatData& formatData);
  84. void processFootnote( const VariableData& variable );
  85. void processNote( const VariableData& variable );
  86. void processVariable ( const TQString& paraText,
  87. const TextFormatting& formatLayout,
  88. const FormatData& formatData);
  89. void processAnchor ( const TQString& paraText,
  90. const TextFormatting& formatLayout,
  91. const FormatData& formatData);
  92. void processTextImage ( const TQString&,
  93. const TextFormatting& formatLayout,
  94. const FormatData& formatData);
  95. TQString textFormatToStyle(const TextFormatting& formatOrigin,
  96. const TextFormatting& formatData, const bool force, TQString& key);
  97. TQString layoutToParagraphStyle(const LayoutData& layoutOrigin,
  98. const LayoutData& layout, const bool force, TQString& styleKey);
  99. TQString escapeOOText(const TQString& strText) const;
  100. TQString escapeOOSpan(const TQString& strText) const;
  101. TQString cellToProperties( const TableCell& cell, TQString& key) const;
  102. bool makeTableRows( const TQString& tableName, const Table& table, int firstRowNumber );
  103. bool makeTable( const FrameAnchor& anchor, const AnchorType anchorType );
  104. bool makePicture( const FrameAnchor& anchor, const AnchorType anchorType );
  105. bool convertUnknownPicture(const TQString& name, const TQString& extension, TQByteArray& image);
  106. void declareFont(const TQString& fontName);
  107. void writeFontDeclaration(void);
  108. void writeContentXml(void);
  109. void writeStylesXml(void);
  110. void writeMetaXml(void);
  111. void writeStartOfFile(const TQString& type);
  112. /**
  113. * For automatic styles: create the name from @p prefix and from the increased @p counter
  114. * (Yes, the counter is increased by the method.)
  115. */
  116. TQString makeAutomaticStyleName(const TQString& prefix, ulong& counter) const;
  117. private: // ZIP methods
  118. bool zipPrepareWriting(const TQString& name);
  119. bool zipDoneWriting(void);
  120. bool zipWriteData(const char* str);
  121. bool zipWriteData(const TQByteArray& array);
  122. bool zipWriteData(const TQCString& cstr);
  123. bool zipWriteData(const TQString& str); ///< Assumes UTF-8
  124. private:
  125. TQTextStream* m_streamOut;
  126. TQString m_pagesize;
  127. StyleMap m_styleMap;
  128. double m_paperBorderTop,m_paperBorderLeft,m_paperBorderBottom,m_paperBorderRight;
  129. KWEFDocumentInfo m_docInfo; ///< document information
  130. TQByteArray m_contentBody; ///< office:body element of content.xml
  131. KZip* m_zip; ///< Output OOWriter file
  132. TQMap<TQString,TQString> m_fontNames; ///< List of used font names (the data() are extra attributes for font declaration time.)
  133. ulong m_pictureNumber; ///< Number of picture (increment *before* use)
  134. ulong m_automaticParagraphStyleNumber; ///< Number of paragraph-based automatic styles (increment *before* use)
  135. ulong m_automaticTextStyleNumber; ///< Number of text-based automatic styles (increment *before* use)
  136. ulong m_footnoteNumber; ///< Number of footnote (for text:id) (increment *before* use)
  137. ulong m_tableNumber; ///< Number of table (for table:name) (increment *before* use)
  138. ulong m_textBoxNumber; ///< Number of a textbox (for draw:text-box) (increment *before* use)
  139. TQString m_styles; ///< Normal paragraph styles (in OO format)
  140. TQString m_contentAutomaticStyles; ///< Automatic styles for content.xml (in OO format)
  141. uint m_size; ///< Size of ZIP entry
  142. int m_paperFormat;
  143. double m_paperWidth;
  144. double m_paperHeight;
  145. int m_paperOrientation;
  146. TQMap<TQString,TQString> m_mapTextStyleKeys; ///< Map of keys to automatic text styles
  147. TQMap<TQString,TQString> m_mapParaStyleKeys; ///< Map of keys to automatic paragraph styles
  148. VariableSettingsData m_varSet; ///< KWord's \<VARIABLESETTINGS\>
  149. int m_numPages; ///< Number of pages @note if the input file comes from a filter, this data is often missing.
  150. double m_columnspacing; ///< Spacing between columns
  151. int m_columns; ///< Number of columns
  152. private: // Variable that would need a link/glue from libexport
  153. TQValueList<FrameAnchor> m_nonInlinedPictureAnchors; ///< Pseudo-anchors for non-inlined anchors \todo: connection to libexport
  154. TQValueList<FrameAnchor> m_nonInlinedTableAnchors; ///< Pseudo-anchors for non-inlined tables \todo: connection to libexport
  155. };
  156. #endif // _EXPORTFILTER_H