-
Notifications
You must be signed in to change notification settings - Fork 1
/
lpt2pdf.c
5099 lines (4426 loc) · 160 KB
/
lpt2pdf.c
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2013, Timothe Litt
* litt @acm.org
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* Except as contained in this notice, the name of the author shall not be
* used in advertising or otherwise to promote the sale, use or other dealings
* in this Software without prior written authorization from the author.
*
*/
/* This compiles two ways:
* As a callable library (default)
* As a stand-alone utility (define PDF_MAIN for this)
*
* The API is documented in lpt2pdf.h. The utility in its usage(), below.
*
* The PDF generated conforms to a subset of the PDF specification:
* http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
*
* When appending, only files produced by this library are accepted, as a number of
* assumptions are made about the structure to simplify this code.
*/
#define LPT2PDF_VERSION "1.0-006"
#define VERSION_REQUIRED "1."
#include <ctype.h>
#include <errno.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#if defined (_MSC_VER) && _MSC_VER < 1600
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef __int16 int_least16_t;
#else
#include <stdint.h>
#endif
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <Windows.h>
#include <io.h>
#include <share.h>
#else
#include <unistd.h> /* ftruncate */
#ifndef VMS
#include <sys/file.h>
#define USE_FLOCK
#endif
#endif
#define PDF_BUILD_
#include "lpt2pdf.h"
/* Bufer size for moving "large" amounts of data, e.g. file contents.
* Can be tuned per OS/Filesystem type.
*/
#ifndef COPY_BUFSIZE
#define COPY_BUFSIZE (8192)
#endif
/* Colors:
*
* PDF RGB takes values from 0 to 1.0
*/
#define RGB_BLACK "0 0 0"
#define RGB_WHITE "1.000 1.000 1.000"
#define RGB_GREEN_LINE "0.780 0.860 0.780"
#define RGB_GREEN_TEXT "0.780 0.860 0.780"
#define RGB_GREEN_BAR "0.880 0.960 0.880"
#define RGB_BLUE_LINE "0.700 0.900 1.000"
#define RGB_BLUE_TEXT "0.700 0.900 1.000"
#define RGB_BLUE_BAR "0.800 0.940 1.000"
#define RGB_YELLOW_LINE "0.900 0.900 0.800"
#define RGB_YELLOW_TEXT "0.700 0.700 0.700" /* Use gray; yellow text not readable */
#define RGB_YELLOW_BAR "1.000 1.000 0.600"
#define RGB_GRAY_LINE "0.700 0.700 0.700"
#define RGB_GRAY_TEXT "0.700 0.700 0.700"
#define RGB_GRAY_BAR "0.800 0.800 0.800"
#define RGB_HOLE_LINE "0.85 0.85 0.85"
#define RGB_HOLE_FILL "0.90 0.90 0.90"
typedef struct {
const char *const line;
const char *const bar;
const char *const text;
const char *const name;
} COLORS;
static const COLORS colors[] = {
#define PDF_PLAIN (0)
{RGB_BLACK, RGB_BLACK, RGB_BLACK, "PLAIN", }, /* PLAIN is used for images too */
#define PDF_GREENBAR (1)
{RGB_GREEN_LINE, RGB_GREEN_BAR, RGB_GREEN_TEXT, "GREENBAR", },
#define PDF_BLUEBAR (2)
{RGB_BLUE_LINE, RGB_BLUE_BAR, RGB_BLUE_TEXT, "BLUEBAR", },
#define PDF_GRAYBAR (3)
{RGB_GRAY_LINE, RGB_GRAY_BAR, RGB_GRAY_TEXT, "GRAYBAR", },
#define PDF_YELLOWBAR (4)
{RGB_YELLOW_LINE, RGB_YELLOW_BAR, RGB_YELLOW_TEXT, "YELLOWBAR", },
};
#define DIM(x) (sizeof (x) / sizeof ((x)[0]))
/* Library error codes */
#define E(x) PDF_E_ ## x
static const char **formlist = NULL;
/* These are the built-in fonts that every reader is required to know about.
* Embedding fonts would be nice, but requires a lot of work to read the file,
* decode its format &... deal with the licensing issues.
*/
static const char *const validFonts[] = {
"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique",
"Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",
"Helvetica", "Helvetica-Bold", "HelveticaOblique", "Helvetica-BoldOblique",
"Symbol", "ZapfDingbats",
NULL
};
/* Character set maps from 0x20 - 0xFF (96) or 0x21 - 0xFE (94)
* The 94-char maps have translations for all 96 for simplicity.
* 0x2426 is used for all undefined/reserved codes.
*/
typedef struct {
const char *name;
const uint16_t size;
const uint16_t nint;
const char ints[2+1];
const char final[1+1];
const short chrset[96];
} CHARSET;
static const CHARSET charsets[] = {
/* CHARSET with no intermediates */
#define CHS(name, size, final) \
{ #name, size, 0, {0}, {#final}, {
/* CHARSET with intermediates */
#define CHSI(name, size, int, final) \
{ #name, size, sizeof(#int)-1, {#int}, {#final}, {
/* CHARSET with intermediates specified as quoted string (usu. " in seq) */
#define CHSIq(name, size, int, final) \
{ #name, size, sizeof(int)-1, {int}, {#final}, {
/* End of CHARSET data */
#define CHSEND } },
#define CHS_ASCII (charsets+0)
CHS (ASCII, 94, B) /* Default G0, G1, GL */
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
/* Should 6/0 be U+2018? */
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 0x2426,
CHSEND
#define CHS_LATIN_1 (charsets+1)
CHS (LATIN_1, 96, A) /* Default G2, G3, GR */
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
CHSEND
CHS (UK, 94, A)
' ', '!', '"', 0xA3, '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 0x2426,
CHSEND
CHS (FINLAND, 94, 5)
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0xC4, 0xD6, 0xC5, 0xDC, '_',
0xE9, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xE4, 0xF6, 0xE5, 0xFC, 0x2426,
CHSEND
CHS (SWEDEN, 94, 7)
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
0xC9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0xC4, 0xD6, 0xC5, 0xDC, '_',
0xE9, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xE4, 0xF6, 0xE5, 0xFC, 0x2426,
CHSEND
CHS (NORWAY, 94, `) /* LA120: 5E:DC 60:E4 7E:FC; VT510: 5E:5E 60:60 7E:7E */
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'#', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0xC6, 0xD8, 0xC5, 0xDC, '_',
0xE4, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xE6, 0xF8, 0xE5, 0xFC, 0x2426,
CHSEND
CHS (GERMANY, 94, K)
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
0xA7, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0xC4, 0xD6, 0xDC, '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xE4, 0xF6, 0xFC, 0xDF, 0x2426,
CHSEND
CHS (ITALY, 94, Y)
' ', '!', '"', 0xA3, '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
0xA7, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0xB0, 0xE7, 0xE9, '^', '_',
0xF9, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xE0, 0xF2, 0xE8, 0xEC, 0x2426,
CHSEND
CHS (FRANCE, 94, R)
' ', '!', '"', 0xA3, '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
0xE0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0xB0, 0xE7, 0xA7, '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xE9, 0xF9, 0xE8, 0xA8, 0x2426,
CHSEND
CHS (SPANISH, 94, Z)
' ', '!', '"', 0xA3, '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
0xA7, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0xA1, 0xD1, 0xBF, '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xB0, 0xF1, 0xE7, '~', 0x2426,
CHSEND
CHS (CANADA-FR, 94, 9)
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
0xE0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0xE2, 0xE7, 0xEA, 0xEE, '_',
0xF4, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xE9, 0xF9, 0xE8, 0xFB, 0x2426,
CHSEND
CHS (DUTCH, 94, 4)
' ', '!', '"', 0xA3, '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
0xBE, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0x133, 0xBD, '|', '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xA8, 0x17F, 0xBC, 0xB4, 0x2426,
CHSEND
CHS (SWISS, 94, =)
' ', '!', '"', 0xF9, '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
0xE0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0xE9, 0xE7, 0xEA, 0xEE, 0xE8,
0xF4, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xE4, 0xF6, 0xFC, 0xFB, 0x2426,
CHSEND
CHSI (PORTUGAL, 94, %, 6)
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0xC3, 0xC7, 0xD5, '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xE3, 0xE7, 0xF5, '~', 0x2426,
CHSEND
CHS (SCS, 94, z)
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
0x17D, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0x160, 0x110, 0x106, 0x106, '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0x161, 0x111, 0x107, 0x10D, 0x2426,
CHSEND
CHS (LINEDRAW, 94, 0) /* These are not exact */
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', ' ',
0x2666, 0x25A9, 0x2409, 0x240C, 0x240D, 0x240A, 0xB0, 0xB1, 0x2424, 0x240B, 0x2518, 0x2510, 0x250C, 0x2514, 0x253C, 0x23BA,
0x23BB, 0x23BC, 0x23BD, 0x2500, 0x251C, 0x2524, 0x2534, 0x252C, 0x2502, 0x2264, 0x2265, 0x3C0, 0x2260, 0xA3, 0xB7, 0x2426,
CHSEND
CHSI (DEC_SUPP, 94, %, 5)
0x2426, 0xA1, 0xA2, 0xA3, 0x2426, 0xA5, 0x2426, 0xA7, 0xA4, 0xA9, 0xAA, 0xAB, 0x2426, 0x2426, 0x2426, 0x2426,
0xB0, 0xB1, 0xB2, 0xB3, 0x2426, 0xB5, 0xB6, 0xB7, 0x2426, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0x2426, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0x2426, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0x152, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0x178, 0x2426, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0x2426, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x153, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFF, 0x2426, 0x2426,
CHSEND
CHS (LATIN_2, 96, B)
0xA0, 0x104, 0x306, 0x141, 0xA4, 0x13D, 0x15A, 0xA7, 0x308, 0x160, 0x15E, 0x164, 0x179, 0xAD, 0x17D, 0x17B,
0x30A, 0x105, 0x328, 0x142, 0x301, 0x13E, 0x15B, 0x30C, 0x327, 0x161, 0x15F, 0x165, 0x17A, 0x30B, 0x17E, 0x17C,
0x154, 0xC1, 0xC2, 0x102, 0xC4, 0x139, 0x106, 0xC7, 0x10C, 0xC9, 0x118, 0xCB, 0x11A, 0xCD, 0xCE, 0x10E,
0x110, 0x143, 0x147, 0xD3, 0xD4, 0x150, 0xD6, 0xD7, 0x158, 0x16E, 0xDA, 0x170, 0xDC, 0xDD, 0x162, 0xDF,
0x155, 0xE1, 0xE2, 0x103, 0xE4, 0x13A, 0x107, 0xE7, 0x10D, 0xE9, 0x119, 0xEB, 0x11B, 0xED, 0xEE, 0x10F,
0x111, 0x144, 0x148, 0xF3, 0xF4, 0x151, 0xF6, 0xF7, 0x159, 0x16F, 0xFA, 0x171, 0xFC, 0xFD, 0x163, 0x307,
CHSEND
CHS (LATIN_CYRILLIC, 96, L)
0x0A0, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407, 0x408, 0x409, 0x40A, 0x40B, 0x40C, 0x0AD, 0x40E, 0x40F,
0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F,
0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F,
0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F,
0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F,
0x2116, 0x451, 0x452, 0x453, 0x454, 0x455, 0x456, 0x457, 0x458, 0x459, 0x45A, 0x45B, 0x45C, 0x0a7, 0x45E, 0x45F,
CHSEND
CHS (LATIN_GREEK, 96, F)
0x0A0, 0x02018, 0x02019, 0x0A3, 0x02426, 0x02426, 0x0A6, 0x0A7, 0x0A8, 0x0A9, 0x2426, 0x0AB, 0x0AC, 0x0AD, 0x2426, 0x2015,
0x0B0, 0x0B1, 0x0B2, 0x0B3, 0x384, 0x385, 0x386, 0x0B7, 0x388, 0x389, 0x38A, 0x0BB, 0x38C, 0x0BD, 0x38E, 0x38F,
0x390, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39A, 0x39B, 0x39C, 0x39D, 0x39E, 0x39F,
0x3A0, 0x3A1, 0x2426, 0x3A3, 0x3A4, 0x3A5, 0x3A6, 0x3A7, 0x3A8, 0x3A9, 0x3AA, 0x3AB, 0x3AC, 0x3AD, 0x3AE, 0x3AF,
0x3B0, 0x3B1, 0x3B2, 0x3B3, 0x3B4, 0x3B5, 0x3B6, 0x3B7, 0x3B8, 0x3B9, 0x3BA, 0x3BB, 0x3BC, 0x3BD, 0x3BE, 0x3BF,
0x3C0, 0x3C1, 0x3C2, 0x3C3, 0x3C4, 0x3C5, 0x3C6, 0x3C7, 0x3C8, 0x3C9, 0x3CA, 0x3CB, 0x3CC, 0x3CD, 0x3CE, 0x2426,
CHSEND
CHS (LATIN_HEBREW, 96, H)
0x0A0, 0x2426, 0x0A2, 0x0A3, 0x0A4, 0x0A5, 0x0A6, 0x0A7, 0x0A8, 0x0A9, 0x0D7, 0x0AB, 0x0AC, 0x0AD, 0x0AE, 0x0AF,
0x0B0, 0x0B1, 0x0B2, 0x0B3, 0x0B4, 0x0B5, 0x0B6, 0x0B7, 0x0B8, 0x0B9, 0x0F7, 0x0BB, 0x0BC, 0x0BD, 0x0BE, 0x2426,
0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426,
0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2017,
0x5D0, 0x5D1, 0x5D2, 0x5D3, 0x5D4, 0x5D5, 0x5D6, 0x5D7, 0x5D8, 0x5D9, 0x5DA, 0x5DB, 0x5DC, 0x5DD, 0x5DE, 0x5DF,
0x5E0, 0x5E1, 0x5E2, 0x5E3, 0x5E4, 0x5E5, 0x5E6, 0x5E7, 0x5E8, 0x5E9, 0x5EA, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426,
CHSEND
CHS (LATIN_5, 96, M)
0x0A0, 0x0A1, 0x0A2, 0x0A3, 0x0A4, 0x0A5, 0x0A6, 0x0A7, 0x0A8, 0x0A9, 0x0AA, 0x0AB, 0x0AC, 0x0AD, 0x0AE, 0x0AF,
0x0B0, 0x0B1, 0x0B2, 0x0B3, 0x0B4, 0x0B5, 0x0B6, 0x0B7, 0x0B8, 0x0B9, 0x0BA, 0x0BB, 0x0BC, 0x0BD, 0x0BE, 0x0BF,
0x0C0, 0x0C1, 0x0C2, 0x0C3, 0x0C4, 0x0C5, 0x0C6, 0x0C7, 0x0C8, 0x0C9, 0x0CA, 0x0CB, 0x0CC, 0x0CD, 0x0CE, 0x0CF,
0x11E, 0x0D1, 0x0D2, 0x0D3, 0x0D4, 0x0D5, 0x0D6, 0x0D7, 0x0D8, 0x0D9, 0x0DA, 0x0DB, 0x0D9, 0x130, 0x15E, 0x0DF,
0x0E0, 0x0E1, 0x0E2, 0x0E3, 0x0E4, 0x0E5, 0x0E6, 0x0E7, 0x0E8, 0x0E9, 0x0EA, 0x0EB, 0x0EC, 0x0ED, 0x0EE, 0x0EF,
0x11F, 0x0F1, 0x0F2, 0x0F3, 0x0F4, 0x0F5, 0x0F6, 0x0F7, 0x0F8, 0x0F9, 0x0FA, 0x0FB, 0x0FC, 0x131, 0x15F, 0x0FF,
CHSEND
CHSI (KOI-8_CYRILLIC, 94, &, 4)
0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426,
0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426,
0x44E, 0x430, 0x431, 0x446, 0x434, 0x435, 0x444, 0x433, 0x445, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E,
0x43F, 0x44F, 0x440, 0x441, 0x442, 0x443, 0x436, 0x432, 0x44C, 0x44B, 0x437, 0x448, 0x44D, 0x449, 0x447, 0x44A,
0x42E, 0x410, 0x411, 0x426, 0x414, 0x415, 0x424, 0x413, 0x425, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E,
0x41F, 0x42F, 0x420, 0x421, 0x422, 0x423, 0x416, 0x412, 0x42C, 0x42B, 0x417, 0x428, 0x42D, 0x429, 0x427, 0x2426,
CHSEND
CHSI (KOI-7_CYRILLIC, 94, &, 5)
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
0x42E, 0x410, 0x411, 0x426, 0x414, 0x415, 0x424, 0x413, 0x425, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E,
0x41F, 0x42F, 0x420, 0x421, 0x422, 0x423, 0x416, 0x412, 0x42C, 0x42B, 0x417, 0x428, 0x42D, 0x429, 0x427, 0x2426,
CHSEND
CHSIq (DEC_GREEK_SUP, 94, "\"", ?)
0x2426, 0x0A1, 0x0A2, 0x0A3, 0x2426, 0x0A5, 0x2426, 0x0A7, 0x0A4, 0x0A9, 0x0AA, 0x0AB, 0x2426, 0x2426, 0x2426, 0x2426,
0x0B0, 0x0B1, 0x0B2, 0x0B3, 0x2426, 0x0B5, 0x0B6, 0x0B7, 0x2426, 0x0B9, 0x0BA, 0x0BB, 0x0BC, 0x0BD, 0x2426, 0x0BF,
0x3CA, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39A, 0x39B, 0x39C, 0x39D, 0x39E, 0x39F,
0x2426, 0x3A0, 0x3A1, 0x3A3, 0x3A4, 0x3A5, 0x3A6, 0x3A7, 0x3A8, 0x3A9, 0x3AC, 0x3AD, 0x3AE, 0x3AF, 0x2426, 0x3CC,
0x3CB, 0x3B1, 0x3B2, 0x3B3, 0x3B4, 0x3B5, 0x3B6, 0x3B7, 0x3B8, 0x3B9, 0x3BA, 0x3BB, 0x3BC, 0x3BD, 0x3BE, 0x3BF,
0x2426, 0x3C0, 0x3C1, 0x3C3, 0x3C4, 0x3C5, 0x3C6, 0x3C7, 0x3C8, 0x3C9, 0x3C2, 0x3CD, 0x3CE, 0x384, 0x2426, 0x2426,
CHSEND
CHSIq (DEC_GREEK, 94, "\"", >)
0x2426, '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
0x3B9, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39A, 0x39B, 0x39C, 0x39D, 0x39E, 0x39F,
0x2426, 0x3A0, 0x3A1, 0x3A3, 0x3A4, 0x3A5, 0x3A6, 0x3A7, 0x3A8, 0x3A9, 0x3AC, 0x3AD, 0x3AE, 0x3AF, 0x2426, 0x3CC,
0x3CB, 0x3B1, 0x3B2, 0x3B3, 0x3B4, 0x3B5, 0x3B6, 0x3B7, 0x3B8, 0x3B9, 0x3BA, 0x3BB, 0x3BC, 0x3BD, 0x3BE, 0x3BF,
0x2426, 0x3C0, 0x3C1, 0x3C3, 0x3C4, 0x3C5, 0x3C6, 0x3C7, 0x3C8, 0x3C9, 0x3C2, 0x3CD, 0x3CE, 0x384, 0x2426, 0x2426,
CHSEND
CHSIq (DEC_HEBREW, 94, "\"", 4)
0x2426, 0x0A1, 0x0A2, 0x0A3, 0x2426, 0x0A5, 0x2426, 0x0A7, 0x0A8, 0x0A9, 0x0AA, 0x0AB, 0x2426, 0x2426, 0x2426, 0x2426,
0x0B0, 0x0B1, 0x0B2, 0x0B3, 0x2426, 0x0B5, 0x0B6, 0x0B7, 0x2426, 0x0B9, 0x0BA, 0x0BB, 0x0BC, 0x0BD, 0x2426, 0x0BF,
0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426,
0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426,
0x5D0, 0x5D1, 0x5D2, 0x5D3, 0x5D4, 0x5D5, 0x5D6, 0x5D7, 0x5D8, 0x5D9, 0x5DA, 0x5DB, 0x5DC, 0x5DD, 0x5DE, 0x5DF,
0x5E0, 0x5E1, 0x5E2, 0x5E3, 0x5E4, 0x5E5, 0x5E6, 0x5E7, 0x5E8, 0x5E9, 0x5EA, 0x2426, 0x2426, 0x2426, 0x2426, 0x2426,
CHSEND
CHSI (DEC_HEBREW7BIT, 94, "%", =)
0x2426, '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
0x5D0, 0x5D1, 0x5D2, 0x5D3, 0x5D4, 0x5D5, 0x5D6, 0x5D7, 0x5D8, 0x5D9, 0x5DA, 0x5DB, 0x5DC, 0x5DD, 0x5DE, 0x5DF,
0x5E0, 0x5E1, 0x5E2, 0x5E3, 0x5E4, 0x5E5, 0x5E6, 0x5E7, 0x5E8, 0x5E9, 0x5EA, '{', '|', '}', '~', 0x2426,
CHSEND
CHSI (DEC_TURKISH, 94, "%", 0)
0x2426, 0x0A1, 0x0A2, 0x0A3, 0x2426, 0x0A5, 0x2426, 0x0A7, 0x0A4, 0x0A9, 0x0AA, 0x0AB, 0x2426, 0x2426, 0x130, 0x2426,
0x0B0, 0x0B1, 0x0B2, 0x0B3, 0x2426, 0x0B5, 0x0B6, 0x0B7, 0x2426, 0x0B9, 0x0BA, 0x0BB, 0x0BC, 0x0BD, 0x131, 0x0BF,
0x0C0, 0x0C1, 0x0C2, 0x0C3, 0x0C4, 0x0C5, 0x0C6, 0x0C7, 0x0C8, 0x0C9, 0x0CA, 0x0CB, 0x0CC, 0x0CD, 0x0CE, 0x0CF,
0x11E, 0x0D1, 0x0D2, 0x0D3, 0x0D4, 0x0D5, 0x0D6, 0x152, 0x0D8, 0x0D9, 0x0DA, 0x0DB, 0x0DC, 0x178, 0x15E, 0x0DF,
0x0E0, 0x0E1, 0x0E2, 0x0E3, 0x0E4, 0x0E5, 0x0E6, 0x0E7, 0x0E8, 0x0E9, 0x0EA, 0x0EB, 0x0EC, 0x0ED, 0x0EE, 0x0EF,
0x11F, 0x0F1, 0x0F2, 0x0F3, 0x0F4, 0x0F5, 0x0F6, 0x153, 0x0F8, 0x0F9, 0x0FA, 0x0FB, 0x0FC, 0x0FF, 0x15F, 0x2426,
CHSEND
CHSI (DEC_TURKISH7BIT, 94, "%", 2)
0x2426, 0x131, '"', '#', '$', '%', 0x11F, '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
0x130, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0x15E, 0xD6, 0xC7, 0xDC, '_',
0x11E, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0x15F, 0xF6, 0xE7, 0xFC, 0x2426,
CHSEND
CHS (DEC_TCS, 94, >) /* DEC spec uses 2308-230B rather than 2502-23A8 */
0x2426, 0x23B7, 0x250C, 0x2500, 0x2320, 0x2321, 0x2502, 0x23A1, 0x23A3, 0x23A4, 0x23A6, 0x239B, 0x239D, 0x239E, 0x23A0, 0x23A8,
0x23AC, 0x23B2, 0x23B3, 0x2216, 0x2215, 0x231D, 0x131F, 0x232A, 0x2E2E, 0x2426, 0x2426, 0x2426, 0x2264, 0x2260, 0x2265, 0x222B,
0x2234, 0x221D, 0x221E, 0xF7, 0x2206, 0x2207, 0x03A6, 0x393, 0x223C, 0x2243, 0x398, 0xD7, 0x39B, 0x21D4, 0x21D2, 0x2261,
0x3A0, 0x3A8, 0x2426, 0x3A3, 0x2426, 0x2426, 0x221A, 0x3A9, 0x39E, 0x3A5, 0x2282, 0x2283, 0x2229, 0x222A, 0x2227, 0x2228,
0xAC, 0x3B1, 0x3B2, 0x3C7, 0x3B4, 0x3B5, 0x3C6, 0x3B3, 0x3B7, 0x3B9, 0x3B8, 0x3BA, 0x3BB, 0x2426, 0x3BD, 0x2202,
0x3C0, 0x3C8, 0x3C1, 0x3C3, 0x3C4, 0x2426, 0x192, 0x3C9, 0x3BE, 0x3C5, 0x3B6, 0x2190, 0x2191, 0x2192, 0x2193, 0x2426,
CHSEND
};
/* Translate Unicode to PDFDocEncoding
* These are the exceptions. 20-7E and A1 - FF are 1:1.
*/
static const struct {
unsigned short ucode;
short pdfcode;
} utran[] = {
#define T(uc,pc) {0x##uc, 0x##pc},
T (2D8,18)
T (2C7,19)
T (2C6,1A)
T (2D9,1B)
T (2DD,1C)
T (2DB,1D)
T (2DA,1E)
T (2DC,1F)
T (2022,80)
T (2020,81)
T (2021,82)
T (2026,83)
T (2014,84)
T (2013,85)
T (192,86)
T (2044,87)
T (2039,88)
T (203A,89)
T (2212,8A)
T (2030,8B)
T (201E,8C)
T (201C,8D)
T (201D,8E)
T (2018,8F)
T (2019,90)
T (201A,91)
T (2122,92)
T (FB01,93)
T (FB02,94)
T (141,95)
T (152,96)
T (160,97)
T (178,98)
T (17D,99)
T (131,9A)
T (142,9B)
T (153,9C)
T (161,9D)
T (17E,9E)
T (20AC,A0)
#undef T
};
/* SHA1: used for creating a document ID
*/
/* Requires: uint32_t, uint8_t, int_least16_t */
#define SHA1HashSize 20
/*
* This structure will hold context information for the SHA-1
* hashing operation
*/
typedef struct SHA1Context {
uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */
uint32_t Length_Low; /* Message length in bits */
uint32_t Length_High; /* Message length in bits */
/* Index into message block array */
int_least16_t Message_Block_Index;
uint8_t Message_Block[64]; /* 512-bit message blocks */
int Computed; /* Is the digest computed? */
int Corrupted; /* Is the message digest corrupted? */
} SHA1Context;
int SHA1Reset( SHA1Context *);
int SHA1Input( SHA1Context *,
const uint8_t *,
unsigned int);
int SHA1Result( SHA1Context *,
uint8_t Message_Digest[SHA1HashSize]);
/* *** End SHA1 *** */
#ifdef ERRDEBUG
static void errout (void ) {
int a = 0;
a = a;
return;
}
#endif
typedef long t_fpos; /* File position */
/* PDF is the context for all operations.
* Presented to the caller as a PDF_HANDLE, but
* intentionally opaque.
*
* SETP contains those parameters set (or settable) by the
* caller. These can be rolled to a new file.
*
* General principle is that there are no fixed sizes,
* no global state, and memory, once allocated is reused
* as much as possible. Dynamic structures grow until pdf_close().
*
* update pdf_free() with any new dynamic memory pointers.
*/
typedef struct {
double top; /* Top margin, in (offset of first bar) */
double bot; /* Bottom margin, in (space after last bar) */
double margin; /* Horizontal margin, in (tractor feed) */
double lno; /* Width of line number, in column */
double cpi; /* Note: LA120 had several fractional cpi */
unsigned int lpi;
double wid; /* Sheet width, in */
double len; /* Sheet length, in */
unsigned int cols; /* Print columns */
char *font; /* Name of text font */
char *nfont; /* Name of number font */
char *nbold; /* Name of label font */
unsigned int frequire; /* File requirements */
#define PDF_FILE_NEW (0)/* File must be empty */
#define PDF_FILE_APPEND (1)/* File can be appended (if PDF) */
#define PDF_FILE_REPLACE (2)/* Non-empty file's contents are replaced */
char *title; /* Document title string */
unsigned int tof; /* Top Of Form line, logical line 1 (e.g of CC tape) */
unsigned int formtype; /* Type of background/form */
char *formfile; /* File containing form image */
double barh; /* Height of form bar */
unsigned int lpp; /* Lines per page (requested) */
} SETP;
typedef struct {
char key[3]; /* Handle validator */
SETP p; /* User-settable parameters */
const CHARSET *gset[4]; /* Designated graphics sets */
const CHARSET *gl, *gr;
/* Below this point initialized to zero
* Be sure to update pdf_reopen for additions.
*/
const CHARSET *ssg;
int errnum; /* Last error */
FILE *pdf; /* Output file handle */
FILE *outf; /* Final output */
#ifdef _WIN32
char *tmpname; /* Temporary file name */
#endif
unsigned int escstate; /* Escape sequence parser */
#define ESC_IDLE (0)
#define ESC_ESCSEQ (1)
#define ESC_CSI (2)
#define ESC_CSIP (3)
#define ESC_CSIINT (4)
#define ESC_BADCSI (5)
#define ESC_BADESC (6)
#define ESC_BADSTR (7)
char escints[4]; /* Intermediate characters of sequence */
unsigned int escin; /* Number of intermediates */
char escprv; /* Private sequence (DEC uses ?) */
uint16_t escpars[16]; /* CSI parameters */
#define ESC_PDEFAULT ((uint16_t)(~0u))
#define ESC_POVERFLOW ((((uint32_t)ESC_PDEFAULT) +1) >> 1)
#define ESC_PMAX (ESC_POVERFLOW -1)
unsigned int escpn; /* Number of parameters */
char *formbuf; /* Graphics data for page */
size_t formsize; /* Buffer allocation */
size_t formlen; /* Length of form data */
#define FORMBUF &pdf->formbuf, &pdf->formsize, &pdf->formlen
unsigned int formobj; /* Form object number */
jmp_buf env;
#ifdef ERRDEBUG
#define ABORT(err) {errout();longjmp(pdf->env,(err));}
#define ABORTps(err) {errout();longjmp(ps->env,(err));}
#else
#define ABORT(err) longjmp (pdf->env, (err))
#define ABORTps(err) longjmp (ps->env, (err))
#endif
char oid[(SHA1HashSize*2) +1]; /* Original document id (when appending) */
char ctime[32]; /* Original doc creation time */
unsigned int prevpc; /* Page count from previous sessions */
char *trail; /* Trailer from previous sessions */
t_fpos anchorp; /* Anchor object location for previous session */
t_fpos anchorpp; /* Position to rewrite parentof previous session */
t_fpos checkpp; /* File position at checkpoint */
unsigned int aobj; /* Anchor object number */
unsigned int obj; /* Last object number assigned */
t_fpos xpos; /* Location of xref */
t_fpos *xref; /* Xref - file position of each object */
size_t xsize; /* Max objects in current xref allocation */
unsigned int flags;
#define PDF_ACTIVE 0x0001 /* Printing active (no more SETs) */
#define PDF_UPDATING 0x0002 /* Updating existing file (append) */
#define PDF_UNCOMPRESSED 0x0004 /* Always write uncompressed text objects */
#define PDF_INIT 0x0008 /* Initialized - metadata read if appending */
#define PDF_WRITTEN 0x0010 /* Headers written */
#define PDF_RESUMED 0x0020 /* Resumed from a checkpoint */
#define PDF_REOPENED 0x0040 /* Reopened (and thus must append) */
#define PDF_TMPFILE 0x0080 /* Using tmpfile for non-seekable output (e.g. stdout) */
unsigned int lpp; /* Lines per page */
short **lines; /* Data for each line */
unsigned int nlines; /* Number of lines allocated */
unsigned int *linesize; /* Allocation for each line */
unsigned int *linelen; /* Highest column written */
unsigned int page; /* Current page number */
unsigned int line; /* Current line number, 0 if nothing written */
SHA1Context sha1; /* Context for document ID hash */
unsigned int pbase; /* Object number of sessions page data */
unsigned int iobj; /* Doc information object number */
short *parsebuf; /* Buffer with input controls expanded */
size_t parsesize; /* Allocated size in shorts */
size_t parseused; /* Shorts used */
#define PARSEBUF &pdf->parsebuf, &pdf->parsesize, &pdf->parseused
char *pagebuf; /* Buffer containing rendered page data */
size_t pbsize; /* Allocated size of pagebuf */
size_t pbused; /* Bytes used in pagebuf */
#define PAGEBUF &pdf->pagebuf, &pdf->pbsize, &pdf->pbused
char *lzwbuf; /* Buffer containing compressed page */
size_t lzwsize; /* Allocated size */
size_t lzwused; /* Bytes used */
#define LZWBUF &pdf->lzwbuf, &pdf->lzwsize, &pdf->lzwused
} PDF;
#define QS(str) (str), (sizeof (str) -1)
/* Used to initialize new contexts.
* Note that any strings:
* Must be copied to malloc'ed memory if a user can pdf_set them
* Must be free'd in pdf_close
* There is exception-style error handling; be careful with allocating
* memory elsewhere.
*
* If you find it necessary to change this change the defaults in the
* SET table below.
*/
static const PDF defaults = {
{'P', 'D', 'F'},
{ /* SETP defaults */
1.00, /* top */
0.500, /* bot */
0.470, /* margin */
0.100, /* lno */
10, /* cpi */
6, /* lpi */
14.875, /* wid */
11.000, /* len */
132, /* cols */
"Courier", /* font */
"Times-Roman", /* nfont */
"Times-Bold", /* nbold */
PDF_FILE_NEW, /* frequire */
"Lineprinter data", /* title */
~0u, /* tof */
PDF_GREENBAR, /* formtype */
NULL, /* formfile */
0.500, /* barh */
0, /* lines per page (requested) */
},
{ CHS_ASCII, CHS_ASCII, CHS_LATIN_1, CHS_LATIN_1 }, /* G0-G3 */
CHS_ASCII, CHS_LATIN_1, /* GL, GR */
};
#define ps ((PDF *)pdf)
/* Points/inch */
#define PT (72)
/* PDF architectural constants */
#define PDF_C_LINELEN (255) /* Maximum line length (lines not in a stream object's data) */
#define PDF_C_HEADER "%PDF-1.4\n%\0302\0245\0302\0261\0303\0253\n"
/* Image characteristics */
typedef struct {
FILE *fh;
double width, height;
unsigned char *buf;
size_t bufsize;
char *imgbuf;
size_t ibsize, ibused;
char *filter;
char *filterpars;
char *colordesc;
size_t cdlength;
size_t ssize, sused;
} IMG;
/* Forward references */
static int dupstrs (PDF *pdf);
static int dupstr (PDF *pdf, char **ptr);
static int pdfreopen (PDF *pdf);
static int pdfset ( PDF *pdf, int arg, va_list ap);
static int checkfont (const char *newfont);
static void pdfinit (PDF *pdf);
static int checkupdate (PDF *pdf);
static void wrhdr (PDF *pdf);
static void wrpage (PDF *pdf);
static void setform (PDF *pdf);
static void barform (PDF *pdf);
static void imageform (PDF *pdf);
static int jpeg_image (PDF *pdf, IMG *img);
static int png_image (PDF *pdf, IMG *img);
static uint32_t crc32 (uint32_t initial, const uint8_t *string, uint32_t length);
static unsigned int addobj (PDF *pdf);
static unsigned int getref (PDF *pdf, char *buf, const char *name);
static unsigned int getint (PDF *pdf, char *buf, const char *name, const char **end);
static char *getstr (PDF *pdf, char *buf, const char *name);
static char *getstr (PDF *pdf, char *buf, const char *name);
static int parsestr (PDF *pdf, const char *string, size_t length, int initial);
static void designateChs (PDF *pdf, const int set, const uint16_t size,
const uint16_t nint, const char *ints, const char final );
static int pdfclose (PDF *pdf, int checkpoint);
static void pdf_free (PDF *pdf);
static void wrstmf (PDF *pdf, char **buf, size_t *len, size_t *used, const char *fmt, ...);
static void wrstm (PDF *pdf, char **buf, size_t *bufsize, size_t *used, char *string, size_t length);
static void wrstw (PDF *pdf, short **buf, size_t *bufsize, size_t *used, short *string, size_t length);
static t_fpos readobj (PDF *pdf, unsigned int obj, char **buf, size_t *len);
static void add2line (PDF *pdf, const short *text, size_t textlen);
static void circle (PDF *pdf, double x, double y, double r);
static int xstrcasecmp (const char *s1, const char *s2);
/* validate a PDF_HANDLE */
#define valarg(arg) { if (!(arg) || \
((PDF *)arg)->key[0] != 'P' || \
((PDF *)arg)->key[1] != 'D' || \
((PDF *)arg)->key[2] != 'F' || \
!((PDF *)arg)->pdf) { errno = E(BAD_HANDLE); return errno; } }
/* Coordinate transformations */
#define yp(y) ((pdf->p.len - (y)) * PT) /* In from top -> page coord */
#define xp(x) ((x) * PT) /* In to page coord */
#define CircleK (0.551784) /* Constant for approximating circles */
/* LZW encoding
*/
/* These constants are in the PDF spec and can not be changed.
*/
#define LZW_CLRCODE (256) /* Clear table code */
#define LZW_EODCODE (257) /* End of data code */
#define LZW_IDCODES (258) /* Number of identity codes */
#define LZW_MINBITS (9) /* Smallest (and initial) codesize */
#define LZW_MAXBITS (12) /* Largest permitted codesize */
#define LZW_DSIZE (1 << LZW_MAXBITS) /* Size of LZW directory */
typedef uint16_t t_lzwCode;
#define TREE_NULL ((t_lzwCode)~0u) /* Null code in directory tree */
typedef struct {
t_lzwCode prev;
t_lzwCode first;
t_lzwCode next;
short ch;
} t_lzwNode;
typedef struct {
FILE *fh; /* File handle for output */
uint8_t **outbuf; /* Buffer for output */
size_t *outsize; /* Size of output buffer */
size_t *outused; /* Data in output buffer */
uint32_t bitbuf; /* Bit packing buffer */
#if LZ_MAXBITS > 32
#error t_lzw.bitbuf is too small to hold LZ_MAXBITS, reduce or find a larger datatype
#endif
unsigned int nbits; /* Number of bits pending in buffer */
t_lzwNode dict[LZW_DSIZE]; /* Standard LZW prefix directory */
t_lzwCode assigned; /* Highest code assigned */
uint16_t codesize; /* Size of current code (bits) */
} t_lzw;
static void lzw_init(t_lzw *lzw, int mode, ...);
#define LZW_FILE (1)
#define LZW_BUFFER (2)
#define LZW_REINIT (3)
#define LZW_BUFALCQ (512)
static void lzw_encode (t_lzw *lzw, char *stream, size_t len);
static t_lzwCode lzw_add_str (t_lzw *lzw, t_lzwCode code, char c);
static t_lzwCode lzw_lookup_str (t_lzw *lzw, t_lzwCode code, char c);
static void lzw_writebits (t_lzw *lzw, unsigned int bits, unsigned int nbits);
static void lzw_flushbits (t_lzw *lzw);
/* *** End LZW *** */
static int encstm (PDF *pdf, char *stream, size_t len);
#if defined (PDF_MAIN) || defined (FONT_IMPORT)
/* This is a very simple driver for the API, and is not optimized.
*/
#define SET(_key, _code, _type, _def, _help) { "-" #_key, PDF_##_code, AT_##_type, #_def, #_help },
typedef struct {
const char *const keyword;
int arg;
int atype;
#define AT_STRING 1
#define AT_NUMBER 2
#define AT_INTEGER 3
const char *const def;
const char *const help;
} ARG;
static const ARG argtable [] = {
SET (bar, BAR_HEIGHT, NUMBER, 0.500in, (Specifies the height of the bar on forms.))
SET (bottom, BOTTOM_MARGIN, NUMBER, 0.500in, (Specifies the height of the bottom margin in inches. Below this there is no bar.))
SET (columns, COLS, INTEGER, 132, (Specifies the number of columns to be printed. Used to center output))
SET (cpi, CPI, NUMBER, 10, (Specifies the characters per inch (horizontal pitch). Fractional pitch is supported.))
SET (font, TEXT_FONT, STRING, Courier, (Specifies the name of the font to use for rendering the input data. Accepted are:%F))
SET (form, FORM_TYPE, STRING, greenbar, (Specifies the form background to be applied. One of:%fPlain is white page.))
SET (image, FORM_IMAGE, STRING, <none>, (Specifies a .jpg or .png image to be used as the form background\nIt will be scaled to fill the area within the margins.\nIt is rendered over the form; for just the image, use -form Plain.))
SET (length, PAGE_LENGTH, NUMBER, 11.000in, (Specifies the length of the page in inches, inclusive of all margins. Calculated automatically if -lpp is used.))
SET (lfont, LABEL_FONT, STRING, Times-Bold, (Specifies the name of the font used to render labels on the form))
SET (lno, LNO_WIDTH, NUMBER, 0.100in, (Specifies the width of the line number column on the form; 0 to omit cols.))
SET (lpi, LPI, INTEGER, 6, (Specifies the lines per inch (vertical pitch): 6 or 8 are supported.))
SET (lpp, LPP, INTEGER, 66, (Specifies the page length in lines. If used, takes precedence over length.))
SET (nfont, LNO_FONT, STRING, Times-Roman, (Specifies the name of the font used to render the numbers on the form))
SET (require, FILE_REQUIRE, STRING, new, (Specifies how to treat the output file. \nNEW will create the file, or if it exists, the file must be empty.\nAPPEND will create the file, or if it exists and is in PDF fomat, data will be appended.\nREPLACE will completely replace the contents of an existing file.))
SET (side, SIDE_MARGIN, NUMBER, 0.470, (Specifies the width of the tractor feed margin on each side of the page.))
SET (title, TITLE, STRING, ("Lineprinter data"),
(Specifies the title embedded in the PDF document))
SET (tof, TOF_OFFSET, INTEGER, (topmargin (6 lines at 6LPI, 8 at 8LPI)),
(Specifies the offset of the logical top of form from the top of page.\nThis is the line on to which <FF> advances, similar to the offset that\noccurs when an operator positions a form with respect to a carriage))
SET (top, TOP_MARGIN, NUMBER, 1.000in, (Specifies the height of the top margin in inches -- above first bar.))
SET (width, PAGE_WIDTH, NUMBER, 14.875in, (Specifies the width of the page in inches, inclusive of all margins))
};
static void do_file (PDF_HANDLE pdf, FILE *fh, const char *filename);
static int usage (const ARG *argtable, size_t nargs);
static void print_hlplist (FILE *file, const char *const *list, int adjcase);
int main (int argc, char **argv, char **env) {
PDF_HANDLE pdf;
int i, of;
int r;
char *infile = NULL, *outfile = NULL;
for (i = 1; i < argc; i++) {
if (!strcmp (argv[i], "--")) {
i++;
break;
}
if (!strcmp (argv[i], "--help") || !strcmp (argv[i], "-h")) {
exit (usage(argtable, DIM(argtable)));
}
if (argv[i][0] == '-') {
i++;
continue;
}
break;
}
of = 0;
if (i < argc) {
of = argc -1;
if (strcmp (argv[of], "-")) {
outfile = argv[of];
}
}
if (!outfile) {
outfile = "-";
}
pdf = pdf_open (outfile);
if (!pdf) {
pdf_perror (NULL, outfile);
exit (2);
}
for (i = 1; i < argc; i++) {
const char *sw = argv[i];
size_t k;
if (!strcmp (sw, "--")) {
i++;
break;
}
if (sw[0] != '-') {
break;
}
if (!argv[++i]) {
fprintf (stderr, "? %s requires an argument\n", argv[i-1]);
exit (3);
}
for (k = 0; k < DIM (argtable); k++) {
if (!strcmp (sw, argtable[k].keyword) ) {
double arg;
char *ep;
long iarg;
switch (argtable[k].atype) {
case AT_STRING:
r = pdf_set (pdf, argtable[k].arg, argv[i]);
break;
case AT_INTEGER:
iarg = strtol (argv[i], &ep, 10);
if (!*argv[i] ||*ep || ep == argv[i]) {
fprintf (stderr, "? not an integer for %s value: %s\n",
argtable[k].keyword, ep);
exit (3);
}
arg = (double) iarg;
r = pdf_set (pdf, argtable[k].arg, arg);
break;
case AT_NUMBER:
if (!*argv[i]) {
fprintf (stderr, "?Missing value for %s\n", argtable[k].keyword);
exit (3);
}
arg = strtod (argv[i], &ep);
if (*ep) {
if (!strcmp (ep, "cm")) {
arg /= 2.54;
} else {
if (!strcmp (ep, "mm")) {
arg /= 25.4;
} else if (strcmp (ep, "in")) {
fprintf (stderr, "?Unknown qualifier for %s value: %s\n",
argtable[k].keyword, ep);
exit (3);
}
}
}
r = pdf_set (pdf, argtable[k].arg, arg);
break;
default:
exit (3);
}
if (r != PDF_OK) {
pdf_perror (pdf, argv[i]);
exit (3);
}
break;
}
}
if (k < DIM (argtable)) {
continue;
}
fprintf (stderr, "Unknown switch %s, --help for usage\n", sw);
exit (3);
}
/* And after all that: */
if (i >= of ) {
do_file (pdf, stdin, "<stdin>");
} else {
while (i < of) {