File: docRtfFontTable.c

package info (click to toggle)
ted 2.11-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 11,064 kB
  • ctags: 13,935
  • sloc: ansic: 120,446; makefile: 7,469; sh: 253
file content (225 lines) | stat: -rw-r--r-- 5,821 bytes parent folder | download
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
/************************************************************************/
/*									*/
/*  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	<psFont.h>
#   include	"docRtf.h"

/************************************************************************/
/*									*/
/*  Consume a font table.						*/
/*									*/
/************************************************************************/

static int docRtfFontPanoseText(	RtfReadingContext *	rrc,
					const unsigned char *	panose,
					int			len )
    {
    if  ( len != FONTlenPANOSE )
	{ LLDEB(len,FONTlenPANOSE); return 0;	}

    memcpy( rrc->rrcCurrentFont.dfPanose, panose, len );

    rrc->rrcCurrentFont.dfPanose[FONTlenPANOSE]= '\0';

    return 0;
    }

static int docRtfFontPanoseGroup( SimpleInputStream *	sis,
				const RtfControlWord *	rcw,
				int			arg,
				RtfReadingContext *	rrc )
    {
    if  ( docRtfReadGroup( sis, rcw->rcwLevel,
				    (RtfControlWord *)0, 0, 0, rrc,
				    docRtfEmptyTable, docRtfEmptyTable,
				    docRtfFontPanoseText ) )
	{ SLDEB(rcw->rcwWord,arg); return -1;	}

    return 0;
    }

static int docRtfFontName(	RtfReadingContext *	rrc,
				const unsigned char *	name,
				int			len )
    {
    DocumentFont *		df;
    DocumentProperties *	dp= &(rrc->rrcBd->bdProperties);

    static char *		scratch;
    char *			fresh;

    fresh= (char *)realloc( scratch, len+ 1 );
    if  ( ! fresh )
	{ XDEB(fresh); return -1;	}
    scratch= fresh;
    strncpy( scratch, (const char *)name, len )[len]= '\0';

    if  ( len > 0 && scratch[len-1] == ';' )
	{ scratch[len-1]= '\0';	}

    if  ( ! scratch[0] )
	{ return 0;	}

    df= docInsertFont( &(dp->dpFontList),
		    rrc->rrcCurrentFont.dfDocFamilyNumber,
		    rrc->rrcCurrentFont.dfFamilyStyle, scratch );

    if  ( ! df )
	{ SSDEB(rrc->rrcCurrentFont.dfFamilyStyle,scratch); return -1; }

    df->dfCharset= rrc->rrcCurrentFont.dfCharset;
    df->dfPitch= rrc->rrcCurrentFont.dfPitch;

    strcpy( df->dfPanose, rrc->rrcCurrentFont.dfPanose );

    rrc->rrcCurrentFont.dfPanose[0]= '\0';

    return 0;
    }

static int docRtfFontNumber(	SimpleInputStream *	sis,
				const RtfControlWord *	rcw,
				int			arg,
				RtfReadingContext *	rrc )
    {
    docCleanFont( &(rrc->rrcCurrentFont) );
    docInitFont( &(rrc->rrcCurrentFont) );

    rrc->rrcCurrentFont.dfDocFamilyNumber= arg;

    return 0;
    }

static int docRtfFontFamily(	SimpleInputStream *	sis,
				const RtfControlWord *	rcw,
				int			arg,
				RtfReadingContext *	rrc	)
    {
    rrc->rrcCurrentFont.dfFamilyStyle= strdup( rcw->rcwWord );

    if  ( ! rrc->rrcCurrentFont.dfFamilyStyle )
	{ XDEB(rrc->rrcCurrentFont.dfFamilyStyle); return -1;	}

    return 0;
    }

static int docRtfFontProperty(	SimpleInputStream *	sis,
				const RtfControlWord *	rcw,
				int			arg,
				RtfReadingContext *	rrc	)
    {
    switch( rcw->rcwId )
	{
	case RTFidFCHARSET:
	    rrc->rrcCurrentFont.dfCharset= arg;
	    break;

	case RTFidFPRQ:
	    rrc->rrcCurrentFont.dfPitch= arg;
	    break;

	default:
	    SLDEB(rcw->rcwWord,arg);
	}

    return 0;
    }

