修复导出 pdf 的问题

This commit is contained in:
锦恢 2025-01-10 15:17:35 +08:00
parent aea1634d2c
commit 1b91990cb3
10 changed files with 53 additions and 14 deletions

View File

@ -4,7 +4,7 @@
## <code>Digital IDE</code> | All in one <code>vscode</code> plugin for Verilog/VHDL development ## <code>Digital IDE</code> | All in one <code>vscode</code> plugin for Verilog/VHDL development
[Document (New)](https://sterben.nitcloud.cn/) | [中文文档 (New)](https://sterben.nitcloud.cn/zh/) | [Bilibili Video](https://www.bilibili.com/video/BV1t14y1179V/?spm_id_from=333.999.0.0) [Document (New)](https://nc-ai.cn/en/) | [中文文档 (New)](https://nc-ai.cn/) | [Bilibili Video](https://www.bilibili.com/video/BV1t14y1179V/?spm_id_from=333.999.0.0)
![](https://img.shields.io/badge/version-0.4.0-purple) ![](https://img.shields.io/badge/version-0.4.0-purple)
![](https://img.shields.io/badge/Verilog-support-green) ![](https://img.shields.io/badge/Verilog-support-green)

View File

@ -120,5 +120,9 @@
"info.progress.launch-lsp": "Starten Sie den Digital LSP-Sprachserver", "info.progress.launch-lsp": "Starten Sie den Digital LSP-Sprachserver",
"info.choose.digital-lsp-targz": "Wählen Sie das Digital LSP-Archiv aus", "info.choose.digital-lsp-targz": "Wählen Sie das Digital LSP-Archiv aus",
"info.digital-lsp.targz": "Digitales LSP-Paket", "info.digital-lsp.targz": "Digitales LSP-Paket",
"error.digital-lsp.incorrect-filename": "Die von Ihnen bereitgestellte Digital-LSP-Archivdatei {0} entspricht nicht der aktuellen Systemarchitektur. Bitte laden Sie die Archivdatei mit dem Namen {1} herunter!" "error.digital-lsp.incorrect-filename": "Die von Ihnen bereitgestellte Digital-LSP-Archivdatei {0} entspricht nicht der aktuellen Systemarchitektur. Bitte laden Sie die Archivdatei mit dem Namen {1} herunter!",
"error.not-valid-browser": "{0} ist kein gültiger Browser-Pfad!",
"info.config-browser-path": "Browser-Pfad konfigurieren",
"info.pdf.exporting": "PDF wird nach {0} exportiert",
"info.generate-pdf-to": "PDF wurde unter {0} generiert"
} }

View File

@ -120,5 +120,9 @@
"info.progress.launch-lsp": "Start the Digital LSP language server", "info.progress.launch-lsp": "Start the Digital LSP language server",
"info.choose.digital-lsp-targz": "Select the Digital LSP archive", "info.choose.digital-lsp-targz": "Select the Digital LSP archive",
"info.digital-lsp.targz": "Digital LSP Package", "info.digital-lsp.targz": "Digital LSP Package",
"error.digital-lsp.incorrect-filename": "The digital LSP archive file {0} you provided does not match the current system architecture. Please download the archive file named {1}!" "error.digital-lsp.incorrect-filename": "The digital LSP archive file {0} you provided does not match the current system architecture. Please download the archive file named {1}!",
"error.not-valid-browser": "{0} is not a valid browser path!",
"info.config-browser-path": "Configure browser path",
"info.pdf.exporting": "Exporting PDF to {0}",
"info.generate-pdf-to": "PDF has been generated to {0}"
} }

View File

@ -120,5 +120,9 @@
"info.progress.launch-lsp": "Digital LSP 言語サーバーを起動する", "info.progress.launch-lsp": "Digital LSP 言語サーバーを起動する",
"info.choose.digital-lsp-targz": "Digital LSPのアーカイブを選択してください", "info.choose.digital-lsp-targz": "Digital LSPのアーカイブを選択してください",
"info.digital-lsp.targz": "デジタルLSPパッケージ", "info.digital-lsp.targz": "デジタルLSPパッケージ",
"error.digital-lsp.incorrect-filename": "提供されたデジタルLSPアーカイブファイル{0}は、現在のシステムアーキテクチャに適合していません。{1}という名前のアーカイブファイルをダウンロードしてください!" "error.digital-lsp.incorrect-filename": "提供されたデジタルLSPアーカイブファイル{0}は、現在のシステムアーキテクチャに適合していません。{1}という名前のアーカイブファイルをダウンロードしてください!",
"error.not-valid-browser": "{0} は有効なブラウザのパスではありません!",
"info.config-browser-path": "ブラウザのパスを設定",
"info.pdf.exporting": "PDFを{0}にエクスポート中",
"info.generate-pdf-to": "PDFは{0}に生成されました"
} }

