Skip to content

fix: reserve viewport margin in adjustViewScaleRatio - #295

Closed
lzwind wants to merge 1 commit into
linuxdeepin:masterfrom
lzwind:agent/bugfix/287307
Closed

lzwind wants to merge 1 commit into
linuxdeepin:masterfrom
lzwind:agent/bugfix/287307

Conversation

@lzwind

@lzwind lzwind commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

fix: reserve viewport margin in adjustViewScaleRatio

  1. Root cause: adjustViewScaleRatio() used full viewport dimensions
    to compute scale ratio without reserving any margin
  2. Fix: subtract 40px (20px per side) from viewport width and height
    before computing the scale ratio
  3. Impact: both crop and non-crop modes now keep >=20px margin on all
    sides; no API change, only local variable adjustment

Log: canvas now keeps 20px margin on all sides of viewport

Influence:

  1. Test image loading with various canvas sizes
  2. Test crop mode entry/exit with different viewport sizes
  3. Verify no regression on manual zoom and page switch

fix: 缩放计算预留画布边距

  1. 根因:adjustViewScaleRatio() 使用 viewport 全量尺寸计算缩放比,
    未预留任何边距
  2. 方案:计算缩放比前从 viewport 尺寸中减去 40px(每侧 20px)
  3. 影响:裁剪与非裁剪模式均保证四边至少 20px 间距;无接口变更

Log: 画布四边预留 20px 边距,修复裁剪时贴边问题

Influence:

  1. 测试不同画布尺寸下的图像加载
  2. 测试不同 viewport 尺寸下裁剪模式进出
  3. 验证手动缩放和页面切换无回归

PMS: BUG-287307

Summary by Sourcery

Bug Fixes:

  • Reserve a 20px margin on each side of the viewport when calculating the view scale ratio, preventing canvas content from reaching the viewport edges in crop and non-crop modes.

1. Root cause: adjustViewScaleRatio() used full viewport dimensions
   to compute scale ratio without reserving any margin
2. Fix: subtract 40px (20px per side) from viewport width and height
   before computing the scale ratio
3. Impact: both crop and non-crop modes now keep >=20px margin on all
   sides; no API change, only local variable adjustment

Log: canvas now keeps 20px margin on all sides of viewport

Influence:
1. Test image loading with various canvas sizes
2. Test crop mode entry/exit with different viewport sizes
3. Verify no regression on manual zoom and page switch

fix: 缩放计算预留画布边距

1. 根因:adjustViewScaleRatio() 使用 viewport 全量尺寸计算缩放比,
   未预留任何边距
2. 方案:计算缩放比前从 viewport 尺寸中减去 40px(每侧 20px)
3. 影响:裁剪与非裁剪模式均保证四边至少 20px 间距;无接口变更

Log: 画布四边预留 20px 边距,修复裁剪时贴边问题

Influence:
1. 测试不同画布尺寸下的图像加载
2. 测试不同 viewport 尺寸下裁剪模式进出
3. 验证手动缩放和页面切换无回归

PMS: BUG-287307
@lzwind
lzwind marked this pull request as draft November 15, 2026 05:22
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind

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 Nov 15, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Reserve 20 pixels on each side of the viewport before calculating the view scale ratio.

  • src/frame/ccentralwidget.cpp L717-719

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 found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/frame/ccentralwidget.cpp" line_range="718-719" />
<code_context>
-        int viewportWidth = view()->viewport()->width();
-        int viewportHeight = view()->viewport()->height();
+        const int margin = 20;
+        int viewportWidth = view()->viewport()->width() - margin * 2;
+        int viewportHeight = view()->viewport()->height() - margin * 2;
         qreal sceneWidth = scene()->width();
         qreal sceneHeight = scene()->height();
</code_context>
<issue_to_address>
**Canvas stays at minimum zoom**

When either viewport dimension is below 40px during an adjustment, the 20px margin subtraction makes an available dimension nonpositive, so the fit ratio is nonpositive and `PageView::scaleWithCenter()` clamps it to 0.1; the canvas is left at minimum zoom instead of fitting. An image-load adjustment stays there after a later resize.

Prevent nonpositive fit dimensions and rerun the adjustment when the viewport is enlarged.
</issue_to_address>

### Comment 2
<location path="src/frame/ccentralwidget.cpp" line_range="718-719" />
<code_context>
-        int viewportWidth = view()->viewport()->width();
-        int viewportHeight = view()->viewport()->height();
+        const int margin = 20;
+        int viewportWidth = view()->viewport()->width() - margin * 2;
+        int viewportHeight = view()->viewport()->height() - margin * 2;
         qreal sceneWidth = scene()->width();
         qreal sceneHeight = scene()->height();
</code_context>
<issue_to_address>
**Canvas exceeds the margins**

When the canvas needs a fit ratio below 0.1, `PageView::scaleWithCenter()` clamps the requested ratio to 0.1, so the canvas remains larger than the margin-reduced viewport and reaches or extends beyond its edges.

Allow this fit adjustment to use ratios below 0.1.
</issue_to_address>

### Comment 3
<location path="src/frame/ccentralwidget.cpp" line_range="718" />
<code_context>
-        int viewportWidth = view()->viewport()->width();
-        int viewportHeight = view()->viewport()->height();
+        const int margin = 20;
+        int viewportWidth = view()->viewport()->width() - margin * 2;
+        int viewportHeight = view()->viewport()->height() - margin * 2;
         qreal sceneWidth = scene()->width();
</code_context>
<issue_to_address>
**Imported images keep the old scale**

When an image is imported through the type-1 adaptation path or `DrawBoard::loadImage()`, those paths do not call `adjustViewScaleRatio()`, so an oversized canvas keeps its previous scale and can reach the viewport edges.

Call `adjustViewScaleRatio()` on both image-import paths.
</issue_to_address>

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

Comment on lines +718 to +719
int viewportWidth = view()->viewport()->width() - margin * 2;
int viewportHeight = view()->viewport()->height() - margin * 2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Canvas stays at minimum zoom

When either viewport dimension is below 40px during an adjustment, the 20px margin subtraction makes an available dimension nonpositive, so the fit ratio is nonpositive and PageView::scaleWithCenter() clamps it to 0.1; the canvas is left at minimum zoom instead of fitting. An image-load adjustment stays there after a later resize.

Prevent nonpositive fit dimensions and rerun the adjustment when the viewport is enlarged.

Prompt for AI agents
In `src/frame/ccentralwidget.cpp` at lines 718-719:

**Canvas stays at minimum zoom**

When either viewport dimension is below 40px during an adjustment, the 20px margin subtraction makes an available dimension nonpositive, so the fit ratio is nonpositive and `PageView::scaleWithCenter()` clamps it to 0.1; the canvas is left at minimum zoom instead of fitting. An image-load adjustment stays there after a later resize.

Prevent nonpositive fit dimensions and rerun the adjustment when the viewport is enlarged.

Comment on lines +718 to +719
int viewportWidth = view()->viewport()->width() - margin * 2;
int viewportHeight = view()->viewport()->height() - margin * 2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Canvas exceeds the margins

When the canvas needs a fit ratio below 0.1, PageView::scaleWithCenter() clamps the requested ratio to 0.1, so the canvas remains larger than the margin-reduced viewport and reaches or extends beyond its edges.

Allow this fit adjustment to use ratios below 0.1.

Prompt for AI agents
In `src/frame/ccentralwidget.cpp` at lines 718-719:

**Canvas exceeds the margins**

When the canvas needs a fit ratio below 0.1, `PageView::scaleWithCenter()` clamps the requested ratio to 0.1, so the canvas remains larger than the margin-reduced viewport and reaches or extends beyond its edges.

Allow this fit adjustment to use ratios below 0.1.

int viewportWidth = view()->viewport()->width();
int viewportHeight = view()->viewport()->height();
const int margin = 20;
int viewportWidth = view()->viewport()->width() - margin * 2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Imported images keep the old scale

When an image is imported through the type-1 adaptation path or DrawBoard::loadImage(), those paths do not call adjustViewScaleRatio(), so an oversized canvas keeps its previous scale and can reach the viewport edges.

Call adjustViewScaleRatio() on both image-import paths.

Prompt for AI agents
In `src/frame/ccentralwidget.cpp` at line 718:

**Imported images keep the old scale**

When an image is imported through the type-1 adaptation path or `DrawBoard::loadImage()`, those paths do not call `adjustViewScaleRatio()`, so an oversized canvas keeps its previous scale and can reach the viewport edges.

Call `adjustViewScaleRatio()` on both image-import paths.

@lzwind lzwind closed this Nov 17, 2026
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