1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ 2 3 /* AbiWord 4 * Copyright (C) 2001 AbiSource, Inc. 5 * Copyright (C) 2002-2004 Marc Maurer (uwog@uwog.net) 6 * Copyright (C) 2001-2003 William Lachance (william.lachance@sympatico.ca) 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 21 * 02110-1301 USA. 22 */ 23 24 /* See bug 1764 25 * This product is not manufactured, approved, or supported by 26 * Corel Corporation or Corel Corporation Limited." 27 */ 28 29 #ifndef IE_IMP_WP_H 30 #define IE_IMP_WP_H 31 32 #include <stdio.h> 33 #include <librevenge/librevenge.h> 34 #include "ie_imp.h" 35 #include "ut_string.h" 36 #include "ut_string_class.h" 37 #include "ut_growbuf.h" 38 #include "ut_mbtowc.h" 39 #include "pd_Document.h" 40 #include "fl_AutoNum.h" 41 #include "fl_TableLayout.h" 42 #include "fp_types.h" 43 44 using namespace std; 45 46 #define WP6_NUM_LIST_LEVELS 8 // see WP6FileStructure.h 47 48 // ABI_ListDefinition: tracks information on the list 49 class ABI_ListDefinition 50 { 51 public: 52 ABI_ListDefinition(int iOutlineHash); setListID(const int iLevel,const UT_uint32 iID)53 void setListID(const int iLevel, const UT_uint32 iID) { m_iListIDs[iLevel-1] = iID; } getListID(const int iLevel)54 UT_uint32 getListID(const int iLevel) const { return m_iListIDs[iLevel-1]; } getListType(const int iLevel)55 FL_ListType getListType(const int iLevel) const { return m_listTypes[iLevel-1]; } 56 void setListType(const int iLevel, const char type); incrementLevelNumber(const int iLevel)57 void incrementLevelNumber(const int iLevel) { m_iListNumbers[iLevel - 1]++; } setLevelNumber(const int iLevel,const int iNumber)58 void setLevelNumber(const int iLevel, const int iNumber) { m_iListNumbers[iLevel - 1] = iNumber; } setListLeftOffset(const int iLevel,const float listLeftOffset)59 void setListLeftOffset(const int iLevel, const float listLeftOffset) { m_listLeftOffset[iLevel - 1] = listLeftOffset; } setListMinLabelWidth(const int iLevel,const float listMinLabelWidth)60 void setListMinLabelWidth(const int iLevel, const float listMinLabelWidth) { m_listMinLabelWidth[iLevel - 1] = listMinLabelWidth; } getLevelNumber(const int iLevel)61 int getLevelNumber(const int iLevel) const { return m_iListNumbers[iLevel - 1]; } getListLeftOffset(const int iLevel)62 float getListLeftOffset(const int iLevel) const { return m_listLeftOffset[iLevel - 1]; } getListMinLabelWidth(const int iLevel)63 float getListMinLabelWidth(const int iLevel) const { return m_listMinLabelWidth[iLevel - 1]; } getOutlineHash()64 int getOutlineHash() const { return m_iOutlineHash; } 65 66 private: 67 //int m_iWPOutlineHash; // we don't use this information in AbiWord, only for id purposes during filtering 68 UT_uint32 m_iListIDs[WP6_NUM_LIST_LEVELS]; 69 int m_iListNumbers[WP6_NUM_LIST_LEVELS]; 70 FL_ListType m_listTypes[WP6_NUM_LIST_LEVELS]; 71 float m_listLeftOffset[WP6_NUM_LIST_LEVELS]; 72 float m_listMinLabelWidth[WP6_NUM_LIST_LEVELS]; 73 int m_iOutlineHash; 74 }; 75 76 class IE_Imp_WordPerfect_Sniffer : public IE_ImpSniffer 77 { 78 friend class IE_Imp; 79 friend class IE_Imp_WordPerfect; 80 81 public: 82 IE_Imp_WordPerfect_Sniffer(); 83 virtual ~IE_Imp_WordPerfect_Sniffer(); 84 85 virtual const IE_SuffixConfidence * getSuffixConfidence (); 86 virtual UT_Confidence_t recognizeContents (GsfInput * input); getMimeConfidence()87 virtual const IE_MimeConfidence * getMimeConfidence () { return NULL; } 88 virtual bool getDlgLabels (const char ** szDesc, 89 const char ** szSuffixList, 90 IEFileType * ft); 91 virtual UT_Error constructImporter (PD_Document * pDocument, 92 IE_Imp ** ppie); 93 }; 94 95 class IE_Imp_WordPerfect : public IE_Imp, public librevenge::RVNGTextInterface 96 { 97 public: 98 IE_Imp_WordPerfect(PD_Document * pDocument); 99 virtual ~IE_Imp_WordPerfect(); 100 101 virtual void pasteFromBuffer(PD_DocumentRange * pDocRange, 102 UT_uint8 * pData, UT_uint32 lenData, const char * szEncoding = 0); 103 104 virtual void setDocumentMetaData(const librevenge::RVNGPropertyList &propList); 105 106 virtual void startDocument(const librevenge::RVNGPropertyList &propList); 107 virtual void endDocument(); 108 defineEmbeddedFont(const librevenge::RVNGPropertyList &)109 virtual void defineEmbeddedFont(const librevenge::RVNGPropertyList & /* propList */) {} 110 definePageStyle(const librevenge::RVNGPropertyList &)111 virtual void definePageStyle(const librevenge::RVNGPropertyList &) {} 112 virtual void openPageSpan(const librevenge::RVNGPropertyList &propList); closePageSpan()113 virtual void closePageSpan() {} 114 virtual void openHeader(const librevenge::RVNGPropertyList &propList); 115 virtual void closeHeader(); 116 virtual void openFooter(const librevenge::RVNGPropertyList &propList); 117 virtual void closeFooter(); 118 defineSectionStyle(const librevenge::RVNGPropertyList &)119 virtual void defineSectionStyle(const librevenge::RVNGPropertyList &) {} 120 virtual void openSection(const librevenge::RVNGPropertyList &propList); closeSection()121 virtual void closeSection() {} 122 defineParagraphStyle(const librevenge::RVNGPropertyList &)123 virtual void defineParagraphStyle(const librevenge::RVNGPropertyList &) {} 124 virtual void openParagraph(const librevenge::RVNGPropertyList &propList); closeParagraph()125 virtual void closeParagraph() {} 126 defineCharacterStyle(const librevenge::RVNGPropertyList &)127 virtual void defineCharacterStyle(const librevenge::RVNGPropertyList &) {} 128 virtual void openSpan(const librevenge::RVNGPropertyList &propList); closeSpan()129 virtual void closeSpan() {} 130 openLink(const librevenge::RVNGPropertyList &)131 virtual void openLink(const librevenge::RVNGPropertyList & /* propList */) {} closeLink()132 virtual void closeLink() {} 133 134 virtual void insertTab(); 135 virtual void insertText(const librevenge::RVNGString &text); 136 virtual void insertSpace(); 137 virtual void insertLineBreak(); insertField(const librevenge::RVNGPropertyList &)138 virtual void insertField(const librevenge::RVNGPropertyList & /* propList */) {} 139 140 virtual void openOrderedListLevel(const librevenge::RVNGPropertyList &propList); 141 virtual void openUnorderedListLevel(const librevenge::RVNGPropertyList &propList); 142 virtual void closeOrderedListLevel(); 143 virtual void closeUnorderedListLevel(); 144 virtual void openListElement(const librevenge::RVNGPropertyList &propList); closeListElement()145 virtual void closeListElement() {} 146 147 virtual void openFootnote(const librevenge::RVNGPropertyList &propList); 148 virtual void closeFootnote(); 149 virtual void openEndnote(const librevenge::RVNGPropertyList &propList); 150 virtual void closeEndnote(); openComment(const librevenge::RVNGPropertyList &)151 virtual void openComment(const librevenge::RVNGPropertyList & /* propList */) {} closeComment()152 virtual void closeComment() {} openTextBox(const librevenge::RVNGPropertyList &)153 virtual void openTextBox(const librevenge::RVNGPropertyList & /* propList */) {} closeTextBox()154 virtual void closeTextBox() {} 155 156 virtual void openTable(const librevenge::RVNGPropertyList &propList); 157 virtual void openTableRow(const librevenge::RVNGPropertyList &propList); closeTableRow()158 virtual void closeTableRow() {} 159 virtual void openTableCell(const librevenge::RVNGPropertyList &propList); closeTableCell()160 virtual void closeTableCell() {} insertCoveredTableCell(const librevenge::RVNGPropertyList &)161 virtual void insertCoveredTableCell(const librevenge::RVNGPropertyList & /* propList */) {} 162 virtual void closeTable(); 163 openFrame(const librevenge::RVNGPropertyList &)164 virtual void openFrame(const librevenge::RVNGPropertyList & /* propList */) {} closeFrame()165 virtual void closeFrame() {} 166 openGroup(const librevenge::RVNGPropertyList &)167 virtual void openGroup(const librevenge::RVNGPropertyList & /* propList */) {} closeGroup()168 virtual void closeGroup() {} 169 defineGraphicStyle(const librevenge::RVNGPropertyList &)170 virtual void defineGraphicStyle(const librevenge::RVNGPropertyList & /* propList */) {} drawRectangle(const librevenge::RVNGPropertyList &)171 virtual void drawRectangle(const librevenge::RVNGPropertyList & /* propList */) {} drawEllipse(const librevenge::RVNGPropertyList &)172 virtual void drawEllipse(const librevenge::RVNGPropertyList & /* propList */) {} drawPolygon(const librevenge::RVNGPropertyList &)173 virtual void drawPolygon(const librevenge::RVNGPropertyList & /* propList */) {} drawPolyline(const librevenge::RVNGPropertyList &)174 virtual void drawPolyline(const librevenge::RVNGPropertyList & /* propList */) {} drawPath(const librevenge::RVNGPropertyList &)175 virtual void drawPath(const librevenge::RVNGPropertyList & /* propList */) {} drawConnector(const librevenge::RVNGPropertyList &)176 virtual void drawConnector(const librevenge::RVNGPropertyList & /* propList */) {} 177 insertBinaryObject(const librevenge::RVNGPropertyList &)178 virtual void insertBinaryObject(const librevenge::RVNGPropertyList & /* propList */) {} insertEquation(const librevenge::RVNGPropertyList &)179 virtual void insertEquation(const librevenge::RVNGPropertyList & /* propList */) {} 180 181 protected: 182 virtual UT_Error _loadFile(GsfInput * input); 183 UT_Error _appendSection(int numColumns, const float, const float); 184 // UT_Error _appendSpan(const guint32 textAttributeBits, const char *fontName, const float fontSize, UT_uint32 listTag = 0); 185 UT_Error _appendListSpan(UT_uint32 listTag); 186 // UT_Error _appendParagraph(const guint8 paragraphJustification, const guint32 textAttributeBits, 187 // const gchar *fontName, const float fontSize, const float lineSpacing); 188 UT_Error _updateDocumentOrderedListDefinition(ABI_ListDefinition *pListDefinition, 189 int iLevel, const char listType, 190 const UT_UTF8String &sTextBeforeNumber, 191 const UT_UTF8String &sTextAfterNumber, 192 int iStartingNumber); 193 UT_Error _updateDocumentUnorderedListDefinition(ABI_ListDefinition *pListDefinition, 194 int level); 195 private: 196 // section props 197 float m_leftPageMargin; 198 float m_rightPageMargin; 199 float m_leftSectionMargin; 200 float m_rightSectionMargin; 201 int m_sectionColumnsCount; 202 UT_sint8 m_headerId; // -1 means no header 203 UT_sint8 m_footerId; // -1 means no footer 204 UT_uint32 m_nextFreeId; 205 206 // paragraph props 207 float m_topMargin; 208 float m_bottomMargin; 209 float m_leftMarginOffset; 210 float m_rightMarginOffset; 211 float m_textIndent; 212 213 // state handling that libwpd can't account for 214 //UT_StringPtrMap m_listStylesHash; 215 ABI_ListDefinition * m_pCurrentListDefinition; 216 bool m_bParagraphChanged; 217 bool m_bParagraphInSection; 218 bool m_bInSection; 219 bool m_bSectionChanged; 220 bool m_bRequireBlock; 221 222 int m_iCurrentListLevel; 223 bool m_bInCell; 224 225 // HACK HACK HACK 226 int m_bHdrFtrOpenCount; 227 }; 228 229 #ifdef HAVE_LIBWPS 230 231 class IE_Imp_MSWorks_Sniffer : public IE_ImpSniffer 232 { 233 friend class IE_Imp; 234 friend class IE_Imp_MSWorks; 235 236 public: 237 IE_Imp_MSWorks_Sniffer(); 238 virtual ~IE_Imp_MSWorks_Sniffer(); 239 240 virtual const IE_SuffixConfidence * getSuffixConfidence (); 241 virtual UT_Confidence_t recognizeContents (GsfInput * input); getMimeConfidence()242 virtual const IE_MimeConfidence * getMimeConfidence () { return NULL; } 243 virtual bool getDlgLabels (const char ** szDesc, 244 const char ** szSuffixList, 245 IEFileType * ft); 246 virtual UT_Error constructImporter (PD_Document * pDocument, 247 IE_Imp ** ppie); 248 }; 249 250 #endif 251 252 #endif /* IE_IMP_WP_H */ 253