2024-11-05 22:43:34 +08:00
|
|
|
|
"use strict";
|
|
|
|
|
define(function (require, exports, module) {
|
|
|
|
|
class A4Utils {
|
|
|
|
|
constructor() {
|
2024-11-10 01:51:52 +08:00
|
|
|
|
// let dpi = this.GetDPI();
|
|
|
|
|
// console.log("dpi: ", dpi)
|
2024-11-08 10:09:31 +08:00
|
|
|
|
//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
|
2024-11-05 22:43:34 +08:00
|
|
|
|
let width_mm = 210; // A4纸宽度,单位:毫米
|
|
|
|
|
let height_mm = 297; // A4纸高度,单位:毫米
|
2024-11-10 01:51:52 +08:00
|
|
|
|
// let width_px = this.MmToPixel(width_mm, dpi);
|
|
|
|
|
// let height_px = this.MmToPixel(height_mm, dpi);
|
|
|
|
|
// this.width = width_px;
|
|
|
|
|
this.width = 750; //按照iphone6
|
|
|
|
|
// this.height = height_px;
|
2024-11-05 22:43:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A4纸
|
2024-11-08 10:09:31 +08:00
|
|
|
|
* 计算 dpi
|
2024-11-05 22:43:34 +08:00
|
|
|
|
*/
|
|
|
|
|
GetDPI() {
|
|
|
|
|
let tempDiv = document.createElement("div");
|
|
|
|
|
tempDiv.style.width = "1in";
|
2024-11-08 10:09:31 +08:00
|
|
|
|
tempDiv.style.height = "1in";
|
2024-11-05 22:43:34 +08:00
|
|
|
|
tempDiv.style.visibility = "hidden";
|
2024-11-08 10:09:31 +08:00
|
|
|
|
//
|
|
|
|
|
// tempDiv.style.position = "fixed"
|
|
|
|
|
// tempDiv.style.top = "0px"
|
|
|
|
|
// tempDiv.style.left = "0px"
|
2024-11-05 22:43:34 +08:00
|
|
|
|
document.body.appendChild(tempDiv);
|
|
|
|
|
let dpi = tempDiv.offsetWidth;
|
2024-11-10 01:51:52 +08:00
|
|
|
|
alert(123)
|
2024-11-05 22:43:34 +08:00
|
|
|
|
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();
|
|
|
|
|
})
|