summaryrefslogtreecommitdiff
path: root/pcl/pcl/pctext.c
blob: 8697938ab541238f8d329b8139f2d2a923d30f4b (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
/* Copyright (C) 2001-2021 Artifex Software, Inc.
   All Rights Reserved.

   This software is provided AS-IS with no warranty, either express or
   implied.

   This software is distributed under license and may not be copied,
   modified or distributed except as expressly authorized under the terms
   of the license contained in the file LICENSE in this distribution.

   Refer to licensing information at http://www.artifex.com or contact
   Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
   CA 94945, U.S.A., +1(415)492-9861, for further information.
*/


/* pctext.c -  PCL5 text printing commands */

#include "math_.h"
#include "gx.h"
#include "gsimage.h"
#include "plvalue.h"
#include "plvocab.h"
#include "pcommand.h"
#include "pcstate.h"
#include "pcdraw.h"
#include "pcfont.h"
#include "pcursor.h"
#include "pcpage.h"
#include "pcfrgrnd.h"
#include "gdebug.h"
#include "gscoord.h"
#include "gsline.h"
#include "gspaint.h"
#include "gspath.h"
#include "gspath2.h"
#include "gsrop.h"
#include "gsstate.h"
#include "gxchar.h"
#include "gxfont.h"             /* for setting next_char proc */
#include "gxstate.h"

#include "gxdevsop.h"       /* For special ops */
#include "gsdevice.h"       /* for gs_currentdevice */

/* pseudo-"dots" (actually 1/300" units) used in underline only */
#define dots(n)     ((float)(7200 / 300 * n))

/*
 * Install a font in the graphic state.
 */
static void
set_gs_font(pcl_state_t * pcs)
{
    gs_font *pfont = (gs_font *) pcs->font->pfont;

    gs_setfont(pcs->pgs, pfont);
    /* font scaling is reflected directly in the ctm */
    pfont->FontMatrix = pfont->orig_FontMatrix;
}

bool
pcl_downloaded_and_bound(const pl_font_t * plfont)
{
    return (plfont->storage != pcds_internal && pl_font_is_bound(plfont));
}

/*
 * Check if a character code is considered "printable" by given symbol set.
 */
bool
char_is_printable(const pl_font_t *font, const pl_symbol_map_t *map, gs_char chr, bool is_stick, bool literal)
{
    bool printable = false;

    if (literal) {              /* transparent data */
        printable = true;
    } else {
        if (is_stick) {
            printable = (chr >= ' ') && (chr <= 0xff);
        } else {
            int map_type = 0;
            if (map == 0 || pcl_downloaded_and_bound(font)) {
                /* PCL TRM 11-18 */
                if (font)
                {
                    map_type = font->font_type;
                }
            } else {
                /* PCL TRM 10-7
                 * symbol map type overrides, font map type
                 */
                map_type = map->type;
            }

            /* We do not treat map type as defined in the
            specification. Instead the default is to use the behavior we have
            observed on several HP devices: Map type 0 is treated as map type
            1. */
            if (map_type == 0) {
                map_type = 1;
            }

            if (map_type == 1) {
                chr &= 0x7f;
                printable = (chr >= ' ');   /* 0-31 and 128-159 are not printable */
            } else if (map_type >= 2) {
                /* 2 is correct but will force all types above 2 here */
                if ((chr == 0) || (chr == '\033') ||
                    ((chr >= '\007') && (chr <= '\017')))
                    printable = false;
                else
                    printable = true;
            }
        }
    }
    return printable;
}

static bool
substituting_allowed(pcl_state_t * pcs, gs_char mapped_chr)
{
    gs_char remapped_chr;       /* NB wrong type */

    if (
           /* msl not yet supported. */
           (pcs->map && pcs->map->format == 1) ||
           /* by experiment HP does not support substitution with bitmap fonts */
           (pcs->font->scaling_technology == plfst_bitmap) ||
           /* the font must be downloaded */
           (!(pcs->font->storage & pcds_downloaded)))
        return false;

    /* mapped chr is something of a misnomer, if the font is bound and
       downloaded it has been identity mappped. */

    remapped_chr = pl_map_symbol(pcs->map, mapped_chr, false,   /* storage not internal */
                                 false, /* unicode not msl */
                                 pcs->memory);

    /* now we can assume the characters are unicode */
    if (
           /* arrows */
           ((remapped_chr >= 0x2190) && (remapped_chr <= 0x21FF)) ||
           /* coptic */
           ((remapped_chr >= 0x0370) && (remapped_chr <= 0x03FF)) ||
           /* math operators */
           ((remapped_chr >= 0x2200) && (remapped_chr <= 0x22FF)) ||
           /* box drawing characters */
           ((remapped_chr >= 0x2500) && (remapped_chr <= 0x257F)) ||
           /* block elements (contiguous with box drawing) */
           ((remapped_chr >= 0x2580) && (remapped_chr <= 0x259F)) ||
           /* Geometric shapes (contiguos with block elements) */
           ((remapped_chr >= 0x25A0) && (remapped_chr <= 0x25FF)) ||
           /* miscellaneous symbols */
           ((remapped_chr >= 0x2600) && (remapped_chr <= 0x26FF)) ||
           /* miscellaneous technical */
           ((remapped_chr >= 0x2300) && (remapped_chr <= 0x23FF)) ||
           /* general punctuation */
           ((remapped_chr >= 0x2000) && (remapped_chr <= 0x206F)) ||
           /* vertical line,  less than, greater than, low line, or micro sign character,  */
           ((remapped_chr == 0x007C) || (remapped_chr == 0x003C) ||
            (remapped_chr == 0x003E) || (remapped_chr == 0x005F) ||
            (remapped_chr == 0x00B5))
        )
        return true;
    return false;
}

/*
 * Retrieve the next character identifier from a string.
 *
 * Both the string pointer and the length are modified.
 *
 * The final operand is true if the text was provided via the literal
 * (transparent) text command: ESC & p <nbytes> X. This distinction is
 * important for characters that are not considered printable by the
 * current symbol set. Normally, such characters are ignored. But if they
 * resulted from the literal (transparent) text command, they are handled as
 * spaces. Characters that are mapped by the symbol set but are not in a font
 * are always dealt with as space characters.
 *
 * The special handling provided for the character code 32 below is not,
 * in fact, correct. PCL fonts may map non-space characters to code 32, and
 * if this is done no special handling is provided for this code; in PCL,
 * a space character is a character not present in the font. Unfortunately,
 * some of the resident fonts used have explicit space characters, and to
 * handle the hmi properly when these fonts are used, this code must handle
 * fonts that have actual characters at code 32 improperly.
 *
 * Returns 0 on success, 2 if the string is exhausted. Note that it is not an
 * error for the string to end in the middle of a 2-byte sequence.
 */
static int
get_next_char(pcl_state_t * pcs,
              const byte ** ppb,
              uint * plen,
              gs_char * pchr,
              gs_char * porig_char,
              bool * pis_space,
              bool * pprint_undefined,
              bool literal, gs_point * pwidth, bool * unstyled_substitution)
{
    const byte *pb = *ppb;
    int len = *plen;
    pl_font_t *plfont = pcs->font;
    bool substituting = false;
    int code = 0;
    gs_char chr;
    gs_char mapped_chr;         /* NB wrong type */
    bool db;

    if (len <= 0)
        return 2;
    *pis_space = false;
    *unstyled_substitution = false;
    chr = pcl_char_get_char(pcs->text_parsing_method, &pb, len);
    /* invalid char: pb has not been incremented */
    if (pb == *ppb) {
        pb++;
    }
    len -= (pb - *ppb);
    *ppb = pb;
    *plen = len;
    *porig_char = chr;
    /* check if the code is considered "printable" in the current symbol set */
    if (!char_is_printable(pcs->font, pcs->map, chr, false, literal)) {
        *pis_space = literal;
        *pchr = 0xffff;
        return 0;
    }

    /* map the symbol.  If the font is downloaded and bound there is
       no symbol set.  We do use the symbol set for internal bound
       fonts. NB WE AREN'T HAPPY WITH THIS LABEL & GOTO. */
  r:db = pcl_downloaded_and_bound(plfont);
    mapped_chr = pl_map_symbol((db ? NULL : pcs->map), chr,
                               plfont->storage == pcds_internal,
                               plfont->font_type == plft_MSL,
                               pcs->memory);
    *pchr = mapped_chr;
    if (mapped_chr == 0xffff) {
        if ((plfont->storage != pcds_internal) &&
            (pl_font_char_width
             (plfont, (void *)(pcs->pgs), mapped_chr, pwidth) == 0)) {
            *pprint_undefined = true;
            return 0;
        }
        *pis_space = true;
        return 0;
    }

    /* NB we assume all internal fonts use unicode */
    if (plfont->storage == pcds_internal && mapped_chr == 0x0020
        && !substituting) {
        *pis_space = true;
        *pchr = 0xffff;
        return 0;
    }

    /* For internal fonts we simulate the font missing the space
       character here.  The character complement is checked to see if
       the the font is Western Latin and Unicode 0020.  We could
       also check for an MSL space here but we know the internal
       reportoire will never contain an MSL font that requires
       simulating a missing space character. */
    if (plfont->storage == pcds_internal &&
        chr == 0x0020 &&
        plfont->character_complement[5] == 0x3f &&
        pl_complement_to_vocab(plfont->character_complement) ==
        plgv_Unicode) {
        *pis_space = true;
        *pchr = 0xffff;
        return 0;
    }

    /* check if the character is in the font and get the character
       width at the same time */
    if (*pis_space == false)
        if (pl_font_char_width(plfont, (void *)(pcs->pgs), mapped_chr, pwidth)
            == 0)
            return 0;

    /*
     * Try an unstyled substitution
     */
    if (!substituting && substituting_allowed(pcs, db ? mapped_chr : chr)) {
        pcl_decache_font(pcs, -1, true);
        code = pcl_recompute_font(pcs, true);
        if (code < 0)
            return code;
        substituting = true;
        *unstyled_substitution = true;
        plfont = pcs->font;
        set_gs_font(pcs);
        goto r;
    }

    /* we substituted and didn't find the character in the font.
       Restore the old font */
    if (substituting) {
        pcl_decache_font(pcs, -1, true);
        code = pcl_recompute_font(pcs, false);
        if (code < 0)
            return code;
        set_gs_font(pcs);
    }

    /*
     * If we get to this point deem the character an undefined
     * character - a space in pcl.
     */
    *pis_space = true;
    *pchr = 0xffff;
    return 0;
}
/*
 * return length of multibyte sequence from starting byte
 * replacement of macro pcl_char_is_2_byte, UTF-8 sequence length may be up to 6 bytes
 *
 * Returns 0 for invalid byte, byte length > 0 of multibyte character sequence
 */
int
pcl_char_bytelen(byte ch, pcl_text_parsing_method_t tpm)
{

    int bytelen = 1;

    switch (tpm) {
        default:
            /* byte length defaults to 1 */
            break;

        case tpm_21_DBCS7:
            /* 0x21-0xff are double-byte */
            bytelen = (ch < 0x21) ? 1 : 2;
            break;

        case tpm_31_sjis:
            /* 0x81-0x9f, 0xe0-0xfc are double-byte */
            bytelen = (ch < 0x81 || (ch > 0x9f && ch < 0xe0)
                       || ch > 0xfc) ? 1 : 2;
            break;

        case tpm_38_DBCS8:
            /* 0x80-0xff are double-byte */
            bytelen = (ch < 0x80) ? 1 : 2;
            break;
        case tpm_83_utf8:
        case tpm_1008_utf8:
            if (ch < 0x80) {
                /* 0xxxxxxx */
                bytelen = 1;
                break;
            }
            if (ch < 0xc2) {
                bytelen = 0;    /* illegal */
                break;
            }
            if (ch < 0xe0) {
                /* 110XXXXx 10xxxxxx */
                bytelen = 2;
                break;
            }
            if (ch < 0xf0) {
                /* 1110XXXX 10Xxxxxx 10xxxxxx */
                bytelen = 3;
                break;
            }
            if (ch < 0xf8) {
                /* 11110XXX 10XXxxxx 10xxxxxx 10xxxxxx */
                bytelen = 4;
                break;
            }
            if (ch < 0xfc) {
                /* 111110XX 10XXxxxx 10xxxxxx 10xxxxxx 10xxxxxx */
                bytelen = 5;
                break;
            }
            if (ch < 0xfe) {
                /* 1111110X 10XXxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */
                bytelen = 6;
                break;
            }
            bytelen = 0;        /* illegal */
            break;
    }
    return bytelen;
}
/*
 * convert multibyte sequence to unicode (16-bit)
 * Both the string pointer and the length are modified.
 *
 * Returns 0 for invalid byte, byte length > 0 of multibyte character sequence
 */
gs_char
pcl_char_get_char(pcl_text_parsing_method_t tpm, const byte ** psrc,
                  int src_len)
/* src_len minimum 1 */
{
    gs_char chr;
    const byte *src = *psrc;
    int bytelen = pcl_char_bytelen(src[0], tpm);

    if (bytelen == 0 || bytelen > src_len) {
        return INVALID_UC;
    }
    switch (tpm) {
        default:
            chr = src[0];
            break;

        case tpm_21_DBCS7:
            /* 0x21-0xff are double-byte */
            chr = (src[0] < 0x21) ? src[0] : (src[0] << 8 | src[1]);
            break;

        case tpm_31_sjis:
            /* 0x81-0x9f, 0xe0-0xfc are double-byte */
            chr = (src[0] < 0x81 || (src[0] > 0x9f && src[0] < 0xe0)
                   || src[0] > 0xfc) ? src[0] : (src[0] << 8 | src[1]);
            break;

        case tpm_38_DBCS8:
            /* 0x80-0xff are double-byte */
            chr = (src[0] < 0x80) ? src[0] : (src[0] << 8 | src[1]);
            break;
        case tpm_83_utf8:
        case tpm_1008_utf8:
            if (src[0] < 0x80) {
                /* 0xxxxxxx */
                chr = src[0];
                break;
            }
            if (src[0] < 0xc2) {
                chr = INVALID_UC;
                break;
            }
            if (src[0] < 0xe0) {
                /* 110XXXXx 10xxxxxx */
                chr = (src[0] & 0x1f);
                chr = (chr << 6) | (src[1] & 0x3f);
                break;
            }
            if (src[0] < 0xf0) {
                /* 1110XXXX 10Xxxxxx 10xxxxxx */
                chr = (src[0] & 0x0f);
                chr = (chr << 6) | (src[1] & 0x3f);
                chr = (chr << 6) | (src[2] & 0x3f);
                break;
            }
            if (src[0] < 0xf8) {
                /* 11110XXX 10XXxxxx 10xxxxxx 10xxxxxx */
                /* chr is 16 bit: overflow */
                chr = INVALID_UC;
                break;
            }
            if (src[0] < 0xfc) {
                /* 111110XX 10XXxxxx 10xxxxxx 10xxxxxx 10xxxxxx */
                /* chr is 16 bit: overflow */
                chr = INVALID_UC;
                break;
            }
            if (src[0] < 0xfe) {
                /* 1111110X 10XXxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */
                /* chr is 16 bit: overflow */
                chr = INVALID_UC;
                break;
            }
            chr = INVALID_UC;
            break;
    }
    *psrc += bytelen;
    return chr;
}

/*
 * Draw the foreground of a character. For transparent text this is the only
 * part that must be drawn.
 */
static int
show_char_foreground(const pcl_state_t * pcs, const gs_char * pbuff)
{
    int code = 0;
    gs_text_enum_t *penum;
    pl_font_t *plfont = pcs->font;
    gs_font *pfont = plfont->pfont;
    gs_text_params_t text;

    /* set vertical writing if -1 which requires double bytes or 1 */
    if ((pcs->text_path == -1 && ((pbuff[0] & 0xff00) != 0)) ||
        (pcs->text_path == 1))
        pfont->WMode = 1;
    else
        pfont->WMode = 0;
    text.operation = TEXT_FROM_CHARS | TEXT_DO_DRAW | TEXT_RETURN_WIDTH;
    text.data.chars = pbuff;
    text.size = 1;
    code = gs_text_begin(pcs->pgs, &text, pcs->memory, &penum);
    if (code >= 0) {
        code = gs_text_process(penum);
        gs_text_release(pcs->pgs, penum, "show_char_foreground");
    }
    return code;
}

static int
show_char_invisible_foreground(const pcl_state_t * pcs, const gs_char * pbuff)
{

    gs_c_param_list list;
    dev_param_req_t request;
    gs_param_name ParamName = "PreserveTrMode";
    gs_param_typed_value Param;
    char *data;
    gs_gstate *pgs = pcs->pgs;
    uint saved_mode = gs_currenttextrenderingmode(pgs);
    int code = 0;

    /* Interrogate the device to see if it supports Text Rendering Mode
     * If it does we can mimic the 'invisible text' by using mode 3. If it
     * doesn't then we drop the text.
     */
    data = (char *)gs_alloc_bytes(pcs->memory, 15, "temporary special_op string");
    memset(data, 0x00, 15);
    memcpy(data, "PreserveTrMode", 15);
    gs_c_param_list_write(&list, pcs->memory);
    /* Make a null object so that the param list won't check for requests */
    Param.type = gs_param_type_null;
    list.procs->xmit_typed((gs_param_list *)&list, ParamName, &Param);
    /* Stuff the data into a structure for passing to the spec_op */
    request.Param = data;
    request.list = &list;

    code = dev_proc(gs_currentdevice(pgs), dev_spec_op)(gs_currentdevice(pgs), gxdso_get_dev_param,
                                                        &request, sizeof(dev_param_req_t));

    if (code != gs_error_undefined) {
        /* The parameter is present in the device, now we need to see its value */
        gs_c_param_list_read(&list);
        list.procs->xmit_typed((gs_param_list *)&list, ParamName, &Param);

        if (Param.type != gs_param_type_bool) {
            /* This really shoudn't happen, but its best to be sure */
            gs_free_object(pcs->memory, data,"temporary special_op string");
            gs_c_param_list_release(&list);
            return gs_error_typecheck;
        }

        if (Param.value.b) {
            /* Its true, so we can set the Tr mode to 3, draw the text
               and then reset the Tr mode */
            gs_settextrenderingmode(pgs, 3);
            code = show_char_foreground(pcs, pbuff);
            gs_settextrenderingmode(pgs, saved_mode);
        }
    } else {
        code = 0;
    }
    gs_free_object(pcs->memory, data,"temporary special_op string");
    gs_c_param_list_release(&list);
    return code;
}



/*
 * draw the opaque background of a character.
 *
 * In the graphic library, characters are masks, hence they are always
 * transparent. Not so in PCL, where characters may be either opaque or
 * transparent.
 *
 * To deal with this dichotomy, opaque characters are rendered as a pair of
 * masks. One is the normal character mask; the other is the bounding box of
 * the character less the character itself.
 *
 * The manner in which the second mask is formed varies based on the font type.
 * For bitmap fonts, the inverse mask is formed as an imagemask object, with
 * inverted polarity. For scalable fonts (which have only provided a path),
 * the inverse is formed by adding the bounding box rectangle as a path to
 * the character path, and using eofill on the resultant path.
 *
 * Special handling is required to achieve the desired raster operation on the
 * "background" mask. From the point of view of the graphic library, the
 * background mask is a normal mask, and hence would utiltise the S = 0
 * portion of the current logical operation (recall that rop's are expressed
 * in an additive sense). The desired effect is, however, the S = 1 portion
 * of the current rop, so the current rop must be inverted in the sense of the
 * source to achive the desired result. In principle, the S = 1 porition of
 * the background rop should be set to the no-op rop, but this is not necessary
 * as the source is a mask.
 *
 * An additional complication arises from the specification provided by HP for
 * handling the source opaque, pattern transparent situation. In this case,
 * the pattern affects only for the foreground pixels of the source; the back-
 * ground must be rendered as a solid, opaque white.
 */
static int
show_char_background(pcl_state_t * pcs, const gs_char * pbuff)
{
    gs_gstate *pgs = pcs->pgs;
    gs_rop3_t rop = (gs_rop3_t) (pcs->logical_op);
    const pl_font_t *plfont = pcs->font;
    gs_font *pfont = plfont->pfont;
    gs_point pt;
    int code = 0, code2;

    /* save the graphic state and set the background raster operation */
    code = pcl_gsave(pcs);
    if (code < 0)
        return code;
    if (pcs->pattern_transparent) {
        code = pcl_set_drawing_color(pcs, pcl_pattern_solid_white, 0, false);
        if (code < 0) {
            (void)pcl_grestore(pcs);
            return code;
        }
    }
    if (((code = gs_setrasterop(pgs, (gs_rop3_t) rop3_know_S_1((int)rop))) < 0) ||
        ((code = gs_currentpoint(pgs, &pt)) < 0)) {
        return code;
    }

    if (plfont->scaling_technology == plfst_bitmap) {
        gs_char chr = pbuff[0];
        gs_glyph glyph = pfont->procs.encode_char(pfont, chr, GS_NO_GLYPH);
        const byte *cdata = pl_font_lookup_glyph(plfont, glyph)->data;
        int nbytes;
        uint used;
        gs_image_enum *pen = NULL;
        gs_image1_t mask;

        /* empty characters have no background */
        if (cdata == 0) {
            return pcl_grestore(pcs);
        }

        /* allocate the image enumerator */
        pen =
            gs_image_enum_alloc(gs_gstate_memory(pgs),
                                "bitmap font background");
        if (pen == 0) {
            (void)pcl_grestore(pcs);
            return e_Memory;
        }

        /* translate the origin to the ul corner of the image */
        pt.x += (float)pl_get_int16(cdata + 6);
        pt.y -= (float)pl_get_int16(cdata + 8);
        gs_translate(pgs, pt.x, pt.y);

        /* set up and render the image mask */
        gs_image_t_init_mask(&mask, false);
        mask.adjust = false;
        mask.Width = pl_get_uint16(cdata + 10);
        mask.Height = pl_get_uint16(cdata + 12);
        nbytes = ((mask.Width + 7) / 8) * mask.Height;
        code = gs_image_init(pen, &mask, false, false, pgs);
        if (code >= 0)
            code = gs_image_next(pen, cdata + 16, nbytes, &used);

        /* clean up */
        code2 = gs_image_cleanup(pen, pgs);
        if (code >= 0)
            code = code2;
        gs_free_object(gs_gstate_memory(pgs), pen, "bitmap font background");

    } else {
        gs_text_params_t text;
        gs_rect bbox;
        gs_text_enum_t *penum = NULL;

        /* clear the path; start the new one from the current point */
        if (((code = gs_newpath(pgs)) < 0) ||
            ((code = gs_moveto(pgs, pt.x, pt.y)) < 0)) {
            (void)pcl_grestore(pcs);
            return code;
        }
        text.data.chars = pbuff;
        text.size = 1;
        text.operation =
            TEXT_FROM_CHARS | TEXT_DO_TRUE_CHARPATH | TEXT_RETURN_WIDTH;
        code = gs_text_begin(pgs, &text, pcs->memory, &penum);
        if (code >= 0)
            code = gs_text_process(penum);
        if (code >= 0) {
            /* append the characters bounding box and use eofill */
            if ((code = gs_pathbbox(pgs, &bbox)) >= 0 &&
                (code = gs_rectappend(pgs, &bbox, 1)) >= 0 &&
                (code = gs_eofill(pgs)) >= 0)
            {
                /* fall through */
            }
        }
        gs_text_release(pgs, penum, "show_char_background");
    }

    code2 = pcl_grestore(pcs);
    if (code >= 0)
        code = code2;
    return code;
}

/*
 * get the advance width.
 */
static int
pcl_get_width(pcl_state_t * pcs, gs_point * advance_vector,
              const gs_point * pscale, gs_char chr, bool is_space,
              bool print_undefined, double *output_width)
{
    int code = 0;
    pcl_font_selection_t *pfp = &(pcs->font_selection[pcs->font_selected]);
    double width;

    if (chr != 0xffff || print_undefined) {
        if (!pfp->params.proportional_spacing || is_space)
        {
            code = pcl_update_hmi_cp(pcs);
            if (code < 0)
                return code;

            width = pcs->hmi_cp;
        }
        else {
            if (pcs->font->scaling_technology == plfst_TrueType ||
                pcs->font->scaling_technology == plfst_MicroType) {
                double tmp;

                tmp = pscale->x / (double) pcs->uom_cp + 0.5;
                tmp -= fmod(tmp, (double) 1.0);
                tmp *= (double) pcs->uom_cp;
                width = advance_vector->x * tmp;

            } else
                width = advance_vector->x * pscale->x;
            width += (double) pcs->uom_cp / 2.0;
            width -= fmod(width, (double) pcs->uom_cp);
        }
    } else if (is_space) {
        code = pcl_update_hmi_cp(pcs);
        if (code < 0)
            return code;
        width = pcs->hmi_cp;
    }
    else
        width = 0.0;
    /* round to nearest integral pcl units */
    *output_width = width;
    return code;
}

/*
 * Show a string of characters.  Provide a general purpose function
 * that can be used in all cases (pcl_show_chars_slow) and a faster
 * function (pcl_show_chars_fast) that can be used for most
 * circumstances.  The latter algorithm can print strings of
 * characters the slow algorithm only prints one character at a time.
 *
 * As is the case for other parts of this code, this code is made more complex
 * by the PostScript-centric nature of the the graphics library, and by a
 * long standing flaw in the PostScript view of fonts. Specifically, the
 * initial introduction of Encoding arrays into PostScript fonts, followed by
 * composite font mechanism, very much confused the concepts of font and text
 * parsing method.
 *
 * A font is an object which accepts a character identifier and returns a
 * "rendering" of that character (which may be a bitmap, may be a path, may
 * be an advance vector, or may be some combination of the above); it may also
 * in some cases apply this rendering to the graphic state (which may include
 * modifying the output). Whether or not a font caches or expects its client
 * to handle caching is a separate issue; there are good areguments for either
 * approach.
 *
 * A text parsing method is an object that accepts a character string and
 * returns one or more character identifiers. A text parsing method is, in
 * principle, completely independent of a font, though for historical reasons
 * the two concepts are often linked at the application level.
 *
 * Because of the PostScript origins of the graphic library, its font interface
 * handles both text parsing and rendering. To achieve flexibility, the client
 * may provide a "get next character" procedure for the graphic library font
 * machinery to work with, but this flexibility is not sufficient for PCL, as
 * the latter potentially needs to perform additional operations on each
 * character. Hence, PCL will not ask the font machiner to render more than
 * one character at a time.
 *
 * Complicating this picture is the nature of memory management in the graphic
 * library. The show class operators in PostScript generally take a string as
 * an operand. PostScript strings have the "getinterval" property: one string
 * may be part of another string. Hence strings cannot have headers. In a
 * relocating memory systems, this implies that strings must be dealt with
 * separately from other objects: they must be allocated as strings. In the
 * case of PCL, this is not necessarily the case (see, for example, the case
 * of transparent mode, below).
 *
 * The original implementation of this routine ignored this distinction and
 * could, in principle, have failed if re-location was enabled. It was also
 * rather hard to read, because it parsed the input string (at least) twice:
 * once the find the character so that PCL-specific actions could be taken,
 * then again via the font machiner.
 *
 *
 * The final operand is true if the text was provided via the literal
 * (transparent) text command: ESC & p <nbytes> X. This distinction is
 * important for characters that are not mapped by the current symbol set.  */

static int
pcl_show_chars_slow(pcl_state_t * pcs,
                    const gs_point * pscale,
                    const byte * str, uint size, bool literal)
{
    gs_gstate *pgs = pcs->pgs;
    gs_char buff[1];
    double rmargin = pcs->margins.right;
    double page_size = pcs->xfm_state.pd_size.x;
    bool source_opaque = !pcs->source_transparent;
    bool invisible_pattern = is_invisible_pattern(pcs);
    bool wrap = pcs->end_of_line_wrap;
    bool is_space = false;
    bool print_undefined = false;
    bool use_rmargin = (pcs->cap.x <= rmargin);
    gs_char chr, orig_chr;
    int code = 0;
    double width;
    gs_point advance_vector;
    bool unstyled_substitution;

    width = pcs->last_width;

    while (get_next_char(pcs, &str, &size, &chr,
                         &orig_chr, &is_space, &print_undefined, literal,
                         &advance_vector, &unstyled_substitution) == 0) {
        double tmp_x;

        /* check if a character was found */
        buff[0] = chr;

        /* round width to integral pcl current units */
        code =
            (pcl_get_width
             (pcs, &advance_vector, pscale, chr, is_space, print_undefined, &width));
        if (code < 0)
            return code;

        /*
         * Check for transitions of the left margin; this check is
         * disabled if the immediately preceding character was a back-space.
         * A move beyond the "right" logical page edge is also considered
         * a margin transition.
         *
         * A little-known feature of PCL is the effect of the line-wrap
         * command on the interpretation of the right margin. If line
         * wrap is in effect, a transition of the left margin will cause
         * a <cr><lf> operation BEFORE the current character is printed. If
         * line-wrap is not in effect, a transition of the right margin will
         * stop printing AFTER the current character is printed.
         *
         * A special case occurs in the non-wrap situation when the current
         * position exactly equals the current margin. In that case, no
         * character is printed.
         */
        if (!pcs->last_was_BS) {
            if (wrap) {
                if ((use_rmargin && (pcs->cap.x + width > rmargin)) ||
                    (pcs->cap.x + width > page_size)) {
                    code = pcl_do_CR(pcs);
                    if (code < 0)
                        return code;
                    code = pcl_do_LF(pcs);
                    if (code < 0)
                        return code;
                    use_rmargin = true;
                }
            } else {
                if (use_rmargin && (pcs->cap.x == rmargin))
                    break;
                else if (pcs->cap.x >= page_size) {
                    pcs->cap.x = page_size;
                    break;
                }
            }
        }

        /*
         * If the immediately preceding character was a BS, the code will
         * center the current character on top of the preceding one. After
         * the character is printed, the current point is returned to the
         * prior point.
         */
        tmp_x = pcs->cap.x;
        if (pcs->last_was_BS) {
            /* hack alert.  It seems if the last width is large, we
               use the horizontal dimension of the page as a guess, the
               centering is replaced by returning to the zero
               coordinate.  It would take quite a bit of time to
               investigate what the hp is doing in this pathological
               case, so we have not done a detailed analysis.  This
               solution prints the tests we have correctly. */
            if (pcs->last_width > pcs->xfm_state.pd_size.x)
                tmp_x = 0;
            else
                tmp_x += (pcs->last_width - width) / 2;
        }
        code = gs_moveto(pgs, tmp_x / pscale->x, pcs->cap.y / pscale->y);
        if (code < 0)
            return code;

        if (chr != 0xffff || print_undefined) {
            /* if source is opaque, show and opaque background */
	    /* retrieve the current cursor position: leftside of character */
            gs_fixed_point pt;
            code = gx_path_current_point(gx_current_path(pcs->pgs), &pt);
            if (source_opaque)
                code = show_char_background(pcs, buff);
            if (code < 0)
                break;

            if (invisible_pattern)
                code = show_char_invisible_foreground(pcs, buff);
            else
                code = show_char_foreground(pcs, buff);

            if (code < 0)
                break;

            if ((code = pcl_mark_page_for_character(pcs, &pt)) < 0)
                return code;
        }

        /*
         * Check again for the first character following a back-space. if
         * this is the case, go back to the original position.
         */
        if (pcs->last_was_BS) {
            pcs->cap.x += pcs->last_width;
            pcs->last_was_BS = false;
        } else
            pcs->cap.x += width;

        /* check for going beyond the margin if not wrapping */
        if (!wrap) {
            if (use_rmargin && (pcs->cap.x > rmargin)) {
                pcs->cap.x = rmargin;
                break;
            } else if (pcs->cap.x >= page_size) {
                pcs->cap.x = page_size;
                break;
            }
        }
        if (unstyled_substitution) {
            pcl_decache_font(pcs, -1, true);
            code = pcl_recompute_font(pcs, false);
            if (code < 0)
                return code;
            set_gs_font(pcs);
        }
    }

    /* record the last width */
    pcs->last_width = width;

    return code;
}

void
pcl_font_scale(pcl_state_t * pcs, gs_point * pscale)
{
    /* set up the font transformation */
    if (pcs->font->scaling_technology == plfst_bitmap) {
        pscale->x = (double) pcl_coord_scale / pcs->font->resolution.x;
        pscale->y = (double) pcl_coord_scale / pcs->font->resolution.y;
    } else {
        /*
         * Outline fonts are 1-point; the font height is given in
         * (quarter-)points.  However, if the font is fixed-width,
         * it must be scaled by pitch, not by height, relative to
         * the nominal pitch of the outline.
         */
        pcl_font_selection_t *pfp = &pcs->font_selection[pcs->font_selected];

        /* AGFA madness - 72.307 points per inch for intellifonts */
        double ppi =
            (pfp->font->scaling_technology ==
             plfst_Intellifont) ? 72.307 : 72.0;
        if (pfp->font->params.proportional_spacing) {
            pscale->x = pscale->y = pfp->params.height_4ths
                * 0.25 * 7200.0 / ppi;
        } else {
            pscale->x = pscale->y = pl_fp_pitch_cp(&pfp->params)
                * (1000.0 / pl_fp_pitch_cp(&pfp->font->params))
                * (7200.0 / (100.0 * ppi));

            /* hack for our internal scalable lineprinter font.  If a
               real lineprinter bitmap font is available it will be
               handled by the bitmap scaling case above */
            if ((pfp->font->params.typeface_family == 0) &&
                (pfp->font->storage == pcds_internal)) {
                pscale->x = pscale->y = 850.0;
            }

        }
        /*
         * Scalable fonts use an upright coordinate system,
         * the opposite from the usual PCL system.
         */
        pscale->y = -pscale->y;
    }
}

/*
 * Set up to handle a string of text.
 *
 * The final operand is true if the text was provided via the literal
 * (transparent) text command: ESC & p <nbytes> X. This distinction is
 * important for characters that are not mapped by the current symbol set.
 */
int
pcl_text(const byte * str, uint size, pcl_state_t * pcs, bool literal)
{
    gs_gstate *pgs = pcs->pgs;
    gs_point scale;
    int code;

    /* rtl files can have text in them - we don't print any characters
       in rtl */
    if (pcs->personality == rtl)
        return 0;
    /* set up the current font and HMI */
    if ((pcs->font == 0) || pcs->font_selection[pcs->font_selected].font == 0) {
        code = pcl_recompute_font(pcs, false);
        if (code < 0)
            return gs_rethrow_code(code);
    }

    /* set up the graphic state */
    code = pcl_set_drawing_color(pcs,
                                 pcs->pattern_type,
                                 pcs->current_pattern_id, false);
    if (code >= 0)
        code = pcl_set_graphics_state(pcs);
    if (code < 0)
        return code;
    set_gs_font(pcs);

    pcl_font_scale(pcs, &scale);
    gs_scale(pgs, scale.x, scale.y);

    /*
     * If floating underline is on, since we're about to print a real
     * character, track the best-underline position.
     * XXX Until we have the font's design value for underline position,
     * use 0.2 em.  This is enough to almost clear descenders in typical
     * fonts; it's also large enough for us to check that the mechanism
     * works.
     */
    if (pcs->underline_enabled && pcs->underline_floating) {
        float yu = fabs(scale.y) / 5.0;

        if (yu > pcs->underline_position)
            pcs->underline_position = yu;
    }

    /* it is not clear if vertical substitutes are allowed in mode -1 */
    if (pcs->text_path != 0)
        pcs->font->allow_vertical_substitutes = true;
    else
        pcs->font->allow_vertical_substitutes = false;

    /* Print remaining characters, restore the ctm */
    code = pcl_show_chars_slow(pcs, &scale, str, size, literal);
    if (code > 0)               /* shouldn't happen */
        code = gs_note_error(gs_error_invalidfont);
    return code;
}

/*
 * Individual non-command/control characters
 */
int
pcl_plain_char(pcl_args_t * pargs, pcl_state_t * pcs)
{
    return pcl_text((const byte *)&(pargs->command), 1, pcs,
                    pcs->display_functions);
}

/*
 * Do any underlining just before a break in motion (vertical motion or
 * negative horizontal motion)...
 */
int pcl_break_underline(pcl_state_t * pcs)
{
    int code = 0;

    if (pcs->underline_enabled)
        code = pcl_do_underline(pcs);

    return code;
}

/*
 * draw underline up to current point, adjust status
 */
int
pcl_do_underline(pcl_state_t * pcs)
{
    int code = 0;

    if (pcs->underline_start.x != pcs->cap.x) {
        gs_gstate *pgs = pcs->pgs;
        float y = pcs->underline_start.y + pcs->underline_position;

        /* save the graphics state */
        code = pcl_gsave(pcs);
        if (code < 0)
            return code;

        code = pcl_set_drawing_color(pcs,
                                     pcs->pattern_type,
                                     pcs->current_pattern_id, false);
        if (code >= 0)
            code = pcl_set_graphics_state(pcs);
        if (code < 0) {
            (void)pcl_grestore(pcs);
            return code;
        }

        /*
         * TRM says (8-34) that underline is 3 dots.  In a victory for
         * common sense, it's not.  Rather, it's 0.01" (which *is* 3 dots
         * at 300 dpi only)
         */
        gs_setlinewidth(pgs, dots(3));
        if ((gs_moveto(pgs, pcs->underline_start.x, y) < 0) ||
            (gs_lineto(pgs, pcs->cap.x, y) < 0) ||
            (gs_stroke(pgs) < 0)) {
            (void)pcl_grestore(pcs);
            return code;
        }

        code = pcl_grestore(pcs);
        if (code < 0)
            return code;
    }

    /*
     * Fixed underline is 5 "dots" (actually 5/300") down.  Floating
     * will be determined on the fly.
     */
    pcs->underline_start = pcs->cap;
    pcs->underline_position = pcs->underline_floating ? 0.0 : dots(5);
    return code;
}

/* ------ Commands ------ */

/*
 * ESC & p <count> X
 *
 * Unparsed text command
 */
static int
pcl_transparent_mode(pcl_args_t * pargs, pcl_state_t * pcs)
{

#ifdef DEBUG
    if (gs_debug_c('i')) {
        pcl_debug_dump_data(pcs->memory, arg_data(pargs), uint_arg(pargs));
    }
#endif

    return pcl_text(arg_data(pargs), uint_arg(pargs), pcs, true);
}

/*
 * ESC & d <0|3> D
 *
 * Enable floating or fixed-depth underlining.
 *
 * NB: If underlining is already enabled, this command is ignored. Underlining
 *     must be specifically disabled to switch from fixed to floating.
 */
static int
pcl_enable_underline(pcl_args_t * pargs, pcl_state_t * pcs)
{
    int type = int_arg(pargs);

    /* ignore command if underlining is already enabled */
    if (pcs->underline_enabled)
        return 0;

    if ((type == 0) || (type == 1)) {
        pcs->underline_floating = false;
        pcs->underline_position = dots(5);
    } else if (type == 3) {
        pcs->underline_floating = true;
        pcs->underline_position = 0.0;
    } else
        return 0;

    pcs->underline_enabled = true;
    pcs->underline_start = pcs->cap;
    return 0;
}

/*
 * ESC & d @
 *
 * Disable underlining
 */
static int
pcl_disable_underline(pcl_args_t * pargs, pcl_state_t * pcs)
{
    int code = 0;

    /* apparently disabling underlining has the side effect of
       flushing any pending underlines.  This side effect is not
       documented */
    if (pcs->underline_enabled == true) {
        code = pcl_do_underline(pcs);
        pcs->underline_enabled = false;
    }
    return code;
}

/* (From PCL5 Comparison Guide, p. 1-56) */

/*
 * ESC & t <method> P
 *
 * Select the text parsing method.
 */
static int
pcl_text_parsing_method(pcl_args_t * pargs, pcl_state_t * pcs)
{
    switch (int_arg(pargs)) {

        case 0:
        case 1:
            pcs->text_parsing_method = tpm_0_SBCS;
            break;

        case 21:
            pcs->text_parsing_method = tpm_21_DBCS7;
            break;

        case 31:
            pcs->text_parsing_method = tpm_31_sjis;
            break;

        case 38:
            pcs->text_parsing_method = tpm_38_DBCS8;
            break;

        case 83:
            pcs->text_parsing_method = tpm_83_utf8;
            break;

        case 1008:
            pcs->text_parsing_method = tpm_1008_utf8;
            break;

        default:
            return e_Range;
    }

    return 0;
}

/* (From PCL5 Comparison Guide, p. 1-57) */

/*
 * ESC & c <direction> T
 *
 * Set the text path direction - not yet implemented.
 */
static int
pcl_text_path_direction(pcl_args_t * pargs, pcl_state_t * pcs)
{
    int direction = int_arg(pargs);

    switch (direction) {

        case 0:
        case 1:
        case -1:
            break;

        default:
            return e_Range;
    }

    pcs->text_path = direction;
    return 0;
}

/* ------ Initialization ------ */
static int
pctext_do_registration(pcl_parser_state_t * pcl_parser_state,
                       gs_memory_t * mem)
{
    /* Register commands */
    DEFINE_CONTROL(0, "(plain char)", pcl_plain_char);

    DEFINE_CLASS('&') {
        'p', 'X',
            PCL_COMMAND("Transparent Mode", pcl_transparent_mode, pca_bytes)
    }, {
        'd', 'D',
            PCL_COMMAND("Enable Underline",
                        pcl_enable_underline, pca_neg_ignore | pca_big_ignore)
    }, {
        'd', '@',
            PCL_COMMAND("Disable Underline",
                        pcl_disable_underline,
                        pca_neg_ignore | pca_big_ignore)
    }, END_CLASS DEFINE_CLASS('&') {
        't', 'P',
            PCL_COMMAND("Text Parsing Method",
                        pcl_text_parsing_method,
                        pca_neg_error | pca_big_error)
    }, {
        'c', 'T',
            PCL_COMMAND("Text Path Direction",
                        pcl_text_path_direction, pca_neg_ok | pca_big_error)
    }, END_CLASS DEFINE_CONTROL(1, "(plain char)", pcl_plain_char);     /* default "command" */

    return 0;
}

static int
pctext_do_reset(pcl_state_t * pcs, pcl_reset_type_t type)
{
    static const uint mask = (pcl_reset_initial
                              | pcl_reset_printer | pcl_reset_overlay);

    if ((type & mask) != 0) {
        pcs->underline_enabled = false;
        pcs->last_was_BS = false;
        pcs->last_width = inch2coord(1.0 / 10.0);
        pcs->text_parsing_method = tpm_0_SBCS;
        pcs->text_path = 0;
    }
    return 0;
}

const pcl_init_t pctext_init = { pctext_do_registration, pctext_do_reset, 0 };