fix: 旋转从 CSS matrix 提取角度 + convert-browser.js 同步

This commit is contained in:
李进
2026-07-27 17:37:04 +08:00
parent c9924d0737
commit f0a19c71d4
2 changed files with 34 additions and 7 deletions
+8 -2
View File
@@ -851,11 +851,17 @@ async function convert(input) {
shapeOpts.rectRadius = Math.max(...brCorners); shapeOpts.rectRadius = Math.max(...brCorners);
} }
// 旋转(CSS transform: rotate // 旋转(CSS transform: rotate 或 matrix
if (n.styles.transform && n.styles.transform !== 'none') { if (n.styles.transform && n.styles.transform !== 'none') {
var rotateMatch = n.styles.transform.match(/rotate\(([\d.]+)deg\)/); var rotateMatch = n.styles.transform.match(/rotate\(([-\d.]+)deg\)/);
if (rotateMatch) { if (rotateMatch) {
shapeOpts.rotate = parseFloat(rotateMatch[1]); shapeOpts.rotate = parseFloat(rotateMatch[1]);
} else {
var matrixMatch = n.styles.transform.match(/matrix\(([-\d.]+),\s*([-\d.]+),\s*([-\d.]+),\s*([-\d.]+)/);
if (matrixMatch) {
var angle = Math.round(Math.atan2(parseFloat(matrixMatch[2]), parseFloat(matrixMatch[1])) * 180 / Math.PI);
if (angle !== 0) shapeOpts.rotate = angle;
}
} }
} }
+26 -5
View File
@@ -450,11 +450,32 @@ async function convertToPptx(input, onProgress) {
shapeOpts.fill.transparency = Math.max(shapeOpts.fill.transparency || 0, opTrans); shapeOpts.fill.transparency = Math.max(shapeOpts.fill.transparency || 0, opTrans);
} }
// 圆角 // 圆角(取四角最大值)
var brVal = n.styles.borderTopLeftRadius; var brCorners = [
if (brVal && brVal !== '0px') { n.styles.borderTopLeftRadius,
if (brVal.includes('%')) shapeOpts.rectRadius = parseFloat(brVal) / 100; n.styles.borderTopRightRadius,
else shapeOpts.rectRadius = parseFloat(brVal) / 72; n.styles.borderBottomLeftRadius,
n.styles.borderBottomRightRadius
].filter(function(v) { return v && v !== '0px'; }).map(function(v) {
if (v.includes('%')) return parseFloat(v) / 100;
return parseFloat(v) / 72;
});
if (brCorners.length > 0) {
shapeOpts.rectRadius = Math.max.apply(null, brCorners);
}
// 旋转
if (n.styles.transform && n.styles.transform !== 'none') {
var rotateMatch = n.styles.transform.match(/rotate\(([-\d.]+)deg\)/);
if (rotateMatch) {
shapeOpts.rotate = parseFloat(rotateMatch[1]);
} else {
var matrixMatch = n.styles.transform.match(/matrix\(([-\d.]+),\s*([-\d.]+),\s*([-\d.]+),\s*([-\d.]+)/);
if (matrixMatch) {
var angle = Math.round(Math.atan2(parseFloat(matrixMatch[2]), parseFloat(matrixMatch[1])) * 180 / Math.PI);
if (angle !== 0) shapeOpts.rotate = angle;
}
}
} }
// 边框 // 边框