static RtfControlWord	docRtfFontGroupGroups[]=
    {
	{ "panose",	RTFidPANOSE,	DOClevANY, docRtfFontPanoseGroup, },

	{ 0, 0, 0 }
    };

static RtfControlWord	docRtfFontGroupWords[]=
    {
	{ "fnil",	RTFidFNIL,	DOClevANY, docRtfFontFamily, },
	{ "froman",	RTFidFROMAN,	DOClevANY, docRtfFontFamily, },
	{ "fswiss",	RTFidFSWISS,	DOClevANY, docRtfFontFamily, },
	{ "fmodern",	RTFidFMODERN,	DOClevANY, docRtfFontFamily, },
	{ "fscript",	RTFidFSCRIPT,	DOClevANY, docRtfFontFamily, },
	{ "fdecor",	RTFidFDECOR,	DOClevANY, docRtfFontFamily, },
	{ "ftech",	RTFidFTECH,	DOClevANY, docRtfFontFamily, },

	{ "fcharset",	RTFidFCHARSET,	DOClevDOC, docRtfFontProperty, },
	{ "fprq",	RTFidFPRQ,	DOClevDOC, docRtfFontProperty, },

	{ 0, 0, 0 }
    };

static int docRtfFontGroup(	SimpleInputStream *	sis,
				const RtfControlWord *	rcw,
				int			arg,
				RtfReadingContext *	rrc	)
    {
    docCleanFont( &(rrc->rrcCurrentFont) );
    docInitFont( &(rrc->rrcCurrentFont) );

    rrc->rrcCurrentFont.dfDocFamilyNumber= arg;

    if  ( docRtfReadGroup( sis, rcw->rcwLevel,
				    (RtfControlWord *)0, 0, 0, rrc,
				    docRtfFontGroupWords, docRtfFontGroupGroups,
				    docRtfFontName ) )
	{ SLDEB(rcw->rcwWord,arg); return -1;	}

    docCleanFont( &(rrc->rrcCurrentFont) );
    docInitFont( &(rrc->rrcCurrentFont) );

    return 0;
    }

static RtfControlWord	docRtfFontTableWords[]=
    {
	{ "f",		RTFidF,		DOClevDOC, docRtfFontNumber, },

	{ "fnil",	RTFidFNIL,	DOClevANY, docRtfFontFamily, },
	{ "froman",	RTFidFROMAN,	DOClevANY, docRtfFontFamily, },
	{ "fswiss",	RTFidFSWISS,	DOClevANY, docRtfFontFamily, },
	{ "fmodern",	RTFidFMODERN,	DOClevANY, docRtfFontFamily, },
	{ "fscript",	RTFidFSCRIPT,	DOClevANY, docRtfFontFamily, },
	{ "fdecor",	RTFidFDECOR,	DOClevANY, docRtfFontFamily, },
	{ "ftech",	RTFidFTECH,	DOClevANY, docRtfFontFamily, },

	{ "fcharset",	RTFidFCHARSET,	DOClevDOC, docRtfFontProperty, },
	{ "fprq",	RTFidFPRQ,	DOClevDOC, docRtfFontProperty, },

	{ 0, 0, 0 }
    };

static RtfControlWord	docRtfFontTableGroups[]=
    {
	{ "f",		RTFidF,		DOClevDOC,  docRtfFontGroup, },

	{ 0, 0, 0 }
    };

int docRtfFontTable(	SimpleInputStream *	sis,
			const RtfControlWord *	rcw,
			int			arg,
			RtfReadingContext *	rrc	)
    {
    if  ( docRtfReadGroup( sis, rcw->rcwLevel,
				(RtfControlWord *)0, 0, 0, rrc,
				docRtfFontTableWords, docRtfFontTableGroups,
				docRtfFontName ) )
	{ SLDEB(rcw->rcwWord,arg); return -1;	}

    return 0;
    }