File size: 12,693 Bytes
ad7128b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>矢量元素导出调试</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.test-section {
margin-bottom: 30px;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
}
.test-title {
font-size: 18px;
font-weight: bold;
margin-bottom: 15px;
color: #333;
}
.svg-container {
display: inline-block;
margin: 10px;
border: 1px solid #ccc;
padding: 10px;
background: white;
}
.debug-info {
background: #f8f9fa;
padding: 10px;
margin-top: 10px;
border-radius: 4px;
font-family: monospace;
font-size: 12px;
}
button {
background: #007bff;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #0056b3;
}
.error {
color: #dc3545;
background: #f8d7da;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
}
.success {
color: #155724;
background: #d4edda;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
}
</style>
</head>
<body>
<div class="container">
<h1>PPT矢量元素导出问题诊断</h1>
<div class="test-section">
<div class="test-title">1. 基础形状元素测试</div>
<div class="svg-container">
<svg width="100" height="100" id="basic-shape">
<path d="M10,10 L90,10 L90,90 L10,90 Z"
fill="#ff6b6b"
stroke="#333"
stroke-width="2"
vector-effect="non-scaling-stroke"/>
</svg>
<div class="debug-info">基础矩形 - 100x100px</div>
</div>
<div class="svg-container">
<svg width="100" height="100" id="circle-shape">
<circle cx="50" cy="50" r="40"
fill="#4ecdc4"
stroke="#333"
stroke-width="2"
vector-effect="non-scaling-stroke"/>
</svg>
<div class="debug-info">圆形 - 半径40px</div>
</div>
</div>
<div class="test-section">
<div class="test-title">2. 复杂路径元素测试</div>
<div class="svg-container">
<svg width="120" height="100" id="complex-path">
<path d="M20,80 C20,80 20,20 50,20 S80,20 80,50 S80,80 50,80 S20,80 20,80"
fill="#45b7d1"
stroke="#333"
stroke-width="2"
vector-effect="non-scaling-stroke"/>
</svg>
<div class="debug-info">复杂曲线路径</div>
</div>
<div class="svg-container">
<svg width="100" height="100" id="star-shape">
<path d="M50,5 L61,35 L95,35 L68,57 L79,91 L50,70 L21,91 L32,57 L5,35 L39,35 Z"
fill="#f7b731"
stroke="#333"
stroke-width="2"
vector-effect="non-scaling-stroke"/>
</svg>
<div class="debug-info">星形路径</div>
</div>
</div>
<div class="test-section">
<div class="test-title">3. 线条元素测试</div>
<div class="svg-container">
<svg width="120" height="80" id="line-element">
<path d="M10,40 L110,40"
stroke="#e74c3c"
stroke-width="3"
vector-effect="non-scaling-stroke"
marker-end="url(#arrowhead)"/>
<defs>
<marker id="arrowhead" markerWidth="10" markerHeight="7"
refX="9" refY="3.5" orient="auto">
<polygon points="0 0, 10 3.5, 0 7" fill="#e74c3c"/>
</marker>
</defs>
</svg>
<div class="debug-info">带箭头的直线</div>
</div>
<div class="svg-container">
<svg width="120" height="80" id="curved-line">
<path d="M10,60 Q60,10 110,60"
stroke="#9b59b6"
stroke-width="3"
fill="none"
vector-effect="non-scaling-stroke"/>
</svg>
<div class="debug-info">二次贝塞尔曲线</div>
</div>
</div>
<div class="test-section">
<div class="test-title">4. 导出测试功能</div>
<button onclick="testSVGSerialization()">测试SVG序列化</button>
<button onclick="testBase64Conversion()">测试Base64转换</button>
<button onclick="testElementDimensions()">测试元素尺寸</button>
<button onclick="runAllTests()">运行所有测试</button>
<div id="test-results"></div>
</div>
<div class="test-section">
<div class="test-title">5. 问题诊断结果</div>
<div id="diagnosis-results">
<p>点击上方按钮开始诊断...</p>
</div>
</div>
</div>
<script>
// SVG序列化测试
function testSVGSerialization() {
const results = document.getElementById('test-results');
results.innerHTML = '<h4>SVG序列化测试结果:</h4>';
const svgElements = ['basic-shape', 'circle-shape', 'complex-path', 'star-shape', 'line-element', 'curved-line'];
svgElements.forEach(id => {
const svg = document.getElementById(id);
if (svg) {
try {
const serializer = new XMLSerializer();
const svgString = serializer.serializeToString(svg);
const isValid = svgString.length > 0 && svgString.includes('<svg');
results.innerHTML += `
<div class="${isValid ? 'success' : 'error'}">
<strong>${id}:</strong> ${isValid ? '✓ 序列化成功' : '✗ 序列化失败'}<br>
<small>长度: ${svgString.length} 字符</small>
</div>
`;
} catch (error) {
results.innerHTML += `
<div class="error">
<strong>${id}:</strong> ✗ 序列化异常: ${error.message}
</div>
`;
}
}
});
}
// Base64转换测试
function testBase64Conversion() {
const results = document.getElementById('test-results');
results.innerHTML = '<h4>Base64转换测试结果:</h4>';
const svg = document.getElementById('basic-shape');
if (svg) {
try {
const serializer = new XMLSerializer();
const svgString = serializer.serializeToString(svg);
const base64 = btoa(unescape(encodeURIComponent(svgString)));
const dataUrl = `data:image/svg+xml;base64,${base64}`;
results.innerHTML += `
<div class="success">
<strong>Base64转换:</strong> ✓ 成功<br>
<small>Data URL长度: ${dataUrl.length} 字符</small><br>
<img src="${dataUrl}" style="max-width: 100px; border: 1px solid #ccc; margin-top: 5px;">
</div>
`;
} catch (error) {
results.innerHTML += `
<div class="error">
<strong>Base64转换:</strong> ✗ 失败: ${error.message}
</div>
`;
}
}
}
// 元素尺寸测试
function testElementDimensions() {
const results = document.getElementById('test-results');
results.innerHTML = '<h4>元素尺寸测试结果:</h4>';
const svgElements = ['basic-shape', 'circle-shape', 'complex-path'];
svgElements.forEach(id => {
const svg = document.getElementById(id);
if (svg) {
const clientWidth = svg.clientWidth;
const clientHeight = svg.clientHeight;
const boundingRect = svg.getBoundingClientRect();
const isValidSize = clientWidth > 0 && clientHeight > 0;
results.innerHTML += `
<div class="${isValidSize ? 'success' : 'error'}">
<strong>${id}:</strong><br>
clientWidth: ${clientWidth}px<br>
clientHeight: ${clientHeight}px<br>
boundingRect: ${boundingRect.width}x${boundingRect.height}px<br>
${isValidSize ? '✓ 尺寸正常' : '✗ 尺寸异常 (可能导致导出失败)'}
</div>
`;
}
});
}
// 运行所有测试
function runAllTests() {
testSVGSerialization();
setTimeout(() => {
testBase64Conversion();
setTimeout(() => {
testElementDimensions();
setTimeout(generateDiagnosis, 500);
}, 500);
}, 500);
}
// 生成诊断报告
function generateDiagnosis() {
const diagnosisDiv = document.getElementById('diagnosis-results');
diagnosisDiv.innerHTML = `
<h4>诊断报告:</h4>
<div class="debug-info">
<strong>可能的问题原因:</strong><br>
1. SVG元素尺寸为0或负数 (clientWidth < 1 || clientHeight < 1)<br>
2. SVG序列化失败或返回空字符串<br>
3. Base64编码过程中出现错误<br>
4. 特殊形状元素(special=true)的DOM查询失败<br>
5. vector-effect="non-scaling-stroke"属性导致的兼容性问题<br><br>
<strong>建议的解决方案:</strong><br>
1. 在导出前检查SVG元素的实际渲染尺寸<br>
2. 添加SVG序列化的错误处理和重试机制<br>
3. 确保DOM元素在导出时已完全渲染<br>
4. 考虑使用setTimeout延迟导出以确保渲染完成<br>
5. 添加更详细的错误日志记录<br>
</div>
`;
}
// 页面加载完成后自动运行基础检查
window.addEventListener('load', () => {
console.log('矢量元素导出调试页面已加载');
console.log('可用的测试函数:', {
testSVGSerialization,
testBase64Conversion,
testElementDimensions,
runAllTests
});
});
</script>
</body>
</html> |