Skip to content

Commit

Permalink
Add "legacy" ESCPOS striping support (qzind#1254)
Browse files Browse the repository at this point in the history
epsonSlices: Restore 2.0.11 behavior; adds dotDensity: "double-legacy"
  • Loading branch information
tresf authored Apr 18, 2024
1 parent ee10757 commit 8b2945c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
11 changes: 11 additions & 0 deletions js/qz-tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,17 @@ var qz = (function() {
}
}

if(_qz.tools.versionCompare(2, 2, 4) < 0) {
for(var i = 0; i < printData.length; i++) {
if (printData[i].constructor === Object) {
// dotDensity: "double-legacy|single-legacy" since 2.2.4. Fallback to "double|single"
if (printData[i].options && typeof printData[i].options.dotDensity === 'string') {
printData[i].options.dotDensity = printData[i].options.dotDensity.toLowerCase().replace("-legacy", "");
}
}
}
}

if (_qz.tools.isVersion(2, 0)) {
/*
2.0.x conversion
Expand Down
3 changes: 3 additions & 0 deletions src/qz/printer/action/PrintRaw.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ private ImageWrapper getWrapper(BufferedImage img, JSONObject opt, PrintOptions.
case "single": density = 32; break;
case "double": density = 33; break;
case "triple": density = 39; break;
// negative: legacy mode
case "single-legacy": density = -32; break;
case "double-legacy": density = -33; break;
}
} else {
density = 32; //default
Expand Down
24 changes: 21 additions & 3 deletions src/qz/printer/action/raw/ImageWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public class ImageWrapper {
private boolean igpDots = false; // PGL only, toggle IGP/PGL default resolution of 72dpi
private int dotDensity = 32; // Generally 32 = Single (normal) 33 = Double (higher res) for ESC/POS. Irrelevant for all other languages.

private boolean legacyMode = false; // Use newlines for ESC/POS spacing; simulates <=2.0.11 behavior

/**
* Creates a new
* <code>ImageWrapper</code> from a
Expand Down Expand Up @@ -199,7 +201,8 @@ public int getDotDensity() {
}

public void setDotDensity(int dotDensity) {
this.dotDensity = dotDensity;
this.legacyMode = dotDensity < 0;
this.dotDensity = Math.abs(dotDensity);
}

public void setLogoId(String logoId) {
Expand Down Expand Up @@ -590,6 +593,11 @@ private void appendEpsonSlices(ByteArrayBuilder builder) {
boolean stripe = dotDensity == 1;
int bytesNeeded = (dotDensity <= 1 || stripe)? 1:3;

if(legacyMode) {
// Temporarily set line spacing to 24 dots
builder.append(new byte[] { 0x1B, 0x33, 24});
}

int offset = 0; // keep track of chunk offset currently being written
boolean zeroPass = true; // track if this segment get rewritten with 1 pixel offset, always true if not striping

Expand Down Expand Up @@ -631,11 +639,21 @@ private void appendEpsonSlices(ByteArrayBuilder builder) {

zeroPass = !zeroPass;
} else {
//shift down for next segment
builder.append(new byte[] {0x1B, 0x4A, (byte)segmentHeight});
if(legacyMode) {
// render a newline to bump the print head down
builder.append(new byte[] {10});
} else {
//shift down for next segment
builder.append(new byte[] {0x1B, 0x4A, (byte)segmentHeight});
}
offset += 8 * bytesNeeded;
}
}

if(legacyMode) {
// Restore line spacing to 30 dots
builder.append(new byte[] { 0x1B, 0x33, 30});
}
}

private ArrayList<float[]> convertToCYMK() throws IOException {
Expand Down

0 comments on commit 8b2945c

Please sign in to comment.