-
Notifications
You must be signed in to change notification settings - Fork 9
Feature/windows screenshot feature improve #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Particaly
wants to merge
2
commits into
ZToolsCenter:main
Choose a base branch
from
Particaly:feature/windows-screenshot-feature-improve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,6 @@ build/ | |
| *.dylib | ||
| *.log | ||
| .DS_Store | ||
|
|
||
| # 构建产物:由 scripts/gen-icons.js 从 src/assets/*.svg 生成 | ||
| src/generated/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * 把 src/assets/*.svg 生成成 C 头文件 src/generated/icon_svgs.h。 | ||
| * | ||
| * 输出形如: | ||
| * static const char* kIconSvg_Rect = "<svg ...>...</svg>"; | ||
| * | ||
| * SVG 原文原样保留(含 currentColor),运行时再把 currentColor 替换成 | ||
| * 目标颜色(normal/hover/active 三态),从而一套文本支持多色。 | ||
| * | ||
| * 自动生成,请勿手动编辑。 | ||
| */ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| // 工具栏按钮 -> SVG 文件名映射(顺序与 src/screenshot_windows.cpp 的 ToolButton 枚举一致) | ||
| // 分隔线(Separator)对应 null,不生成图标。 | ||
| const ICON_MAP = { | ||
| Rect: 'square', | ||
| Circle: 'circle', | ||
| Arrow: 'arrow-up-right', | ||
| Brush: 'pencil', | ||
| Mosaic: 'mosaic', | ||
| Text: 'text', | ||
| Translate: 'translate', | ||
| Undo: 'arrow-back-up', | ||
| Redo: 'arrow-forward-up', | ||
| Save: 'download', | ||
| Cancel: 'x', | ||
| Confirm: 'check', | ||
| }; | ||
|
|
||
| const ASSETS_DIR = path.join(__dirname, '..', 'src', 'assets'); | ||
| const OUT_DIR = path.join(__dirname, '..', 'src', 'generated'); | ||
| const OUT_FILE = path.join(OUT_DIR, 'icon_svgs.h'); | ||
|
|
||
| // C 字符串字面量转义:处理 " \ 和换行 | ||
| function toCLiteral(str) { | ||
| // 把字符串按行拆开,每行用独立字面量拼接,保证可读性且避免超长行 | ||
| return str | ||
| .replace(/\\/g, '\\\\') | ||
| .replace(/"/g, '\\"') | ||
| .split(/\r?\n/) | ||
| .map((line) => ` "${line}"`) | ||
| .join('\n'); | ||
| } | ||
|
|
||
| function main() { | ||
| if (!fs.existsSync(ASSETS_DIR)) { | ||
| console.error(`✖ assets dir not found: ${ASSETS_DIR}`); | ||
| process.exit(1); | ||
| } | ||
| fs.mkdirSync(OUT_DIR, { recursive: true }); | ||
|
|
||
| const lines = []; | ||
| lines.push('#pragma once'); | ||
| lines.push('// AUTO-GENERATED by scripts/gen-icons.js — DO NOT EDIT.'); | ||
| lines.push('// SVG 原文保留 currentColor,运行时替换为目标颜色。'); | ||
| lines.push(''); | ||
|
|
||
| for (const [key, fileBase] of Object.entries(ICON_MAP)) { | ||
| const svgPath = path.join(ASSETS_DIR, `${fileBase}.svg`); | ||
| if (!fs.existsSync(svgPath)) { | ||
| console.error(`✖ missing svg: ${svgPath}`); | ||
| process.exit(1); | ||
| } | ||
| const raw = fs.readFileSync(svgPath, 'utf8').trim(); | ||
| // 折叠成单行,去掉换行,再按 C 字面量拼接(更紧凑) | ||
| const oneLine = raw.replace(/\r?\n/g, '').replace(/\s+/g, ' '); | ||
| lines.push(`static const char* kIconSvg_${key} =`); | ||
| lines.push(` "${oneLine.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}";`); | ||
| lines.push(''); | ||
| } | ||
|
|
||
| // 所有图标文本的数组(按 ToolButton 枚举顺序,分隔线为 nullptr) | ||
| lines.push('// 按 ToolButton 枚举顺序的 SVG 文本数组,分隔线为 nullptr。'); | ||
| lines.push('static const char* const kIconSvgs[] = {'); | ||
| // 顺序:Rect Circle Arrow Brush Mosaic Text Translate SEP1 Undo Redo SEP2 Save Cancel Confirm | ||
| lines.push(' kIconSvg_Rect, kIconSvg_Circle, kIconSvg_Arrow, kIconSvg_Brush,'); | ||
| lines.push(' kIconSvg_Mosaic, kIconSvg_Text, kIconSvg_Translate, nullptr,'); | ||
| lines.push(' kIconSvg_Undo, kIconSvg_Redo, nullptr,'); | ||
| lines.push(' kIconSvg_Save, kIconSvg_Cancel, kIconSvg_Confirm'); | ||
| lines.push('};'); | ||
| lines.push(''); | ||
|
|
||
| fs.writeFileSync(OUT_FILE, lines.join('\n'), 'utf8'); | ||
| console.log(`✓ generated ${path.relative(path.join(__dirname, '..'), OUT_FILE)} (${Object.keys(ICON_MAP).length} icons)`); | ||
| } | ||
|
|
||
| main(); | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在
scripts/gen-icons.js中,函数toCLiteral被定义了但从未在代码中被调用。为了保持代码的整洁和可维护性,建议将这段未使用的死代码删除。