• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ie_imp_RTF.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- */
00002 /* Copyright (C) 1999 AbiSource, Inc.
00003  * Copyright (C) 2003 Tomas Frydrych <tomas@frydrych.uklinux.net>
00004  * Copyright (C) 2004, 2009 Hubert Figuiere <hub@figuiere.net>
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019  * 02110-1301 USA.
00020  */
00021 
00022 /* RTF importer by Peter Arnold <petera@intrinsica.co.uk> */
00023 
00024 #ifndef IE_IMP_RTF_H
00025 #define IE_IMP_RTF_H
00026 
00027 #include <stdio.h>
00028 #include <string>
00029 #include <vector>
00030 #include "ie_imp.h"
00031 #include "ut_growbuf.h"
00032 #include "ut_stack.h"
00033 #include "pt_Types.h"
00034 #include "pd_Document.h"
00035 #include "pp_Revision.h"
00036 #include "ut_mbtowc.h"
00037 #include "fl_AutoLists.h"
00038 #include "fl_AutoNum.h"
00039 #include "fl_BlockLayout.h"
00040 #include  "ie_Table.h"
00041 #include "ie_imp_RTFParse.h"
00042 
00043 class IE_Imp_RTF;
00044 class RTF_msword97_list;
00045 class ie_imp_cell;
00046 class ie_imp_table;
00047 class ie_imp_table_control;
00048 class RTFProps_FrameProps;
00049 class FG_Graphic;
00050 
00051 
00052 // Font table entry
00053 struct ABI_EXPORT RTFFontTableItem
00054 {
00055  public:
00056     enum FontFamilyEnum { ffNone, ffRoman, ffSwiss, ffModern, ffScript, ffDecorative, ffTechnical, ffBiDirectional};
00057     enum FontPitch { fpDefault, fpFixed, fpVariable};
00058 
00059     RTFFontTableItem(FontFamilyEnum fontFamily, int charSet, int codepage, FontPitch pitch,
00060                         const char* panose, const char* pFontName, const char* pAlternativeFontName);
00061     ~RTFFontTableItem();
00062 
00063     FontFamilyEnum m_family;
00064     int m_charSet;
00065     int m_codepage;
00066     const char* m_szEncoding;
00067     FontPitch m_pitch;
00068     unsigned char m_panose[10];
00069     char* m_pFontName;
00070     char* m_pAlternativeFontName;
00071 };
00072 
00073 // Set true if Character properties have been changed in list structure.
00074 class ABI_EXPORT RTFProps_CharProps
00075 {
00076 public:
00077     RTFProps_CharProps(void);
00078     ~RTFProps_CharProps(void);
00079     bool    m_deleted;
00080     bool    m_bold;
00081     bool    m_italic;
00082     bool    m_underline;
00083     bool    m_overline;
00084     bool    m_strikeout;
00085     bool    m_topline;
00086     bool    m_botline;
00087     bool    m_superscript;
00088     double  m_superscript_pos;       // unit is pt. if 0.0, ignore
00089     bool    m_subscript;
00090     double  m_subscript_pos;         // unit is pt. if 0.0, ignore
00091     double  m_fontSize;         // font size in points
00092     UT_uint32    m_fontNumber;      // index into font table
00093     bool    m_hasColour;        // if false, ignore colour number
00094     UT_uint32    m_colourNumber;    // index into colour table
00095     bool    m_hasBgColour; // if false, ignore colour number
00096     UT_uint32  m_bgcolourNumber; // index into colour table
00097     UT_sint32  m_styleNumber ; //index into the style table
00098     UT_uint32  m_listTag; // tag for lists to hang off
00099     const char * m_szLang;
00100     UT_BidiCharType m_dir;
00101     UT_BidiCharType m_dirOverride;
00102     bool    m_Hidden;
00103     PP_RevisionType m_eRevision;
00104     UT_uint32 m_iCurrentRevisionId;
00105 };
00106 
00107 class ABI_EXPORT RTFProps_bCharProps
00108 {
00109 public:
00110     RTFProps_bCharProps(void);
00111     ~RTFProps_bCharProps(void);
00112 
00113     bool    bm_deleted;
00114     bool    bm_bold;
00115     bool    bm_italic;
00116     bool    bm_underline;
00117     bool    bm_overline;
00118     bool    bm_strikeout;
00119     bool    bm_topline;
00120     bool    bm_botline;
00121     bool bm_superscript;
00122     bool bm_superscript_pos;       // unit is pt. if 0.0, ignore
00123     bool bm_subscript;
00124     bool bm_subscript_pos;         // unit is pt. if 0.0, ignore
00125     bool bm_fontSize;           // font size in points
00126     bool bm_fontNumber;     // index into font table
00127     bool    bm_hasColour;        // if false, ignore colour number
00128     bool bm_colourNumber;   // index into colour table
00129     bool bm_hasBgColour; // if false, ignore colour number
00130     bool bm_bgcolourNumber; // index into colour table
00131     bool bm_listTag; // tag for lists to hanfg off
00132     bool bm_RTL;
00133     bool bm_dirOverride;
00134     bool bm_Hidden;
00135 };
00136 
00137 struct ABI_EXPORT _rtfListTable
00138 {
00139     UT_uint32 start_value;
00140     UT_uint32 level;
00141     bool bullet;
00142     bool simple;
00143     bool continueList;
00144     bool hangingIndent;
00145     FL_ListType type;
00146     bool bold;
00147     bool italic;
00148     bool caps;
00149     bool scaps;
00150     bool underline;
00151     bool nounderline;
00152     bool strike;
00153     bool isList;
00154     UT_uint32 forecolor;
00155     UT_uint32 font;
00156     UT_uint32 fontsize;
00157     UT_uint32 indent;
00158     bool prevlist;
00159     char textbefore[129];
00160     char textafter[129];
00161     UT_uint32 iWord97Override;
00162     UT_uint32 iWord97Level;
00163 };
00164 
00165 enum rtfCellBorder
00166 {
00167     rtfCellBorderBot,
00168     rtfCellBorderLeft,
00169     rtfCellBorderRight,
00170     rtfCellBorderTop
00171 };
00172 
00173 
00174 enum rtfBorder
00175 {
00176     rtfBorderBot,
00177     rtfBorderLeft,
00178     rtfBorderRight,
00179     rtfBorderTop
00180 };
00181 
00182 struct ABI_EXPORT RTFProps_CellProps
00183 {
00184     RTFProps_CellProps();
00185     RTFProps_CellProps & operator=(const RTFProps_CellProps&);
00186     bool      m_bVerticalMerged;
00187     bool      m_bVerticalMergedFirst;
00188     bool      m_bHorizontalMerged;
00189     bool      m_bHorizontalMergedFirst;
00190     std::string m_sCellProps;
00191     rtfCellBorder  m_iCurBorder;
00192     bool      m_bLeftBorder;
00193     bool      m_bRightBorder;
00194     bool      m_bTopBorder;
00195     bool      m_bBotBorder;
00196     UT_sint32 m_iCellx;
00197 };
00198 
00199 struct ABI_EXPORT RTFProps_TableProps
00200 {
00201     RTFProps_TableProps();
00202     RTFProps_TableProps& operator=(const RTFProps_TableProps&);
00203     bool      m_bAutoFit;
00204 };
00205 
00206 // Paragraph properties
00207 struct ABI_EXPORT RTFProps_ParaProps
00208 {
00209     enum ParaJustification { pjLeft, pjCentre, pjRight, pjFull};
00210 
00211     RTFProps_ParaProps();
00212     RTFProps_ParaProps& operator=(const RTFProps_ParaProps&);
00213 
00214     ParaJustification   m_justification;
00215     UT_uint32   m_spaceBefore;  // space above paragraph in twips
00216     UT_uint32   m_spaceAfter;   // space above paragraph in twips
00217     UT_sint32   m_indentLeft;   // left indent in twips
00218     UT_sint32   m_indentRight;  // right indent in twips
00219     UT_sint32   m_indentFirst;  // first line indent in twips
00220     double  m_lineSpaceVal;     // line spaceing value
00221     bool    m_lineSpaceExact;   // TRUE if m_lineSpaceVal is an exact value, FALSE if multiple
00222     std::vector<UT_sint32> m_tabStops;
00223     std::vector<eTabType> m_tabTypes;
00224     std::vector<eTabLeader> m_tabLeader;
00225     bool         m_isList;       // TRUE if para is an element of a list
00226     UT_sint32       m_level;        // Level of list in para
00227     char            m_pszStyle[30]; // Type of List
00228     UT_uint32       m_rawID;        // raw ID of list
00229     UT_uint32       m_rawParentID;        // raw Parent ID of list
00230     char            m_pszListDecimal[64]; // char between levels
00231     char            m_pszListDelim[64];   // char between levels
00232     char            m_pszFieldFont[64];   // field font name
00233     UT_uint32       m_startValue;         // Start value of the list
00234     eTabType        m_curTabType;        // Current Tab type
00235     eTabLeader      m_curTabLeader;       // Current Tab Leader
00236     UT_uint32       m_iOverride;          // 1's index to override table
00237     UT_uint32       m_iOverrideLevel;     // 0's index to the level
00238     _rtfListTable   m_rtfListTable;
00239     UT_sint32  m_styleNumber ; //index into the style table
00240     UT_BidiCharType m_dir;
00241     UT_sint32       m_tableLevel; //nesting level of the paragram in a table.
00242     bool            m_bInTable; // true if paragraph is in a table
00243     PP_RevisionType m_eRevision;
00244     UT_uint32 m_iCurrentRevisionId;
00245     // Borders & shading
00246     bool            m_bMergeBordersShading;
00247     bool            m_bBotBorder;
00248     UT_sint32       m_iBotBorderStyle; // Number to represent style of border
00249     UT_sint32       m_iBotBorderCol; // index to color table
00250     UT_sint32       m_iBotBorderWidth;  // Thickness in twips
00251     UT_sint32       m_iBotBorderSpacing; // Spacing to text in twips
00252     bool            m_bLeftBorder;
00253     UT_sint32       m_iLeftBorderStyle; // Number to represent style of border
00254     UT_sint32       m_iLeftBorderCol; // index to color table
00255     UT_sint32       m_iLeftBorderWidth;  // Thickness in twips
00256     UT_sint32       m_iLeftBorderSpacing; // Spacing to text in twips
00257     bool            m_bRightBorder;
00258     UT_sint32       m_iRightBorderStyle; // Number to represent style of border
00259     UT_sint32       m_iRightBorderCol; // index to color table
00260     UT_sint32       m_iRightBorderWidth;  // Thickness in twips
00261     UT_sint32       m_iRightBorderSpacing; // Spacing to text in twips
00262     bool            m_bTopBorder;
00263     UT_sint32       m_iTopBorderStyle; // Number to represent style of border
00264                                        // 0 no border
00265                                        // 1 solid
00266                                        // 2 dotted
00267                                        // 3 dashed
00268     UT_sint32       m_iTopBorderCol; // index to color table
00269     UT_sint32       m_iTopBorderWidth;  // Thickness in twips
00270     UT_sint32       m_iTopBorderSpacing; // Spacing to text in twips
00271     UT_sint32       m_iCurBorder; // 0=bot,1=left,2=right,3=top
00272     UT_sint32       m_iShadingPattern; // Number to represent the style of shading
00273     UT_sint32       m_iShadingForeCol; // The Foreground color
00274     UT_sint32       m_iShadingBackCol; // The Foreground color
00275 
00276 };
00277 
00278 // These are set true if changed in list definitions.
00279 class ABI_EXPORT RTFProps_bParaProps
00280 {
00281 public:
00282     RTFProps_bParaProps(void);
00283     ~RTFProps_bParaProps(void);
00284 
00285     bool        bm_justification;
00286     bool        bm_spaceBefore; // space above paragraph in twips
00287     bool        bm_spaceAfter;  // space above paragraph in twips
00288     bool        bm_indentLeft;  // left indent in twips
00289     bool        bm_indentRight; // right indent in twips
00290     bool        bm_indentFirst; // first line indent in twips
00291     bool        bm_lineSpaceVal;        // line spaceing value
00292     bool        bm_lineSpaceExact;  // TRUE if m_lineSpaceVal is an exact value, FALSE if multiple
00293     bool        bm_tabStops;
00294     bool        bm_tabTypes;
00295     bool        bm_tabLeader;
00296     bool        bm_curTabType;        // Current Tab type
00297     bool        bm_curTabLeader;       // Current Tab Leader
00298     bool        bm_rtfListTable;
00299     bool        bm_dom_dir;
00300 };
00301 
00302 
00303 //typedef struct sect_prop
00304 //{
00305 //    int cCols;                  // number of columns
00306 //    SBK sbk;                    // section break type
00307 //    int xaPgn;                  // x position of page number in twips
00308 //    int yaPgn;                  // y position of page number in twips
00309 //    PGN pgnFormat;              // how the page number is formatted
00310 //} SEP;                  // SEction Properties
00311 
00312 
00313 // Lists Level class
00314 class ABI_EXPORT RTF_msword97_level
00315 {
00316 public:
00317     RTF_msword97_level( RTF_msword97_list * pmsword97List, UT_uint32 level);
00318     ~RTF_msword97_level();
00319     void buildAbiListProperties( const char ** szListID,
00320                                  const char ** szParentID,
00321                                  const char ** szLevel,
00322                                  const char ** szStartat,
00323                                  const char ** szFieldFont,
00324                                  const char ** szListDelim,
00325                                  const char ** szListDecimal,
00326                                  const char ** szAlign,
00327                                  const char ** szIndent,
00328                                  const char ** szListStyle);
00329     bool ParseLevelText(const std::string & szLevelText,const std::string & szLevelNumbers, UT_uint32 iLevel);
00330     UT_sint32 m_levelStartAt;
00331     UT_uint32 m_AbiLevelID;
00332     static UT_uint32 m_sPreviousLevel;
00333     UT_uint32 m_RTFListType;
00334     std::string m_listDelim;
00335     char      m_cLevelFollow;
00336     bool m_bStartNewList;
00337     bool m_bRestart;
00338     RTFProps_ParaProps * m_pParaProps;
00339     RTFProps_CharProps *  m_pCharProps;
00340     RTFProps_bParaProps * m_pbParaProps;
00341     RTFProps_bCharProps *  m_pbCharProps;
00342 private:
00343     UT_uint32 m_localLevel;
00344     RTF_msword97_list * m_pMSWord97_list ;
00345 };
00346 
00347 // List Header Class
00348 class ABI_EXPORT RTF_msword97_list
00349 {
00350 public:
00351     RTF_msword97_list(  IE_Imp_RTF * pie_rtf);
00352     ~RTF_msword97_list();
00353     UT_uint32 m_RTF_listID;
00354     UT_uint32 m_RTF_listTemplateID;
00355     RTF_msword97_level * m_RTF_level[9];
00356     IE_Imp_RTF * m_pie_rtf;
00357 };
00358 
00359 // List Header Override
00360 class ABI_EXPORT RTF_msword97_listOverride
00361 {
00362 public:
00363     RTF_msword97_listOverride(  IE_Imp_RTF * pie_rtf);
00364     ~RTF_msword97_listOverride();
00365     void buildAbiListProperties( const char ** szListID,
00366                                  const char ** szParentID,
00367                                  const char ** szLevel,
00368                                  const char ** szStartat,
00369                                  const char ** szFieldFont,
00370                                  const char ** szListDelim,
00371                                  const char ** szListDecimal,
00372                                  const char ** szAlign,
00373                                  const char ** szIndent,
00374                                  const char ** szListStyle,
00375                                  UT_uint32 iLevel);
00376     UT_uint32 m_RTF_listID;
00377     UT_uint32 m_OverrideCount;
00378     RTFProps_ParaProps * m_pParaProps;
00379     RTFProps_CharProps * m_pCharProps;
00380     RTFProps_bParaProps * m_pbParaProps;
00381     RTFProps_bCharProps * m_pbCharProps;
00382     bool setList(void);
00383     bool isTab(UT_uint32 iLevel);
00384     std::vector<UT_sint32>* getTabStopVect(UT_uint32 iLevel);
00385     std::vector<eTabType>* getTabTypeVect(UT_uint32 iLevel);
00386     std::vector<eTabLeader>* getTabLeaderVect(UT_uint32 iLevel);
00387     bool isDeletedChanged(UT_uint32 iLevel);
00388     bool getDeleted(UT_uint32 iLevel);
00389     bool isBoldChanged(UT_uint32 iLevel);
00390     bool getBold(UT_uint32 iLevel);
00391     bool isItalicChanged(UT_uint32 iLevel);
00392     bool getItalic(UT_uint32 iLevel);
00393     bool isUnderlineChanged(UT_uint32 iLevel);
00394     bool getUnderline(UT_uint32 iLevel);
00395     bool isStrikeoutChanged(UT_uint32 iLevel);
00396     bool getStrikeout(UT_uint32 iLevel);
00397     bool isSuperscriptChanged(UT_uint32 iLevel);
00398     bool getSuperscript(UT_uint32 iLevel);
00399     bool isSuperscriptPosChanged(UT_uint32 iLevel);
00400     double getSuperscriptPos(UT_uint32 iLevel);
00401     bool isSubscriptChanged(UT_uint32 iLevel);
00402     bool getSubscript(UT_uint32 iLevel);
00403     bool isSubscriptPosChanged(UT_uint32 iLevel);
00404     double getSubscriptPos(UT_uint32 iLevel);
00405     bool isFontSizeChanged(UT_uint32 iLevel);
00406     double getFontSize(UT_uint32 iLevel);
00407     bool isHasColourChanged(UT_uint32 iLevel);
00408     bool getHasColour(UT_uint32 iLevel);
00409     bool isColourNumberChanged(UT_uint32 iLevel);
00410     UT_uint32 getColourNumber(UT_uint32 iLevel);
00411     bool isHasBgColourChanged(UT_uint32 iLevel);
00412     bool getHasBgColour(UT_uint32 iLevel);
00413     bool isBgColourNumberChanged(UT_uint32 iLevel);
00414     UT_uint32 getBgColourNumber(UT_uint32 iLevel);
00415     bool isFontNumberChanged(UT_uint32 iLevel);
00416     UT_uint32 getFontNumber(UT_uint32 iLevel);
00417 
00418 private:
00419     IE_Imp_RTF * m_pie_rtf;
00420     RTF_msword97_list* m_pList;
00421 };
00422 
00423 struct ABI_EXPORT RTFProps_ImageProps
00424 {
00425     enum IPSizeType { ipstNone, ipstGoal, ipstScale };
00426 
00427     RTFProps_ImageProps ();
00428     IPSizeType sizeType;
00429     UT_uint16 wGoal;
00430     UT_uint16 hGoal;
00431     UT_uint16 scaleX;
00432     UT_uint16 scaleY;
00433     UT_uint32 width;
00434     UT_uint32 height;
00435     bool bCrop;
00436     UT_sint32 cropt;
00437     UT_sint32 cropb;
00438     UT_sint32 cropl;
00439     UT_sint32 cropr;
00440 };
00441 
00442 // Section properties
00443 struct ABI_EXPORT RTFProps_SectionProps
00444 {
00445     enum ESectionBreak {sbkNone, sbkColumn, sbkEven, sbkOdd, sbkPage};
00446     enum EPageNumber {pgDecimal, pgURoman, pgLRoman, pgULtr, pgLLtr};
00447 
00448     RTFProps_SectionProps();
00449 
00450     UT_uint32       m_numCols;
00451     bool m_bColumnLine;
00452     ESectionBreak   m_breakType;
00453     EPageNumber     m_pageNumFormat;
00454     UT_sint32       m_leftMargTwips;
00455     UT_sint32       m_rightMargTwips;
00456     UT_sint32       m_topMargTwips;
00457     UT_sint32       m_bottomMargTwips;
00458     UT_sint32       m_headerYTwips;
00459     UT_sint32       m_footerYTwips;
00460     UT_sint32       m_gutterTwips;
00461     UT_sint32       m_colSpaceTwips;
00462     UT_BidiCharType m_dir;
00463 };
00464 
00465 
00472 struct ABI_EXPORT RTFHdrFtr
00473 {
00474     enum HdrFtrType {hftNone,
00475                      hftHeader,
00476                      hftHeaderEven,
00477                      hftHeaderFirst,
00478                      hftHeaderLast,
00479                      hftFooter,
00480                      hftFooterEven,
00481                      hftFooterFirst,
00482                      hftFooterLast };
00483 
00484     RTFHdrFtr () : m_type(hftNone), m_id(0), m_buf(1024) {}
00485 
00486     HdrFtrType      m_type;
00487     UT_uint32       m_id;
00488     UT_ByteBuf      m_buf;
00489 };
00490 
00491 // RTFStateStore
00492 struct ABI_EXPORT RTFStateStore
00493 {
00494     RTFStateStore();
00495     RTFStateStore * clone();
00496     // RTFStateStore& operator=(const RTFStateStore& s)
00497 
00498     enum DestinationStateTypes { rdsNorm, rdsSkip, rdsFootnote, rdsHeader, rdsFooter, rdsField };
00499     enum InternalStateTypes { risNorm, risBin, risHex };
00500 
00501     DestinationStateTypes   m_destinationState;     // Reading or skipping text
00502     InternalStateTypes      m_internalState;        // Normal, binary or hex
00503     RTFProps_CharProps      m_charProps;            // Character properties
00504     RTFProps_ParaProps      m_paraProps;            // Paragraph properties
00505     RTFProps_SectionProps   m_sectionProps;         // Section properties
00506     RTFProps_CellProps      m_cellProps;            // Cell properties
00507     RTFProps_TableProps     m_tableProps;           // Table properties
00508     UT_uint32               m_unicodeAlternateSkipCount;    // value of N in "\ucN"
00509     UT_uint32               m_unicodeInAlternate;           // chars left in alternate "\u<u><A>"
00510     UT_UTF8String           m_revAttr;              // the revision attribute stored in abirevision
00511     bool                    m_bInKeywordStar;        // true if in star keyword
00512 };
00513 
00514 
00515 /*
00516 typedef struct doc_prop
00517 {
00518     int xaPage;                 // page width in twips
00519     int yaPage;                 // page height in twips
00520     int xaLeft;                 // left margin in twips
00521     int yaTop;                  // top margin in twips
00522     int xaRight;                // right margin in twips
00523     int yaBottom;               // bottom margin in twips
00524     int pgnStart;               // starting page number in twips
00525     char fFacingp;              // facing pages enabled?
00526     char fLandscape;            // landscape or portrait??
00527 } DOP;                  // DOcument Properties
00528 */
00529 
00530 
00531 //
00532 // Little class to be used for tracking pasted table state.
00533 //
00534 class ABI_EXPORT ABI_Paste_Table
00535 {
00536 public:
00537     ABI_Paste_Table(void);
00538     virtual ~ABI_Paste_Table(void);
00539     bool                  m_bHasPastedTableStrux;
00540     bool                  m_bHasPastedCellStrux;
00541     UT_sint32             m_iRowNumberAtPaste;
00542     bool                  m_bHasPastedBlockStrux;
00543     UT_sint32             m_iMaxRightCell;
00544     UT_sint32             m_iCurRightCell;
00545     UT_sint32             m_iCurTopCell;
00546     bool                  m_bPasteAfterRow;
00547     UT_sint32             m_iPrevPasteTop;
00548     UT_sint32             m_iNumRows;
00549 };
00550 
00551 //
00552 // Little class to be used for importing annotations
00553 //
00554 class ABI_EXPORT ABI_RTF_Annotation
00555 {
00556  public:
00557     ABI_RTF_Annotation();
00558     virtual ~ABI_RTF_Annotation() {}
00559     UT_sint32          m_iAnnNumber;
00560     UT_UTF8String      m_sAuthor;
00561     UT_UTF8String      m_sAuthorId;
00562     UT_UTF8String      m_sDate;
00563     UT_UTF8String      m_sTitle;
00564     pf_Frag *          m_pInsertFrag;
00565     PT_DocPosition     m_Annpos;
00566     UT_sint32          m_iRTFLevel;
00567     static UT_sint32   newNumber();
00568 private:
00569     static UT_sint32 sAnnotationNumber;
00570 };
00571 
00572 // The importer/reader for Rich Text Format files
00573 
00574 class ABI_EXPORT IE_Imp_RTF_Sniffer : public IE_ImpSniffer
00575 {
00576     friend class IE_Imp;
00577 
00578 public:
00579     IE_Imp_RTF_Sniffer();
00580     virtual ~IE_Imp_RTF_Sniffer() {}
00581 
00582     virtual const IE_SuffixConfidence * getSuffixConfidence ();
00583     virtual const IE_MimeConfidence * getMimeConfidence ();
00584     virtual UT_Confidence_t recognizeContents (const char * szBuf,
00585                                     UT_uint32 iNumbytes);
00586     virtual bool getDlgLabels (const char ** szDesc,
00587                                const char ** szSuffixList,
00588                                IEFileType * ft);
00589     virtual UT_Error constructImporter (PD_Document * pDocument,
00590                                         IE_Imp ** ppie);
00591 
00592 };
00593 
00594 class ABI_EXPORT IE_Imp_RTF : public IE_Imp
00595 {
00596 public:
00597     IE_Imp_RTF(PD_Document * pDocument);
00598     ~IE_Imp_RTF();
00599 
00600     virtual bool supportsLoadStylesOnly() const {return true;}
00601     virtual bool        pasteFromBuffer(PD_DocumentRange * pDocRange,
00602                                         const unsigned char * pData,
00603                                         UT_uint32 lenData,
00604                                         const char * szEncoding = 0);
00605     UT_sint32 get_vecWord97ListsCount(void) const
00606         { return m_vecWord97Lists.size();}
00607     RTF_msword97_list *  get_vecWord97NthList(UT_sint32 i) const
00608         { return m_vecWord97Lists.at(i);}
00609     bool  isWord97Lists(void) const
00610         { return !m_vecWord97Lists.empty();}
00611 
00612     enum PictFormat {
00613         picNone,
00614         picPNG,
00615         picJPEG,
00616         picBMP,
00617         picWMF,
00618         picPICT,
00619         picEMF,
00620         picGIF,
00621         picSVG
00622     };
00623 
00624 protected:
00625     virtual UT_Error    _loadFile(GsfInput * input);
00626     UT_Error            _parseFile(GsfInput * fp);
00627     UT_Error            _writeHeader(GsfInput * fp);
00628     UT_Error            _parseHdrFtr ();
00629     UT_Error            _parseText();
00630 
00631 
00632 // importer helper methods
00633 private:
00634 
00635 
00636     typedef enum {
00637         RBT_START = 0,
00638         RBT_END
00639     } RTFBookmarkType;
00640 
00641     bool AddChar(UT_UCSChar ch);
00642 public:
00643     bool FlushStoredChars(bool forceInsertPara = false);
00644 private:
00645     bool StartNewPara();
00646     bool HandleParKeyword();
00647     bool StartNewSection();
00648 public:
00649     bool PushRTFState();
00650     bool PopRTFState();
00651     bool ParseChar(UT_UCSChar ch,bool no_convert=1);
00652     void setStruxImage(bool b)
00653         { m_bStruxImage = b;}
00654     bool isStruxImage(void) const
00655         { return m_bStruxImage;}
00656 private:
00657     bool ParseRTFKeyword();
00658     bool ReadCharFromFileWithCRLF(unsigned char* pCh);
00659     bool ReadCharFromFile(unsigned char* pCh);
00660     bool ReadContentFromFile(UT_UTF8String & str);
00661     std::string s_unEscapeXMLString();
00662     UT_UCS4Char ReadHexChar(void);
00663     bool SkipBackChar(unsigned char ch);
00664     bool ReadKeyword(unsigned char* pKeyword, UT_sint32* pParam,
00665                      bool* pParamUsed,
00666                      UT_uint32 keywordBuffLen);
00667     bool TranslateKeyword(unsigned char* pKeyword, UT_sint32 param,
00668                           bool fParam);
00669 public:
00670     bool TranslateKeywordID(RTF_KEYWORD_ID keywordID,
00671                             UT_sint32 param, bool fParam);
00672     bool insertStrux(PTStruxType pts , const gchar ** attrs=NULL, const gchar ** props=NULL);
00673 
00674     /*  Parser stuff */
00675     bool StandardKeywordParser(IE_Imp_RTFGroupParser *parser);
00676 private:
00677     RTF_KEYWORD_ID KeywordToID(const char * keyword);
00678 
00679     bool HandleStarKeyword();
00680 
00681     bool HandlePCData(UT_UTF8String & str);
00682     bool HandlePCData(std::string& str);
00683 
00684     bool ReadColourTable();
00685     bool ReadFontTable();
00686     bool RegisterFont(RTFFontTableItem::FontFamilyEnum fontFamily,
00687                       RTFFontTableItem::FontPitch pitch,
00688                       UT_uint16 fontIndex,
00689                       int charSet, int codepage,
00690                       UT_UTF8String sFontNames[]);
00691     bool PostProcessAndValidatePanose(UT_UTF8String &Panose);
00692     bool ReadRevisionTable();
00693     void setEncoding();
00694     bool ReadRDFTriples();
00695 public:
00696     bool HandlePicture();
00697     void clearImageName(void)
00698         { m_sImageName.clear();}
00699 
00700 private:
00701     bool HandleObject();
00702     bool HandleField();
00703     bool HandleStyleDefinition(void);
00704     bool HandleHeaderFooter(RTFHdrFtr::HdrFtrType hftype, UT_uint32 & headerID);
00705 public:
00706     bool SkipCurrentGroup(bool bConsumeLastBrace = false);
00707 private:
00708     bool StuffCurrentGroup(UT_ByteBuf & buf);
00709     bool LoadPictData(PictFormat format, const char * image_name,
00710                       struct RTFProps_ImageProps & imgProps,
00711                       bool isBinary = false, long binaryLen = 0);
00712     bool InsertImage (const FG_Graphic *, const char * image_name,
00713                       const struct RTFProps_ImageProps & imgProps);
00714 
00715     RTFFontTableItem* GetNthTableFont(UT_sint32 fontNum);
00716     UT_uint32 GetNthTableColour(UT_sint32 colNum);
00717     UT_sint32 GetNthTableBgColour(UT_sint32 colNum);
00718 
00719 // ListTable handlers.
00720     bool ReadListTable(void);
00721     bool HandleListLevel(RTF_msword97_list * pList, UT_uint32 levelCount  );
00722     bool HandleTableList(void);
00723     char * getCharsInsideBrace(void);
00724     bool ParseCharParaProps(unsigned char * pKeyword,
00725                             UT_sint32 param, bool fParam,
00726                             RTFProps_CharProps * pChars,
00727                             RTFProps_ParaProps * pParas,
00728                             RTFProps_bCharProps * pbChars,
00729                             RTFProps_bParaProps * pbParas);
00730     bool ReadListOverrideTable(void);
00731     bool HandleTableListOverride(void);
00732 
00733     bool buildAllProps( std::string & s,  RTFProps_ParaProps * pParas,
00734                        RTFProps_CharProps * pChars,
00735                        RTFProps_bParaProps * pbParas,
00736                        RTFProps_bCharProps * pbChars);
00737 
00738 
00739     // Character property handlers
00740     bool ResetCharacterAttributes();
00741     bool buildCharacterProps(std::string & propBuffer);
00742     bool ApplyCharacterAttributes();
00743     bool HandleBoolCharacterProp(bool state, bool* pProp);
00744     bool HandleDeleted(bool state);
00745     bool HandleBold(bool state);
00746     bool HandleItalic(bool state);
00747     bool HandleHidden(bool state);
00748     bool HandleUnderline(bool state);
00749     bool HandleOverline(bool state);
00750     bool HandleStrikeout(bool state);
00751     bool HandleTopline(bool state);
00752     bool HandleBotline(bool state);
00753     bool HandleSuperscript(bool state);
00754     bool HandleSuperscriptPosition(UT_uint32 pos);
00755     bool HandleSubscript(bool state);
00756     bool HandleSubscriptPosition(UT_uint32 pos);
00757     bool HandleFontSize(long sizeInHalfPoints);
00758     bool HandleBookmark (RTFBookmarkType type);
00759     bool HandleRDFAnchor (RTFBookmarkType type);
00760     bool HandleListTag(long id);
00761 
00762     bool HandleDeltaMoveID();
00763     bool HandleRevisedText(PP_RevisionType eType, UT_uint32 iId);
00764     bool HandleRevisedTextTimestamp(UT_uint32 iDttm);
00765 
00766     // Generic handlers
00767     bool HandleFloatCharacterProp(double val, double* pProp);
00768     bool HandleU32CharacterProp(UT_uint32 val, UT_uint32* pProp);
00769     bool HandleFace(UT_uint32 fontNumber);
00770     bool HandleColour(UT_uint32 colourNumber);
00771     bool HandleBackgroundColour (UT_uint32 colourNumber);
00772 
00773     // Paragraph property handlers
00774     bool ResetParagraphAttributes();
00775     bool ApplyParagraphAttributes(bool bDontInsert = false);
00776     bool SetParaJustification(RTFProps_ParaProps::ParaJustification just);
00777     bool AddTabstop(UT_sint32 stopDist, eTabType tabType, eTabLeader tableader);
00778     bool AddTabstop(UT_sint32 stopDist, eTabType tabType,
00779                     eTabLeader tabLeader,  RTFProps_ParaProps * pParas);
00780 
00781 
00782 // Paste AbiWord tables
00783  public:
00784     bool HandleAbiTable(void);
00785     bool HandleAbiCell(void);
00786     bool HandleAbiEndTable(void);
00787     bool HandleAbiEndCell(void);
00788     bool HandleAbiLists(void);
00789     bool HandleAbiMathml(void);
00790     bool CreateDataItemfromStream(void);
00791     bool HandleAbiEmbed(void);
00792     bool isPastedTableOpen(void);
00793     bool markPasteBlock(void);
00794     bool isBlockNeededForPasteTable(void);
00795 
00796     bool       HandleLists(_rtfListTable & rtfListTable );
00797     UT_uint32  mapID(UT_uint32 id);
00798     UT_uint32  mapParentID(UT_uint32 id);
00799 
00800 // Table methods
00801     bool           ResetCellAttributes(void);
00802     bool           ResetTableAttributes(void);
00803     ie_imp_table * getTable(void);
00804     ie_imp_cell *  getCell(void);
00805     void           FlushCellProps(void);
00806     void           FlushTableProps(void);
00807     void           OpenTable(bool bDontFlush = false);
00808     void           CloseTable(bool bForceClose = false);
00809     void           SaveRowInfo(void);
00810     void           RemoveRowInfo(void);
00811     void           HandleCell(void);
00812     void           HandleCellX(UT_sint32 cellx);
00813     void           HandleRow(void);
00814     UT_sint32      getPasteDepth(void);
00815     void           closePastedTableIfNeeded(void);
00816 
00817  private:
00818 
00819     void           HandleNote();
00820     void           StartAnnotation();
00821     void           EndAnnotation();
00822     void           HandleAnnotation();
00823     void           HandleNoteReference();
00824 // Shape handlers in ie_imp_RTFObjectsAndPicts.cpp
00825     void           HandleShape(void);
00826     void           HandleShapePict(void);
00827 
00828 public:
00829     void           HandleShapeText(RTFProps_FrameProps & frame);
00830     void           addFrame(RTFProps_FrameProps & frame);
00831     bool           isFrameIn(void)
00832         { return m_bFrameStruxIn;}
00833 
00834     bool           bUseInsertNotAppend(void);
00835 
00836 private:
00837 //  void           HandleEndShape(void);
00838 // Meta data
00839     bool           HandleInfoMetaData(void);
00840 // Little convience wrapper
00841     void           _setStringProperty(std::string & sPropString,
00842                                       const char * szProp, const char * szVal);
00843 
00844     // Section property handlers
00845     bool ApplySectionAttributes();
00846     bool ResetSectionAttributes();
00847     typedef enum {
00848         RTF_TOKEN_NONE = 0,
00849         RTF_TOKEN_OPEN_BRACE,
00850         RTF_TOKEN_CLOSE_BRACE,
00851         RTF_TOKEN_KEYWORD,
00852         RTF_TOKEN_DATA,
00853         RTF_TOKEN_ERROR = -1
00854     } RTFTokenType;
00855     RTFTokenType NextToken (unsigned char *pKeyword, UT_sint32* pParam,
00856                             bool* pParamUsed, UT_uint32 len,
00857                             bool bIgnoreWhiteSpace = false);
00858 
00859     UT_Error _isBidiDocument();
00860     bool     _appendSpan();
00861     bool     _insertSpan();
00862     void     _formRevisionAttr(std::string & s, const std::string & props, const std::string & style);
00863 
00864 
00865 private:
00866     // static helpers to decode
00867     static bool digVal(char ch, int& value, int base);
00868     static bool hexVal(char c, int& value);
00869 
00870 
00871 // import member vars
00872 private:
00873     /* keyword for new gen parser */
00874     static bool keywordSorted;
00875     static void _initialKeywordSort(void);
00876 
00877     UT_GrowBuf m_gbBlock;
00878     char *m_szFileDirName;
00879 
00880     int m_groupCount;
00881     bool m_newParaFlagged;
00882     bool m_newSectionFlagged;
00883     int m_cbBin;
00884 
00885     // headers and footers
00886     // headers and footers are NOT part of the state. They change each time
00887     // they are defined and sections inherit them from the previous
00888     // this is not part of section properties, they are not reset by \sectd
00889     // TODO: handle \titlepg and \facingpg cases.
00890     UT_uint32       m_currentHdrID;     // these are numbers.
00891     UT_uint32       m_currentFtrID;
00892     UT_uint32       m_currentHdrEvenID;     // these are numbers.
00893     UT_uint32       m_currentFtrEvenID;
00894     UT_uint32       m_currentHdrFirstID;     // these are numbers.
00895     UT_uint32       m_currentFtrFirstID;
00896     UT_uint32       m_currentHdrLastID;     // these are numbers.
00897     UT_uint32       m_currentFtrLastID;
00898 
00899 
00900     UT_Stack m_stateStack;
00901     RTFStateStore m_currentRTFState;
00902 
00903     std::vector<RTFFontTableItem*> m_fontTable;
00904     std::vector<UT_sint32> m_colourTable;
00905     std::vector<RTFHdrFtr*> m_hdrFtrTable;
00906     std::vector<std::string> m_styleTable;
00907 
00908     struct _rtfAbiListTable
00909     {
00910         UT_uint32 orig_id;
00911         UT_uint32 orig_parentid;
00912         UT_uint32 start_value;
00913         UT_uint32 level;
00914         bool hasBeenMapped;
00915         UT_uint32 mapped_id;
00916         UT_uint32 mapped_parentid;
00917     };
00918     std::vector<_rtfAbiListTable *> m_vecAbiListTable;
00919     _rtfAbiListTable * getAbiList( UT_uint32 i) const
00920         { return m_vecAbiListTable.at(i); }
00921 
00922     RTF_msword97_listOverride* _getTableListOverride(UT_uint32 id);
00923 
00924     UT_uint32 m_numLists;
00925     bool m_bisAbiList;
00926     bool m_bisNOTList; // true if the current stream does not have  abi list extensions
00927     bool m_bParaHasRTFList;
00928     bool m_bParaHasRTFContinue;
00929 
00930     GsfInput* m_pImportFile;
00931 
00932     const unsigned char *       m_pPasteBuffer;
00933     UT_uint32           m_lenPasteBuffer;
00934     const unsigned char *       m_pCurrentCharInPasteBuffer;
00935     PT_DocPosition      m_dposPaste;
00936     PT_DocPosition      m_dOrigPos;
00937     UT_uint32           deflangid;
00938     UT_UCS4_mbtowc      m_mbtowc;
00939     bool                m_parsingHdrFtr;
00940     UT_uint32           m_icurOverride;
00941     UT_uint32           m_icurOverrideLevel;
00942     std::vector<RTF_msword97_list *> m_vecWord97Lists;
00943     std::vector<RTF_msword97_listOverride*> m_vecWord97ListOverride;
00944     void _appendHdrFtr ();
00945     bool _appendField (const gchar *xmlField,
00946                        const gchar ** pszAttribs=NULL);
00947     gchar *_parseFldinstBlock (UT_ByteBuf & buf, gchar *xmlField,
00948                                   bool & isXML);
00949     bool                m_bAppendAnyway;
00950     RTFProps_SectionProps m_sectdProps ;
00951     ie_imp_table_control  m_TableControl;
00952     pf_Frag_Strux*     m_lastCellSDH;
00953     bool                  m_bNestTableProps;
00954     bool                  m_bParaWrittenForSection;
00955     bool                  m_bCellBlank;
00956     bool                  m_bEndTableOpen;
00957     bool                  m_bInFootnote;
00958     UT_sint32             m_iDepthAtFootnote;
00959     UT_uint32             m_iLastFootnoteId;
00960     UT_uint32             m_iLastEndnoteId;
00961     std::string             m_hyperlinkBase;
00962     UT_uint32             m_iHyperlinkOpen;
00963     UT_uint32             m_iRDFAnchorOpen;
00964     bool                  m_bBidiMode;
00965     UT_Stack              m_pasteTableStack;
00966     bool                  m_bFootnotePending;
00967     bool                  m_bFtnReferencePending;
00968     bool                  m_bNoteIsFNote;
00969     bool                  m_bStyleImportDone;
00970     bool                  m_bCellHandled;
00971     bool                  m_bContentFlushed;
00972     bool                  m_bRowJustPassed;
00973     UT_sint32             m_iStackLevelAtRow;
00974     bool                  m_bDoCloseTable;
00975     UT_sint32             m_iNoCellsSinceLastRow;
00976     RTFStateStore         m_FootnoteRefState;
00977     bool                  m_bFieldRecognized;
00978     UT_sint32             m_iIsInHeaderFooter;
00979     bool                  m_bSectionHasPara;
00980     bool                  m_bStruxInserted;
00981     bool                  m_bStruxImage;
00982     UT_UTF8String         m_sImageName;
00983     bool                  m_bFrameStruxIn;
00984 
00985     UT_BidiCharType       m_iAutoBidiOverride;
00986     UT_BidiCharType       m_iBidiLastType;
00987     UT_BidiCharType       m_iBidiNextType;
00988 
00989     const char* m_szDefaultEncoding; // Document default char encoding.
00990     int m_iDefaultFontNumber;        // Document default font.
00991     PT_DocPosition        m_dPosBeforeFootnote;
00992     bool                  m_bMovedPos;
00993     ABI_RTF_Annotation *  m_pAnnotation;
00994     pf_Frag *             m_pDelayedFrag; // insert before this frag if non-null
00995     PT_DocPosition        m_posSavedDocPosition;
00996     bool                  m_bInAnnotation;
00997     bool                  m_bFrameTextBox;
00998     bool                  m_bParaActive;
00999     bool                  m_bCellActive;
01000 
01001     std::string           m_ctMoveID;
01002 
01003     PD_XMLIDCreatorHandle  m_XMLIDCreatorHandle;
01004     std::map< std::string, std::string > m_rdfAnchorCloseXMLIDs;
01005 
01006 };
01007 
01008 #endif /* IE_IMP_RTF_H */
01009 

Generated on Sat May 18 2013 for AbiWord by  doxygen 1.7.1