From f0a19c71d41f034c39f27003ed5068a66d5ac90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=BF=9B?= Date: Mon, 27 Jul 2026 17:37:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=8B=E8=BD=AC=E4=BB=8E=20CSS=20matr?= =?UTF-8?q?ix=20=E6=8F=90=E5=8F=96=E8=A7=92=E5=BA=A6=20+=20convert-browser?= =?UTF-8?q?.js=20=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convert-w2p.js | 10 ++++++++-- web-to-ppt/convert-browser.js | 31 ++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/convert-w2p.js b/convert-w2p.js index 00f1670..a3fae21 100644 --- a/convert-w2p.js +++ b/convert-w2p.js @@ -851,11 +851,17 @@ async function convert(input) { shapeOpts.rectRadius = Math.max(...brCorners); } - // 旋转(CSS transform: rotate) + // 旋转(CSS transform: rotate 或 matrix) 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) { 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; + } } } diff --git a/web-to-ppt/convert-browser.js b/web-to-ppt/convert-browser.js index b8cbac3..e68455d 100644 --- a/web-to-ppt/convert-browser.js +++ b/web-to-ppt/convert-browser.js @@ -450,11 +450,32 @@ async function convertToPptx(input, onProgress) { shapeOpts.fill.transparency = Math.max(shapeOpts.fill.transparency || 0, opTrans); } - // 圆角 - var brVal = n.styles.borderTopLeftRadius; - if (brVal && brVal !== '0px') { - if (brVal.includes('%')) shapeOpts.rectRadius = parseFloat(brVal) / 100; - else shapeOpts.rectRadius = parseFloat(brVal) / 72; + // 圆角(取四角最大值) + var brCorners = [ + n.styles.borderTopLeftRadius, + n.styles.borderTopRightRadius, + 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; + } + } } // 边框