AmendHub

Download:

thecloud

/

SimpleSpooler

/

amendments

/

5

FilterData tweaks

- after re-checking the IW1 and IWII manuals, add 1B4C and 1B61 to filter
- also check 1BF8 (an undefined code) to test filter efficacy on IWII
- keep index in same place while we still have characters to remove

thecloud made amendment 5 1 day ago
--- PrintQueue.c Thu Jul 30 00:10:57 2026 +++ PrintQueue.c Thu Jul 30 16:46:25 2026 @@ -50,18 +50,26 @@ void FilterData(long *count, void *data) * for the ImageWriter II. Some of the printer control sequences * it can emit are not understood by an ImageWriter I. We can filter * these out so the unused parameters of the commands are not printed. - * Currently, we filter the following IW II-only sequences: - * 1B48xxxxxxxx (page size command, plus 4 parameter bytes) - * 1B4Bxx (set color command, plus 1 parameter byte) + * + * In IW1 mode, we filter the following IW II-only control sequences: + * 1B48xxxxxxxx (page length command, plus 4 parameter bytes) + * 1BF8xxxxxxxx (same as 1B48, but for testing the filter on IW II) + * 1B4Cxxxxxx (page left margin command, plus 3 parameter bytes) + * 1B4Bxx (select color command, plus 1 parameter byte) + * 1B61xx (print quality command, plus 1 parameter byte) + * * We can also optionally filter the command that backs up the paper: * 1B72 (set reverse line feeding) + * * Since control sequences can span data blocks, the 1B might have been * sent out before we get the command code. Our filter changes the * command code to FF which will be ignored, and removes the parameter - * bytes which follow, if any. + * bytes which follow. (There is no need to filter IW II-only control + * sequences that have no parameters.) */ char *p; long length, index; + char nopCmd = 0xFF; Boolean iw1Mode, noReverse; GetPrinterOptions(NULL, NULL, &iw1Mode, &noReverse); @@ -75,16 +83,21 @@ void FilterData(long *count, void *data) } if (gProcessingEscape) { if (iw1Mode) { - if (p[index] == 0x48) { - p[index] = 0xFF; /* change command to no-op */ - gBytesToRemove = 4; /* remove 4 bytes after this */ - } else if (p[index] == 0x4B) { - p[index] = 0xFF; /* change command to no-op */ - gBytesToRemove = 1; /* remove 1 byte after this */ + switch (p[index]) { + case 0xF8: + case 0x48: + p[index] = nopCmd; gBytesToRemove = 4; break; + case 0x4C: + p[index] = nopCmd; gBytesToRemove = 3; break; + case 0x4B: + case 0x61: + p[index] = nopCmd; gBytesToRemove = 1; break; + default: + break; } } if (noReverse && p[index] == 0x72) { - p[index] = 0xFF; /* change command to no-op */ + p[index] = nopCmd; } gProcessingEscape = false; continue; @@ -92,6 +105,7 @@ void FilterData(long *count, void *data) if (gBytesToRemove > 0 && length > (index+1)) { /* remove one byte by shifting remaining bytes left */ BlockMove(&p[index+1],&p[index],(length-index)-1); + index -= 1; length -= 1; gBytesToRemove -= 1; }