Skip to content

fix: prevent text truncation when saving edited images - #428

Open
JWWTSL wants to merge 1 commit into
linuxdeepin:masterfrom
JWWTSL:agent/pms-bug-bot/3b3edc5b945f
Open

JWWTSL wants to merge 1 commit into
linuxdeepin:masterfrom
JWWTSL:agent/pms-bug-bot/3b3edc5b945f

Conversation

@JWWTSL

@JWWTSL JWWTSL commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

The save path (ImageEditController::saveComposite in imageeditcontroller.cpp) used QPainter::drawText(rect, flags, text) which clips text to the rectangle boundary by default, while the QML preview path (EditCanvas.qml) used CanvasContext.fillText() with context.scale() that does not clip text. This rendering strategy mismatch caused text annotations to be truncated when saving edited images, even though they displayed correctly in the preview.

Key evidence: (1) QML preview uses fixed 20px font + context.scale() without clipping; (2) C++ save path uses drawText(QRectF, flags, text) with default clipping enabled; (3) Qt documentation confirms drawText(rect, flags, text) clips text to the rectangle.

Fix

Added Qt::TextDontClip | Qt::TextSingleLine flags to the text annotation drawText call and Qt::TextDontClip to the number annotation drawText call in saveComposite, making the save rendering behavior consistent with the QML preview (no clipping, single-line rendering).

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target code was authored during feature development (TASK-393981), not a previous bug fix — this change does not revert any historical fix
  • Only 2 references exist (header declaration and a test for the empty-URL branch); neither is affected by the flag change
  • No function signatures changed, no new functions added, no control flow modified

Business Impact Scope

Affected functional module: Image Editor — Text/Number Annotation Save. When users add text or number annotations in edit mode and save, the saved image rendering now matches the on-screen preview. The change only affects the drawText rendering flags within saveComposite, with no impact on other editing features (crop, effects, undo/redo, etc.).

Verification Suggestion

Test adding long text annotations → save → verify text is complete and not truncated. Test number annotations → save → verify correct display. Verify mixed annotation types save correctly.


根因分析

保存路径(imageeditcontroller.cpp 中的 ImageEditController::saveComposite)使用 QPainter::drawText(rect, flags, text),默认将文本裁剪到矩形边界内;而 QML 预览路径(EditCanvas.qml)使用 CanvasContext.fillText() 配合 context.scale(),不裁剪文本。两条路径渲染策略不一致导致保存编辑图片时文本标注被截断,尽管预览中显示正常。

关键证据:(1) QML 预览使用固定 20px 字号 + context.scale() 不裁剪;(2) C++ 保存路径使用 drawText(QRectF, flags, text) 且默认启用裁剪;(3) Qt 文档确认 drawText(rect, flags, text) 会将文本裁剪到矩形内。

修复方案

在 saveComposite 中为文本标注的 drawText 调用添加 Qt::TextDontClip | Qt::TextSingleLine 标志,为序号标注的 drawText 调用添加 Qt::TextDontClip 标志,使保存渲染行为与 QML 预览一致(不裁剪、单行渲染)。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标代码在功能开发(TASK-393981)期间编写,非历史 bug 修复产物——本次修改不会撤销任何历史修复
  • 仅有 2 处引用(头文件声明和一个空 URL 分支测试),均不受标志位变更影响
  • 无函数签名变更,无新增函数,无控制流修改

业务影响范围

受影响功能模块:图片编辑 — 文本/序号标注保存。用户在编辑模式添加文本或序号标注并保存时,保存图片的渲染将与屏幕预览一致。改动仅影响 saveComposite 内 drawText 的渲染标志,不影响其他编辑功能(裁剪、特效、撤销重做等)。

验证建议

测试添加较长文本标注 → 保存 → 验证文本完整不截断。测试序号标注 → 保存 → 验证显示正常。验证混合标注类型保存正确。

Summary by Sourcery

Bug Fixes:

  • Prevent text and number annotations from being truncated when saved in edited images, keeping saved rendering consistent with the preview.

1. Root cause: saveComposite used QPainter::drawText(rect, flags, text)
   which clips text to the rect boundary, while QML preview used
   CanvasContext.fillText() without clipping — mismatch caused truncation
2. Fix: add Qt::TextDontClip | Qt::TextSingleLine to text annotation
   drawText and Qt::TextDontClip to number annotation drawText, matching
   the QML preview rendering behavior
3. Impact: saved images now render text annotations identically to the
   on-screen preview, no longer clipping wide text content

Log: Fix text truncation in saved edited images to match preview

Influence:
1. Test text annotation save with long text content
2. Test number annotation save with multi-digit numbers
3. Verify mixed annotations save correctly

fix: 修复保存编辑图片时文本被截断的问题

1. 根因:saveComposite 使用 QPainter::drawText(rect, flags, text) 默认
   裁剪文本到矩形边界,而 QML 预览使用 CanvasContext.fillText() 不裁剪
   — 两条路径渲染策略不一致导致保存时文本被截断
2. 方案:为文本标注 drawText 添加 Qt::TextDontClip | Qt::TextSingleLine
   标志,为序号标注 drawText 添加 Qt::TextDontClip 标志,使保存渲染
   行为与 QML 预览一致
3. 影响:保存的图片中文本标注渲染与屏幕预览一致,不再裁剪宽文本

Log: 修复保存编辑图片时文本标注被截断的问题

Influence:
1. 测试长文本标注保存后文本完整不被截断
2. 测试多位数序号标注保存后正常显示
3. 验证混合标注保存结果正确

PMS: BUG-379123
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JWWTSL

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 Oct 27, 2026

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

Reviewer's Guide

Updates ImageEditController::saveComposite so saved text and number annotations are not truncated by QPainter's default rectangle clipping, matching the on-screen preview. Review the flag semantics and verify long text, number, and mixed annotations after saving.

Sequence diagram for annotation preview and save rendering

sequenceDiagram
    participant User
    participant EditCanvas
    participant ImageEditController
    participant QPainter

    User->>EditCanvas: Add text or number annotation
    EditCanvas->>EditCanvas: fillText()
    EditCanvas-->>User: Preview renders without clipping
    User->>ImageEditController: saveComposite()
    ImageEditController->>QPainter: drawText(annotation bounds, flags, text)
    QPainter-->>ImageEditController: Render annotation without clipping
    ImageEditController-->>User: Saved image matches preview
Loading

File-Level Changes

Change Details Files
Align saved annotation rendering with the unclipped QML preview by changing the text drawing flags.
  • Disable rectangle clipping for number annotations.
  • Disable clipping and enforce single-line rendering for text annotations.
  • Leave annotation geometry, sizing, and control flow unchanged.
src/src/imageeditcontroller.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 reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次变更通过为 QPainter::drawText 增加 Qt::TextDontClip / Qt::TextSingleLine 文本标志,修复了编辑图片保存时文字被截断的问题。改动范围小、目标明确,语法正确、逻辑合理,无安全漏洞,四维度均通过。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例


本报告由 AI 代码审查工具自动生成

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