shaoyongjun 0bd5a87973 to:sync
2024-11-05 22:43:34 +08:00

37 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
define(function (require, exports, module) {
class A4Utils {
constructor() {
let dpi = this.GetDPI();
let width_mm = 210; // A4纸宽度单位毫米
let height_mm = 297; // A4纸高度单位毫米
let width_px = this.MmToPixel(width_mm, dpi);
let height_px = this.MmToPixel(height_mm, dpi);
this.width = width_px;
this.height = height_px;
}
/**
* A4纸
*/
GetDPI() {
let tempDiv = document.createElement("div");
tempDiv.style.width = "1in";
tempDiv.style.visibility = "hidden";
document.body.appendChild(tempDiv);
let dpi = tempDiv.offsetWidth;
document.body.removeChild(tempDiv);
return dpi;
}
MmToPixel(mm, dpi) {
// 1 inch = 25.4 mm
let inches = mm / 25.4;
let pixels = inches * dpi;
return Math.round(pixels);
}
}
module.exports = new A4Utils();
})