diff --git a/css/style.css b/css/style.css
index 98ebdedd2..b79e0f558 100644
--- a/css/style.css
+++ b/css/style.css
@@ -381,6 +381,10 @@ button > .fa-caret-down {
border-bottom: 1px dashed;
}
+summary {
+ cursor: pointer;
+}
+
code {
color: #31708F;
background-color: #D9EDF7;
diff --git a/sample.html b/sample.html
index 6ffd3ad36..b493a419d 100755
--- a/sample.html
+++ b/sample.html
@@ -1613,6 +1613,7 @@
Options
"Density: " + data[i].density + "dpi" +
"Connection: " + data[i].connection + "" +
(data[i].trays ? "Trays: " + data[i].trays + "" : "") +
+ accumulateSizes(data[i]) +
"";
}
@@ -1620,6 +1621,45 @@ Options
}).catch(displayError);
}
+ function accumulateSizes(data) {
+ var html = "";
+ if(data.sizes) {
+ var html = "Sizes: (" + data.sizes.length + ")
";
+ var sizes = data.sizes;
+ html += "";
+ for(var size in sizes) {
+ html += "" + sizes[size].name + "
";
+
+ var inch = sizes[size].in.width + " x " + sizes[size].in.height;
+ var mill = sizes[size].mm.width + " x " + sizes[size].mm.height;
+
+ var inchTrunc = truncate(sizes[size].in.width, 3) + " x " + truncate(sizes[size].in.height, 3);
+ var millTrunc = truncate(sizes[size].mm.width, 3) + " x " + truncate(sizes[size].mm.height, 3);
+
+ html += "- in: " + inchTrunc + "
";
+ html += "- mm: " + millTrunc + "
";
+
+ html += "
";
+ }
+ html += "
";
+ }
+ return html;
+ }
+
+ function truncate(val, length, ellipsis) {
+ var truncated;
+ if(isNaN(val)) {
+ truncated = val.substring(0, length);
+ } else {
+ var mult = Math.pow(10, length);
+ truncated = Math.floor(val * mult) / mult;
+ }
+ if(ellipsis === false) {
+ return truncated;
+ }
+ return val === truncated ? val : truncated + "…";
+ }
+
/// Raw Printers ///
function printCommand() {
diff --git a/src/qz/printer/PrintServiceMatcher.java b/src/qz/printer/PrintServiceMatcher.java
index b474af2ae..e77a29d42 100644
--- a/src/qz/printer/PrintServiceMatcher.java
+++ b/src/qz/printer/PrintServiceMatcher.java
@@ -22,11 +22,8 @@
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.ResolutionSyntax;
-import javax.print.attribute.standard.Media;
-import javax.print.attribute.standard.MediaTray;
-import javax.print.attribute.standard.PrinterName;
-import javax.print.attribute.standard.PrinterResolution;
-import java.util.Locale;
+import javax.print.attribute.standard.*;
+import java.util.*;
public class PrintServiceMatcher {
private static final Logger log = LogManager.getLogger(PrintServiceMatcher.class);
@@ -174,8 +171,35 @@ public static JSONArray getPrintersJSON(boolean includeDetails) throws JSONExcep
log.info("Gathering printer MediaTray information...");
mediaTrayCrawled = true;
}
+
+ HashSet uniqueSizes = new HashSet<>();
+
for(Media m : (Media[])ps.getSupportedAttributeValues(Media.class, null, null)) {
if (m instanceof MediaTray) { jsonService.accumulate("trays", m.toString()); }
+ if (m instanceof MediaSizeName) {
+ if(uniqueSizes.add(m.toString())) {
+ MediaSize mediaSize = MediaSize.getMediaSizeForName((MediaSizeName)m);
+ if(mediaSize == null) {
+ continue;
+ }
+
+ JSONObject sizes = new JSONObject();
+ sizes.put("name", m.toString());
+
+ JSONObject in = new JSONObject();
+ in.put("width", mediaSize.getX(MediaPrintableArea.INCH));
+ in.put("height", mediaSize.getY(MediaPrintableArea.INCH));
+ sizes.put("in", in);
+
+ JSONObject mm = new JSONObject();
+ mm.put("width", mediaSize.getX(MediaPrintableArea.MM));
+ mm.put("height", mediaSize.getY(MediaPrintableArea.MM));
+ sizes.put("mm", mm);
+
+ jsonService.accumulate("sizes", sizes);
+ }
+
+ }
}
PrinterResolution res = printer.getResolution().value();