Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8335 maxcodehac 1
 
2
   GNU UnRTF, a command-line program to convert RTF documents to other formats.
3
   Copyright (C) 2000,2001 Zachary Thayer Smith
4
5
 
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 2 of the License, or
8
   (at your option) any later version.
9
10
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
15
 
16
   along with this program; if not, write to the Free Software
17
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
 
20
=============================================================================*/
21
22
 
23
 
24
 * Module name:    ps
25
 * Author name:    Zach Smith
26
 * Create date:    18 Sep 01
27
 * Purpose:        PostScript(TM)-specific output module
28
 *----------------------------------------------------------------------
29
 * Changes:
30
 * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks
31
 * 23 Sep 01, tuorfa@yahoo.com: added shadow, outline, strikethru, underline
32
 * 23 Sep 01, tuorfa@yahoo.com: revised PS program to use ISOLatin1Encoding
33
 * 28 Sep 01, tuorfa@yahoo.com: added support for Helvetica,Courier,Symbol
34
 *--------------------------------------------------------------------*/
35
36
 
37
 
38
 
39
 
40
#include 
41
#include "malloc.h"
42
#include "defs.h"
43
#include "error.h"
44
#include "main.h"
45
#include "output.h"
46
47
 
48
 
49
 
50
ascii [96] = {
51
	/* 0x20 */ " ", "!", "\"", "#", "$", "\%", "&", "'",
52
	/* 0x28 */ "\\(", "\\)", "*", "+", ",", "-", ".", "/",
53
	/* 0x30 */ "0", "1", "2", "3", "4", "5", "6", "7",
54
	/* 0x38 */ "8", "9", ":", ";", "<", "=", ">", "?",
55
	/* 0x40 */ "@", "A", "B", "C", "D", "E", "F", "G",
56
	/* 0x48 */ "H", "I", "J", "K", "L", "M", "N", "O",
57
	/* 0x50 */ "P", "Q", "R", "S", "T", "U", "V", "W",
58
	/* 0x58 */ "X", "Y", "Z", "\\[", "\\\\", "\\]", "^", "_",
59
	/* 0x60 */ "`", "a", "b", "c", "d", "e", "f", "g",
60
	/* 0x68 */ "h", "i", "j", "k", "l", "m", "n", "o",
61
	/* 0x70 */ "p", "q", "r", "s", "t", "u", "v", "w",
62
	/* 0x78 */ "x", "y", "z", "{", "|", "}", "~", "",
63
};
64
65
 
66
 
67
/* 0x80 */ "\\200","\\201","\\202","\\203",
68
/* 0x84 */ "\\204","\\205","\\206","\\207",
69
/* 0x88 */ "\\210","\\211","\\212","\\213",
70
/* 0x8c */ "\\214","\\215","\\216","\\217",
71
/* 0x90 */ "\\220","\\221","\\222","\\223",
72
/* 0x94 */ "\\224","\\225","\\226","\\227",
73
/* 0x98 */ "\\230","\\231","\\232","\\233",
74
/* 0x9c */ "\\234","\\235","\\236","\\237",
75
/* 0xa0 */ "\\240","\\241","\\242","\\243",
76
/* 0xa4 */ "\\244","\\245","\\246","\\247",
77
/* 0xa8 */ "\\250","\\251","\\252","\\253",
78
/* 0xac */ "\\254","\\255","\\256","\\257",
79
/* 0xb0 */ "\\260","\\261","\\262","\\263",
80
/* 0xb4 */ "\\264","\\265","\\266","\\267",
81
/* 0xb8 */ "\\270","\\271","\\272","\\273",
82
/* 0xbc */ "\\274","\\275","\\276","\\277",
83
/* 0xc0 */ "\\300","\\301","\\302","\\303",
84
/* 0xc4 */ "\\304","\\305","\\306","\\307",
85
/* 0xc8 */ "\\310","\\311","\\312","\\313",
86
/* 0xcc */ "\\314","\\315","\\316","\\317",
87
/* 0xd0 */ "\\320","\\321","\\322","\\323",
88
/* 0xd4 */ "\\324","\\325","\\326","\\327",
89
/* 0xd8 */ "\\330","\\331","\\332","\\333",
90
/* 0xdc */ "\\334","\\335","\\336","\\337",
91
/* 0xe0 */ "\\340","\\341","\\342","\\343",
92
/* 0xe4 */ "\\344","\\345","\\346","\\347",
93
/* 0xe8 */ "\\350","\\351","\\352","\\353",
94
/* 0xec */ "\\354","\\355","\\356","\\357",
95
/* 0xf0 */ "\\360","\\361","\\362","\\363",
96
/* 0xf4 */ "\\364","\\365","\\366","\\367",
97
/* 0xf8 */ "\\370","\\371","\\372","\\373",
98
/* 0xfc */ "\\374","\\375","\\376","\\377",
99
};
100
101
 
102
 
103
	"?",
104
};
105
106
 
107
	"?",
108
};
109
110
 
111
	"?",
112
};
113
114
 
115
 
116
 
117
 
118
%% --------- \n\n\
119
  didShowPage not { \n\
120
    showpage \n\
121
  } if\n\n\
122
%%%%EOF\n"
123
124
 
125
 
126
 
127
 
128
%%%%!PS\n\
129
%%--------------------------------------------------------------------------\n\
130
%% GNU UnRTF, a command-line program to convert RTF documents to other formats.\n\
131
%% Copyright (C) 2000,2001 Zachary Thayer Smith\n\
132
%%\n\
133
%% This program is free software; you can redistribute it and/or modify\n\
134
%% it under the terms of the GNU General Public License as published by\n\
135
%% the Free Software Foundation; either version 2 of the License, or\n\
136
%% (at your option) any later version.\n\
137
%%\n\
138
%% This program is distributed in the hope that it will be useful,\n\
139
%% but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
140
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
141
%% GNU General Public License for more details.\n\
142
%%\n\
143
%% You should have received a copy of the GNU General Public License\n\
144
%% along with this program; if not, write to the Free Software\n\
145
%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\
146
%%\n\
147
%% The author is reachable by electronic mail at tuorfa@yahoo.com.\n\
148
%%--------------------------------------------------------------------------\n\
149
%%%%EndComments \n\
150
%%\n\
151
%%         --------- Note, this PS code is unfinished -------- \n\
152
%%         --------- Note, this PS code is unfinished -------- \n\
153
%%         --------- Note, this PS code is unfinished -------- \n\
154
%%         --------- Note, this PS code is unfinished -------- \n\
155
%%         --------- Note, this PS code is unfinished -------- \n\
156
%%\n\
157
%% ----------- Variables ------------\n\
158
/fontFamily /Times def\n\
159
/fontAscent 0 def %% ascent for current font\n\
160
/fontDescent 0 def %% descent for current font\n\
161
/lineAscent 0 def \n\
162
/lineDescent 0 def \n\
163
/pageWidthInches 8.5 def \n\
164
/pageHeightInches 11 def \n\
165
/leftMargin 20 def \n\
166
/rightMargin 20 def \n\
167
/topMargin 20 def \n\
168
/bottomMargin 20 def \n\
169
/DPI 72 def \n\
170
/pageWidth pageWidthInches DPI mul def \n\
171
/rightLimit pageWidth rightMargin sub def \n\
172
/pageHeight pageHeightInches DPI mul def \n\
173
/x 0 def \n\
174
/y 0 def \n\
175
/bold false def \n\
176
/italic false def \n\
177
/underline false def \n\
178
/overline false def \n\
179
/intercharSpace 0 def \n\
180
/strike false def \n\
181
/outline false def \n\
182
/shadow false def \n\
183
/fontSize 12 def \n\
184
/didBR false def \n\
185
/didParSkip false def \n\
186
/didShowPage false def \n\
187
%%------------------------------------------------------\n\
188
%% Set up the ISO fonts \n\
189
%% Times \n\
190
%% ----- \n\
191
/Times-Roman findfont dup length dict begin {		\n\
192
	1 index /FID ne { def } { pop pop } ifelse	\n\
193
} forall						\n\
194
/Encoding ISOLatin1Encoding def 			\n\
195
currentdict end						\n\
196
/TRomanISO exch definefont pop			\n\
197
/Times-Bold findfont dup length dict begin {		\n\
198
	1 index /FID ne { def } { pop pop } ifelse	\n\
199
} forall						\n\
200
/Encoding ISOLatin1Encoding def 			\n\
201
currentdict end						\n\
202
/TBoldISO exch definefont pop			\n\
203
/Times-BoldItalic findfont dup length dict begin {	\n\
204
	1 index /FID ne { def } { pop pop } ifelse	\n\
205
} forall						\n\
206
/Encoding ISOLatin1Encoding def 			\n\
207
currentdict end						\n\
208
/TBoldItalicISO exch definefont pop			\n\
209
/Times-Italic findfont dup length dict begin {		\n\
210
	1 index /FID ne { def } { pop pop } ifelse	\n\
211
} forall						\n\
212
/Encoding ISOLatin1Encoding def 			\n\
213
currentdict end						\n\
214
/TItalicISO exch definefont pop			\n\
215
%% Courier \n\
216
%% ----- \n\
217
/Courier-Roman findfont dup length dict begin {		\n\
218
	1 index /FID ne { def } { pop pop } ifelse	\n\
219
} forall						\n\
220
/Encoding ISOLatin1Encoding def 			\n\
221
currentdict end						\n\
222
/CRomanISO exch definefont pop			\n\
223
/Courier-Bold findfont dup length dict begin {		\n\
224
	1 index /FID ne { def } { pop pop } ifelse	\n\
225
} forall						\n\
226
/Encoding ISOLatin1Encoding def 			\n\
227
currentdict end						\n\
228
/CBoldISO exch definefont pop			\n\
229
/Courier-BoldItalic findfont dup length dict begin {	\n\
230
	1 index /FID ne { def } { pop pop } ifelse	\n\
231
} forall						\n\
232
/Encoding ISOLatin1Encoding def 			\n\
233
currentdict end						\n\
234
/CBoldItalicISO exch definefont pop			\n\
235
/Courier-Italic findfont dup length dict begin {		\n\
236
	1 index /FID ne { def } { pop pop } ifelse	\n\
237
} forall						\n\
238
/Encoding ISOLatin1Encoding def 			\n\
239
currentdict end						\n\
240
/CItalicISO exch definefont pop			\n\
241
%% Symbol \n\
242
%% ----- \n\
243
/Symbol-Roman findfont dup length dict begin {		\n\
244
	1 index /FID ne { def } { pop pop } ifelse	\n\
245
} forall						\n\
246
/Encoding ISOLatin1Encoding def 			\n\
247
currentdict end						\n\
248
/SRomanISO exch definefont pop			\n\
249
/Symbol-Bold findfont dup length dict begin {		\n\
250
	1 index /FID ne { def } { pop pop } ifelse	\n\
251
} forall						\n\
252
/Encoding ISOLatin1Encoding def 			\n\
253
currentdict end						\n\
254
/SBoldISO exch definefont pop			\n\
255
/Symbol-BoldItalic findfont dup length dict begin {	\n\
256
	1 index /FID ne { def } { pop pop } ifelse	\n\
257
} forall						\n\
258
/Encoding ISOLatin1Encoding def 			\n\
259
currentdict end						\n\
260
/SBoldItalicISO exch definefont pop			\n\
261
/Symbol-Italic findfont dup length dict begin {		\n\
262
	1 index /FID ne { def } { pop pop } ifelse	\n\
263
} forall						\n\
264
/Encoding ISOLatin1Encoding def 			\n\
265
currentdict end						\n\
266
/SItalicISO exch definefont pop			\n\
267
%% Helvetica \n\
268
%% --------- \n\
269
/Helvetica-Roman findfont dup length dict begin {		\n\
270
	1 index /FID ne { def } { pop pop } ifelse	\n\
271
} forall						\n\
272
/Encoding ISOLatin1Encoding def 			\n\
273
currentdict end						\n\
274
/HRomanISO exch definefont pop			\n\
275
/Helvetica-Bold findfont dup length dict begin {		\n\
276
	1 index /FID ne { def } { pop pop } ifelse	\n\
277
} forall						\n\
278
/Encoding ISOLatin1Encoding def 			\n\
279
currentdict end						\n\
280
/HBoldISO exch definefont pop			\n\
281
/Helvetica-BoldOblique findfont dup length dict begin {	\n\
282
	1 index /FID ne { def } { pop pop } ifelse	\n\
283
} forall						\n\
284
/Encoding ISOLatin1Encoding def 			\n\
285
currentdict end						\n\
286
/HBoldItalicISO exch definefont pop			\n\
287
/Helvetica-Oblique findfont dup length dict begin {		\n\
288
	1 index /FID ne { def } { pop pop } ifelse	\n\
289
} forall						\n\
290
/Encoding ISOLatin1Encoding def 			\n\
291
currentdict end						\n\
292
/HItalicISO exch definefont pop			\n\
293
%% \n\
294
%% Ideally, before we can draw a line of text, we need to collect all the\n\
295
%% words that will be on it, just as I do in my Beest HTML viewer, as well\n\
296
%% as character attributes for each word. But for now, this implementation \n\
297
%% does not bother. It determines the maximize ascent and descent after\n\
298
%% drawing the text, not before. XX\n\
299
%% \n\
300
%% ----------- Functions ------------\n\
301
/updateFont { \n\
302
	/f0 null def \n\
303
	(Times) fontFamily eq (Times New Roman) fontFamily eq or {		bold { \n\
304
			italic { /TBoldItalicISO } { /TBoldISO } ifelse \n\
305
		} { \n\
306
			italic { /TItalicISO } { /TRomanISO } ifelse \n\
307
		} \n\
308
		ifelse \n\
309
	} if 	(Helvetica) fontFamily eq (Arial) fontFamily eq or { 		bold { \n\
310
			italic { /HBoldItalicISO } { /HBoldISO } ifelse \n\
311
		} { \n\
312
			italic { /HItalicISO } { /HRomanISO } ifelse \n\
313
		} \n\
314
		ifelse \n\
315
	} if	(Courier) fontFamily eq (Courier New) fontFamily eq or {		bold { \n\
316
			italic { /CBoldItalicISO } { /CBoldISO } ifelse \n\
317
		} { \n\
318
			italic { /CItalicISO } { /CRomanISO } ifelse \n\
319
		} \n\
320
		ifelse \n\
321
	} if 	(Symbol) fontFamily eq { 		bold { \n\
322
			italic { /SBoldItalicISO } { /SBoldISO } ifelse \n\
323
		} { \n\
324
			italic { /SItalicISO } { /SRomanISO } ifelse \n\
325
		} \n\
326
		ifelse \n\
327
	} if 	findfont /f0 exch def  \n\
328
	/bboxBottom f0 /FontBBox get 1 get 1000 div fontSize mul -1 mul def \n\
329
	/bboxTop    f0 /FontBBox get 3 get 1000 div fontSize mul def \n\
330
	f0 fontSize scalefont setfont \n\
331
	lineAscent bboxTop lt { /lineAscent bboxTop def } if  \n\
332
	lineDescent bboxBottom lt { /lineDescent bboxBottom def } if  \n\
333
	/fontAscent bboxTop def \n\
334
	/fontDescent bboxBottom def \n\
335
} def\n\
336
/FS { \n\
337
	/fontSize exch def updateFont \n\
338
} def \n\
339
/F { \n\
340
	/fontFamily exch def updateFont \n\
341
} def \n\
342
/resetX { \n\
343
	/x leftMargin def\n\
344
} def \n\
345
/resetY { \n\
346
	/y pageHeight topMargin sub def \n\
347
} def \n\
348
/BR {  \n\
349
	/oldx x def \n\
350
	/y y lineAscent lineDescent add sub def  \n\
351
	resetX \n\
352
	y bottomMargin lt { \n\
353
		showpage \n\
354
		/didShowPage true \n\
355
		resetY \n\
356
	} if \n\
357
	oldx 0 eq didBR and { /didParSkip true def } if \n\
358
	/didBR true def \n\
359
	% /lineAscent 0 def \n\
360
	% /lineDescent 0 def \n\
361
} def \n\
362
/P { \n\
363
	didParSkip not { BR } if \n\
364
	didParSkip not { BR } if \n\
365
} \n\
366
def \n\
367
/acharpath { \n\
368
	/acstr exch def pop /acsp exch def 	newpath 	str {		/ch exch def		1 string 0 ch put false charpath		acsp 0 rmoveto	} forall} def \n\
369
/A { \n\
370
	/str exch def \n\
371
	/w str stringwidth pop \n\
372
		str length intercharSpace mul add \n\
373
		def \n\
374
		x w add rightLimit ge { BR } if \n\
375
	x y moveto \n\
376
	outline {                                           \n\
377
		shadow {                                    \n\
378
			1 -0.1 0 {                        \n\
379
				/offset exch def \n\
380
				offset setgray                 \n\
381
				x offset 3 mul add y offset 3 mul sub moveto 				intercharSpace 0 str acharpath \n\
382
				%% str false charpath \n\
383
				fontSize 30 div setlinewidth stroke \n\
384
			} for                               \n\
385
			0 setgray \n\
386
 
387
			intercharSpace 0 str acharpath      \n\
388
			%% str false charpath \n\
389
			fontSize 30 div setlinewidth stroke \n\
390
		} ifelse                                    \n\
391
	} {                                                 \n\
392
		shadow {                                    \n\
393
			1 -0.1 0 {                        \n\
394
				/offset exch def \n\
395
				offset setgray                 \n\
396
				x offset 3 mul add y offset 3 mul sub moveto 				intercharSpace 0 str ashow  \n\
397
				%% str show \n\
398
			} for                               \n\
399
			0 setgray		} {                                         \n\
400
 
401
			%% str show \n\
402
		} ifelse                                    \n\
403
	} ifelse                                            \n\
404
	strike {							\n\
405
		newpath fontSize 20 div setlinewidth			\n\
406
		x y fontAscent 0.32 mul add dup /y2 exch def moveto	\n\
407
		x w add y2 lineto stroke				\n\
408
	} if								\n\
409
	underline {							\n\
410
		newpath fontSize 20 div setlinewidth			\n\
411
		x y fontAscent 0.2 mul sub dup /y2 exch def moveto	\n\
412
		x w add y2 lineto stroke				\n\
413
	} if								\n\
414
	overline {							\n\
415
		%% I don't think RTF supports this, but it can be used later. \n\
416
		newpath fontSize 20 div setlinewidth			\n\
417
		x y fontAscent 1.2 mul add dup /y2 exch def moveto	\n\
418
		x w add y2 lineto stroke				\n\
419
	} if					\n\
420
	/x x w add def  			\n\
421
	/didBR false def 			\n\
422
	/didShowPage false def 			\n\
423
} def \n\
424
\n\
425
%% These are only binary for now \n\
426
/X1 { /intercharSpace exch def } def\n\
427
/X0 { /intercharSpace 0 def } def\n\
428
/O1 { /outline false def } def\n\
429
/O0 { /outline false def } def\n\
430
/H1 { /shadow true def } def\n\
431
/H0 { /shadow false def } def\n\
432
/S1 { /strike true def } def\n\
433
/S0 { /strike false def } def\n\
434
/B1 { /bold true def updateFont } def\n\
435
/B0 { /bold false def updateFont } def\n\
436
/I1 { /italic true def updateFont } def\n\
437
/I0 { /italic false def updateFont } def\n\
438
/U1 { /underline true def } def\n\
439
/U0 { /underline false def } def\n\
440
updateFont \n\
441
resetX resetY \n\
442
\n\
443
"
444
445
 
