### Install Dependencies Source: https://github.com/hitoysmaker/fontplayer/blob/main/README.md Install the necessary project dependencies. ```bash npm run install ``` -------------------------------- ### Run Development Server Source: https://github.com/hitoysmaker/fontplayer/blob/main/README.md Start the development server for the application. ```bash npm run dev ``` -------------------------------- ### Build Tauri Application Source: https://github.com/hitoysmaker/fontplayer/blob/main/README.md Package the application using Tauri. ```bash npx tauri build ``` -------------------------------- ### Run Tauri Development Environment Source: https://github.com/hitoysmaker/fontplayer/blob/main/README.md Test the application within the Tauri development environment. ```bash npx tauri dev ``` -------------------------------- ### FontPlayer Base Styles and Loading Animations Source: https://github.com/hitoysmaker/fontplayer/blob/main/index.html Defines the full-screen layout for the application and three distinct loading animation keyframes. ```css body, html { width: 100%; height: 100%; position: relative; padding: 0; margin: 0; overflow: hidden; } .empty { .empty-loading { .loading-1 { animation: loading-1 2s; animation-iteration-count: infinite; } .loading-2 { animation: loading-2 2s; animation-iteration-count: infinite; } .loading-3 { animation: loading-3 2s; animation-iteration-count: infinite; } } } @keyframes loading-1 { 0% { opacity: 1; } 25% { opacity: 0.5; } 50% { opacity: 1; } } @keyframes loading-2 { 0% { opacity: 1; } 50% { opacity: 0.5; } 75% { opacity: 1; } } @keyframes loading-3 { 0% { opacity: 1; } 75% { opacity: 0.5; } 100% { opacity: 1; } } ``` -------------------------------- ### 重叠矩形测试逻辑 Source: https://github.com/hitoysmaker/fontplayer/blob/main/public/test-overlap-fix.html 执行重叠矩形的去除测试,并在页面上显示结果及绘制合并前后的轮廓。 ```javascript // 测试1: 重叠矩形 window.testOverlappingRectangles = async function() { const resultDiv = document.getElementById('result1'); resultDiv.innerHTML = '

正在测试...

'; resultDiv.className = 'test-result'; try { // 确保WASM模块已初始化 if (!remove_overlap) { await initWasm(); } const result = await remove_overlap(JSON.stringify(testContours)); const parsedResult = JSON.parse(result); // 绘制原始轮廓 drawContours('canvas1', testContours, '原始轮廓'); // 绘制结果 setTimeout(() => { drawContours('canvas1', parsedResult, '合并后结果'); }, 1000); resultDiv.innerHTML = `

✅ 测试成功!

输入轮廓数: ${testContours.length}

输出轮廓数: ${parsedResult.length}

详细结果
${JSON.stringify(parsedResult, null, 2)}
`; resultDiv.className = 'test-result success'; } catch (error) { resultDiv.innerHTML = `

❌ 测试失败: ${error.message}

`; resultDiv.className = 'test-result error'; } }; ``` -------------------------------- ### 带孔洞形状测试逻辑 Source: https://github.com/hitoysmaker/fontplayer/blob/main/public/test-overlap-fix.html 执行带孔洞形状的去除测试,并在页面上显示结果及绘制处理前后的轮廓。 ```javascript // 测试2: 带孔洞的形状 window.testShapeWithHole = async function() { const resultDiv = document.getElementById('result2'); resultDiv.innerHTML = '

正在测试...

'; resultDiv.className = 'test-result'; try { // 确保WASM模块已初始化 if (!remove_overlap) { await initWasm(); } const result = await remove_overlap(JSON.stringify(testContoursWithHole)); const parsedResult = JSON.parse(result); // 绘制原始轮廓 drawContours('canvas2', testContoursWithHole, '原始轮廓(带孔洞)'); // 绘制结果 setTimeout(() => { drawContours('canvas2', parsedResult, '处理后结果'); }, 1000); resultDiv.innerHTML = `

✅ 测试成功!

