Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Long e-books to PDF: rhwp time limit follows the text, calibre PDF route (#127)
KnifeLemonb85231aa1801
diff --git a/docs/ENGINES.md b/docs/ENGINES.mdindex 549d4cb9..3ff7b465 100644--- a/docs/ENGINES.md+++ b/docs/ENGINES.md@@ -31,7 +31,7 @@ Filee chooses engines automatically. Settings → *Engines* shows their status,| Pandoc | **optional download** (~42 MB, 240 MB on disk) | Markdown ↔ DOCX/ODT/RTF, DOCX/ODT/HTML/RTF → Markdown, HTML ↔ DOCX/ODT, markup languages (reStructuredText, LaTeX, Org, AsciiDoc, Typst, MediaWiki, DocBook, Jupyter, Textile, man, OPML) ↔ Markdown/HTML/DOCX/ODT and each other (and → RTF, EPUB, TXT), Markdown and markup → PPTX slides || Ghostscript | **optional download** (~20 MB, 31 MB on disk) | EPS/PS → PDF, PDF → EPS/PS, PostScript-based AI → PDF (images through PDF and PDFium); smaller PDFs when a preset asks for it || FFmpeg | **optional download** (~100 MB, 272 MB on disk) | **all video and audio**: video ↔ video (H.264, HEVC, AV1), video → animated GIF / APNG, a still frame or every frame, audio and subtitle extraction, audio ↔ audio (also APE, WavPack, TTA, DSD, DTS, ALAC, …), GIF, APNG and photos → MP4/WEBM/MOV, images → HEIC |-| Calibre | **optional download** (~216 MB, 660 MB on disk) | rare e-book formats: LIT, LRF, CHM, PDB, PML, RB, SNB, TCR, OEB → EPUB; EPUB → MOBI, AZW3, LIT, LRF, PDB, PML, RB, SNB, TCR |+| Calibre | **optional download** (~216 MB, 660 MB on disk) | rare e-book formats: LIT, LRF, CHM, PDB, PML, RB, SNB, TCR, OEB → EPUB; EPUB → MOBI, AZW3, LIT, LRF, PDB, PML, RB, SNB, TCR; e-books → PDF (ranked above the HWPX writer, see below) |DOCX, XLSX, XLS, ODS and PPTX → PDF need neither Microsoft Office nor LibreOffice: they are read in-process, written as HWPXand rendered by rhwp. Anything the built-in readers understand (including PDF) is written as DOCX by the DOCX writer.@@ -699,6 +699,17 @@ LIT, LRF, CHM, PDB, PML, RB, SNB, TCR and OEB → EPUB, and EPUB → MOBI, AZW3,EPUB is the hub, so for example FB2 → AZW3 is FB2 → EPUB (built in) → AZW3 (calibre). Its edges cost 20, sobuilt-in routes always win where they exist.+calibre also makes PDFs of EPUB, MOBI, AZW3, AZW, PRC, FB2, HTMLZ, TXTZ and the formats only it reads (one+`ebook-convert` run: A4 with `--paper-size a4`, page numbers with `--pdf-page-numbers`, calibre's margins and font+sizes; the built-in route ignores the preset's PDF options too). For long books it is much faster than the built-in+route, HWPX writer → rhwp (a 640-page novel: about a minute against some 48 minutes, #127), but the built-in route+stays the default so results don't change under users. The PDF edges cost 23: in the default engine order the+built-in route costs 31 (HWPX writer 10 + 8, rhwp 10 + 3) and calibre 23 + 9, so the built-in route wins by one; once+the user moves calibre above the HWPX writer in Settings → *Engines*, calibre costs at most 31 and the built-in route+at least 32. LIT, LRF and the other formats only calibre reads go straight to PDF instead of calibre → EPUB → HWPX+writer → rhwp. When rhwp runs out of time and calibre is installed, the error says to rank calibre higher; Filee+never switches engines by itself.+- The pinned `calibre-64bit-<version>.msi` from download.calibre-ebook.com is unpacked like LibreOffice; the folderwith `ebook-convert.exe` becomes `engines/calibre`.- Each run gets its own configuration, cache and temp folders in the job's work directory@@ -716,6 +727,14 @@ the column, spaced equation commands, and, in an HWPX exported from an HWP (rhwpmarker), the stored line of a cell paragraph that holds only a floating table moved up to the paragraph's top, so thetable is not drawn over the paragraphs below it (#49).+rhwp renders text slowly: about 1 s per KB of section XML, some 4 s per page of a novel (rhwp 0.8.7 on an+i7-1185G7, pictures cost little). So each rhwp run's time limit follows the document's text: 2 minutes + 30 minutes+per MB of unpacked `Contents/section*.xml` (an HWP counts three times its file size, its text being deflated), at most+60 minutes, after which a rhwp that hangs is stopped. The progress estimate assumes 15 minutes per MB. Cancelling+stops rhwp at once. A time-out fails with "rhwp couldn't finish this long document in time" (with calibre installed,+it suggests ranking calibre above the HWPX writer for e-books). The other engines keep fixed limits: LibreOffice 3+minutes, Ghostscript 5, Pandoc 2 and calibre 10 (it made the 640-page novel's PDF in a minute).+## ArchivesThe archive engine (`Archives/ArchiveConverter.cs`, id `archive`) uses Filee's own copy of the 7-Zip console programdiff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.jsonindex 52c51462..7156a29f 100644--- a/src/Filee.App/Assets/i18n/en.json+++ b/src/Filee.App/Assets/i18n/en.json@@ -75,6 +75,8 @@"error.cannot_turn": "Rotate and flip work on images only","error.too_many_frames": "Too many frames to save as pictures, raise \"Every Nth frame\"","error.not_enough_space": "Not enough free disk space for the pictures",+ "error.rhwp_timeout": "rhwp couldn't finish this long document in time",+ "error.rhwp_timeout_calibre": "rhwp couldn't finish this long document in time. For an e-book, move Calibre above the HWPX writer in Settings → Engines, and Calibre makes the PDF much faster","error.conversion_failed": "The engine reported an error","notice.pdf_not_smaller": "Couldn't make it smaller, so it was copied as it is",@@ -107,7 +109,7 @@"engine.ffmpeg.description": "Video and audio: MP4, MOV, MKV, WEBM, MP3, M4A, WAV, FLAC and more.\nAlso extracts sound and subtitles, makes GIF and APNG animations and saves images as HEIC.","engine.pandoc.description": "Markdown and HTML ↔ ODT and RTF, DOCX → Markdown\nreStructuredText, LaTeX, Org, AsciiDoc, Typst, MediaWiki, DocBook, Jupyter and more ↔ Markdown, HTML, DOCX and ODT\nMarkdown and Org → PPTX slides","engine.ghostscript.description": "EPS, PostScript and older Illustrator files to PDF and images; PDF to EPS and PS.",- "engine.calibre.description": "Rare e-book formats (LIT, LRF, CHM, PDB, RB…) and Kindle output (MOBI, AZW3).",+ "engine.calibre.description": "Rare e-book formats (LIT, LRF, CHM, PDB, RB…) and Kindle output (MOBI, AZW3).\nAbove the HWPX writer, it also makes the PDFs of e-books (much faster for long books).","engine.libreoffice.description": "Reads older and less common formats: DOC, PPT, Pages, Keynote, Numbers, WordPerfect, ClarisWorks, Publisher, Visio…\nAlso saves as DOC, XLS, PPT, ODT, ODP, OpenDocument templates and EMF.","profile.images": "Images",diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.jsonindex 1c53de4d..454ae5d7 100644--- a/src/Filee.App/Assets/i18n/ko.json+++ b/src/Filee.App/Assets/i18n/ko.json@@ -75,6 +75,8 @@"error.cannot_turn": "회전·반전은 이미지에만 할 수 있어요","error.too_many_frames": "프레임이 너무 많아요. 'N번째 프레임마다' 값을 늘려 주세요","error.not_enough_space": "이미지를 저장할 디스크 공간이 부족해요",+ "error.rhwp_timeout": "문서가 길어서 rhwp가 제한 시간 안에 끝내지 못했어요",+ "error.rhwp_timeout_calibre": "문서가 길어서 rhwp가 제한 시간 안에 끝내지 못했어요. 전자책이라면 설정 → 변환 엔진에서 Calibre를 HWPX writer보다 위로 옮겨 주세요. Calibre가 PDF를 훨씬 빨리 만들어요","error.conversion_failed": "엔진에서 오류가 발생했어요","notice.pdf_not_smaller": "더 작게 만들 수 없어서 그대로 복사했어요",@@ -107,7 +109,7 @@"engine.ffmpeg.description": "MP4, MOV, MKV, WEBM, MP3, M4A, WAV, FLAC 등 동영상·오디오를 변환해요.\n소리·자막 추출, GIF·APNG 만들기, 이미지 → HEIC도 해요.","engine.pandoc.description": "마크다운·HTML ↔ ODT·RTF, DOCX → 마크다운\nreStructuredText·LaTeX·Org·AsciiDoc·Typst·MediaWiki·DocBook·Jupyter 등 ↔ 마크다운·HTML·DOCX·ODT\n마크다운·Org → PPTX 슬라이드","engine.ghostscript.description": "EPS, 포스트스크립트, 예전 일러스트레이터 파일을 PDF와 이미지로, PDF를 EPS·PS로.",- "engine.calibre.description": "드문 전자책 형식(LIT, LRF, CHM, PDB, RB…)과 킨들용 출력(MOBI, AZW3).",+ "engine.calibre.description": "드문 전자책 형식(LIT, LRF, CHM, PDB, RB…)과 킨들용 출력(MOBI, AZW3).\nHWPX writer보다 위에 두면 전자책 PDF도 만들어요(긴 책은 훨씬 빨라요).","engine.libreoffice.description": "DOC, PPT, Pages, Keynote, Numbers, 워드퍼펙트, ClarisWorks, Publisher, Visio 같은 오래되었거나 드문 형식을 읽어요.\nDOC·XLS·PPT·ODT·ODP, 오픈도큐먼트 서식 파일, EMF로 저장도 해요.","profile.images": "이미지",diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.jsonindex abb0b93a..66346f96 100644--- a/src/Filee.App/Assets/i18n/zh-CN.json+++ b/src/Filee.App/Assets/i18n/zh-CN.json@@ -75,6 +75,8 @@"error.cannot_turn": "只能旋转和翻转图片","error.too_many_frames": "帧数太多,请调大“每 N 帧”","error.not_enough_space": "磁盘空间不足,无法保存这些图片",+ "error.rhwp_timeout": "文档太长,rhwp 未能在时限内完成",+ "error.rhwp_timeout_calibre": "文档太长,rhwp 未能在时限内完成。如果是电子书,请在“设置 → 转换引擎”中把 Calibre 移到 HWPX writer 之上,Calibre 生成 PDF 要快得多","error.conversion_failed": "转换引擎出错","notice.pdf_not_smaller": "无法再缩小,已原样复制",@@ -107,7 +109,7 @@"engine.ffmpeg.description": "MP4、MOV、MKV、WEBM、MP3、M4A、WAV、FLAC 等视频和音频。\n还能提取声音和字幕、制作 GIF 和 APNG、把图片保存为 HEIC。","engine.pandoc.description": "Markdown 和 HTML ↔ ODT、RTF,DOCX → Markdown\nreStructuredText、LaTeX、Org、AsciiDoc、Typst、MediaWiki、DocBook、Jupyter 等 ↔ Markdown、HTML、DOCX、ODT\nMarkdown 和 Org → PPTX 幻灯片","engine.ghostscript.description": "EPS、PostScript 和旧版 Illustrator 文件转为 PDF 和图片;PDF 转为 EPS 和 PS。",- "engine.calibre.description": "少见的电子书格式(LIT、LRF、CHM、PDB、RB…)以及 Kindle 输出(MOBI、AZW3)。",+ "engine.calibre.description": "少见的电子书格式(LIT、LRF、CHM、PDB、RB…)以及 Kindle 输出(MOBI、AZW3)。\n排在 HWPX writer 之上时,也由它把电子书转为 PDF(长书快得多)。","engine.libreoffice.description": "读取较旧或少见的格式,如 DOC、PPT、Pages、Keynote、Numbers、WordPerfect、ClarisWorks、Publisher、Visio。\n也能保存为 DOC、XLS、PPT、ODT、ODP、OpenDocument 模板或 EMF。","profile.images": "图片",diff --git a/src/Filee.Engines/Ebooks/CalibreConverter.cs b/src/Filee.Engines/Ebooks/CalibreConverter.csindex 7e204609..931dc21a 100644--- a/src/Filee.Engines/Ebooks/CalibreConverter.cs+++ b/src/Filee.Engines/Ebooks/CalibreConverter.cs@@ -3,6 +3,9 @@// AZW3, LIT, LRF, PDB, PML, RB, SNB and TCR. EPUB is the hub: the built-in engine handles every other step, and// calibre's edges cost more so built-in routes always win where they exist.//+// calibre also makes PDFs of e-books, much faster than the built-in route (HWPX writer → rhwp) for long books (#127).+// That route stays the default; calibre's PDF edges win once the user ranks calibre above the HWPX writer.+//// Each run gets its own calibre configuration, cache and temp folders inside the job's work directory, so Filee// never reads or changes the settings of a calibre the user may have installed.@@ -24,6 +27,16 @@ public sealed partial class CalibreConverter : IConverter/// <summary>Formats only calibre writes.</summary>internal static readonly string[] Outputs = ["mobi", "azw3", "lit", "lrf", "pdb", "pml", "rb", "snb", "tcr"];+ /// <summary>Books calibre makes PDFs of: the ones the built-in engines read too, and <see cref="Inputs"/>.</summary>+ internal static readonly string[] PdfInputs = ["epub", "mobi", "azw3", "azw", "prc", "fb2", "htmlz", "txtz", .. Inputs];++ /// <summary>+ /// Cost of e-book → PDF. The built-in route costs 31 in the default engine order (HWPX writer 10 + 8, rhwp 10 + 3)+ /// and calibre ranks last (+ 9), so 23 loses by one. Ranked above the HWPX writer, calibre costs at most 23 + 8+ /// and the built-in route at least 32 (the HWPX writer moves down to + 9).+ /// </summary>+ internal const int PdfCost = 23;+private string? _executable;public string Id => "calibre";@@ -36,6 +49,7 @@ public sealed partial class CalibreConverter : IConverter[.. Inputs.Select(from => new ConversionEdge(from, "epub", 20)),.. Outputs.Select(to => new ConversionEdge("epub", to, 20)),+ .. PdfInputs.Select(from => new ConversionEdge(from, "pdf", PdfCost)),];public EngineStatus GetStatus()@@ -68,7 +82,7 @@ public sealed partial class CalibreConverter : IConverter["PYTHONIOENCODING"] = "utf-8",};progress?.Report(0.02);- var result = await ProcessRunner.RunAsync(executable, [input, temp], Timeout, cancellationToken,+ var result = await ProcessRunner.RunAsync(executable, [input, temp, .. OutputOptions(step.To)], Timeout, cancellationToken,workingDirectory: work, environment: environment, onOutput: line => ReportProgress(line, progress));if (result.ExitCode != 0 || !File.Exists(temp))throw new InvalidOperationException($"Calibre failed (exit {result.ExitCode}). {LastLines(result.StandardError.Trim().Length > 0 ? result.StandardError : result.StandardOutput)}");@@ -81,6 +95,13 @@ public sealed partial class CalibreConverter : IConverterreturn [output];}+ /// <summary>+ /// ebook-convert's options for a target. PDF: A4 like the built-in route (calibre's default is Letter) and page+ /// numbers; margins (72 pt) and font sizes stay calibre's.+ /// </summary>+ internal static string[] OutputOptions(string to) =>+ to == "pdf" ? ["--paper-size", "a4", "--pdf-page-numbers"] : [];+/// <summary>ebook-convert prints "34% Running transforms on e-book..." while it works.</summary>private static void ReportProgress(string line, IProgress<double>? progress){diff --git a/src/Filee.Engines/Hwp/RhwpConverter.cs b/src/Filee.Engines/Hwp/RhwpConverter.csindex a1a69756..a59eabe3 100644--- a/src/Filee.Engines/Hwp/RhwpConverter.cs+++ b/src/Filee.Engines/Hwp/RhwpConverter.cs@@ -1,7 +1,9 @@// HWP / HWPX → PDF, HWP → HWPX and HWPX → HWP with the rhwp command line tool (MIT, https://github.com/edwardkim/rhwp).// Bundled under engines/rhwp. Works without Hancom Office, so there is no automation approval dialog.+using System.IO.Compression;using Filee.Core.Conversion;+using Filee.Engines.Ebooks;using Filee.Engines.Infrastructure;namespace Filee.Engines.Hwp;@@ -9,7 +11,18 @@ namespace Filee.Engines.Hwp;/// <summary>Renders HWP and HWPX documents to PDF and converts between the two 한글 formats.</summary>public sealed class RhwpConverter : IConverter{- private static readonly TimeSpan Timeout = TimeSpan.FromMinutes(2);+ // rhwp renders text slowly: about 1 s per KB of section XML (some 4 s per page of a novel) with rhwp 0.8.7 on an+ // i7-1185G7, so a 640-page book takes some 48 minutes; export-hwpx and convert take seconds for the same book. The+ // time limit grows with the document's text, and still stops a rhwp that hangs.+ private static readonly TimeSpan BaseTimeLimit = TimeSpan.FromMinutes(2);+ private static readonly TimeSpan TimeLimitPerMegabyte = TimeSpan.FromMinutes(30);+ private static readonly TimeSpan MaxTimeLimit = TimeSpan.FromMinutes(60);++ /// <summary>Usual rendering time per MB of section XML (drives the progress estimate of long documents).</summary>+ private static readonly TimeSpan TypicalPerMegabyte = TimeSpan.FromMinutes(15);++ private static readonly TimeSpan TypicalDuration = TimeSpan.FromSeconds(1.5);+private string? _exe;public string Id => "rhwp";@@ -35,21 +48,31 @@ public sealed class RhwpConverter : IConverter{var exe = _exe ?? Locate() ?? throw new InvalidOperationException("rhwp was not found.");var temp = Path.Combine(step.WorkDirectory, $"rhwp-{Guid.NewGuid():N}.{step.To}");- var input = step.To == "pdf" ? await PrepareAsync(exe, step, cancellationToken) : step.InputPath;- string[] arguments = step.To switch+ try+ {+ var input = step.To == "pdf" ? await PrepareAsync(exe, step, cancellationToken) : step.InputPath;+ string[] arguments = step.To switch+ {+ "pdf" => ["export-pdf", input, "-o", temp, .. RhwpInput.PdfOptions()],+ "hwpx" => ["export-hwpx", step.InputPath, temp],+ "hwp" => ["convert", step.InputPath, temp],+ _ => throw new NotSupportedException(step.To),+ };++ var text = TextSize(input);+ progress?.Report(0.1);+ ProcessResult result;+ using (ProgressEstimate.Start(progress, step.To == "pdf" ? Typical(text) : TypicalDuration))+ result = await ProcessRunner.RunAsync(exe, arguments, TimeLimit(text), cancellationToken);+ if (!File.Exists(temp) || new FileInfo(temp).Length == 0)+ throw new InvalidOperationException($"rhwp failed (exit {result.ExitCode}). {result.StandardError.Trim()}");+ }+ catch (TimeoutException ex){- "pdf" => ["export-pdf", input, "-o", temp, .. RhwpInput.PdfOptions()],- "hwpx" => ["export-hwpx", step.InputPath, temp],- "hwp" => ["convert", step.InputPath, temp],- _ => throw new NotSupportedException(step.To),- };-- progress?.Report(0.1);- ProcessResult result;- using (ProgressEstimate.Start(progress, TimeSpan.FromSeconds(1.5)))- result = await ProcessRunner.RunAsync(exe, arguments, Timeout, cancellationToken);- if (!File.Exists(temp) || new FileInfo(temp).Length == 0)- throw new InvalidOperationException($"rhwp failed (exit {result.ExitCode}). {result.StandardError.Trim()}");+ // E-books reach rhwp through the HWPX writer; calibre makes their PDFs much faster when it is ranked above it.+ throw new ConversionRefusedException(+ CalibreConverter.Locate() is null ? "error.rhwp_timeout" : "error.rhwp_timeout_calibre", ex.Message);+ }var target = step.Output.Allocate(step.To);if (target is null)@@ -70,13 +93,48 @@ public sealed class RhwpConverter : IConverterif (step.From == "hwp"){hwpx = Path.Combine(step.WorkDirectory, $"rhwp-{Guid.NewGuid():N}.hwpx");- await ProcessRunner.RunAsync(exe, ["export-hwpx", step.InputPath, hwpx], Timeout, cancellationToken);+ await ProcessRunner.RunAsync(exe, ["export-hwpx", step.InputPath, hwpx], TimeLimit(TextSize(step.InputPath)), cancellationToken);if (!File.Exists(hwpx) || new FileInfo(hwpx).Length == 0)return step.InputPath;}return RhwpInput.Prepare(hwpx, step.WorkDirectory) ?? step.InputPath;}+ /// <summary>How long one rhwp run on a document with <paramref name="textBytes"/> of text may take.</summary>+ internal static TimeSpan TimeLimit(long textBytes)+ {+ var limit = BaseTimeLimit + TimeLimitPerMegabyte * (textBytes / 1048576.0);+ return limit < MaxTimeLimit ? limit : MaxTimeLimit;+ }++ private static TimeSpan Typical(long textBytes)+ {+ var typical = TypicalPerMegabyte * (textBytes / 1048576.0);+ return typical > TypicalDuration ? typical : TypicalDuration;+ }++ /// <summary>+ /// The size of a document's text, which rendering time follows: the unpacked section XML of an HWPX (pictures left+ /// out), else three times the file (an HWP deflates its body text to about a third).+ /// </summary>+ internal static long TextSize(string path)+ {+ try+ {+ using var zip = ZipFile.OpenRead(path);+ var sections = zip.Entries+ .Where(e => e.FullName.StartsWith("Contents/section", StringComparison.OrdinalIgnoreCase)+ && e.FullName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))+ .Sum(e => e.Length);+ if (sections > 0)+ return sections;+ }+ catch (InvalidDataException) { } // not a ZIP: an HWP+ catch (IOException) { }+ catch (UnauthorizedAccessException) { }+ return new FileInfo(path).Length * 3;+ }+/// <summary>Filee's own copy (engines/rhwp), never one found elsewhere on the system.</summary>private static string? Locate() =>EngineEnvironment.FindBundled("rhwp") is { } bundleddiff --git a/tests/Filee.Engines.Tests/DocumentEngineTests.cs b/tests/Filee.Engines.Tests/DocumentEngineTests.csindex 61e20e2f..f741567b 100644--- a/tests/Filee.Engines.Tests/DocumentEngineTests.cs+++ b/tests/Filee.Engines.Tests/DocumentEngineTests.cs@@ -1,8 +1,10 @@// Tests for engines that are downloaded or bundled separately (LibreOffice, rhwp).// They skip automatically when the engine is not available, so CI stays green without them.+using System.IO.Compression;using Filee.Core.Conversion;using Filee.Core.Presets;+using Filee.Engines.Hwp;using Filee.Engines.Office;namespace Filee.Engines.Tests;@@ -92,6 +94,22 @@ public class DocumentEngineTests(EngineFixture fx) : IClassFixture<EngineFixtureAssert.Contains("두 번째 문단입니다", HwpxAssert.ReadBackText(back.Outputs.Single()));}+ [Fact]+ public async Task Rhwp_time_limit_grows_with_the_documents_text()+ {+ var dir = fx.NewFolder();+ var hwpx = await fx.MakeHwpxAsync(dir);+ using (var zip = ZipFile.OpenRead(hwpx))+ Assert.Equal(zip.Entries.Where(e => e.FullName.StartsWith("Contents/section", StringComparison.Ordinal)).Sum(e => e.Length), RhwpConverter.TextSize(hwpx));+ var hwp = Path.Combine(dir, "deflated.hwp");+ await File.WriteAllBytesAsync(hwp, new byte[1000], TestContext.Current.CancellationToken);+ Assert.Equal(3000, RhwpConverter.TextSize(hwp)); // not a ZIP: an HWP's text is deflated to about a third++ Assert.Equal(TimeSpan.FromMinutes(2), RhwpConverter.TimeLimit(0));+ Assert.Equal(TimeSpan.FromMinutes(32), RhwpConverter.TimeLimit(1024 * 1024));+ Assert.Equal(TimeSpan.FromMinutes(60), RhwpConverter.TimeLimit(100 * 1024 * 1024)); // a hung rhwp is still stopped+ }+[Fact]public async Task LibreOffice_with_H2Orestart_reads_hwpx(){diff --git a/tests/Filee.Engines.Tests/EbookTests.cs b/tests/Filee.Engines.Tests/EbookTests.csindex 8045f04f..f8339011 100644--- a/tests/Filee.Engines.Tests/EbookTests.cs+++ b/tests/Filee.Engines.Tests/EbookTests.cs@@ -77,6 +77,43 @@ public class EbookTests(EngineFixture fx) : IClassFixture<EngineFixture>Assert.Equal("ebook", Assert.Single(planner.Plan("epub", "fb2")!.Steps).Converter.Id);}+ /// <summary>The engine order with calibre moved to <paramref name="index"/>.</summary>+ private List<string> CalibreAt(int index)+ {+ var order = fx.Catalog.Priority.Where(id => id != "calibre").ToList();+ order.Insert(index, "calibre");+ return order;+ }++ [Fact]+ public void Calibre_makes_e_book_pdfs_only_when_ranked_above_the_hwpx_writer()+ {+ string[] installed = ["calibre", "rhwp", "pandoc", "libreoffice"];+ var writer = fx.Catalog.Priority.ToList().IndexOf("hwpx-writer");+ RoutePlanner Planner(IReadOnlyList<string> priority) =>+ new ConverterCatalog(fx.Converters) { Priority = priority }.CreatePlanner(installed);+ var byDefault = fx.Catalog.CreatePlanner(installed);+ var belowWriter = Planner(CalibreAt(writer + 1));+ var aboveWriter = Planner(CalibreAt(writer));+ var first = Planner(CalibreAt(0));++ // Books the built-in engines read: the default stays HWPX writer → rhwp (#127 moved calibre to the top).+ foreach (var from in CalibreConverter.PdfInputs.Except(CalibreConverter.Inputs))+ {+ Assert.Equal(["hwpx-writer", "rhwp"], byDefault.Plan(from, "pdf")!.Steps.Select(s => s.Converter.Id));+ Assert.Equal(["hwpx-writer", "rhwp"], belowWriter.Plan(from, "pdf")!.Steps.Select(s => s.Converter.Id));+ Assert.Equal("calibre", Assert.Single(aboveWriter.Plan(from, "pdf")!.Steps).Converter.Id);+ Assert.Equal("calibre", Assert.Single(first.Plan(from, "pdf")!.Steps).Converter.Id);+ }+ Assert.Equal(["hwpx-writer", "rhwp", "pdfium"], byDefault.Plan("epub", "png")!.Steps.Select(s => s.Converter.Id));+ Assert.Equal(["calibre", "pdfium"], first.Plan("epub", "png")!.Steps.Select(s => s.Converter.Id));++ // Formats only calibre reads: one calibre run instead of calibre → EPUB → HWPX writer → rhwp.+ Assert.Equal("calibre", Assert.Single(byDefault.Plan("lit", "pdf")!.Steps).Converter.Id);+ // Other documents keep their engines.+ Assert.DoesNotContain("calibre", first.Plan("docx", "pdf")!.Steps.Select(s => s.Converter.Id));+ }+// ───────────────────────── EPUB ─────────────────────────[Fact]@@ -444,6 +481,26 @@ public class EbookTests(EngineFixture fx) : IClassFixture<EngineFixture>Assert.Contains("밤하늘에", text);Assert.Contains("주석 내용입니다.", text);}++ [Fact]+ public async Task Calibre_ranked_first_makes_a4_pdfs_of_e_books()+ {+ Assert.SkipUnless(HasCalibre, "calibre not found (pwsh build/fetch-engines.ps1 -Only calibre)");+ var epub = EbookBuilders.Epub(fx.NewFolder());+ var catalog = new ConverterCatalog(fx.Converters) { Priority = CalibreAt(0) };+ await using var queue = new JobQueue(catalog);+ var job = new ConversionJob([epub], new Preset { TargetFormat = "pdf" }, "pdf");++ await queue.RunAsync(job);++ Assert.True(job.State == JobState.Completed, string.Join("; ", job.Files.Select(f => $"{f.ErrorKey} {f.ErrorDetail}")));+ using var pdf = UglyToad.PdfPig.PdfDocument.Open(job.Outputs.Single());+ Assert.Contains("calibre", pdf.Information.Producer, StringComparison.OrdinalIgnoreCase);+ var page = pdf.GetPage(pdf.NumberOfPages);+ Assert.Equal(595, page.Width, 2.0); // A4 in points (calibre: 594.96 × 840.96)+ Assert.Equal(842, page.Height, 2.0);+ Assert.Contains("밤하늘에", string.Concat(pdf.GetPages().Select(p => p.Text)));+ }}/// <summary>EPUB structure checks (the OCF / OPF rules epubcheck applies first).</summary>