Skip to content

fix(print): render page with white background - #218

Open
Resurgamz wants to merge 1 commit into
linuxdeepin:release/eaglefrom
Resurgamz:feature/fix-BUG221301
Open

fix(print): render page with white background#218
Resurgamz wants to merge 1 commit into
linuxdeepin:release/eaglefrom
Resurgamz:feature/fix-BUG221301

Conversation

@Resurgamz

@Resurgamz Resurgamz commented Jul 23, 2026

Copy link
Copy Markdown

问题\n修复打印预览中透明画布区域显示黑色矩形框的问题。\n\n## 修复方案\n在打印入口渲染页面图像时显式传入 Qt::white 作为背景色,避免透明像素在预览或打印后端按黑色合成。\n\n## 验证\n- cmake --build obj-x86_64-linux-gnu -j2\n\n## PMS\n- BUG-221301\n- 根因分析:analysis-report.md

Summary by Sourcery

Bug Fixes:

  • Fix print preview and backend rendering where transparent canvas regions appeared as black rectangles by rendering page images with an explicit white background.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Resurgamz

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR ensures printed/previewed pages use a white background instead of treating transparent canvas regions as black by passing an explicit background color when rendering the page image for the print dialog.

Sequence diagram for updated print preview background rendering

sequenceDiagram
    actor User
    participant TopTilte
    participant DrawApp as drawApp
    participant DrawBoard as drawBoard
    participant Page as page
    participant Context as page_context
    participant CPrintManager as CPrintManager

    User ->> TopTilte: trigger Print action
    TopTilte ->> DrawApp: topMainWindowWidget()
    TopTilte ->> DrawApp: drawBoard()
    DrawApp ->> DrawBoard: currentPage()
    DrawBoard ->> Page: currentPage
    Page ->> Page: context()
    Page ->> Context: context
    Context ->> Context: renderToImage(Qt::white)
    Context -->> TopTilte: rendered_image
    TopTilte ->> CPrintManager: CPrintManager(topMainWindowWidget)
    TopTilte ->> CPrintManager: showPrintDialog(rendered_image, topMainWindowWidget, page->name())
Loading

File-Level Changes

Change Details Files
Ensure page image for printing is rendered with an explicit white background to avoid transparent areas appearing as black in print preview/output.
  • Update the print action handler to obtain the current page image with a specified background color instead of using the default rendering.
  • Pass Qt::white as the background color when rendering the page image used by CPrintManager::showPrintDialog.
src/frame/toptoolbar.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider whether using a hardcoded Qt::white is always appropriate for printing (e.g., dark themes or custom page backgrounds) and, if not, derive the background color from the page or user settings instead.
  • It may be clearer to guard showPrintDialog with an early return when page or page->context() is null, rather than nesting the call inside the conditional.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider whether using a hardcoded `Qt::white` is always appropriate for printing (e.g., dark themes or custom page backgrounds) and, if not, derive the background color from the page or user settings instead.
- It may be clearer to guard `showPrintDialog` with an early return when `page` or `page->context()` is null, rather than nesting the call inside the conditional.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了打印预览背景透明导致显示异常的问题,逻辑正确且无安全风险。
修改简单有效,通过显式传入白色背景色解决显示异常,无明显质量与性能问题。

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

代码在 TopTilte::initMenu 函数中调用 renderToImage 时显式传入 Qt::white,符合 QImage renderToImage(const QColor &bgColor = Qt::transparent, const QSize &desImageSize = QSize()) 的函数声明,正确修复了背景透明导致的打印异常问题。
潜在问题:无
建议:无需修改

  • 2.代码质量(良好)✓

代码修改简洁明了,直接针对问题根因进行修复,格式规范,对齐正确。
潜在问题:无
建议:无需修改

  • 3.代码性能(无性能问题)✓

仅修改了传入参数,不涉及算法复杂度或额外资源消耗,对性能无负面影响。
潜在问题:
建议:无需修改

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改仅为参数传递的调整,不涉及外部输入处理、文件操作或内存管理,不存在安全风险。

  • 建议:无需修改

■ 【改进建议代码示例】

// 当前代码已是最优修复方案,无需进一步改进
void TopTilte::initMenu()
{
    // ...
    CPrintManager manager(drawApp->topMainWindowWidget());
    auto page = drawApp->drawBoard()->currentPage();
    if (page != nullptr && page->context() != nullptr)
        manager.showPrintDialog(page->context()->renderToImage(Qt::white), drawApp->topMainWindowWidget(),
                                page->name());
    // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants