wangxichen 5 ngày trước cách đây
mục cha
commit
2c4f8a9236

+ 20 - 1
src/com/mes/print/Printer.java

@@ -73,4 +73,23 @@ public class Printer {
 	public static String getCurrentName() {
 		return com.mes.print.config.PrinterConfig.get("printer.name", "");
 	}
-}
+
+        /**
+         * 预热:初始化打印实现 + (HP 模式) 提前加载流转卡模板/字体
+         * 建议在主程序启动时异步调用一次,避免首单打印卡顿
+         */
+        public static void warmUp() {
+                long t0 = System.currentTimeMillis();
+                try {
+                        PrinterFactory.get();
+                } catch (Exception e) {
+                        System.err.println("[Printer] 工厂预热失败: " + e.getMessage());
+                        return;
+                }
+                String type = getCurrentType();
+                if ("hp".equals(type)) {
+                        com.mes.print.template.FlowCardRenderer.warmUp();
+                }
+                System.out.println("[Printer] 预热总耗时 " + (System.currentTimeMillis() - t0) + "ms");
+        }
+}

+ 17 - 1
src/com/mes/print/template/FlowCardRenderer.java

@@ -200,4 +200,20 @@ public class FlowCardRenderer {
 			return null;
 		}
 	}
-}
+
+        /**
+         * 预热:提前加载 PDF 模板 + 渲染底图 + 探测中文字体
+         * 首次调用耗时约 3-5s,后续 render() 只要几十毫秒
+         */
+        public static void warmUp() {
+                long t0 = System.currentTimeMillis();
+                try {
+                        getTemplateImage();
+                        pickChineseFont(TEXT_FONT_SIZE);
+                        System.out.println("[流转卡] 预热完成 " + (System.currentTimeMillis() - t0) + "ms");
+                } catch (Exception e) {
+                        System.err.println("[流转卡] 预热失败: " + e.getMessage());
+                }
+        }
+
+}