1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
|
/************************************************************************/
/* */
/* Read/Write RTF files. */
/* */
/************************************************************************/
# ifndef DOC_RTF_H
# define DOC_RTF_H
# include <stdlib.h>
# include <string.h>
# include <stdio.h>
# include <ctype.h>
# include <time.h>
# include <appDebugon.h>
# include "docBuf.h"
# include <sioGeneral.h>
# include "docRtfTagEnum.h"
# include "docRtfShapeEnum.h"
/************************************************************************/
/* */
/* Context for Reading RTF. */
/* */
/* To ensure proper field/bookmark nesting.. A stack op active */
/* is kept to be flushed at the appropriate transitions. (Field end, */
/* field start, paragraph end.) */
/* */
/************************************************************************/
typedef struct RtfBookmarkLevel
{
int rblFieldNumber;
struct RtfBookmarkLevel * rblPrevious;
} RtfBookmarkLevel;
typedef struct RtfReadingContext
{
int rrcLevel;
int rrcSplitLevel;
/****************************************/
/* The depth in the document */
/* == Type of BufferItem. */
/****************************************/
int rrcComplainUnknown;
/****************************************/
/* Complain about unknown control */
/****************************************/
int rrcCharacterAhead;
/****************************************/
/* Character that could not be unread */
/* using ungetc(). */
/****************************************/
int rrcCurrentLine;
BufferDocument * rrcBd;
BufferItem * rrcBi;
/****************************************/
/* The current position in the input. */
/****************************************/
TextAttribute rrcCurrentTextAttribute;
int rrcInDeletedText;
BorderProperties rrcTextBorderProperties;
int rrcTextShadingPattern;
int rrcTextShadingLevel;
int rrcTextForeground;
int rrcTextBackground;
/****************************************/
/* Text attributes of the current pos. */
/****************************************/
TextFrameProperties rrcTextFrameProperties;
ParagraphProperties rrcParagraphProperties;
CellProperties rrcCellProperties;
RowProperties rrcRowProperties;
SectionProperties rrcSectionProperties;
BorderProperties rrcBorderProperties;
ShapeProperties rrcShapeProperties;
DrawingShape rrcShape;
DocumentStyle rrcStyle;
TabStop rrcTabStop;
RGB8Color rrcColor;
int rrcGotComponent;
struct tm rrcTm;
unsigned char * rrcInfoText;
int rrcExternalItemKind;
ParagraphNumber rrcParagraphNumber;
int rrcWhichPnText;
ParagraphNumber * rrcParagraphNumbers;
int rrcParagraphNumberCount;
DocumentList rrcDocumentList;
/****************************************/
/* Document properties. */
/****************************************/
DocumentFont rrcCurrentFont;
/****************************************/
/* For reading the font table. */
/* Style sheet. */
/****************************************/
InsertedObject * rrcInsertedObject;
int rrcFieldNumber;
unsigned char rrcBookmarkName[DOCmaxBOOKMARK+1];
unsigned char rrcBookmarkSize;
RtfBookmarkLevel * rrcTopBookmark;
/****************************************/
/* For reading 'objects' and pictures. */
/* For reading 'fields'. */
/****************************************/
int rrcJustAfterPntext;
int rrcPageAfterPntext;
/****************************************/
/* For coping with the way word saves */
/* {\pntext ... } */
/****************************************/
unsigned char rrcInputMapping[256];
} RtfReadingContext;
/************************************************************************/
/* */
/* What you can find in an RTF file. */
/* */
/************************************************************************/
# define RTFfiCTRLGROUP 1
# define RTFfiWORD 2
# define RTFfiCHAR 3
# define RTFfiTAB 4
# define RTFfiCLOSE 5
# define RTFfiSTARGROUP 6
# define RTFfiTEXTGROUP 7
/************************************************************************/
/* */
/* Writing context. */
/* */
/************************************************************************/
typedef struct PushedAttribute
{
struct PushedAttribute * paNext;
TextAttribute paTextAttribute;
} PushedAttribute;
typedef struct RtfWritingContext
{
TextAttribute rwcTextAttribute;
ParagraphProperties rwcParagraphProperties;
RowProperties rwcRowProperties;
TextAttribute rwcOutsideTableTextAttribute;
ParagraphProperties rwcOutsideTableParagraphProperties;
PushedAttribute * rwcOutsideFldrsltAttribute;
int rwcInFldrslt;
int rwcInTable;
int rwcHasPrecedingTags;
int rwcSaveBookmarks;
int rwcSaveAsLink;
int rwcSaveAsLinkAsRef;
int rwcSaveAsLinkAsPageref;
DocumentField rwcSaveAsHyperlinkField;
DocumentField rwcSaveAsRefField;
DocumentField rwcSaveAsPagerefField;
unsigned char rwcOutputMapping[256];
} RtfWritingContext;
/************************************************************************/
/* Map control words to functions that handle them. */
/************************************************************************/
typedef struct RtfControlWord
{
char * rcwWord;
RtfTag rcwId;
ItemLevel rcwLevel;
int (*rcwApply)( SimpleInputStream * sis,
const struct RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
int rcwEnumValue;
int (*rcwPrepare)( SimpleInputStream * sis,
const struct RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
struct RtfControlWord * rcwDetailWords;
} RtfControlWord;
# define TEDszRTFCONTROL 32
typedef int (*RtfAddTextParticule)( RtfReadingContext * rrc,
const unsigned char * text,
int len );
/************************************************************************/
/* Common data. */
/************************************************************************/
extern RtfControlWord docRtfEmptyTable[];
extern RtfControlWord docRtfDocumentWords[];
extern RtfControlWord docRtfDocumentGroups[];
extern RtfControlWord docRtfPropertyWords[];
/************************************************************************/
/* Routine declarations. */
/************************************************************************/
extern void docRtfInitReadingContext( RtfReadingContext * rrc );
extern void docRtfCleanReadingContext( RtfReadingContext * rrc );
extern int docRtfCopyReadingContext( RtfReadingContext * to,
const RtfReadingContext * from );
extern void docRtfCopyReadingContextBack( RtfReadingContext * to,
RtfReadingContext * from );
extern const RtfControlWord * docRtfFindWord( const char * controlWord,
const RtfControlWord * contolWords,
int listOnly );
extern int docRtfApplyControlWord( SimpleInputStream * sis,
const RtfControlWord * rcw,
int gotArg,
int arg,
RtfReadingContext * rrc );
extern int docRtfReadGroup( SimpleInputStream * sis,
int textLevel,
const RtfControlWord * firstApply,
int gotArg,
int arg,
RtfReadingContext * rrc,
const RtfControlWord * contolWords,
const RtfControlWord * groupWords,
RtfAddTextParticule addParticule );
extern int docRtfFindControl( SimpleInputStream * sis,
RtfReadingContext * rrc,
int * pC,
char * controlWord,
int * pGotArg,
int * pArg );
extern int docRtfIgnoreWord( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfIgnoreParticule( RtfReadingContext * rrc,
const unsigned char * text,
int len );
extern int docRtfIgnoreText( RtfReadingContext * rrc,
const unsigned char * text,
int len );
extern int docRtfRefuseText( RtfReadingContext * rrc,
const unsigned char * text,
int len );
extern int docRtfSkipGroup( SimpleInputStream * sis,
const RtfControlWord * groupRcw,
int textLevel,
RtfReadingContext * rrc );
extern int docRtfConsumeGroup( SimpleInputStream * sis,
int textLevel,
RtfReadingContext * internRrc,
const RtfControlWord * contolWords,
const RtfControlWord * groupWords,
RtfAddTextParticule addParticule );
extern int docRtfReadPict( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfReadNonshppict(SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfReadShppict( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfReadObject( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfAdjustLevel( RtfReadingContext * rrc,
int toLevel,
int textLevel );
extern int docRtfReadShape( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfTextParticule( RtfReadingContext * rrc,
const unsigned char * text,
int len );
extern int docRtfReadField( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfReadLookupEntry(SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfReadExtIt( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfReadFootnote( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfChftn( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfBkmkStart( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfBkmkEnd( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfSpecialToField( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfRememberProperty( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfFlushBookmarks( int fieldNumber,
BufferItem * bi,
RtfReadingContext * rrc );
extern int docRtfFontTable( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfColorTable( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfRevisionTable( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfStylesheet( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfListtable( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfReadInfo( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfRememberDocProperty( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern void docRtfWriteArgTag( const char * tag,
int * pCol,
int arg,
SimpleOutputStream * sos );
extern void docRtfWriteTag( const char * tag,
int * pCol,
SimpleOutputStream * sos );
extern void docRtfEscapeString( const unsigned char * s,
const unsigned char * outputMapping,
int * pCol,
int n,
SimpleOutputStream * sos );
extern void docRtfWriteNextLine( int * pCol,
SimpleOutputStream * sos );
extern void docRtfSaveBorder( char * tag,
int * pCol,
const BorderProperties * bp,
SimpleOutputStream * sos );
extern void docRtfSaveTextAttribute( SimpleOutputStream * sos,
int * pCol,
const PropertyMask * updMask,
const TextAttribute * ta );
extern void docRtfSaveParagraphProperties( SimpleOutputStream * sos,
int * pCol,
const PropertyMask * updMask,
const ParagraphProperties * pp );
extern void docRtfWriteDestinationBegin( const char * tag,
int * pCol,
SimpleOutputStream * sos );
extern void docRtfWriteDestinationEnd( int * pCol,
SimpleOutputStream * sos );
extern int docRtfSavePictureTags( InsertedObject * io,
int * pCol,
SimpleOutputStream * sos );
extern int docRtfWriteMemoryBuffer( const MemoryBuffer * mb,
int * pCol,
SimpleOutputStream * sos );
extern int docRtfReadUnknownGroup( SimpleInputStream * sis,
RtfReadingContext * rrc );
extern int docRtfReadWordGroup( SimpleInputStream * sis,
int textLevel,
RtfReadingContext * rrc,
int gotArg,
int arg,
const char * controlWord,
const RtfControlWord * contolWords,
const RtfControlWord * groupWords,
RtfAddTextParticule addParticule );
extern void docRtfSaveSectionProperties( SimpleOutputStream * sos,
const unsigned char * outputMapping,
int * pCol,
const PropertyMask * updMask,
const SectionProperties * sp );
extern void docRtfWriteFontTable( SimpleOutputStream * sos,
int * pCol,
const DocumentFontList * dfl );
extern void docRtfWriteColorTable( SimpleOutputStream * sos,
int * pCol,
const DocumentProperties * dp );
extern void docRtfWriteRevisorTable( SimpleOutputStream * sos,
const unsigned char * outputMapping,
int * pCol,
const DocumentProperties * dp );
extern void docRtfWriteStyleSheet( SimpleOutputStream * sos,
const unsigned char * outputMapping,
int * pCol,
const DocumentStyleSheet * dss );
extern int docRtfRememberParagraphProperty( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfBeginBorder( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfBrdrProperty( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfRememberSectionProperty( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfRememberTextProperty( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern void docRtfWriteArgDestinationBegin( const char * tag,
int * pCol,
int arg,
SimpleOutputStream * sos );
extern int docRtfSaveDocumentProperties( SimpleOutputStream * sos,
int * pCol,
RtfWritingContext * rwc,
const BufferDocument * bd );
extern void docRtfReadSetAnsicpg( RtfReadingContext * rrc,
int arg );
extern void docRtfSaveTextFrameProperties(
SimpleOutputStream * sos,
int * pCol,
const PropertyMask * updMask,
const TextFrameProperties * tfp );
extern int docRtfRememberTextFrameProperty(
SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc );
extern int docRtfSaveSectHeadersFooters(SimpleOutputStream * sos,
int * pCol,
const BufferItem * bi,
const BufferDocument * bd,
RtfWritingContext * rwc );
extern int docRtfSaveExternalItem( SimpleOutputStream * sos,
int * pCol,
const BufferItem * bi,
const BufferDocument * bd,
const char * tag,
RtfWritingContext * rwc );
extern int docRtfSaveDocNotesSeparators(SimpleOutputStream * sos,
int * pCol,
const BufferDocument * bd,
RtfWritingContext * rwc );
# endif /* DOC_RTF_H */
|