Skip to content

Commit

Permalink
Merge branch 'master' into custom-ports
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf authored May 6, 2024
2 parents 753f980 + 2ab63ba commit c4383fc
Show file tree
Hide file tree
Showing 60 changed files with 879 additions and 55 deletions.
2 changes: 1 addition & 1 deletion ant/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ java.download=https://bell-sw.com/pages/downloads/#/java-11-lts
# Java vendor to bundle into software (e.g. "*BellSoft|Adoptium|Microsoft|Amazon|IBM")
jlink.java.vendor="BellSoft"
# Java vendor to bundle into software (e.g. "11.0.17+7")
jlink.java.version="11.0.20.1+1"
jlink.java.version="11.0.22+12"
# Java garbage collector flavor to use (e.g. "hotspot|openj9")
jlink.java.gc="hotspot"
# Java garbage collector version to use (e.g. openj9: "0.35.0", zulu: "11.62.17")
Expand Down
13 changes: 12 additions & 1 deletion 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 Expand Up @@ -1474,7 +1485,7 @@ var qz = (function() {
* @param {number} [options.bounds.y=0] Distance from top for bounding box starting corner
* @param {number} [options.bounds.width=0] Width of bounding box
* @param {number} [options.bounds.height=0] Height of bounding box
* @param {string} [options.colorType='color'] Valid values <code>[color | grayscale | blackwhite]</code>
* @param {string} [options.colorType='color'] Valid values <code>[color | grayscale | blackwhite | default]</code>
* @param {number} [options.copies=1] Number of copies to be printed.
* @param {number|Array<number>|Object|Array<Object>|string} [options.density=0] Pixel density (DPI, DPMM, or DPCM depending on <code>[options.units]</code>).
* If provided as an array, uses the first supported density found (or the first entry if none found).
Expand Down
Binary file removed lib/commons-codec-1.16.0.jar
Binary file not shown.
Binary file added lib/commons-codec-1.16.1.jar
Binary file not shown.
Binary file removed lib/commons-io-2.13.0.jar
Binary file not shown.
Binary file added lib/commons-io-2.16.1.jar
Binary file not shown.
Binary file removed lib/commons-lang3-3.13.0.jar
Binary file not shown.
Binary file added lib/commons-lang3-3.14.0.jar
Binary file not shown.
Binary file removed lib/commons-pool2-2.11.1.jar
Binary file not shown.
Binary file added lib/commons-pool2-2.12.0.jar
Binary file not shown.
Binary file removed lib/communication/jna-5.13.0.jar
Binary file not shown.
Binary file added lib/communication/jna-5.14.0.jar
Binary file not shown.
Binary file removed lib/communication/jna-platform-5.13.0.jar
Binary file not shown.
Binary file added lib/communication/jna-platform-5.14.0.jar
Binary file not shown.
Binary file removed lib/communication/jssc-2.9.6-SNAPSHOT.jar
Binary file not shown.
Binary file added lib/communication/jssc-2.9.6.jar
Binary file not shown.
Binary file removed lib/logging/log4j-api-2.20.0.jar
Binary file not shown.
Binary file added lib/logging/log4j-api-2.23.1.jar
Binary file not shown.
Binary file removed lib/logging/log4j-core-2.20.0.jar
Binary file not shown.
Binary file added lib/logging/log4j-core-2.23.1.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ <h3>Pixel Printing</h3>
<option value="color">Color</option>
<option value="grayscale">Grayscale</option>
<option value="blackwhite">Black & White</option>
<option value="default">Default</option>
</select>
</div>

Expand Down
3 changes: 3 additions & 0 deletions src/qz/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import qz.utils.*;
import qz.ws.PrintSocketServer;
import qz.ws.SingleInstanceChecker;
import qz.ws.substitutions.Substitutions;

import java.io.File;
import java.security.cert.X509Certificate;
Expand All @@ -43,6 +44,8 @@ public static void main(String ... args) {
log.info(Constants.ABOUT_TITLE + " vendor: {}", Constants.ABOUT_COMPANY);
log.info("Java version: {}", Constants.JAVA_VERSION.toString());
log.info("Java vendor: {}", Constants.JAVA_VENDOR);
Substitutions.setEnabled(PrefsSearch.getBoolean(ArgValue.SECURITY_SUBSTITUTIONS_ENABLE));
Substitutions.setStrict(PrefsSearch.getBoolean(ArgValue.SECURITY_SUBSTITUTIONS_STRICT));

CertificateManager certManager = null;
try {
Expand Down
4 changes: 4 additions & 0 deletions src/qz/common/TrayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import qz.ws.PrintSocketServer;
import qz.ws.SingleInstanceChecker;
import qz.ws.WebsocketPorts;
import qz.ws.substitutions.Substitutions;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -99,6 +100,9 @@ public TrayManager(boolean isHeadless) {
// Set strict certificate mode preference
Certificate.setTrustBuiltIn(!getPref(TRAY_STRICTMODE));

// Configures JSON websocket messages
Substitutions.getInstance();

// Set FileIO security
FileUtilities.setFileIoEnabled(getPref(SECURITY_FILE_ENABLED));
FileUtilities.setFileIoStrict(getPref(SECURITY_FILE_STRICT));
Expand Down
3 changes: 3 additions & 0 deletions src/qz/installer/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ public Installer removeLegacyFiles() {
files.add("demo/js/qz-websocket.js");
files.add("windows-icon.ico");

// QZ Tray 2.2.3-SNAPSHOT accidentally wrote certs in the wrong place
dirs.add("ssl");

// QZ Tray 2.1 files
if(SystemUtilities.isMac()) {
// Moved to macOS Application Bundle standard https://developer.apple.com/go/?id=bundle-structure
Expand Down
6 changes: 4 additions & 2 deletions src/qz/installer/certificate/CertificateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,11 @@ public static File getWritableLocation(String ... suffixes) throws IOException {
// Last, fallback on a directory we won't ever see again :/
locs.add(TEMP_DIR);
} else {
// Same as above, but with suffixes added (usually "ssl")
// Same as above, but with suffixes added (usually "ssl"), skipping the install location
for(Path saveLocation : SAVE_LOCATIONS) {
locs.add(Paths.get(saveLocation.toString(), suffixes));
if(!saveLocation.equals(SystemUtilities.getJarParentPath())) {
locs.add(Paths.get(saveLocation.toString(), suffixes));
}
}
// Last, fallback on a directory we won't ever see again :/
locs.add(Paths.get(TEMP_DIR.toString(), suffixes));
Expand Down
8 changes: 7 additions & 1 deletion src/qz/installer/shortcut/WindowsShortcutCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

package qz.installer.shortcut;

import com.sun.jna.platform.win32.Win32Exception;
import mslinks.ShellLinkException;
import mslinks.ShellLinkHelper;
import qz.common.Constants;
Expand All @@ -32,7 +33,12 @@ public void createDesktopShortcut() {
}

public boolean canAutoStart() {
return Files.exists(Paths.get(WindowsSpecialFolders.COMMON_STARTUP.toString(), SHORTCUT_NAME));
try {
return Files.exists(Paths.get(WindowsSpecialFolders.COMMON_STARTUP.toString(), SHORTCUT_NAME));
} catch(Win32Exception e) {
log.warn("An exception occurred locating the startup folder; autostart cannot be determined.", e);
}
return false;
}

private void createShortcut(String folderPath) {
Expand Down
3 changes: 2 additions & 1 deletion src/qz/printer/PrintOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,8 @@ public enum ColorType {
COLOR(Chromaticity.COLOR),
GREYSCALE(Chromaticity.MONOCHROME),
GRAYSCALE(Chromaticity.MONOCHROME),
BLACKWHITE(Chromaticity.MONOCHROME);
BLACKWHITE(Chromaticity.MONOCHROME),
DEFAULT(null);

private final Chromaticity chromatic;

Expand Down
4 changes: 2 additions & 2 deletions src/qz/printer/action/PrintHTML.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

public class PrintHTML extends PrintImage implements PrintProcessor {

Expand Down Expand Up @@ -192,7 +191,8 @@ public void print(PrintOutput output, PrintOptions options) throws PrinterExcept
settings.setJobName(pxlOpts.getJobName(Constants.HTML_PRINT));
settings.setPrintQuality(PrintQuality.HIGH);

if (pxlOpts.getColorType() != null) {
// If colortype is default, leave printColor blank. The system's printer settings will be used instead.
if (pxlOpts.getColorType() != PrintOptions.ColorType.DEFAULT) {
settings.setPrintColor(getColor(pxlOpts));
}
if (pxlOpts.getDuplex() == Sides.DUPLEX || pxlOpts.getDuplex() == Sides.TWO_SIDED_LONG_EDGE) {
Expand Down
3 changes: 2 additions & 1 deletion src/qz/printer/action/PrintPixel.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ protected PrintRequestAttributeSet applyDefaultSettings(PrintOptions.Pixel pxlOp
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();

//apply general attributes
if (pxlOpts.getColorType() != null) {
// If colortype is default, leave printColor blank. The system's printer settings will be used instead.
if (pxlOpts.getColorType() != PrintOptions.ColorType.DEFAULT) {
attributes.add(pxlOpts.getColorType().getAsChromaticity());
}
attributes.add(pxlOpts.getDuplex());
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
7 changes: 6 additions & 1 deletion src/qz/printer/info/NativePrinterMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ public ArrayList<PrintService> findMissing(boolean exhaustive, PrintService[] se
ArrayList<PrintService> serviceList = new ArrayList<>(Arrays.asList(services)); // shrinking list drastically improves performance

for(NativePrinter printer : values()) {
if (serviceList.contains(printer.getPrintService())) {
int index = serviceList.indexOf(printer.getPrintService());
if (index >= 0) {
// Java's `PrintService.equals(o)` method uses getName().equals(). This causes issues if a stale PrintService has been replaced
// by a new PrintService of the same name. For that reason, we always refresh the PrintService reference in NativePrinter.
// See: https://github.com/qzind/tray/issues/1259
printer.setPrintService(serviceList.get(index));
serviceList.remove(printer.getPrintService()); // existing match
} else {
if(exhaustive) {
Expand Down
4 changes: 2 additions & 2 deletions src/qz/printer/status/job/NativeJobStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public enum NativeJobStatus implements NativeStatus {
ABORTED(Level.ERROR),
CANCELED(Level.WARN),
COMPLETE(Level.INFO),
DELETED(Level.WARN),
DELETING(Level.WARN),
DELETED(Level.INFO),
DELETING(Level.INFO),
ERROR(Level.ERROR),
OFFLINE(Level.ERROR),
PRINTING(Level.INFO),
Expand Down
Loading

0 comments on commit c4383fc

Please sign in to comment.