svgcanvas
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "svgcanvas" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-b4ede391c954d2f66f942a9e0d5a6577e5c4344e2364d59c81ef23ee727a6969. Verify the upstream source and version against https://skillhub.cn/skills/user_3ff3c268/svg-to-canvas-replica before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Purpose: Replicate an A4 SVG source (viewBox 21000×29700) onto Canvas 2D with zero-error transfer of coordinates, text, and styles. Features include SVG parsing (supports rect/line/polygon/text/image and <style> class mapping), SVG-to-pixel coordinate conversion (scale 0.0590476), page-number element detection (footer-text and pure digits), and school/organization rendering mode switch. Trigger phrases: replicate SVG template, draw SVG to Canvas, restore paper template, zero-error replication, extract SVG coordinates. Pure front-end implementation with zero dependencies; compatible with browsers and WeChat mini programs.
Introduction source: third_party · user_3ff3c268 · 1.2.0 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Limits and differences
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: SVG 转 Canvas 精确复刻管线
display_name: SVG 精准复刻到 Canvas(印刷级还原)
description: 将 A4 SVG 源文件(viewBox 21000×29700)的坐标/文字/样式零误差复刻到 Canvas 2D。含 SVG 解析(rect/line/polygon/text/image + <style> class 映射)、SVG→px 坐标换算(0.0590476)、页码元素检测(footer-text+纯数字)、学校版/机构版渲染切换。触发词:复刻 SVG 模板/把 svg 画到 canvas/还原纸质模板/零误差复刻/提取 SVG 坐标。纯前端零依赖,浏览器与微信小程序通用。
market_desc: 将 A4 SVG 源文件的坐标/文字/样式零误差复刻到 Canvas 2D:解析 rect/line/polygon/text/image + 样式类映射,坐标系换算,页码元素检测。适合把设计稿、图表、模板精准还原成可绘制的 Canvas。纯前端零依赖。 【闭环归属】本技能是「Canvas 内容工厂闭环」的第 3 步(共 3 步:网格→PDF→SVG 复刻)。要可打印内容 + 精准还原设计稿,配齐这 3 个技能即可;总控入口:canvas-content-factory。
version: 1.2.0
tags: [canvas, svg, 复刻, 还原, 打印, 微信小程序]
changelog: 升级 v1.2.0:中性化署名、场景拓宽、补充闭环归属交叉引用。
SVG 转 Canvas 精确复刻管线
工具模块。纯前端 Canvas 2D,零依赖。
这是什么(给人看)
你手上有现成的纸质模板 SVG(比如作业纸、练字纸、表格),想把它变成能在小程序/网页里自由改字、缩放、导出 PDF 的画面?本技能把 SVG 的每一个坐标、线条、文字、图片零误差搬到 Canvas 上——不是截图,是矢量的、可再编辑的。学校版/机构版模板还能一键切换。复刻任何纸质模板都通用。
- 已附
selftest.js:用桩 ctx 验证"坐标真的被换算对",PASS 才算靠谱。
何时使用
- "把这个 SVG 模板复刻成 Canvas" / "把 svg 画到 canvas 上"
- 需要精准还原某个纸质模板(坐标系、线型、字号一致)
- 模板有学校版/机构版两种样式要切换
坐标系换算(AI 必读)
| 坐标系 | 尺寸 | 关系 |
|---|---|---|
| SVG viewBox | 21000 × 29700 | 1 单位 = 0.01mm |
| 物理 | 210 × 297 mm | A4 |
| Canvas px | 1240 × 1754 | 150dpi |
var SVG_TO_PX = 0.0590476; // SVG 单位 → Canvas px(日常用这项)
// 元素坐标保持 SVG 单位解析,渲染时统一 * SVG_TO_PX
数据提取流程
- 读 SVG 文本 → 正则
<style>动态解析 class →{stroke,strokeWidth,dashArray}/fill/{fontSize,fontFamily,fontWeight} - 解析
<rect><line><polygon><text><image>,坐标保持 SVG 单位(不转换) - 学校版机构版切换:行数不同(
rows/rowsInst),核心绘制逻辑共享 - 渲染时
renderElements(ctx, elements)把每个坐标* SVG_TO_PX
核心函数签名(AI 直接调用)
// 解析 SVG 文本 → { source, totalElements, elements:[{type,x,y,w,h,stroke,fill,classes,...}] }
SvgToElements.parseSVG(svgText, sourceName, imgBase)
// 复刻渲染:自动 *SVG_TO_PX;image 需调用方提供 drawImage 加载逻辑
Replica.renderElements(ctx, elements, { scale?, drawImage? })
// 页码元素识别:classes 含 'footer-text' 且 text 为纯数字 → 返回该元素(供 drawAll 替换为页码)
Replica.detectPageNo(elements) // -> element | null
// 模板配置 JSON 结构(源自 SVG 实测)
// { name, grid:{ cellW, cellH, cols, rows, rowsInst, startX, startY },
// features:{ errorRow, pinyin, correctionCol },
// branding:{ logo:{x,y,w,h}, qr:{x,y,w,h}, slogan } }
反例(避免)
- ❌ 手算坐标(易错):一律
* SVG_TO_PX,零人工推算。 - ❌ 复刻后丢失 class 样式:
<style>必须动态解析,不能硬编码颜色。 - ❌ 机构版也画学校版行数:渲染前按
isInstitution取rowsInst。 - ❌ 图片直接丢:
<image>需调用方按defaultSrc加载后再drawImage。
自测
node references/selftest.js # 验证解析/坐标换算/页码检测/复刻坐标,PASS 方可交付
引用文件
references/svg-to-elements.js— SVG 解析模块(UMD)references/replica.js— Canvas 复刻渲染 + 页码检测(UMD)references/selftest.js— Node 自测(桩 ctx 验证坐标换算)
注意事项
- 元素坐标为 SVG 单位,渲染统一缩放;Canvas 内部尺寸固定 1240×1754。
- 与
canvas-grid-engine(负责"画"新网格)互补:本技能负责"复刻"已有模板。
Canvas 工具链(组合使用)
本技能是「Canvas 工具链」的一环,四件组合覆盖「画 → 复刻 → 导出 → 验证」完整闭环:
- Canvas 学习纸网格引擎(画):13 种教育网格 + 汉字居中 + 拼音标注,生成米字格/田字格字帖。
- SVG 转 Canvas 复刻引擎(复刻):把现有纸质模板 SVG 零误差复刻成可改字、可打印的 Canvas。
- Canvas 多页 PDF 导出(导出):多页 Canvas 一键合成标准 A4 PDF 直接打印。
- 小程序 Canvas 验证工作流(验证):本地预览 + 截图视觉回归,杜绝格子歪、字偏。
完整方案与演示见「 Canvas 工具链落地页」(链接发布后回填)。
Current listing version
1.2.0
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 SVG 到 Canvas 零误差复刻功能,解决教育模板、设计稿还原等实际需求
- 与网格生成、PDF 导出形成完整工具链,具备闭环价值
Highlights
- 触发词覆盖全面且边界清晰,如“复刻 SVG 模板”、“零误差复刻”等
Areas to improve
-
文档过长 Reported severity: Minor
SKILL.md 内容约 600 行,超出建议长度
Recommendation: 建议精简重复说明,保留核心流程与关键参数
Highlights
- 结构清晰,包含坐标系换算、核心函数、反例、自测等完整模块
- frontmatter 完整,引用文件明确
Highlights
- 提供自测脚本验证坐标换算,确保执行可靠性
- UMD 模块设计,参数说明清晰,异常处理合理
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.