Skip to content

fix viewport#19134

Merged
star-e merged 1 commit into
cocos:v3.8.61from
star-e:v3.8.61-fix
Jan 23, 2026
Merged

fix viewport#19134
star-e merged 1 commit into
cocos:v3.8.61from
star-e:v3.8.61-fix

Conversation

@star-e
Copy link
Copy Markdown
Contributor

@star-e star-e commented Jan 23, 2026

Re: #

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

Greptile Overview

Greptile Summary

This PR adds Math.ceil() to round up canvasSize.width and canvasSize.height at the end of _calculateLabelFont() method. This ensures that canvas dimensions are always integers rather than fractional values.

Key Changes:

  • Added two lines in text-processing.ts:257-258 to ceil canvas dimensions after all overflow mode calculations complete
  • Applied uniformly after all canvas size calculations (NONE, SHRINK, CLAMP, RESIZE_HEIGHT overflow modes)

Impact:
HTML Canvas elements require integer dimensions for proper rendering. Fractional pixel values from font calculations can cause viewport and rendering artifacts. This fix prevents such issues by ensuring dimensions are whole numbers before the canvas is used in _updateLabelDimensions().

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is simple, well-placed, and follows best practices for canvas dimension handling. Using Math.ceil() ensures dimensions are always valid integers without truncating content. The fix is applied after all size calculations, preserving existing logic while preventing fractional pixel issues. No breaking changes or side effects expected.
  • No files require special attention

Important Files Changed

Filename Overview
cocos/2d/assembler/label/text-processing.ts Added Math.ceil() to ensure canvas dimensions are integers, preventing potential rendering issues from fractional pixel values

Sequence Diagram

sequenceDiagram
    participant Client as Label Component
    participant TP as TextProcessing
    participant Canvas as HTML Canvas
    
    Client->>TP: processingString()
    TP->>TP: _calculateLabelFont()
    Note over TP: Calculate canvasSize based on<br/>overflow mode (NONE, SHRINK, etc.)
    TP->>TP: Math.ceil(canvasSize.width)
    TP->>TP: Math.ceil(canvasSize.height)
    Note over TP: NEW: Ensure integer dimensions<br/>to fix viewport issues
    
    Client->>TP: generateRenderInfo()
    TP->>TP: _updateLabelDimensions()
    TP->>Canvas: canvas.width = canvasSize.width
    TP->>Canvas: canvas.height = canvasSize.height
    Note over Canvas: Canvas dimensions must be integers<br/>Fractional values can cause rendering issues
Loading

@star-e star-e merged commit e8c5011 into cocos:v3.8.61 Jan 23, 2026
11 of 13 checks passed
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

cocos-robot pushed a commit to cocos-robot/engine that referenced this pull request Jan 23, 2026
@github-actions
Copy link
Copy Markdown

Code Size Check Report

Wechat (WASM) Before After Diff
2D Empty (legacy pipeline) 1001979 bytes 1001979 bytes ✅ 0 bytes
2D All (legacy pipeline) 2662998 bytes 2662998 bytes ✅ 0 bytes
2D All (new pipeline) 2750227 bytes 2750227 bytes ✅ 0 bytes
(2D + 3D) All 10003609 bytes 10003609 bytes ✅ 0 bytes
Web (WASM + ASMJS) Before After Diff
(2D + 3D) All 16915881 bytes 16915881 bytes ✅ 0 bytes

Interface Check Report

This pull request does not change any public interfaces !

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.

1 participant