446
 
447
 
448
 
449
 * Name:	ps_init
450
 * Purpose:	Generates an OutputPersonality object for the PostScript(TM)
451
 *		format.
452
 * Args:	None.
453
 * Returns:	OutputPersonality.
454
 *=======================================================================*/
455
456
 
457
ps_init (void)
458
{
459
	OutputPersonality* op;
460
461
 
462
463
 
464
	op->comment_end = "\n";
465
466
 
467
	op->word_end = ")A ";
468
469
 
470
	op->document_end = PS_END;
471
472
 
473
	op->header_end = "%% header end\n";
474
475
 
476
	op->document_title_end = "\n";
477
478
 
479
	op->document_author_end = "\n";
480
481
 
482
	op->document_changedate_end = "\n";
483
484
 
485
	op->body_end = "\n";
486
487
 
488
	op->paragraph_end = "\n";
489
490
 
491
	op->center_end = "";
492
493
 
494
	op->justify_end = "";
495
496
 
497
	op->align_left_end = "";
498
499
 
500
	op->align_right_end = "";
501
502
 
503
	op->line_break = "BR\n";
504
	op->page_break = "\n";
505
506
 
507
	op->hyperlink_end = ")A U0 ";
508
509
 
510
	op->imagelink_end = "";
511
512
 
513
	op->table_end = "\n% TABLE ENDS (not implemented)\nP\n";
514
515
 
516
	op->table_row_end = "( |)A BR\n";
517
518
 
519
	op->table_cell_end = "";
520
521
 
522
	op->font_begin = "(%s) F ";
523
	op->font_end = "";
524
525
 
526
	op->fontsize_end = "";
527
528
 
529
	op->smaller_end = "";
530
531
 
532
	op->bigger_end = "";
533
534
 
535
	op->foreground_end = "";
536
537
 
538
	op->background_end = "";
539
540
 
541
	op->bold_end = "B0 ";
542
543
 
544
	op->italic_end = "I0 ";
545
546
 
547
	op->underline_end = "U0 ";
548
549
 
550
	op->dbl_underline_end = "U0 ";
551
552
 
553
	op->superscript_end = "";
554
555
 
556
	op->subscript_end = "";
557
558
 
559
	op->strikethru_end = "S0 ";
560
561
 
562
	op->dbl_strikethru_end = "S0 ";
563
564
 
565
	op->emboss_end = "";
566
567
 
568
	op->engrave_end = "";
569
570
 
571
	op->shadow_end= "H0 ";
572
573
 
574
	op->outline_end= "O0 ";
575
576
 
577
	op->expand_end = "X0 ";
578
579
 
580
	op->simulate_all_caps = TRUE;
581
	op->simulate_word_underline = TRUE;
582
583
 
584
585
 
586
	op->ansi_first_char = 0x80;
587
	op->ansi_last_char = 0xff;
588
589
 
590
	op->cp437_first_char = 0x80;
591
	op->cp437_last_char = 0x80;
592
593
 
594
	op->cp850_first_char = 0x80;
595
	op->cp850_last_char = 0x80;
596
597
 
598
	op->mac_first_char = 0x80;
599
	op->mac_last_char = 0x80;
600
601
 
602
	op->chars.left_quote = "`";
603
	op->chars.right_dbl_quote = "''";
604
	op->chars.left_dbl_quote = "``";
605
606
 
607
}
608