fix: 旋转从 CSS matrix 提取角度 + convert-browser.js 同步
This commit is contained in:
+8
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 边框
|
||||
|
||||
Reference in New Issue
Block a user