输入轮廓数: ${testContoursWithHole.length}

输出轮廓数: ${parsedResult.length}

``` -------------------------------- ### testComplexShape function implementation Source: https://github.com/hitoysmaker/fontplayer/blob/main/public/test-overlap-fix.html This function initializes the WASM module, processes a set of overlapping contours, and updates the UI with the test results and visualizations. ```javascript window.testComplexShape = async function() { const resultDiv = document.getElementById('result3'); resultDiv.innerHTML = '

正在测试...

'; resultDiv.className = 'test-result'; try { // 创建一个复杂的测试形状 const complexContours = [ // 外轮廓 [ { type: 'LINE', start: { x: 50, y: 50 }, end: { x: 200, y: 50 } }, { type: 'LINE', start: { x: 200, y: 50 }, end: { x: 200, y: 200 } }, { type: 'LINE', start: { x: 200, y: 200 }, end: { x: 50, y: 200 } }, { type: 'LINE', start: { x: 50, y: 200 }, end: { x: 50, y: 50 } } ], // 重叠的圆形(用多边形近似) [ { type: 'LINE', start: { x: 100, y: 100 }, end: { x: 150, y: 100 } }, { type: 'LINE', start: { x: 150, y: 100 }, end: { x: 150, y: 150 } }, { type: 'LINE', start: { x: 150, y: 150 }, end: { x: 100, y: 150 } }, { type: 'LINE', start: { x: 100, y: 150 }, end: { x: 100, y: 100 } } ] ]; // 确保WASM模块已初始化 if (!remove_overlap) { await initWasm(); } const result = await remove_overlap(JSON.stringify(complexContours)); const parsedResult = JSON.parse(result); // 绘制原始轮廓 drawContours('canvas3', complexContours, '复杂形状'); // 绘制结果 setTimeout(() => { drawContours('canvas3', parsedResult, '处理后结果'); }, 1000); resultDiv.innerHTML = `

✅ 测试成功!

输入轮廓数: ${complexContours.length}

输出轮廓数: ${parsedResult.length}

详细结果
${JSON.stringify(parsedResult, null, 2)}
`; resultDiv.className = 'test-result success'; } catch (error) { resultDiv.innerHTML = `

❌ 测试失败: ${error.message}

`; resultDiv.className = 'test-result error'; } }; ``` -------------------------------- ### WASM 模块初始化与测试数据定义 Source: https://github.com/hitoysmaker/fontplayer/blob/main/public/test-overlap-fix.html 初始化 WASM 模块并定义用于测试的轮廓数据结构,包括重叠矩形和带孔洞的形状。 ```javascript // 导入WASM模块 import wasmModule from './overlap_wasm.js'; // 初始化WASM模块 let remove_overlap; async function initWasm() { try { await wasmModule(); remove_overlap = wasmModule.remove_overlap; console.log('WASM module initialized successfully'); } catch (error) { console.error('Failed to initialize WASM module:', error); throw error; } } // 测试数据:两个重叠的矩形 const testContours = [ [ // 第一个矩形(外轮廓) { type: 'LINE', start: { x: 50, y: 50 }, end: { x: 150, y: 50 } }, { type: 'LINE', start: { x: 150, y: 50 }, end: { x: 150, y: 150 } }, { type: 'LINE', start: { x: 150, y: 150 }, end: { x: 50, y: 150 } }, { type: 'LINE', start: { x: 50, y: 150 }, end: { x: 50, y: 50 } } ], [ // 第二个矩形(与第一个重叠) { type: 'LINE', start: { x: 100, y: 100 }, end: { x: 200, y: 100 } }, { type: 'LINE', start: { x: 200, y: 100 }, end: { x: 200, y: 200 } }, { type: 'LINE', start: { x: 200, y: 200 }, end: { x: 100, y: 200 } }, { type: 'LINE', start: { x: 100, y: 200 }, end: { x: 100, y: 100 } } ] ]; // 测试数据:带孔洞的形状 const testContoursWithHole = [ [ // 外轮廓(逆时针) { type: 'LINE', start: { x: 50, y: 50 }, end: { x: 250, y: 50 } }, { type: 'LINE', start: { x: 250, y: 50 }, end: { x: 250, y: 250 } }, { type: 'LINE', start: { x: 250, y: 250 }, end: { x: 50, y: 250 } }, { type: 'LINE', start: { x: 50, y: 250 }, end: { x: 50, y: 50 } } ], [ // 内轮廓(孔洞,顺时针) { type: 'LINE', start: { x: 100, y: 100 }, end: { x: 100, y: 200 } }, { type: 'LINE', start: { x: 100, y: 200 }, end: { x: 200, y: 200 } }, { type: 'LINE', start: { x: 200, y: 200 }, end: { x: 200, y: 100 } }, { type: 'LINE', start: { x: 200, y: 100 }, end: { x: 100, y: 100 } } ] ]; ``` -------------------------------- ### 轮廓绘制函数 drawContours Source: https://github.com/hitoysmaker/fontplayer/blob/main/public/test-overlap-fix.html 将定义的轮廓数据绘制到指定的 HTML Canvas 元素上,支持直线和三次贝塞尔曲线。 ```javascript // 绘制轮廓到canvas function drawContours(canvasId, contours, title) { const canvas = document.getElementById(canvasId); const ctx = canvas.getContext('2d'); // 清空画布 ctx.clearRect(0, 0, canvas.width, canvas.height); // 设置样式 ctx.strokeStyle = '#000'; ctx.lineWidth = 2; ctx.fillStyle = 'rgba(0, 100, 255, 0.3)'; // 绘制标题 ctx.fillStyle = '#000'; ctx.font = '16px Arial'; ctx.fillText(title, 10, 20); // 绘制每个轮廓 contours.forEach((contour, index) => { if (contour.length === 0) return; ctx.beginPath(); ctx.moveTo(contour[0].start.x, contour[0].start.y); contour.forEach(segment => { if (segment.type === 'LINE') { ctx.lineTo(segment.end.x, segment.end.y); } else if (segment.type === 'CUBIC_BEZIER') { ctx.bezierCurveTo( segment.control1.x, segment.control1.y, segment.control2.x, segment.control2.y, segment.end.x, segment.end.y ); } }); ctx.closePath(); ctx.fill(); ctx.stroke(); }); } ``` -------------------------------- ### Test WASM Function Source: https://github.com/hitoysmaker/fontplayer/blob/main/public/test-wasm.html This function dynamically imports the WASM module, initializes it, and executes the remove_overlap function with sample contour data. It updates the DOM with the test status and results. ```javascript async function testWasm() { const statusDiv = document.getElementById('status'); const resultDiv = document.getElementById('result'); try { statusDiv.textContent = 'Loading WASM module...'; // 使用动态import加载WASM模块 const wasmModule = await import('/overlap_wasm.js'); statusDiv.textContent = 'Initializing WASM...'; // 初始化WASM模块 await wasmModule.default(); statusDiv.textContent = 'WASM initialized successfully!'; // 测试函数 const testContours = [ [ { type: 'LINE', start: { x: 0, y: 0 }, end: { x: 100, y: 0 } }, { type: 'LINE', start: { x: 100, y: 0 }, end: { x: 100, y: 100 } }, { type: 'LINE', start: { x: 100, y: 100 }, end: { x: 0, y: 100 } }, { type: 'LINE', start: { x: 0, y: 100 }, end: { x: 0, y: 0 } } ] ]; const result = wasmModule.remove_overlap(JSON.stringify(testContours)); const parsedResult = JSON.parse(result); resultDiv.innerHTML = `

Test Result:

${JSON.stringify(parsedResult, null, 2)}
`; statusDiv.textContent = '✅ WASM test completed successfully!'; } catch (error) { statusDiv.textContent = `❌ Error: ${error.message}`; console.error('WASM test error:', error); } } // 页面加载时自动测试 window.addEventListener('load', testWasm); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.