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

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1