Repository navigation
refactor(htmltopdf): remove QtWebEngine dependency - #449
deepin-bot[bot] merged 4 commits into
Conversation
Replace the QWebEnginePage-based HTML-to-PDF conversion with QTextDocument + QPrinter, so htmltopdf no longer links WebEngine at all: - htmltopdfconverter: render HTML with QTextDocument and print it to vector PDF via QPrinter (A4, fonts embedded automatically); add a custom image handler that separates display size from embedded resolution (oversized screenshots are clamped to the text area and embedded up to 300dpi) and scale handler sizes by the print paint device DPI to keep physical size consistent with text - main.cpp: drop WebEngine crash workarounds (Wayland --disable-gpu, sw_64 --js-flags=--jitless), no longer needed - build: htmltopdf.pro/CMakeLists.txt link PrintSupport instead of WebEngineWidgets; drop unused webenginewidgets from the reader qmake sources (no WebEngine code in the main program) - debian/control: remove qt6-webengine-dev and libqt6webenginecore6-bin - linglong.yaml: use org.deepin.runtime.dtk instead of the webengine runtime The command-line interface is unchanged; Model.cpp still launches htmltopdf as a subprocess.
Reviewer's GuideAPIReplace the converter’s WebEngine page member and completion slots with the QObject-based QTextDocument/QPrinter converter interface.
Uses of the APIKeep the htmltopdf command-line entry point intact while removing the WebEngine-specific startup workarounds.
ImplementationImplement HTML-to-PDF rendering with QTextDocument and QPrinter, including DPI-aware image sizing, capped embedding resolution, and resource preloading for print clones.
ConfigurationReplace WebEngine build and runtime dependencies with PrintSupport or the DTK runtime, and remove unused WebEngine modules and package dependencies.
Configure the test target’s PrintSupport dependencies and moc generation so it can compile the converter’s white-box tests.
TestsAdd white-box coverage for PDF conversion, image sizing and embedding, DPI scaling, and preloaded resources surviving document cloning.
Keep the application alive for printer-based tests and explicitly flush coverage before bypassing unstable third-party teardown.
Recognize the observed third-party teardown crashes and include htmltopdf sources in coverage collection.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
QTextDocument::print() lays out and draws on an internal clone of the document, and QTextDocument::clone() copies neither the baseUrl nor the cachedResources of the original. The override loadResource() of EmbeddingTextDocument (the 300-dpi embedding cap) therefore never runs for the clone; print()'s rendering fell back to the resource loader's relative-path resolution, which depends on the current working directory and silently drops every image when the cwd is not the HTML directory. Worse, the first layout pass caches the raw QPixmap in cachedResources, so resource()-based preload stored the unscaled image and the cap never took effect. Fix preloadImageResources() to: - call loadResource() directly (bypassing the resource() cache hit) via a new EmbeddingTextDocument::loadScaledResource() wrapper, since the virtual is protected and cannot be invoked from a free function; - store the scaled QImage under both the resolved URL and the original resource name, so lookups on the original document (baseUrl resolves the name) and inside print()'s baseUrl-less clone (resolved(name) == name) both hit. HTML-to-PDF now embeds capped-resolution images regardless of the process working directory.
Add GTest coverage for the QTextDocument+QPrinter converter, following the existing white-box pattern (include the .cpp in a single TU behind UT_HTMLTOPDF_ENABLED, custom moc for the anonymous-namespace handler): - HtmlTopdfDpiTest: reference DPI from the primary screen, layout scale factor for non-96dpi displays - HtmlTopdfConvertTest: basic conversion, missing input, unwritable output, oversized image embedded under the 300-dpi cap - HtmlTopdfImageHandlerTest: intrinsic size, CSS-constrained size, clamp, aspect ratio, huge/small/missing image paths - HtmlTopdfEmbeddingTest: loadResource scaling cap, aspect ratio, no scaling under the cap, missing file - HtmlTopdfPreloadTest: preload caches images that survive the print clone, embedding cap propagates through the clone, empty doc no-crash Also fix tests/main.cpp: the QCoreApplication was destroyed at the end of its single-statement scope, so any QPrinter constructed afterwards aborted with "Must construct a QCoreApplication before a QPrinter". Hold it in a static unique_ptr for the whole run. And extend test-prj-running.sh coverage extraction to htmltopdf/ alongside reader/. All 1287 tests pass (23 new).
Third-party libraries (djvulibre, deepin-pdfium, Qt's GL cleanup) segfault or abort during the exit-time global destruction of the full test binary, and gcov's atexit writeback is registered after those destructors, so no .gcda file survives and lcov captures nothing. RUN_ALL_TESTS already writes the gtest XML, so after it returns: explicitly __gcov_dump() the counters, flush stdio, then _exit() to skip the crashing exit-time destructors entirely. Note the declaration must be a strong reference: a weak one never makes the linker pull gcov-dump.o out of libgcov.a, leaving the pointer null. The test target always links with -fprofile-arcs, so the symbol always resolves. Also accept exit 139 (SIGSEGV) alongside 134 in test-prj-running.sh's exit-time-crash tolerance, matching the third-party teardown crashes observed on this system.
ea636c9 to
b84f6ea
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整,存在少量残留调试代码 ✅ 通过 潜在问题: 建议: ["删除 ut_htmltopdfconverter.cpp 第1086行的临时注释 '// ---- 临时诊断(排查后删除) ----'", '删除 tests/main.cpp 中未使用的 #if defined(CMAKE_SAFETYTEST_ARG_ON) / #include <sanitizer/asan_interface.h> / #endif 代码块', '将 preloadImageResources 参数类型改为 EmbeddingTextDocument*,移除不必要的 static_cast', '将测试中的 QTextDocument *clone = doc.clone() 替换为 std::unique_ptr clone(doc.clone())'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// 1. 删除 tests/htmltopdf/ut_htmltopdfconverter.cpp 第1086行的临时注释
// 将:
// // ---- 临时诊断(排查后删除) ----
//
// #endif // UT_HTMLTOPDF_ENABLED
// 改为:
// #endif // UT_HTMLTOPDF_ENABLED
// 2. 删除 tests/main.cpp 中未使用的 ASan 头文件包含
// 移除以下三行:
// #if defined(CMAKE_SAFETYTEST_ARG_ON)
// #include <sanitizer/asan_interface.h>
// #endif
// 3. 修改 preloadImageResources 参数类型
// 将:
// void preloadImageResources(QTextDocument *document)
// {
// auto *embeddingDoc = static_cast<EmbeddingTextDocument *>(document);
// 改为:
// void preloadImageResources(EmbeddingTextDocument *document)
// {
// auto *embeddingDoc = document;
// 4. 使用智能指针管理 clone 生命周期
// 将:
// QTextDocument *clone = doc.clone();
// ASSERT_NE(clone, nullptr);
// ...
// delete clone;
// 改为:
// std::unique_ptr<QTextDocument> clone(doc.clone());
// ASSERT_NE(clone, nullptr);
// ...
// // 无需手动 delete本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
Summary
Port of the htmltopdf QtWebEngine removal to current master (originally developed against 6.0.11.1 / qmake+Qt5.11.3). htmltopdf no longer links QtWebEngine at all: HTML is rendered with
QTextDocumentand printed to vector PDF viaQPrinter.Changes
QWebEnginePagewithQTextDocument+QPrinter(A4, 10mm page margins, fonts embedded automatically by the PDF engine).QTextImageHandler), keeping the physical image size consistent with text at any printer DPI.--disable-gpu, sw_64--js-flags=--jitless) — no longer applicable.PrintSupportinstead ofWebEngineWidgets.deepin_reader.pro,reader.pro,src.pri): drop the unusedwebenginewidgetsmodule (the main program contains no WebEngine code).qt6-webengine-dev(Build-Depends) andlibqt6webenginecore6-bin(Depends).org.deepin.runtime.webengine→org.deepin.runtime.dtk/6.7.0.The CLI is unchanged (
htmltopdf <input.html> <output.pdf>); the main program still launches htmltopdf as a subprocess, so no reader-side changes are needed.Verification
htmltopdfbuilds via CMake (Qt 6.8) andlddshows no WebEngine/Chromium libraries.width/heightattributes render at the given CSS size (missing dimension completed from the image aspect ratio, matching browser semantics).[!mipsel !mips64el]guards on the removed WebEngine entries are gone with them.Summary by Sourcery
Remove QtWebEngine from HTML-to-PDF conversion and project packaging while retaining compatible PDF output with improved image quality and portability.
New Features:
Bug Fixes:
Enhancements:
Deployment:
Tests: