ztxkutils 2.10.66-35 → 2.10.66-37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/print.js +7 -4
  2. package/package.json +1 -1
package/dist/print.js CHANGED
@@ -58,7 +58,7 @@ function printCurrentDom(_a) {
58
58
  document.head.appendChild(styleDom);
59
59
  window.print();
60
60
  }
61
- function getTextDimensions(text) {
61
+ function getTextDimensions(text, fontSize) {
62
62
  // 创建一个临时元素
63
63
  var tempElement = document.createElement('div');
64
64
  // 设置元素内容为传入的文本
@@ -69,6 +69,9 @@ function getTextDimensions(text) {
69
69
  tempElement.style.opacity = '0'; // 完全透明
70
70
  tempElement.style.pointerEvents = 'none'; // 不响应鼠标事件
71
71
  tempElement.style.whiteSpace = 'nowrap'; // 防止文本换行影响宽度测量
72
+ tempElement.style.fontSize = fontSize;
73
+ tempElement.style.fontFamily = '微软雅黑';
74
+ tempElement.style.padding = '40px 10px';
72
75
  // 插入到body中
73
76
  document.body.appendChild(tempElement);
74
77
  // 获取元素的宽高
@@ -78,8 +81,8 @@ function getTextDimensions(text) {
78
81
  document.body.removeChild(tempElement);
79
82
  // 返回测量结果
80
83
  return {
81
- width: width > 340 ? 340 : width,
82
- height: height > 200 ? 200 : height,
84
+ width: width > 440 ? 440 : width < 240 ? 240 : width,
85
+ height: height > 200 ? 200 : height < 100 ? 100 : height,
83
86
  };
84
87
  }
85
88
  /**
@@ -103,7 +106,7 @@ function createWaterHandle(obj) {
103
106
  var _a = obj || {}, waterText = _a.waterText, opacity = _a.opacity, fontSize = _a.fontSize, cavansWidth = _a.cavansWidth, cavansHeight = _a.cavansHeight;
104
107
  var canvas = document.createElement('canvas');
105
108
  // 如何计算水印的大小。创建一个元素插入到body中,获取到宽高后移除
106
- var _b = getTextDimensions(waterText), textWidth = _b.width, textHeight = _b.height;
109
+ var _b = getTextDimensions(waterText, fontSize || '18px'), textWidth = _b.width, textHeight = _b.height;
107
110
  var defaultCanvasWidth = waterText
108
111
  ? waterText.length > 10
109
112
  ? textWidth
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.10.66-35",
3
+ "version": "2.10.66-37",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",