var originalRect = annots[0][0].getRect()
// 原矩形坐标(原点:左下角)
const originalRect = {
left: 167.17929077148438,
bottom: 288.0683898925781,
right: 317.1792907714844,
top: 333.0683898925781
};
/**
- 以矩形中心为基准缩放,返回新的边框坐标(左下角原点)
- @param {object} rect 原矩形 {left, bottom, right, top}
- @param {number} scale 缩放比例(1=原大小,1.2=放大20%,0.8=缩小20%)
- @returns {object} 新矩形坐标
*/
function scaleFromCenter(rect, scale) {
// 1. 计算原宽高
const width = rect.right - rect.left;const height = rect.top - rect.bottom;
// 2. 计算中心点坐标(左下角原点)
const centerX = rect.left + width / 2;
const centerY = rect.bottom + height / 2;
// 3. 计算缩放后的新宽高
const newWidth = width * scale;
const newHeight = height * scale;
// 4. 以中心为基准计算新坐标
const newLeft = centerX - newWidth / 2;
const newRight = centerX + newWidth / 2;
const newBottom = centerY - newHeight / 2;
const newTop = centerY + newHeight / 2;
return {
left: newLeft,
bottom: newBottom,
right: newRight,
top: newTop
};
}