📄 rtfdecoder.h
字号:
//RtfDecoder.h
#ifndef CRTFDECODER
#define CRTFDECODER
// RTF parser declarations#include <ctype.h>
#include <stddef.h>
#include "../include/decoderbase.h"
#define MIDBUFSIZE (8*1024*1024)
#define OUTBUFSIZE (8*1024*1024)
#define MAXCHARSET (1000)
// RTF parser error codes
#define ecOK 0 // Everything's fine!#define ecStackUnderflow 1 // Unmatched '}'#define ecStackOverflow 2 // Too many '{' -- memory exhausted#define ecUnmatchedBrace 3 // RTF ended during an open group.#define ecInvalidHex 4 // invalid hex character found in data#define ecBadTable 5 // RTF table (sym or prop) invalid#define ecAssertion 6 // Assertion failure#define ecEndOfFile 7 // End of file reached while reading RTF#define fTrue 1
#define fFalse 0
typedef struct char_prop
{
char fBold;
char fUnderline;
char fItalic;
} CHP; // CHaracter Properties
typedef enum {justL, justR, justC, justF } JUST;
typedef struct para_prop
{
int xaLeft; // left indent in twips
int xaRight; // right indent in twips
int xaFirst; // first line indent in twips
JUST just; // justification
} PAP; // PAragraph Properties
typedef enum {sbkNon, sbkCol, sbkEvn, sbkOdd, sbkPg} SBK;
typedef enum {pgDec, pgURom, pgLRom, pgULtr, pgLLtr} PGN;
typedef struct sect_prop
{
int cCols; // number of columns
SBK sbk; // section break type
int xaPgn; // x position of page number in twips
int yaPgn; // y position of page number in twips
PGN pgnFormat; // how the page number is formatted
} SEP; // SEction Properties
typedef struct doc_prop
{
int xaPage; // page width in twips
int yaPage; // page height in twips
int xaLeft; // left margin in twips
int yaTop; // top margin in twips
int xaRight; // right margin in twips
int yaBottom; // bottom margin in twips
int pgnStart; // starting page number in twips
char fFacingp; // facing pages enabled?
char fLandscape; // landscape or portrait??
} DOP; // DOcument Properties
typedef enum { rdsNorm, rdsSkip } RDS; // Rtf Destination State
typedef enum { risNorm, risBin, risHex } RIS; // Rtf Internal State
typedef struct save // property save structure
{
struct save *pNext; // next save
CHP chp;
PAP pap;
SEP sep;
DOP dop;
RDS rds;
RIS ris;
} SAVE;
// What types of properties are there?
typedef enum {
ipropBold, ipropItalic, ipropUnderline, ipropLeftInd,
ipropRightInd, ipropFirstInd, ipropCols, ipropPgnX,
ipropPgnY, ipropXaPage, ipropYaPage, ipropXaLeft,
ipropXaRight, ipropYaTop, ipropYaBottom, ipropPgnStart,
ipropSbk, ipropPgnFormat, ipropFacingp, ipropLandscape,
ipropJust, ipropPard, ipropPlain, ipropSectd,
ipropMax
} IPROP;
typedef enum {actnSpec, actnByte, actnWord} ACTN;
typedef enum {propChp, propPap, propSep, propDop} PROPTYPE;
typedef struct propmod
{
ACTN actn; // size of value
PROPTYPE prop; // structure containing value
int offset; // offset of value from base of structure
} PROP;
typedef enum {ipfnBin, ipfnHex, ipfnSkipDest } IPFN;
typedef enum {idestPict, idestSkip } IDEST;
typedef enum {kwdChar, kwdDest, kwdProp, kwdSpec} KWD;
typedef struct symbol
{
char *szKeyword; // RTF keyword
int dflt; // default value to use
bool fPassDflt; // true to use default value from this table
KWD kwd; // base action to take
int idx; // index into property table if kwd == kwdProp
// index into destination table if kwd == kwdDest
// character to print if kwd == kwdChar
} SYM;
// RTF parser tables
//charset和code page转换表
//rtf解码类
class CRtfDecoder:public CDecoderBase
{
public:
int m_cGroup;
int m_midbuflen;
int m_outbuflen;
bool m_fSkipDestIfUnk;
long m_cbBin;
long m_lParam;
long m_previousparam; //前一个param值
int m_curCharset; //当前Charset值
int m_curCodePage; //当前CodePage值
int m_previousCodeP; //前一个CodePage值
int m_outCodePage; //输出缓冲区CodePage值
int allCharset[MAXCHARSET]; //全部的Charset值表
bool m_firstentry; //第一次进入
RDS rds;
RIS ris;
CHP chp;
PAP pap;
SEP sep;
DOP dop;
SAVE *psave;
int isymMax;
unsigned char *p_midbuf;
unsigned char *p_outbuf;
public:
CRtfDecoder(CPublicResource *ps=NULL);
~CRtfDecoder();
public:
int ecRtfParse(u_char *inbuf,int insize);
int ecPushRtfState(void);
int ecPopRtfState(void);
int ecParseRtfKeyword(u_char *buf,int &pos,int size);
int ecParseChar(int c);
int ecTranslateKeyword(char *szKeyword, int param, bool fParam);
int ecPrintChar(int ch);
int ecEndGroupAction(RDS rds);
int ecApplyPropChange(IPROP iprop, int val);
int ecChangeDest(IDEST idest);
int ecParseSpecialKeyword(IPFN ipfn);
int ecParseSpecialProperty(IPROP iprop, int val);
int ecParseHexByte(void);
int ecMidBuftoOutBuf(void);
int ecIntToStr(int ch,unsigned char *out);
public:
bool reset();
int is_me(u_char *buf,int len);
bool decode(u_char *inbuf,int insize,u_char *outbuf,int outbufsize);
u_char* get_result(int &retsize,int &type);
bool continue_decode();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -