shaoyongjun 57cdbdba50 to:sync
2024-11-08 10:09:31 +08:00

64 lines
1.8 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();
console.log("dpi: ", dpi)
//A0纸尺寸841mm×1189mm
//
// A1纸尺寸594mm×841mm
//
// A2纸尺寸420mm×594mm
//
// A3纸尺寸297mm×420mm
//
// A4纸尺寸210mm×297mm
//
// A5纸尺寸148mm×210mm
//
// A6纸尺寸105mm×148mm
//
// A7纸尺寸74mm×105mm
//
// A8纸尺寸52mm×74mm
//
// A9纸尺寸37mm×52mm
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纸
* 计算 dpi
*/
GetDPI() {
let tempDiv = document.createElement("div");
tempDiv.style.width = "1in";
tempDiv.style.height = "1in";
tempDiv.style.visibility = "hidden";
//
// tempDiv.style.position = "fixed"
// tempDiv.style.top = "0px"
// tempDiv.style.left = "0px"
document.body.appendChild(tempDiv);
let dpi = tempDiv.offsetWidth;
// alert(123)
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();
})