-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimagewriter.cpp
More file actions
2290 lines (2094 loc) · 60.7 KB
/
imagewriter.cpp
File metadata and controls
2290 lines (2094 loc) · 60.7 KB
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
/*
GSport - an Apple //gs Emulator
Copyright (C) 2010 - 2011 by GSport contributors
Based on the KEGS emulator written by and Copyright (C) 2003 Kent Dickey
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Copyright (C) 2002-2004 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
Modified for the GSport emulator by Christopher G. Mason 03/2014
Extensively rewritten to provide full emulation of the Apple ImageWriter II
and LQ printers.
Information used to write this emulator was provided by
Apple's "ImageWriter II Technical Reference Manual"
ISBN# 0-201-17766-8
and
Apple's "ImageWriter LQ Reference Manual"
ISBN# 0-201-17751-X
*/
#include "imagewriter.h"
#include <math.h>
#include "support.h"
//#include "png.h"
//#pragma comment( lib, "libpng.lib" )
//#pragma comment (lib, "zdll.lib" )
static Imagewriter* defaultImagewriter = NULL;
static FILE *textPrinterFile = NULL;
#ifdef WIN32
const char* const textPrinterFileName = ".\\printer.txt";
#else
const char* const textPrinterFileName = "./printer.txt";
#endif
#define PARAM16(I) (params[I+1]*256+params[I])
#define PIXX ((Bitu)floor(curX*dpi+0.5))
#define PIXY ((Bitu)floor(curY*dpi+0.5))
//These ugly defines are so we can convert multibyte parameters from strings into some nice ints.
#define paramc(I) (params[I]-'0')
#define PARAM2(I) (paramc(I)*10+paramc(I+1))
#define PARAM3(I) (paramc(I)*100+paramc(I+1)*10+paramc(I+2))
#define PARAM4(I) (paramc(I)*1000+paramc(I+1)*100+paramc(I+2)*10+paramc(I+3))
static Bitu printer_timout;
static bool timeout_dirty;
static const char* document_path;
extern "C" char* g_imagewriter_fixed_font;
extern "C" char* g_imagewriter_prop_font;
extern "C" int iw_scc_write;
#include "iw_charmaps.h"
#define SWITCHA_CHARSET_MASK 0x07
#define SWITCHA_CHARSET_US 0x00
#define SWITCHA_CHARSET_IT 0x01
#define SWITCHA_CHARSET_DK 0x02
#define SWITCHA_CHARSET_UK 0x03
#define SWITCHA_CHARSET_DE 0x04
#define SWITCHA_CHARSET_SE 0x05
#define SWITCHA_CHARSET_FR 0x06
#define SWITCHA_CHARSET_ES 0x07
#define SWITCHA_PERFORATIONSKIP 0x10
#define SWITCHA_LFAFTERCR 0x80
#ifdef HAVE_SDL
void Imagewriter::FillPalette(Bit8u redmax, Bit8u greenmax, Bit8u bluemax, Bit8u colorID, SDL_Palette* pal)
{
float red=redmax/30.9;
float green=greenmax/30.9;
float blue=bluemax/30.9;
Bit8u colormask=colorID<<=5;
for(int i = 0; i < 32;i++) {
pal->colors[i+colormask].r=255-(red*(float)i);
pal->colors[i+colormask].g=255-(green*(float)i);
pal->colors[i+colormask].b=255-(blue*(float)i);
}
}
#endif // HAVE_SDL
Imagewriter::Imagewriter(Bit16u dpi, Bit16u paperSize, Bit16u bannerSize, char* output, bool multipageOutput)
{
#ifdef HAVE_SDL
if (FT_Init_FreeType(&FTlib))
{
page = NULL;
}
else
{
SDL_Init(SDL_INIT_EVERYTHING);
this->output = output;
this->multipageOutput = multipageOutput;
this->port = port;
if (bannerSize)
{
defaultPageWidth = ((Real64)paperSizes[0][0]/(Real64)72);
defaultPageHeight = (((Real64)paperSizes[0][1]*bannerSize)/(Real64)72);
dpi = 144;
}
else
{
if (paperSize >= N_PAPER_SIZES)
{
printf("Printer: unsupported paper size %d\n", paperSize);
paperSize = 0;
}
defaultPageWidth = ((Real64)paperSizes[paperSize][0]/(Real64)72);
defaultPageHeight = ((Real64)paperSizes[paperSize][1]/(Real64)72);
}
this->dpi = dpi;
// Create page
page = SDL_CreateRGBSurface(
SDL_SWSURFACE,
(Bitu)(defaultPageWidth*dpi),
(Bitu)(defaultPageHeight*dpi),
8,
0,
0,
0,
0);
// Set a grey palette
SDL_Palette* palette = page->format->palette;
for (Bitu i=0; i<32; i++)
{
palette->colors[i].r =255;
palette->colors[i].g =255;
palette->colors[i].b =255;
}
// 0 = all white needed for logic 000
FillPalette( 0, 0, 0, 1, palette);
// 1 = magenta* 001
FillPalette( 0, 255, 0, 1, palette);
// 2 = cyan* 010
FillPalette(255, 0, 0, 2, palette);
// 3 = "violet" 011
FillPalette(255, 255, 0, 3, palette);
// 4 = yellow* 100
FillPalette( 0, 0, 255, 4, palette);
// 5 = red 101
FillPalette( 0, 255, 255, 5, palette);
// 6 = green 110
FillPalette(255, 0, 255, 6, palette);
// 7 = black 111
FillPalette(255, 255, 255, 7, palette);
// 0 = all white needed for logic 000
/*FillPalette( 0, 0, 0, 1, palette);
// 1 = yellow* 100 IW
FillPalette( 0, 0, 255, 1, palette);
// 2 = magenta* 001 IW
FillPalette( 0, 255, 0, 2, palette);
// 3 = cyan* 010 IW
FillPalette(255, 0, 0, 3, palette);
// 4 = red 101 IW
FillPalette( 0, 255, 255, 4, palette);
// 5 = green 110 IW
FillPalette(255, 0, 255, 5, palette);
// 6 = "violet" 011 IW
FillPalette(255, 255, 0, 6, palette);
// 7 = black 111
FillPalette(255, 255, 255, 7, palette);*/
// yyyxxxxx bit pattern: yyy=color xxxxx = intensity: 31=max
// Printing colors on top of each other ORs them and gets the
// correct resulting color.
// i.e. magenta on blank page yyy=001
// then yellow on magenta 001 | 100 = 101 = red
color=COLOR_BLACK;
curFont = NULL;
charRead = false;
autoFeed = false;
outputHandle = NULL;
resetPrinter();
//Only initialize native printer here if multipage output is off. That way the user doesn't get prompted every page.
if (strcasecmp(output, "printer") == 0 && !multipageOutput)
{
#if defined (WIN32)
// Show Print dialog to obtain a printer device context
ShowCursor(1);
PRINTDLG pd;
pd.lStructSize = sizeof(PRINTDLG);
pd.hDevMode = (HANDLE) NULL;
pd.hDevNames = (HANDLE) NULL;
pd.Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE;
pd.hwndOwner = NULL;
pd.hDC = (HDC) NULL;
pd.nFromPage = 0xFFFF;
pd.nToPage = 0xFFFF;
pd.nMinPage = 1;
pd.nMaxPage = 0xFFFF;
pd.nCopies = 1;
pd.hInstance = NULL;
pd.lCustData = 0L;
pd.lpfnPrintHook = (LPPRINTHOOKPROC) NULL;
pd.lpfnSetupHook = (LPSETUPHOOKPROC) NULL;
pd.lpPrintTemplateName = (LPCSTR) NULL;
pd.lpSetupTemplateName = (LPCSTR) NULL;
pd.hPrintTemplate = (HANDLE) NULL;
pd.hSetupTemplate = (HANDLE) NULL;
if(!PrintDlg(&pd))
{
//If user presses cancel, warn them with a dialog and switch output to bitmap files
this->output = "bmp";
MessageBox(NULL,"You did not select a printer.\nAll printer output will be saved as bitmap files.\nTo select a printer, press F4 and select 'Reset Virtual ImageWriter'",NULL,MB_ICONEXCLAMATION);
}
printerDC = pd.hDC;
ShowCursor(0);
#endif // WIN32
}
}
#endif // HAVE_SDL
#ifndef HAVE_SDL
this->output = output;
this->multipageOutput = multipageOutput;
#endif // !HAVE_SDL
};
void Imagewriter::resetPrinterHard()
{
#ifdef HAVE_SDL
charRead = false;
resetPrinter();
#endif // HAVE_SDL
}
void Imagewriter::resetPrinter()
{
#ifdef HAVE_SDL
printRes = 0;
color=COLOR_BLACK;
curX = curY = 0.0;
ESCSeen = false;
FSSeen = false;
ESCCmd = 0;
numParam = neededParam = 0;
topMargin = 0.0;
leftMargin = 0.25; //Most all Apple II software including GS/OS assume a 1/4 inch margin on an Imagewriter
rightMargin = pageWidth = defaultPageWidth;
bottomMargin = pageHeight = defaultPageHeight;
lineSpacing = (Real64)1/6;
cpi = 12.0;
printRes = 2;
definedUnit = 96;
curCharTable = 1;
style = STYLE_BOLD;
score = SCORE_NONE;
extraIntraSpace = 0.0;
printUpperContr = true;
bitGraph.remBytes = 0;
densk = 0;
densl = 1;
densy = 2;
densz = 3;
charTables[0] = 0; // Italics
charTables[1] = charTables[2] = charTables[3] = 437;
multipoint = false;
multiPointSize = 0.0;
multicpi = 0.0;
hmi = -1.0;
switcha = SWITCHA_CHARSET_US;
switchb = ' ';
numPrintAsChar = 0;
LQtypeFace = fixed;
verticalDot = 0;
selectCodepage(charTables[curCharTable]);
updateFont();
updateSwitch();
#endif // HAVE_SDL
newPage(false,true);
#ifdef HAVE_SDL
// Default tabs => Each eight characters
/*for (Bitu i=0;i<32;i++)
horiztabs[i] = i*8*(1/(Real64)cpi);*/
numHorizTabs = 0;
numVertTabs = 0;
#endif // HAVE_SDL
}
Imagewriter::~Imagewriter(void)
{
#ifdef HAVE_SDL
finishMultipage();
if (page != NULL)
{
SDL_FreeSurface(page);
page = NULL;
FT_Done_FreeType(FTlib);
}
#if defined (WIN32)
DeleteDC(printerDC);
#endif
#endif // HAVE_SDL
};
#ifdef HAVE_SDL
void Imagewriter::selectCodepage(Bit16u cp)
{
Bit16u *mapToUse = NULL;
switch(cp)
{
case 0: // Italics, use cp437
case 437:
mapToUse = (Bit16u*)&cp437Map;
break;
default:
//LOG(LOG_MISC,LOG_WARN)("Unsupported codepage %i. Using CP437 instead.", cp);
mapToUse = (Bit16u*)&cp437Map;
}
for (int i=0; i<256; i++)
curMap[i] = mapToUse[i];
}
#endif // HAVE_SDL
#ifdef HAVE_SDL
void Imagewriter::updateFont()
{
// char buffer[1000];
if (curFont != NULL)
FT_Done_Face(curFont);
char* fontName;
switch (LQtypeFace)
{
case fixed:
fontName = g_imagewriter_fixed_font;
break;
case prop:
fontName = g_imagewriter_prop_font;
break;
default:
fontName = g_imagewriter_fixed_font;
}
if (FT_New_Face(FTlib, fontName, 0, &curFont))
{
printf("Unable to load font %s\n");
//LOG_MSG("Unable to load font %s", fontName);
curFont = NULL;
}
Real64 horizPoints = 10;
Real64 vertPoints = 10;
if (!multipoint)
{
actcpi = cpi;
if (!(style & STYLE_CONDENSED)) {
horizPoints *= 10.0/cpi;
//vertPoints *= 10.0/cpi;
}
if (!(style & STYLE_PROP)) {
if ((cpi == 10.0) && (style & STYLE_CONDENSED)) {
actcpi = 17.14;
horizPoints *= 10.0/17.14;
}
if ((cpi == 12.0) && (style & STYLE_CONDENSED)) {
actcpi = 20.0;
horizPoints *= 10.0/20.0;
vertPoints *= 10.0/12.0;
}
} else if (style & STYLE_CONDENSED) horizPoints /= 2.0;
if ((style & STYLE_DOUBLEWIDTH)) {
actcpi /= 2.0;
horizPoints *= 2.0;
}
} else { // multipoint true
actcpi = multicpi;
horizPoints = vertPoints = multiPointSize;
}
if (style & STYLE_SUPERSCRIPT || style & STYLE_SUBSCRIPT || style & STYLE_HALFHEIGHT) {
//horizPoints *= 2.0/3.0;
vertPoints *= 2.0/3.0;
//actcpi /= 2.0/3.0;
}
FT_Set_Char_Size(curFont, (Bit16u)horizPoints*64, (Bit16u)vertPoints*64, dpi, dpi);
if (style & STYLE_ITALICS || charTables[curCharTable] == 0)
{
FT_Matrix matrix;
matrix.xx = 0x10000L;
matrix.xy = (FT_Fixed)(0.20 * 0x10000L);
matrix.yx = 0;
matrix.yy = 0x10000L;
FT_Set_Transform(curFont, &matrix, 0);
}
}
void Imagewriter::updateSwitch()
{
//Set international character mappping (Switches A-1 to A3)
int charmap = (switcha & SWITCHA_CHARSET_MASK);
curMap[0x23] = intCharSets[charmap][0];
curMap[0x40] = intCharSets[charmap][1];
curMap[0x5b] = intCharSets[charmap][2];
curMap[0x5c] = intCharSets[charmap][3];
curMap[0x5d] = intCharSets[charmap][4];
curMap[0x60] = intCharSets[charmap][5];
curMap[0x7b] = intCharSets[charmap][6];
curMap[0x7c] = intCharSets[charmap][7];
curMap[0x7d] = intCharSets[charmap][8];
curMap[0x7e] = intCharSets[charmap][9];
if (switcha & SWITCHA_PERFORATIONSKIP)
{
topMargin = 0.25;
bottomMargin = pageHeight - 0.25;
}
else
{
topMargin = 0.0;
bottomMargin = pageHeight - 0.0;
}
//MSB control (Switch B-6)
if (!(switchb & 32))
{
msb = 255;
}
else msb = 0;
}
void Imagewriter::slashzero(Bit16u penX, Bit16u penY)
{
FT_Face slashFont = curFont;
FT_UInt slashindex = FT_Get_Char_Index(slashFont, curMap[0x2f]);
FT_Load_Glyph(slashFont, slashindex, FT_LOAD_DEFAULT);
FT_Render_Glyph(slashFont->glyph, FT_RENDER_MODE_NORMAL);
blitGlyph(slashFont->glyph->bitmap, penX, penY, false);
blitGlyph(slashFont->glyph->bitmap, penX+1, penY, true);
if (style & STYLE_BOLD) {
blitGlyph(slashFont->glyph->bitmap, penX+1, penY, true);
blitGlyph(slashFont->glyph->bitmap, penX+2, penY, true);
blitGlyph(slashFont->glyph->bitmap, penX+3, penY, true);
}
}
#endif // HAVE_SDL
#ifdef HAVE_SDL
bool Imagewriter::processCommandChar(Bit8u ch)
{
if (ESCSeen || FSSeen)
{
ESCCmd = ch;
if(FSSeen) ESCCmd |= 0x800;
ESCSeen = FSSeen = false;
numParam = 0;
switch (ESCCmd) {
case 0x21: // Select bold font (ESC !) IW
case 0x22: // Cancel bold font (ESC ") IW
case 0x24: // Cancel MSB control and Mousetext (ESC $) IW
case 0x2b: // custom char width is 8 dots (ESC -) IW
case 0x2e: // custom char width is 8 dots (ESC +) IW
case 0x30: // Clear all tabs (ESC 0) IW
case 0x31: // Insert 1 intercharacter spaces (ESC 1) IW
case 0x32: // Insert 2 intercharacter spaces (ESC 2) IW
case 0x33: // Insert 3 intercharacter spaces (ESC 3) IW
case 0x34: // Insert 4 intercharacter spaces (ESC 4) IW
case 0x35: // Insert 5 intercharacter spaces (ESC 5) IW
case 0x36: // Insert 6 intercharacter spaces (ESC 6) IW
case 0x3c: // bidirectional mode (one line) (ESC <) IW
case 0x3e: // Unidirectional mode (one line) (ESC >) IW
case 0x3f: // Send ID string (ESC ?) IW
case 0x41: // Select 1/6-inch line spacing (ESC A) IW
case 0x42: // Select 1/8-inch line spacing (ESC B) IW
case 0x45: // 12 cpi, 96 dpi graphics (ESC E) IW
case 0x4d: // Same as ESC a2 (ESC M) IW
case 0x4e: // 10 cpi, 80 dpi graphics (ESC N) IW
case 0x4f: // Disable paper-out detector (ESC O) IW
case 0x50: // Proportional, 160 dpi graphics (ESC P) IW
case 0x51: // 17 cpi, 136 dpi graphics (ESC Q) IW
case 0x57: // Cancel halfheight printing (ESC W) IW
case 0x58: // Turn underline on (ESC X) IW
case 0x59: // Turn underline off (ESC Y) IW
case 0x63: // Initialize printer (ESC c) IW
case 0x65: // 13.4 cpi, 107 dpi graphics (ESC e) IW
case 0x66: // Select forward feed mode (ESC f) IW
case 0x6b: // Select optional font (ESC k) IW LQ
case 0x6d: // Same as ESC a0 (ESC m) IW
case 0x6e: // 9 cpi, 72 dpi graphics (ESC n) IW
case 0x6f: // Enable paper-out detector (ESC o) IW
case 0x70: // Proportional, 144 dpi graphics (ESC p) IW
case 0x72: // Select reverse feed mode (ESC r) IW
case 0x71: // 15 cpi, 120 dpi graphics (ESC q) IW
case 0x77: // Select halfheight printing (ESC w) IW
case 0x78: // Select superscript printing (ESC x) IW
case 0x79: // Select subscript printing (ESC y) IW
case 0x7a: // Cancel superscript/subscript printing (ESC z) IW
neededParam = 0;
break;
case 0x3d: // Internal font ID (ESC = n) IW LQ
case 0x40: // Select output bin (ESC @ n) IW LQ
case 0x4b: // Select printing color (ESC K n) IW
case 0x61: // Select font (ESC a n) IW
case 0x6c: // Insert CR before LF and FF (ESC l n) IW
case 0x73: // Set intercharacter space (ESC s n) IW
case 0x74: // Shift printing downward n/216 inch (ESC t n) IW LQ
case 0x833: // Feed n lines of blank space (US n) IW
neededParam = 1;
break;
case 0x44: // Set soft switches to closed (on)= 1 (ESC D nn) IW
case 0x54: // Distance between lines to be nn/144 inch (ESC T nn) IW
case 0x5a: // Set soft switches to open (off) = 0 (ESC Z nn) IW
neededParam = 2;
break;
case 0x4c: // Set left margin at column nnn (ESC L nnn) IW
case 0x67: // Print graphics for next nnn * 8 databytes (ESC g nnn) IW
case 0x75: // Add one tab stop at nnn (ESC u nnn) IW
neededParam = 3;
break;
case 0x28: // Set horizontal tabs (ESC ( nnn,) IW
numHorizTabs = 0;
case 0x29: // Delete horizontal tabs (ESC ) nnn,) IW
case 0x43: // Print hi-res graphics for next nnnn*3 databytes (ESC C nnnn) IW LQ
case 0x47: // Print graphics for next nnnn databytes (ESC G nnnn) IW
case 0x46: // Place printhead nnnn dots from left margin (ESC F nnnn) IW
case 0x48: // Set pagelength to nnnn/144 (ESC H nnnn) IW
case 0x53: // Print graphics for next nnnn databytes (ESC S nnnn) IW
case 0x52: // Repeat character c nnn times (ESC R nnn c) IW
case 0x68: // Place printhead nnnn hi-res dots from left margin (ESC h nnnn) IW LQ
neededParam = 4;
break;
case 0x56: //Repeat Print nnnn repetitions of dot column c (ESC V nnnn c) IW
neededParam = 5;
msb = 255;
break;
case 0x55: //Repeat Print nnnn repetitions of hi-res dot column abc (ESC U nnnn abc) IW LQ
neededParam = 7;
msb = 255;
break;
case 0x27: // Select user-defined set (ESC ')
case 0x49: // Define user-defined characters (ESC I)
//LOG(LOG_MISC,LOG_ERROR)("User-defined characters not supported!");
return true;
default:
/*LOG_MSG("PRINTER: Unknown command %c (%02Xh) %c , unable to skip parameters.",
(ESCCmd & 0x800)?"FS":"ESC",ESCCmd, ESCCmd);*/
neededParam = 0;
ESCCmd = 0;
return true;
}
if (neededParam > 0)
return true;
}
if (numParam < neededParam)
{
params[numParam++] = ch;
if (numParam < neededParam)
return true;
}
if (ESCCmd != 0)
{
switch (ESCCmd)
{
case 0x19: // Control paper loading/ejecting (ESC EM)
// We are not really loading paper, so most commands can be ignored
if (params[0] == 'R')
newPage(true,false); // TODO resetx?
break;
case 0x73: // Set intercharacter space (ESC s) IW
if (style & STYLE_PROP)
{
extraIntraSpace = (Real64)paramc(0);
updateFont();
}
break;
case 0x46: // Set absolute horizontal print position (ESC F nnnn) IW
{
int x = 0;
//convert any leading spaces in parameters to zeros
while (x < 4)
{
if (params[x] == ' ') params[x] = '0';
x++;
}
Real64 unitSize = definedUnit;
if (unitSize < 0)
unitSize = (Real64)72.0;
Real64 newX = leftMargin + ((Real64)PARAM4(0)/unitSize);
if (newX <= rightMargin)
curX = newX;
}
break;
case 0x68: // Set absolute horizontal hi-res print position (ESC h nnnn) IW LQ
{
int x = 0;
//convert any leading spaces in parameters to zeros
while (x < 4)
{
if (params[x] == ' ') params[x] = '0';
x++;
}
Real64 unitSize = definedUnit*2;
if (unitSize < 0)
unitSize = (Real64)72.0;
Real64 newX = leftMargin + ((Real64)PARAM4(0)/unitSize);
if (newX <= rightMargin)
curX = newX;
}
break;
case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36:// Insert 1-6 intercharacter spaces (ESC 1 to 6) IW
{
if (style & STYLE_PROP) //This function only works in proportional mode
{
Real64 unitSize = definedUnit;
if (unitSize < 0)
unitSize = (Real64)72.0;
Real64 newX = ((Real64)(ESCCmd-'0')/unitSize);
if (newX <= rightMargin)
curX = newX;
}
break;
}
case 0x47: case 0x53: // Print graphics (ESC G nnnn) IW
{
int x = 0;
printRes &= ~8;
//convert any leading spaces in parameters to zeros
while (x < 4)
{
if (params[x] == ' ') params[x] = '0';
x++;
}
setupBitImage(printRes, PARAM4(0));
break;
}
case 0x43: // Print hi-res graphics (ESC G nnnn) IW LQ
{
int x = 0;
printRes |= 8;
//convert any leading spaces in parameters to zeros
while (x < 4)
{
if (params[x] == ' ') params[x] = '0';
x++;
}
setupBitImage(printRes, PARAM4(0));
break;
}
case 0x67: // Print graphics (ESC g nnn) IW
{
int x = 0;
printRes &= ~8;
//convert any leading spaces in parameters to zeros
while (x < 4)
{
if (params[x] == ' ') params[x] = '0';
x++;
}
setupBitImage(printRes, (PARAM3(0)*8));
break;
}
case 0x56: //Repeat Print nnnn repetitions of dot column byte c (ESC V nnnn c)IW
{
int x = 0;
printRes &= ~8;
//convert any leading spaces in parameters to zeros
while (x < 4)
{
if (params[x] == ' ') params[x] = '0';
x++;
}
x = 0;
while ( x < PARAM4(0))
{
setupBitImage(printRes, 1);
printBitGraph(params[4]);
x++;
}
msb = 0;
break;
}
case 0x55: //Repeat Print nnnn repetitions of hi-res dot column byte abc (ESC U nnnn abc) IW LQ
{
int x = 0;
printRes |= 8;
//convert any leading spaces in parameters to zeros
while (x < 4)
{
if (params[x] == ' ') params[x] = '0';
x++;
}
x = 0;
while ( x < PARAM4(0))
{
setupBitImage(printRes, 1);
printBitGraph(params[4]);
printBitGraph(params[5]);
printBitGraph(params[6]);
x++;
}
msb = 0;
break;
}
case 0x74: // Shift printing downward n/216 inch (ESC t n) IW LQ
{
verticalDot = paramc(0);
break;
}
case 0x6e: // 9 cpi, 72/144 dpi graphics (ESC n) IW
cpi = 9.0;
style &= (0xffff - STYLE_PROP);
printRes = 0;
definedUnit = 72;
extraIntraSpace = 0.0;
LQtypeFace = fixed;
updateFont();
break;
case 0x4e: // 10 cpi, 80/160 dpi graphics (ESC N) IW
cpi = 10.0;
printRes = 1;
style &= (0xffff - STYLE_PROP);
definedUnit = 80;
extraIntraSpace = 0.0;
LQtypeFace = fixed;
updateFont();
break;
case 0x45: // 12 cpi, 96/192 dpi graphics (ESC E) IW
cpi = 12.0;
printRes = 2;
style &= (0xffff - STYLE_PROP);
definedUnit = 96;
extraIntraSpace = 0.0;
LQtypeFace = fixed;
updateFont();
break;
case 0x65: // 13.4 cpi, 107/216 dpi graphics (ESC e) IW
cpi = 13.4;
printRes = 3;
style &= (0xffff - STYLE_PROP);
definedUnit = 107;
extraIntraSpace = 0.0;
LQtypeFace = fixed;
updateFont();
break;
case 0x71: // 15 cpi, 120/240 dpi graphics (ESC q) IW
cpi = 15;
printRes = 4;
style &= (0xffff - STYLE_PROP);
definedUnit = 120;
extraIntraSpace = 0.0;
LQtypeFace = fixed;
updateFont();
break;
case 0x51: // 17 cpi, 136/272 dpi graphics (ESC Q) IW
cpi = 17;
printRes = 5;
style &= (0xffff - STYLE_PROP);
definedUnit = 136;
extraIntraSpace = 0.0;
LQtypeFace = fixed;
updateFont();
break;
case 0x70: // Proportional, 144/288 dpi graphics (ESC p) IW
style |= STYLE_PROP;
cpi = 10;
//printQuality = QUALITY_LQ;
printRes = 6;
definedUnit = 144;
LQtypeFace = prop;
updateFont();
break;
case 0x50: // Proportional, 160/320 dpi graphics (ESC P) IW
style |= STYLE_PROP;
cpi = 12;
//printQuality = QUALITY_LQ;
printRes = 7;
definedUnit = 160;
LQtypeFace = prop;
updateFont();
break;
case 0x54: // Set n/144-inch line spacing (ESC T nn) IW
lineSpacing = (Real64)PARAM2(0)/144;
break;
case 0x59: // Turn underline off (ESC Y) IW
style &= ~STYLE_UNDERLINE;
updateFont();
break;
case 0x58: // Turn underline on (ESC X) IW
style |= STYLE_UNDERLINE;
score = SCORE_SINGLE;
updateFont();
break;
case 0x42: // Select 1/8-inch line spacing (ESC B) IW
lineSpacing = (Real64)1/8;
break;
case 0x41: // Select 1/6-inch line spacing (ESC A) IW
lineSpacing = (Real64)1/6;
break;
case 0x3c: case 0x3e: // Unidirectional mode (one line) (ESC <)
// We don't have a print head, so just ignore this
break;
case 0x63: // Initialize printer (ESC c) IW
resetPrinter();
break;
case 0x48: // Set page length in lines (ESC H nnnn) IW
{
int x = 0;
//convert any leading spaces in parameters to zeros
while (x < 4)
{
if (params[x] == ' ') params[x] = '0';
x++;
}
pageHeight = (Real64)PARAM4(0)/144;
bottomMargin = pageHeight;
topMargin = 0.0;
// trigger margins computation
updateSwitch();
break;
}
case 0x21: // Select bold font (ESC !) IW
style |= STYLE_BOLD;
updateFont();
break;
case 0x22: // Cancel bold font (ESC ") IW
style &= ~STYLE_BOLD;
updateFont();
break;
case 0x78: // Select superscript printing (ESC x) IW
style |= STYLE_SUPERSCRIPT;
updateFont();
break;
case 0x79: // Select subscript printing (ESC y) IW
style |= STYLE_SUBSCRIPT;
updateFont();
break;
case 0x7a: // Cancel superscript/subscript printing (ESC z) IW
style &= 0xFFFF - STYLE_SUPERSCRIPT - STYLE_SUBSCRIPT;
updateFont();
break;
case 0x77: // Select halfheight printing (ESC w) IW
style |= STYLE_HALFHEIGHT;
updateFont();
break;
case 0x57: // Cancel halfheight printing (ESC W) IW
style &= ~STYLE_HALFHEIGHT;
updateFont();
break;
case 0x72: // Reverse paper feed (ESC r) IW
{
printf("Reverse Feed\n");
if(lineSpacing > 0) lineSpacing *= -1;
break;
}
case 0x66: // Forward paper feed (ESC f) IW
{
if(lineSpacing < 0) lineSpacing *= -1;
break;
}
case 0x61: // Select typeface (ESC a n) IW worry about this later
break;
case 0x6d: case 0x4d: //Same as ESC a n commands
break;
case 0x4c: // Set left margin (ESC L nnn) IW
{
int x = 0;
//convert any leading spaces in parameters to zeros
while (x < 4)
{
if (params[x] == ' ') params[x] = '0';
x++;
}
leftMargin = (Real64)(PARAM3(0)-1.0) / (Real64)cpi;
if (curX < leftMargin)
curX = leftMargin;
break;
}
case 0x4b: // Select printing color (ESC K) IW
switch (paramc(0))
{
case 0: break;
case 1: params[0] = 4; break;
case 2: params[0] = 1; break;
case 3: params[0] = 2; break;
case 4: params[0] = 5; break;
case 5: params[0] = 6; break;
case 6: params[0] = 3; break;
}
if(paramc(0)==0) color = COLOR_BLACK;
else color = params[0]<<5;
break;
case 0x3d: // Internal font ID (ESC = n) IW LQ
//Ignore for now
break;
case 0x3f: //Send ID string to computer (ESC ?) IW
//insert SCC send code here
printf("Sending ID String\n");
iw_scc_write = true;
break;
case 0x52: // Repeat character c for nnn times (ESC R nnn c) IW
{
int x = 0;
//convert any leading spaces in parameters to zeros
while (x < 4)
{
if (params[x] == ' ') params[x] = '0';
x++;
}
x = 0;
ESCCmd = 0;
while (x < PARAM3(0))
{
printChar(params[3]);
x++;
}
break;
}
case 0x30: //Clear all tabs
numHorizTabs = 0;
break;
case 0x28: // Set horizontal tabs (ESC ( nnn,) IW
{
int x = 0;
//convert any leading spaces in parameters to zeros
while (x < 4)
{
if (params[x] == ' ') params[x] = '0';
x++;
}
if (params[3] == '.' || (numHorizTabs>0 && horiztabs[numHorizTabs-1] > (Real64)PARAM3(0)*(1/(Real64)cpi)))
{
horiztabs[numHorizTabs++] = (Real64)PARAM3(0)*(1/(Real64)cpi);
//printf("Adding tab %d, and end\n",PARAM3(0));
//printf("Number of Tabs:%d\n",numHorizTabs);
}
else if (params[3] == ',' && numHorizTabs < 32)
{
horiztabs[numHorizTabs++] = (Real64)PARAM3(0)*(1/(Real64)cpi);
numParam = 0;
neededParam = 4;
//printf("Adding tab %d, plus more\n", PARAM3(0));
//printf("Number of Tabs:%d\n",numHorizTabs);