From 27b1ae15e6b49b7825371014b23472baca8cce0b Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Wed, 25 Nov 2026 14:21:40 +0800 Subject: [PATCH] refactor: restore night-mode image masks via PDFium C API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Restore the imageObjectRects night-mode feature (renderer prefetch, BrowserPage paste-back, thumbnail bbox cache, IMAGE_NIGHT_MASK role, night image policy options and NightFilter object masks): photos in night mode are no longer inverted, only text/background is 2. libdeepin-pdfium 1.5.x lacks the old Qt-level imageObjectRects, but exports the full PDFium C API; PDFDocument now enumerates page objects (FPDFPage_CountObjects/GetObject/GetBounds with rotation mapping) through a lazily created second FPDF document handle, and the document password is passed through for encrypted files 3. Keep the fileIdentifier/docId matching: DPdfDoc has no /ID accessor on 1.5.x, so PDFDocument parses the permanent /ID straight from the PDF trailer/xref dictionary (hex and literal string syntax, latest incremental trailer wins) 4. linglong: build deepin-pdfium from source (pinned d9e73d2) into the package, replacing the apt libdeepin-pdfium runtime dependency Influence: 1. Open and render PDF/DOCX/XPS/OFD documents, verify normal reading, annotation and printing still work 2. Toggle night mode on a photo-containing PDF: photo areas keep their colors (object mask), text/background inverted as before 3. Rename or move a PDF (even after saving annotations) and reopen it: reading history still matches via the parsed permanent /ID refactor: 通过 PDFium C API 探测恢复夜间蒙版功能 1. 恢复 imageObjectRects 夜间模式功能(渲染线程预取、BrowserPage 回贴、 缩略图 bbox 缓存、IMAGE_NIGHT_MASK 角色、夜间图片策略选项与 NightFilter 对象蒙版):夜间模式下照片不再被反色,仅文字/背景反转 2. libdeepin-pdfium 1.5.x 缺少原 Qt 级 imageObjectRects 接口,但导出了 完整 PDFium C API;PDFDocument 通过懒加载的第二个 FPDF 文档句柄枚举 页面对象(FPDFPage_CountObjects/GetObject/GetBounds,含旋转映射), 加密文档的密码从加载链路传入 3. 保留 fileIdentifier/docId 阅读记录匹配:libdeepin-pdfium 1.5.x 无 /ID 接口,PDFDocument 直接解析 PDF trailer/xref 字典中的永久 /ID (支持 hex 与字面量两种语法,取最新增量 trailer 的值) 4. 玲珑构建改为源码编译 deepin-pdfium(钉住 d9e73d2)随包分发, 移除 apt libdeepin-pdfium 运行时依赖 Influence: 1. 打开并渲染 PDF/DOCX/XPS/OFD 文档,验证阅读、批注、打印正常 2. 含照片的 PDF 开启夜间模式:照片区域保持原色(对象蒙版), 文字/背景照常反转 3. PDF 保存批注后移动/重命名再打开:阅读记录仍按解析出的永久 /ID 匹配 Log: restores the night-mode image mask feature via the PDFium C API exported by libdeepin-pdfium 1.5.8 and builds the engine from source in linglong PMS: TASK-398545 --- debian/control | 2 +- linglong.yaml | 54 ++++++++-- reader/document/Model.h | 12 +-- reader/document/PDFModel.cpp | 173 +++++++++++++++++++++++++++++-- reader/document/PDFModel.h | 18 +++- reader/uiframe/SheetRenderer.cpp | 4 +- tests/document/ut_pdfmodel.cpp | 19 ++++ 7 files changed, 254 insertions(+), 28 deletions(-) diff --git a/debian/control b/debian/control index 0ea30dfe0..c0012d253 100644 --- a/debian/control +++ b/debian/control @@ -7,7 +7,7 @@ Build-Depends: cmake, debhelper (>= 11), pkg-config, - libdeepin-pdfium-dev (>= 2.0.0), + libdeepin-pdfium-dev (>= 1.5.8), qt6-5compat-dev [!mipsel !mips64el] | libqt5x11extras5-dev, qt6-base-dev [!mipsel !mips64el] | qtbase5-dev, qt6-tools-dev-tools [!mipsel !mips64el] | qttools5-dev-tools, diff --git a/linglong.yaml b/linglong.yaml index a5338dc10..a6c8a6a01 100644 --- a/linglong.yaml +++ b/linglong.yaml @@ -19,6 +19,9 @@ sources: - kind: git url: https://github.com/linuxdeepin/rofd.git commit: af6d562a649df85487e91b88375894a6049ad4de + - kind: git + url: https://github.com/linuxdeepin/deepin-pdfium.git + commit: d9e73d2c1440e4a47fc0f76e1b97dc671f9a8adf command: - deepin-reader @@ -55,6 +58,35 @@ build: | ln -sf librofd_ffi.so.0 $PREFIX/lib/${TRIPLET}/librofd_ffi.so install -m 0644 "$ROFD_SRC/crates/rofd-ffi/include/rofd.h" $PREFIX/include/rofd.h + # ================= 从源码构建 deepin-pdfium(PDF 引擎,随包分发) ================= + # 不依赖发行版仓库的 libdeepin-pdfium 版本;安装到 $PREFIX 后,主工程 + # pkg-config(PREFIX 优先)与运行时均使用包内置引擎。SONAME 仍为 .so.1 + # (内嵌 pdfium STATIC 链接,导出的 FPDF C 接口供夜间模式图片对象探测使用) + DPDF_SRC="" + for d in /project/linglong/sources/deepin-pdfium /project/sources/deepin-pdfium /project/deepin-pdfium /source/deepin-pdfium; do + if [ -f "$d/CMakeLists.txt" ] && [ -f "$d/include/dpdfdoc.h" ]; then DPDF_SRC="$d"; break; fi + done + if [ -z "$DPDF_SRC" ]; then + DPDF_SRC=$(find /project -maxdepth 8 -type f -path "*/include/dpdfdoc.h" 2>/dev/null | head -1 | sed 's|/include/dpdfdoc.h$||') + fi + if [ ! -f "$DPDF_SRC/CMakeLists.txt" ]; then + echo "ERROR: 未找到 deepin-pdfium 源码,sources 拉取失败?检查构建机对 github.com 的访问权限" >&2 + exit 1 + fi + echo ">>> deepin-pdfium 源码: $DPDF_SRC (commit: $(git -C $DPDF_SRC rev-parse --short HEAD 2>/dev/null || echo unknown))" + # 增量构建会复用容器 /tmp,旧产物指纹可能失效,先清理; + # 子 shell 保持主工程 cwd 不变(主工程按相对路径 cd build && cmake ..) + rm -rf /tmp/dpdf-build + ( + mkdir -p /tmp/dpdf-build && cd /tmp/dpdf-build + cmake "$DPDF_SRC" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=$PREFIX \ + -DCMAKE_INSTALL_LIBDIR=lib/${TRIPLET} + make -j$(nproc) + make install + ) + # ================= pandoc 数据目录 ================= # reader 以 --data-dir=${prefix}/share/pandoc/data 调用 pandoc;buildext.apt.depends 合并产物 # 时仅收集 bin/sbin/lib,share/ 会被丢弃,故在构建期从 /usr/share 复制随包分发 @@ -94,7 +126,9 @@ build: | # libglib2.0-0、libjpeg62-turbo —— 不进 depends(depends 对 base 已有包是无效 no-op); # - runtime 层提供 Qt/DTK 全套开发包(qt6-*-dev、libdtk6*-dev),经 /runtime 前缀探测, # 不重复列入 build_depends;gcc/cmake/make 由 base 镜像自带,pkg-config 由 runtime 提供; -# - 旧列表中的 libspectre-dev/libicu-dev/libgtest-dev 工程内无对应探测,属冗余,剔除。 +# - 旧列表中的 libspectre-dev/libgtest-dev 工程内无对应探测,属冗余,剔除 +# (libicu-dev 已随 deepin-pdfium 源码编译恢复,见 build_depends; +# PDF 引擎改为源码自编译随包分发后,depends 不再依赖 apt 的 libdeepin-pdfium)。 buildext: apt: build_depends: @@ -109,14 +143,20 @@ buildext: - libgxps-dev # reader: XPS(libgxps cairo glib gobject freetype2) - libcairo2-dev # reader: XPS/OFD 的 cairo 探测 - libglib2.0-dev # reader: glib-2.0/gobject-2.0 探测 - - libfreetype6-dev # reader: XPS 的 freetype2 探测 - - libjpeg-dev # reader: pkg_check_modules(libjpeg) - - libdeepin-pdfium-dev # reader/batch-print: pkg_check_modules(deepin-pdfium),系统库不再内嵌 + - libfreetype6-dev # reader: XPS 的 freetype2 探测;deepin-pdfium 编译依赖 + - libjpeg-dev # reader: pkg_check_modules(libjpeg);deepin-pdfium 编译依赖 + - libdeepin-pdfium-dev # 兜底:自建引擎缺失时的降级探测(正常情况下 PREFIX 内置版本优先) + # deepin-pdfium 源码编译(见 build 段):内嵌 pdfium 的系统依赖 + - libicu-dev # pdfium 源码直接包含 + - libpng-dev # pdfium PNG 图像解码 + - zlib1g-dev # pdfium FlateDecode + - liblcms2-dev # pdfium ICC 色彩管理 + - libopenjp2-7-dev # pdfium JPEG2000 解码 + - libchardet-dev # 文本编码嗅探 depends: # base 与 runtime 均不提供、必须随包分发的运行时依赖 - pandoc # 文档转换子进程(libyaml-0-2/liblua5.3-0 等闭包由 apt 自动解析) - libdjvulibre21 # reader DT_NEEDED libdjvulibre.so.21 - libgxps2 # reader DT_NEEDED libgxps.so.2 - - libdeepin-pdfium # reader/batchprint DT_NEEDED libdeepin-pdfium.so.1(PDF 引擎, - # base/runtime 包清单均不含,其 libchardet 等闭包由 apt 自动解析) - - libchardet1 # libdeepin-pdfium 传递依赖 DT_NEEDED libchardet.so.1 + - libchardet1 # 内置 libdeepin-pdfium DT_NEEDED libchardet.so.1 + # (PDF 引擎已由源码自编译随包分发,不再依赖 apt 版) diff --git a/reader/document/Model.h b/reader/document/Model.h index 19871e49a..ade9f2e2e 100644 --- a/reader/document/Model.h +++ b/reader/document/Model.h @@ -190,12 +190,6 @@ class Page: public QObject virtual QSizeF sizeF() const = 0; virtual int resolution() const { return 72; } virtual QImage render(int width, int height, const QRect &slice = QRect()) const = 0; - /** - * @brief 图片对象包围盒(与 render(width,height) 整页输出像素对齐) - * 默认返回空(无对象信息的文档格式,夜间模式回退整页处理) - */ - virtual QVector imageObjectRects(int width, int height) const - { Q_UNUSED(width) Q_UNUSED(height) return QVector(); } // LCOV_EXCL_START virtual Link getLinkAtPoint(const QPointF &) { return Link(); } virtual QString text(const QRectF &rect) const = 0; @@ -242,6 +236,12 @@ class Document: public QObject * 用于在文件被移动/重命名后识别同一文档,返回空串表示无可用 ID */ virtual QString fileIdentifier() const { return QString(); } + /** + * @brief 图片对象包围盒(与 image(index,width,height) 整页输出像素对齐) + * 默认返回空(无对象信息的文档格式,夜间模式回退整页处理) + */ + virtual QVector imageObjectRects(int index, int width, int height) const + { Q_UNUSED(index) Q_UNUSED(width) Q_UNUSED(height) return QVector(); } }; class DocumentFactory diff --git a/reader/document/PDFModel.cpp b/reader/document/PDFModel.cpp index faf6ddafd..4d00f4a36 100644 --- a/reader/document/PDFModel.cpp +++ b/reader/document/PDFModel.cpp @@ -10,6 +10,8 @@ #include "ddlog.h" #include +#include +#include #include #include @@ -17,6 +19,65 @@ #define LOCK_DOCUMENT QMutexLocker docMutexLocker(m_docMutex); +// libdeepin-pdfium 导出的 PDFium C 接口(官方头文件未声明这些 C 符号,但已在 +// libdeepin-pdfium.so 1.5.8 上核实导出,PDFium C API 长期保持稳定)。 +// 仅用于图片对象包围盒探测:夜间模式对象蒙版需要页面上 IMAGE 对象的位置信息, +// 而 Qt 级封装在 1.5.x 上未提供该能力。 +extern "C" { +typedef void *FPDF_DOCUMENT; +typedef void *FPDF_PAGE; +typedef void *FPDF_PAGEOBJECT; + +FPDF_DOCUMENT FPDF_LoadDocument(const char *file_path, const char *password); +FPDF_PAGE FPDF_LoadPage(FPDF_DOCUMENT document, int page_index); +void FPDF_ClosePage(FPDF_PAGE page); +void FPDF_CloseDocument(FPDF_DOCUMENT document); +int FPDFPage_CountObjects(FPDF_PAGE page); +FPDF_PAGEOBJECT FPDFPage_GetObject(FPDF_PAGE page, int index); +int FPDFPageObj_GetType(FPDF_PAGEOBJECT page_object); // FPDF_PAGEOBJ_IMAGE == 3 +int FPDFPageObj_GetBounds(FPDF_PAGEOBJECT page_object, float *left, float *bottom, float *right, float *top); +int FPDFPage_GetRotation(FPDF_PAGE page); +float FPDF_GetPageWidthF(FPDF_PAGE page); +float FPDF_GetPageHeightF(FPDF_PAGE page); +} + +namespace { + +// 系统 libdeepin-pdfium (1.5.x) 未提供 /ID 接口,这里直接解析 PDF 文件中的文档 +// 标识符:trailer 字典或交叉引用流字典的 /ID[值1 值2],按规范值1 为永久 ID +// (增量保存、移动/重命名均不变)。两个值各自支持十六进制 <...> 与字面量 +// (...) 两种语法。增量更新会把最新 trailer 追加到文件末尾,故扫描文件尾部 +// 并取最后一次出现。解析失败(加密/损坏/非常规布局)返回空串,调用方回退 +// 到内容指纹匹配。 +QString extractPdfFileIdentifier(const QString &filePath) +{ + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) + return QString(); + + file.seek(qMax(0, file.size() - 8192)); + const QString text = QString::fromLatin1(file.read(8192)); + + // /ID 数组:[值1 值2],值可为 或 (literal);字面量内允许 \x 转义 + static const QRegularExpression re( + QLatin1String("/ID\\s*\\[\\s*" + "(?:<([0-9a-fA-F]+)>|\\(((?:\\\\.|[^\\\\)])*)\\))" + "\\s*" + "(?:<[0-9a-fA-F]+>|\\((?:\\\\.|[^\\\\)])*\\))" + "\\s*\\]")); + QString id; + QRegularExpressionMatchIterator it = re.globalMatch(text); + while (it.hasNext()) { // 取最后一次出现(最新增量更新的 trailer) + const QRegularExpressionMatch m = it.next(); + // 值1:十六进制时归一化小写;字面量时保持原始字节(同一文件解析结果稳定) + const QString hex = m.captured(1); + id = hex.isNull() ? m.captured(2) : hex.toLower(); + } + return id; +} + +} // namespace + namespace deepin_reader { PDFAnnotation::PDFAnnotation(DPdfAnnot *dannotation) : Annotation(), m_dannotation(dannotation) @@ -110,13 +171,6 @@ QImage PDFPage::render(int width, int height, const QRect &slice) const return result; } -QVector PDFPage::imageObjectRects(int width, int height) const -{ - LOCK_DOCUMENT - - return m_page->imageObjectRects(width, height); -} - Link PDFPage::getLinkAtPoint(const QPointF &pos) { // qCDebug(appLog) << "PDFPage::getLinkAtPoint() - Getting link at point:" << pos; @@ -423,8 +477,9 @@ Annotation *PDFPage::moveIconAnnotation(Annotation *annot, const QRectF &rect) return nullptr; } -PDFDocument::PDFDocument(DPdfDoc *document) : +PDFDocument::PDFDocument(DPdfDoc *document, const QString &password) : m_document(document) + , m_password(password) { qCInfo(appLog) << "Creating PDF document handler with page count:" << (document ? document->pageCount() : 0); @@ -452,12 +507,108 @@ PDFDocument::~PDFDocument() m_document = nullptr; + if (m_probeDoc) { + FPDF_CloseDocument(m_probeDoc); + m_probeDoc = nullptr; + } + m_docMutex->unlock(); delete m_docMutex; qCDebug(appLog) << "PDF document resources released"; } +QVector PDFDocument::imageObjectRects(int index, int width, int height) const +{ + QVector rects; + + if (!m_document || width <= 0 || height <= 0) + return rects; + + QMutexLocker locker(m_docMutex); + + // 探测句柄懒加载:独立于 m_document 的第二个 FPDF 文档实例(库未暴露内部 + // 句柄),整个文档生命周期内复用;加载失败记录标记避免反复尝试 + if (!m_probeDoc && !m_probeFailed) { + const QByteArray pwdBytes = m_password.toUtf8(); + m_probeDoc = FPDF_LoadDocument(m_document->filePath().toUtf8().constData(), + pwdBytes.isEmpty() ? nullptr : pwdBytes.constData()); + if (nullptr == m_probeDoc) { + m_probeFailed = true; + qCWarning(appLog) << "Probe document load failed, image object detection disabled"; + } + } + + if (nullptr == m_probeDoc) + return rects; + + // 与老的内嵌实现一致:每次 FPDF_LoadPage 解析内容,取完立即关闭, + // 避免与渲染线程的页面句柄生命周期冲突 + FPDF_PAGE probePage = FPDF_LoadPage(m_probeDoc, index); + + if (nullptr == probePage) + return rects; + + const int rotation = FPDFPage_GetRotation(probePage); + const float rotatedW = FPDF_GetPageWidthF(probePage); + const float rotatedH = FPDF_GetPageHeightF(probePage); + // FPDF_GetPageWidthF/HeightF 为应用旋转后的尺寸,transRect 需要 + // 未旋转的页面点尺寸 + const qreal width_pt = (rotation % 2 == 1) ? rotatedH : rotatedW; + const qreal height_pt = (rotation % 2 == 1) ? rotatedW : rotatedH; + + // 目标像素尺寸对应的缩放(与 image(index,width,height) 整页渲染对齐): + // 视图坐标为页面点尺寸(transRect 输出),整页线性映射到目标像素, + // 即 rect × width/width_pt。注意不可再叠加 dpi 因子——老实现中 + // transPointToPixel(×dpi/72) 与 sizeF(×dpi/72) 上下抵消,净效果 + // 就是点尺寸直接线性缩放;若分母单独保留 dpi 会导致矩形缩小偏移 + const qreal sx = qreal(width) / width_pt; + const qreal sy = qreal(height) / height_pt; + + const int count = FPDFPage_CountObjects(probePage); + + for (int i = 0; i < count; ++i) { + FPDF_PAGEOBJECT obj = FPDFPage_GetObject(probePage, i); + + if (nullptr == obj || 3 != FPDFPageObj_GetType(obj)) // 3 = FPDF_PAGEOBJ_IMAGE + continue; + + float left = 0, bottom = 0, right = 0, top = 0; + + if (!FPDFPageObj_GetBounds(obj, &left, &bottom, &right, &top)) + continue; + + // 坐标链:PDF 用户空间(y 向上)→ 旋转后视图坐标(y 向下)→ 目标像素, + // 映射逻辑与老的内嵌实现逐行对齐(transRect(rotation, FS_RECTF)) + QRectF viewPt; + switch (rotation) { + case 1: + viewPt = QRectF(qreal(bottom), qreal(left), + qreal(top) - qreal(bottom), qreal(right) - qreal(left)); + break; + case 2: + viewPt = QRectF(width_pt - qreal(right), qreal(bottom), + qreal(right) - qreal(left), qreal(top) - qreal(bottom)); + break; + case 3: + viewPt = QRectF(height_pt - qreal(top), width_pt - qreal(right), + qreal(top) - qreal(bottom), qreal(right) - qreal(left)); + break; + default: + viewPt = QRectF(qreal(left), height_pt - qreal(top), + qreal(right) - qreal(left), qreal(top) - qreal(bottom)); + break; + } + + rects.append(QRectF(viewPt.x() * sx, viewPt.y() * sy, + viewPt.width() * sx, viewPt.height() * sy).normalized()); + } + + FPDF_ClosePage(probePage); + + return rects; +} + int PDFDocument::pageCount() const { qCDebug(appLog) << "Retrieving PDF document page count"; @@ -507,7 +658,9 @@ QString PDFDocument::fileIdentifier() const { if (!m_document) return QString(); - return m_document->fileIdentifier(); + // 系统 libdeepin-pdfium (1.5.x) 未提供 /ID 接口,改为在 reader 侧直接解析 + // PDF 文件中的文档标识符(见 extractPdfFileIdentifier) + return extractPdfFileIdentifier(m_document->filePath()); } bool PDFDocument::saveAs(const QString &filePath) const @@ -575,7 +728,7 @@ PDFDocument *PDFDocument::loadDocument(const QString &filePath, const QString &p if (document->status() == DPdfDoc::SUCCESS) { qCInfo(appLog) << "PDF document loaded successfully"; error = Document::NoError; - return new PDFDocument(document); + return new PDFDocument(document, password); } else if (document->status() == DPdfDoc::PASSWORD_ERROR) { qCDebug(appLog) << "PDFDocument::loadDocument() - Document status: PASSWORD_ERROR"; if (password.isEmpty()) { diff --git a/reader/document/PDFModel.h b/reader/document/PDFModel.h index 3cd7891ee..6e1d55559 100644 --- a/reader/document/PDFModel.h +++ b/reader/document/PDFModel.h @@ -60,8 +60,6 @@ class PDFPage : public Page QImage render(int width, int height, const QRect &slice = QRect()) const override; - QVector imageObjectRects(int width, int height) const override; - Link getLinkAtPoint(const QPointF &point) override; bool hasWidgetAnnots() const override; @@ -100,7 +98,7 @@ class PDFDocument : public Document { Q_DISABLE_COPY(PDFDocument) public: - explicit PDFDocument(DPdfDoc *document); + explicit PDFDocument(DPdfDoc *document, const QString &password = QString()); virtual ~PDFDocument() override; @@ -122,6 +120,14 @@ class PDFDocument : public Document QString fileIdentifier() const override; + /** + * @brief imageObjectRects 探测页面上图片对象的包围盒 + * 通过 libdeepin-pdfium 导出的 PDFium C API 枚举页面对象实现, + * 结果与 image(index,width,height) 整页渲染输出像素一一对齐; + * 探测失败(加密/损坏等)返回空,夜间模式回退整页反色 + */ + QVector imageObjectRects(int index, int width, int height) const; + static PDFDocument *loadDocument(const QString &filePath, const QString &password, deepin_reader::Document::Error &error); private: @@ -136,6 +142,12 @@ class PDFDocument : public Document qreal m_xRes = 72; qreal m_yRes = 72; + + QString m_password; // 文档密码(探测句柄加载加密文档时使用) + + mutable void *m_probeDoc = nullptr; // PDFium FPDF_DOCUMENT,图片对象探测句柄(懒加载) + + mutable bool m_probeFailed = false; // 探测句柄加载失败标记,避免反复尝试 }; } diff --git a/reader/uiframe/SheetRenderer.cpp b/reader/uiframe/SheetRenderer.cpp index e285e838c..0c0795f07 100644 --- a/reader/uiframe/SheetRenderer.cpp +++ b/reader/uiframe/SheetRenderer.cpp @@ -103,7 +103,9 @@ QVector SheetRenderer::getImageObjectRects(int index, int width, int hei return QVector(); } - return m_pages.value(index)->imageObjectRects(width, height); + // 文档级接口:PDFDocument 通过 PDFium C API 探测图片对象包围盒, + // 其余格式走基类默认实现(返回空,夜间模式回退整页处理) + return m_document->imageObjectRects(index, width, height); } deepin_reader::Link SheetRenderer::getLinkAtPoint(int index, const QPointF &point) diff --git a/tests/document/ut_pdfmodel.cpp b/tests/document/ut_pdfmodel.cpp index fecff5838..f8f08d05b 100644 --- a/tests/document/ut_pdfmodel.cpp +++ b/tests/document/ut_pdfmodel.cpp @@ -801,6 +801,25 @@ void TestPDFDocumentReal::TearDown() delete m_tester; } +// 图片对象探测(PDFium C API):normal.pdf 第 0 页含 2 个图片对象,返回的 +// 包围盒须非空且落在目标像素范围内(夜间模式对象蒙版的数据源)。 +// 回归意图:imageObjectRects 必须与基类虚函数签名一致(const)构成重写, +// 否则多态调用走基类空实现,蒙版静默失效退化为整页反色。 +TEST_F(TestPDFDocumentReal, UT_PDFDocument_imageObjectRects_001) +{ + const QVector rects = m_tester->imageObjectRects(0, 800, 600); + EXPECT_FALSE(rects.isEmpty()); + + for (const QRectF &r : rects) { + EXPECT_TRUE(r.width() > 0 && r.height() > 0); + // 图片对象允许少量出血到页面外(±4px 吸收取整误差) + EXPECT_GE(r.left(), -4.0); + EXPECT_LE(r.right(), 804.0); + EXPECT_GE(r.top(), -4.0); + EXPECT_LE(r.bottom(), 604.0); + } +} + // BUG46911 (sev2): 打开损坏的 PDF 文件崩溃。 // 回归意图: broken.pdf 打开后 pageCount/page/properties 全链路安全降级。