View File

@ -120,5 +120,9 @@
"info.progress.launch-lsp": "启动 Digital LSP 语言服务器", "info.progress.launch-lsp": "启动 Digital LSP 语言服务器",
"info.choose.digital-lsp-targz": "选择 Digital LSP 的压缩包", "info.choose.digital-lsp-targz": "选择 Digital LSP 的压缩包",
"info.digital-lsp.targz": "Digital LSP 压缩包", "info.digital-lsp.targz": "Digital LSP 压缩包",
"error.digital-lsp.incorrect-filename": "您提供的 digital lsp 压缩包文件 {0} 并不是一个符合当前系统架构的,请下载名为 {1} 的压缩包文件!" "error.digital-lsp.incorrect-filename": "您提供的 digital lsp 压缩包文件 {0} 并不是一个符合当前系统架构的,请下载名为 {1} 的压缩包文件!",
"error.not-valid-browser": "{0} 并不是一个有效的浏览器路径!",
"info.config-browser-path": "配置浏览器路径",
"info.pdf.exporting": "正在导出 pdf 到 {0}",
"info.generate-pdf-to": "pdf 已经生成至 {0}"
} }

View File

@ -120,5 +120,9 @@
"info.progress.launch-lsp": "啟動 Digital LSP 語言伺服器", "info.progress.launch-lsp": "啟動 Digital LSP 語言伺服器",
"info.choose.digital-lsp-targz": "選擇 Digital LSP 的壓縮包", "info.choose.digital-lsp-targz": "選擇 Digital LSP 的壓縮包",
"info.digital-lsp.targz": "數位LSP壓縮包", "info.digital-lsp.targz": "數位LSP壓縮包",
"error.digital-lsp.incorrect-filename": "您提供的 digital lsp 壓縮包文件 {0} 並不是一個符合當前系統架構的,請下載名為 {1} 的壓縮包文件!" "error.digital-lsp.incorrect-filename": "您提供的 digital lsp 壓縮包文件 {0} 並不是一個符合當前系統架構的,請下載名為 {1} 的壓縮包文件!",
"error.not-valid-browser": "{0} 並不是一個有效的瀏覽器路徑!",
"info.config-browser-path": "配置瀏覽器路徑",
"info.pdf.exporting": "正在導出PDF到{0}",
"info.generate-pdf-to": "PDF 已生成至 {0}"
} }

View File

@ -198,7 +198,8 @@
"xc7a35tftg256-1", "xc7a35tftg256-1",
"xc7a35tcsg324-1", "xc7a35tcsg324-1",
"xc7z035ffg676-2", "xc7z035ffg676-2",
"xc7z020clg484-1" "xc7z020clg484-1",
"hello-world"
] ]
} }
}, },

View File

@ -43,6 +43,11 @@ function registerFileDocExport(context: vscode.ExtensionContext) {
new ExportFunctionItem('html', ' html', 'only support light theme', exportCurrentFileDocAsHTML) new ExportFunctionItem('html', ' html', 'only support light theme', exportCurrentFileDocAsHTML)
]; ];
if (uri === undefined && vscode.window.activeTextEditor) {
// TODO: 制作新的 doc UI
uri = vscode.Uri.file(vscode.window.activeTextEditor.document.fileName);
}
const item = await vscode.window.showQuickPick(items, option); const item = await vscode.window.showQuickPick(items, option);
if (item) { if (item) {
item.exportFunc(uri); item.exportFunc(uri);

View File

@ -5,6 +5,7 @@ import * as puppeteer from 'puppeteer-core';
import { makeShowHTML } from './html'; import { makeShowHTML } from './html';
import { hdlFile, hdlPath } from '../../hdlFs'; import { hdlFile, hdlPath } from '../../hdlFs';
import { AbsPath, MainOutput, opeParam, ReportType } from '../../global'; import { AbsPath, MainOutput, opeParam, ReportType } from '../../global';
import { t } from '../../i18n';
// TODO : finish it in each platform // TODO : finish it in each platform
function getDefaultBrowerPath(): AbsPath { function getDefaultBrowerPath(): AbsPath {
@ -27,10 +28,18 @@ function getDefaultBrowerPath(): AbsPath {
async function htmlFile2PdfFile(htmlPath: AbsPath, pdfPath: AbsPath) { async function htmlFile2PdfFile(htmlPath: AbsPath, pdfPath: AbsPath) {
const pdfConfig = vscode.workspace.getConfiguration("digital-ide.function.doc.pdf"); const pdfConfig = vscode.workspace.getConfiguration("digital-ide.function.doc.pdf");
const platformDefaultBrowerPath = getDefaultBrowerPath(); const platformDefaultBrowerPath = getDefaultBrowerPath();
const browserPath = pdfConfig.get('browserPath', platformDefaultBrowerPath);
const browserPath = pdfConfig.get<string>('browserPath') || platformDefaultBrowerPath;
if (!fs.existsSync(browserPath)) { if (!fs.existsSync(browserPath)) {
vscode.window.showErrorMessage("Path " + browserPath + " is not a valid browser path!"); const res = await vscode.window.showErrorMessage(
t('error.not-valid-browser', browserPath),
{ title: t('info.config-browser-path'), value: true }
);
if (res?.value) {
await vscode.commands.executeCommand('workbench.action.openSettings', 'digital-ide.function.doc.pdf.browserPath');
}
return; return;
} }
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
@ -48,7 +57,7 @@ async function htmlFile2PdfFile(htmlPath: AbsPath, pdfPath: AbsPath) {
scale: pdfConfig.scale, scale: pdfConfig.scale,
displayHeaderFooter: pdfConfig.displayHeaderFooter, displayHeaderFooter: pdfConfig.displayHeaderFooter,
headerTemplate: pdfConfig.headerTemplate, headerTemplate: pdfConfig.headerTemplate,
footerTemplate: pdfConfig.footerTemplate, footerTemplate: `<div style="font-size: 15px; margin: 0 auto;">CodeDoc - Powered By Digital IDE</div>`,
printBackground: pdfConfig.printBackground, printBackground: pdfConfig.printBackground,
landscape: pdfConfig.landscape, landscape: pdfConfig.landscape,
format: pdfConfig.format, format: pdfConfig.format,
@ -74,7 +83,8 @@ async function exportCurrentFileDocAsPDF(uri: vscode.Uri) {
return vscode.window.withProgress({ return vscode.window.withProgress({
location: vscode.ProgressLocation.Notification, location: vscode.ProgressLocation.Notification,
title: '[Digital-IDE]: Export ' + currentFilePath + '...' title: t('info.pdf.exporting', currentFilePath),
cancellable: true
}, async progress => { }, async progress => {
try { try {
const html = await makeShowHTML(uri, "pdf"); const html = await makeShowHTML(uri, "pdf");
@ -102,15 +112,18 @@ async function exportCurrentFileDocAsPDF(uri: vscode.Uri) {
fs.writeFileSync(tempHtmlPath, html); fs.writeFileSync(tempHtmlPath, html);
await htmlFile2PdfFile(tempHtmlPath, pdfPath); await htmlFile2PdfFile(tempHtmlPath, pdfPath);
hdlFile.rmSync(tempHtmlPath); // hdlFile.rmSync(tempHtmlPath);
// 在当前编辑器中打开生成的 pdf // 在当前编辑器中打开生成的 pdf
vscode.window.showInformationMessage('pdf generated at ' + pdfPath); if (fs.existsSync(pdfPath)) {
vscode.window.showInformationMessage(t('info.generate-pdf-to', pdfFolderPath));
}
} catch (error) { } catch (error) {
MainOutput.report("error happen in export pdf: " + error, { MainOutput.report("error happen in export pdf: " + error, {
level: ReportType.Error level: ReportType.Error
}); });
return;
} }
}); });
} }

View File

@ -170,7 +170,7 @@ async function html2pdf(htmlPath: string, pdfPath: string, moduleName: string, w
scale: 1, scale: 1,
displayHeaderFooter: true, displayHeaderFooter: true,
// headerTemplate: `<div style="font-size: 12px; margin-left: 1cm;">module ${moduleName}</div>`, // headerTemplate: `<div style="font-size: 12px; margin-left: 1cm;">module ${moduleName}</div>`,
footerTemplate: `<div style="font-size: 15px; margin: 0 auto;">Netlist for <code>${moduleName}</code> - 由 Digital IDE 生成 </div>`, footerTemplate: `<div style="font-size: 15px; margin: 0 auto;">Netlist for <code>${moduleName}</code> - Powered By Digital IDE</div>`,
printBackground: true, printBackground: true,
landscape: true, landscape: true,
width: width width: width