Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
493 changes: 492 additions & 1 deletion Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ UI 采用新艺术运动风格的 Material Design 3 主题,浅色使用暖白

- 桌面三栏工作台、手机分段工作台、中文/英文、系统主题及明暗切换。手机工具菜单显示图标、名称与用途说明,键盘展开时隐藏底部导航和导出操作。
- 长文本编辑、撤销/重做、TXT/DOCX/PDF/RTF 导入、插图及比例设置、分页和右对齐。
- 导入 PDF 时可提取纯文本继续排版,也可在原页上操作。「按原页排手写」把可替换的文字写回原来的位置,保留分栏与表格线;「在原页上填字」允许在表格或扫描件上框选答题区。两种原页模式都按原尺寸导出图片 PDF,关闭前请先导出。
- Markdown 预览与清洗(四种表格格式)、LaTeX 公式预览与 Unicode 转换、常见 CircuiTikZ 电路手写绘制、中文书信排版。
- 内置/上传字体、背景上传、背景边距识别、全部现有排版/扰动/墨色/删除线参数。
- 工作台可选择内置字体,也可从文件导入 TTF / OTF。使用随桌面应用启动的本机引擎时,在「字体排版 → 本机字体库」可搜索系统字体。「我的字体 → 打开字体文件夹」适合一次添加多款字体,复制文件后点击刷新即可。该目录位于用户数据目录,升级应用时可保留。
- 背景上传、背景边距识别、全部现有排版/扰动/墨色/删除线参数。
- 内置预设、自定义预设保存/加载、JSON 导入/导出、设备草稿自动保存。
- 「纸张 → 页面排版 → 排版预设」可切换标准排版与作业笔记;作业笔记增加正文留白和条目续行缩进,长公式优先在关系符处换行,保留原文、字体、背景及横线对齐。选择随草稿和参数预设保存,旧草稿默认使用标准排版。
- 预览支持缩放和翻页。开启「即时预览」后,修改文字或排版参数会自动刷新。开启「预览全部页面」可检查整份稿件,关闭时只预览第一页。可保存单页 PNG,或导出全部页面为 PDF 或图片 ZIP。生成时显示任务进度与队列状态。
Expand Down
45 changes: 44 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
{
"@@locale": "en",
"pdfImport": "Import PDF",
"pdfText": "Extract plain text",
"pdfTextHint": "Open selectable text in the workbench editor and reflow it on the current paper.",
"pdfLayout": "Rewrite in the original layout",
"pdfLayoutHint": "Replace readable lines with handwriting in place, keeping pages, columns and artwork. Scans retain their original appearance.",
"pdfFill": "Write on the original pages",
"pdfFillHint": "Keep the complete page image and draw answer areas. Works with scans.",
"pdfLocal": "Your local engine processes the file. Page modes export a flattened image PDF. Edits last until you close the document.",
"pdfRemote": "This file will be sent to the current engine at {engine}. Page modes export a flattened image PDF. Edits last until you close the document.",
"pdfLayoutHelp": "Tap a handwritten line to edit it. Export keeps each page’s print size.",
"pdfFillHelp": "Drag a rectangle to write in it. Tap an answer to edit or remove it.",
"pdfFontError": "The selected font could not be loaded. Choose a bundled font or a local font file in the workbench and retry.",
"pdfEncrypted": "This PDF is password protected. Export an unlocked copy in your PDF reader and import it again.",
"pdfLimit": "This document exceeds a file, page, complexity or export limit. Split it into smaller PDFs and retry.",
"pdfInvalid": "This PDF could not be read. Check the file or save a fresh copy from your PDF reader.",
"pdfEngineOld": "The current engine does not support PDF page import. Update the Panache engine or choose plain text.",
"pdfFailed": "PDF processing failed. {detail}",
"pdfCloseTitle": "Close this PDF?",
"pdfCloseHint": "Closing clears this editing session. Export the PDF first to keep the result.",
"pdfReview": "Review before exporting",
"pdfWarnings": "{pages} page(s) contain scans, text that could not be replaced or elements that might not render fully. Check those pages before saving.",
"pdfNoText": "No replaceable text on this page. Export keeps its image. Use “Write on the original pages” to add handwriting.",
"pdfPartial": "Some text or graphics could only be partially processed. Check this preview.",
"pdfProgress": "Exporting page {current} of {total}",
"pdfBoxText": "Text in this area",
"appTitle": "Panache",
"workspace": "Workspace",
"guide": "Guide",
Expand All @@ -20,7 +45,25 @@
"redo": "Redo",
"parameters": "Paper & handwriting",
"font": "Handwriting font",
"uploadFont": "Upload font",
"importFontFile": "Import font from file",
"localFonts": "Local font library",
"systemFonts": "System fonts",
"personalFonts": "My fonts",
"searchFonts": "Search font names",
"openFontFolder": "Open font folder",
"refreshFonts": "Refresh font list",
"moreFonts": "Show more fonts",
"noMatchingFonts": "No matching fonts",
"personalFontsEmpty": "Add TTF or OTF files to this folder, then refresh the list.",
"openFontFolderFailed": "Open this folder manually: {path}",
"chooseBundledFont": "Choose a bundled font",
"@openFontFolderFailed": {
"placeholders": {
"path": {
"type": "String"
}
}
},
"background": "Paper background",
"uploadBackground": "Upload background",
"detectBackground": "Detect margins & spacing",
Expand Down
70 changes: 69 additions & 1 deletion app/lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
@@ -1,5 +1,61 @@
{
"@@locale": "zh",
"pdfImport": "导入 PDF",
"pdfText": "提取纯文字",
"pdfTextHint": "把可复制的文字放入工作台编辑器,使用当前纸张重新排版。",
"pdfLayout": "按原页排手写",
"pdfLayoutHint": "按原页文字行的位置换成手写,保留分页、分栏和底图。扫描页保留原貌。",
"pdfFill": "在原页上填字",
"pdfFillHint": "完整保留页面图像,框选空白处填写。可用于扫描件。",
"pdfLocal": "文件由本机引擎处理。原页模式导出平面图像 PDF,关闭后清除本次编辑。",
"pdfRemote": "此文件将发送到当前引擎 {engine}。原页模式导出平面图像 PDF,关闭后清除本次编辑。",
"@pdfRemote": {
"placeholders": {
"engine": {
"type": "String"
}
}
},
"pdfLayoutHelp": "点按手写行可以修改。导出时保留各页尺寸。",
"pdfFillHelp": "拖出矩形,输入内容。点按已填文字可以修改或移除。",
"pdfFontError": "无法载入所选字体。请返回工作台选择内置字体或本机字体文件后重试。",
"pdfEncrypted": "此 PDF 受密码保护。请在有权访问的 PDF 阅读器中导出未加密副本,再重新导入。",
"pdfLimit": "文件超过引擎或导出的大小、页数或复杂度上限。请拆分成较小的 PDF 后重试。",
"pdfInvalid": "无法读取该 PDF。请检查文件,或在 PDF 阅读器中重新另存一份。",
"pdfEngineOld": "当前引擎不支持 PDF 原页处理。请更新 Panache 引擎或选择提取纯文字。",
"pdfFailed": "PDF 处理失败。{detail}",
"@pdfFailed": {
"placeholders": {
"detail": {
"type": "String"
}
}
},
"pdfCloseTitle": "关闭这份 PDF?",
"pdfCloseHint": "关闭后会清除本次编辑。如需保留成品,请先导出 PDF。",
"pdfReview": "检查导出页面",
"pdfWarnings": "有 {pages} 页含无法替换的文字、扫描内容或可能无法完整绘制的元素。请确认已查看这些页面。",
"@pdfWarnings": {
"placeholders": {
"pages": {
"type": "int"
}
}
},
"pdfNoText": "该页没有可替换的文字。导出会保留原页图像。如需写字,请使用「在原页上填字」。",
"pdfPartial": "该页含部分无法替换的文字或无法完整绘制的元素,请核对预览。",
"pdfProgress": "正在导出第 {current} / {total} 页",
"@pdfProgress": {
"placeholders": {
"current": {
"type": "int"
},
"total": {
"type": "int"
}
}
},
"pdfBoxText": "区域文字",
"appTitle": "Panache",
"workspace": "工作台",
"guide": "使用指南",
Expand All @@ -20,7 +76,19 @@
"redo": "重做",
"parameters": "纸张与笔迹",
"font": "手写字体",
"uploadFont": "上传字体",
"importFontFile": "从文件导入字体",
"localFonts": "本机字体库",
"systemFonts": "系统字体",
"personalFonts": "我的字体",
"searchFonts": "搜索字体名称",
"openFontFolder": "打开字体文件夹",
"refreshFonts": "刷新字体列表",
"moreFonts": "显示更多字体",
"noMatchingFonts": "未找到匹配的字体",
"personalFontsEmpty": "将 TTF 或 OTF 字体放入此文件夹,然后刷新列表。",
"openFontFolderFailed": "请手动打开字体文件夹:{path}",
"@openFontFolderFailed": {"placeholders": {"path": {"type": "String"}}},
"chooseBundledFont": "选择内置字体",
"background": "纸张背景",
"uploadBackground": "上传背景",
"detectBackground": "识别边距和行距",
Expand Down
235 changes: 235 additions & 0 deletions app/lib/screens/dialogs/local_font_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../l10n/app_localizations.dart';
import '../../services/api.dart';
import '../../services/local_fonts.dart';

class LocalFontDialog extends StatefulWidget {
const LocalFontDialog({super.key, required this.api});
final HandwritingApi api;

@override
State<LocalFontDialog> createState() => _LocalFontDialogState();
}

class _LocalFontDialogState extends State<LocalFontDialog> {
final search = TextEditingController();
final scroll = ScrollController();
LocalFontSource source = LocalFontSource.system;
List<LocalFont> fonts = [];
String? directory;
int? nextOffset;
int generation = 0;
bool loading = true;
Object? error;
Timer? debounce;

@override
void initState() {
super.initState();
load();
}

@override
void dispose() {
debounce?.cancel();
search.dispose();
scroll.dispose();
super.dispose();
}

void reload({bool typing = false, bool refresh = false}) {
debounce?.cancel();
generation++;
if (scroll.hasClients) scroll.jumpTo(0);
setState(() {
fonts = [];
nextOffset = null;
error = null;
loading = true;
});
if (typing) {
debounce = Timer(const Duration(milliseconds: 200), load);
} else {
load(refresh: refresh);
}
}

Future<void> load({bool refresh = false}) async {
final request = ++generation;
setState(() {
loading = true;
error = null;
});
try {
final page = await widget.api.listLocalFonts(
source: source,
query: search.text.trim(),
offset: nextOffset ?? 0,
refresh: refresh,
);
if (!mounted || request != generation) return;
setState(() {
fonts = [...fonts, ...page.fonts];
nextOffset = page.nextOffset;
directory = page.directory;
loading = false;
});
} catch (e) {
if (!mounted || request != generation) return;
setState(() {
error = e;
loading = false;
});
}
}

Future<void> openDirectory() async {
final path = directory;
if (path == null) return;
try {
if (await launchUrl(
Uri.directory(path),
mode: LaunchMode.externalApplication,
)) {
return;
}
} catch (_) {
// Show the path so it can still be opened manually.
}
if (mounted) {
final l = AppLocalizations.of(context)!;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: SelectableText(l.openFontFolderFailed(path))),
);
}
}

@override
Widget build(BuildContext context) {
final l = AppLocalizations.of(context)!;
final personal = source == LocalFontSource.user;
return AlertDialog(
title: Text(l.localFonts),
content: SizedBox(
width: 460,
height: 420,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SegmentedButton<LocalFontSource>(
segments: [
ButtonSegment(
value: LocalFontSource.system,
label: Text(l.systemFonts),
),
ButtonSegment(
value: LocalFontSource.user,
label: Text(l.personalFonts),
),
],
selected: {source},
onSelectionChanged: (selection) {
source = selection.single;
search.clear();
reload();
},
),
const SizedBox(height: 12),
TextField(
controller: search,
onChanged: (_) => reload(typing: true),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.search),
hintText: l.searchFonts,
),
),
if (personal)
Row(
children: [
Expanded(
child: Align(
alignment: AlignmentDirectional.centerStart,
child: TextButton.icon(
onPressed: directory == null ? null : openDirectory,
icon: const Icon(Icons.folder_open_outlined),
label: Text(l.openFontFolder),
),
),
),
IconButton(
tooltip: l.refreshFonts,
onPressed: loading ? null : () => reload(refresh: true),
icon: const Icon(Icons.refresh),
),
],
),
const SizedBox(height: 6),
Expanded(
child: ListView.builder(
controller: scroll,
itemCount: fonts.length + 1,
itemBuilder: (context, index) {
if (index < fonts.length) {
final font = fonts[index];
return ListTile(
title: Text(font.name),
subtitle: font.filename == font.name
? null
: Text(
font.filename,
overflow: TextOverflow.ellipsis,
),
onTap: () => Navigator.pop(context, font),
);
}
if (loading) {
return const Center(child: CircularProgressIndicator());
}
if (error != null) {
return Column(
children: [
SelectableText('${l.errorTitle}: $error'),
TextButton(
onPressed: () =>
fonts.isEmpty ? reload(refresh: true) : load(),
child: Text(l.retry),
),
],
);
}
if (nextOffset != null) {
return TextButton(
onPressed: load,
child: Text(l.moreFonts),
);
}
if (fonts.isEmpty) {
return Padding(
padding: const EdgeInsets.all(12),
child: Text(
personal && search.text.trim().isEmpty
? l.personalFontsEmpty
: l.noMatchingFonts,
),
);
}
return const SizedBox.shrink();
},
),
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(l.cancel),
),
],
);
}
}
Loading
Loading