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
|
/************************************************************************/
/* */
/* Read the various document tables of an RTF text file into a */
/* BufferDocument. */
/* */
/************************************************************************/
# include "tedConfig.h"
# include <stdlib.h>
# include <string.h>
# include <stdio.h>
# include <ctype.h>
# include <appDebugon.h>
# include <appUnit.h>
# include "docRtf.h"
/************************************************************************/
/* */
/* Read a color table. */
/* */
/************************************************************************/
static int docRtfSaveColor( RtfReadingContext * rrc,
const unsigned char * text,
int len )
{
DocumentProperties * dp= &(rrc->rrcBd->bdProperties);
RGB8Color * fresh;
fresh= (RGB8Color *)realloc( dp->dpColors,
( dp->dpColorCount+ 1) * sizeof( RGB8Color ) );
if ( ! fresh )
{ LXDEB(dp->dpColorCount,fresh); return -1; }
dp->dpColors= fresh;
fresh[dp->dpColorCount++]= rrc->rrcColor;
if ( ! rrc->rrcGotComponent )
{
if ( dp->dpDefaultColor < 0 )
{ dp->dpDefaultColor= dp->dpColorCount; }
}
rrc->rrcGotComponent= 0;
return 0;
}
static int docRtfColorComp( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc )
{
switch( rcw->rcwId )
{
case RTFidRED:
rrc->rrcGotComponent= 1;
rrc->rrcColor.rgb8Red= arg;
break;
case RTFidGREEN:
rrc->rrcGotComponent= 1;
rrc->rrcColor.rgb8Green= arg;
break;
case RTFidBLUE:
rrc->rrcGotComponent= 1;
rrc->rrcColor.rgb8Blue= arg;
break;
default:
/* SLDEB(rcw->rcwWord,arg); */
break;
}
return 0;
}
static RtfControlWord docRtfColorTableWords[]=
{
{ "red", RTFidRED, DOClevANY, docRtfColorComp, },
{ "green", RTFidGREEN, DOClevANY, docRtfColorComp, },
{ "blue", RTFidBLUE, DOClevANY, docRtfColorComp, },
{ 0, 0, 0 }
};
int docRtfColorTable( SimpleInputStream * sis,
const RtfControlWord * rcw,
int arg,
RtfReadingContext * rrc )
{
rrc->rrcGotComponent= 0;
if ( docRtfReadGroup( sis, rcw->rcwLevel,
(RtfControlWord *)0, 0, 0, rrc,
docRtfColorTableWords, docRtfEmptyTable,
docRtfSaveColor ) )
{ SLDEB(rcw->rcwWord,arg); return -1; }
return 0;
}
|