Skip to content

Improve label rendering with system font - #3107

Merged
halx99 merged 21 commits into
devfrom
direct-write-text-rendering
Apr 4, 2026
Merged

Improve label rendering with system font#3107
halx99 merged 21 commits into
devfrom
direct-write-text-rendering

Conversation

@halx99

@halx99 halx99 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator
  • Added DWriteTextRenderer implementation for Windows platform
  • Updated Device::getTextureDataForText to use DirectWrite instead of BitmapDC
  • Adjusted Label and Texture2D to enable stroke support on Windows
  • Removed legacy BitmapDC and SafeRelease helpers
  • Updated cpp-tests to validate DirectWrite text rendering with '&' character
  • Implement stroke effect and shrink support in WASM
  • Remove stroke macro guard, as Axmol now enables stroke effect across all platforms
  • Remove unused shadow field from FontDefinition
  • Unify WinRT text renderer with Win32 logic under msw, adding stroke rendering support

This patch modernizes Windows text rendering by switching from GDI to DirectWrite, providing consistent alignment, stroke support across platforms.

Describe your changes

Issue ticket number and link

Checklist before requesting a review

For each PR

  • Add Copyright if it missed:
    - "Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md)."

  • I have performed a self-review of my code.

    Optional:

    • I have checked readme and add important infos to this PR.
    • I have added/adapted some tests too.

For core/new feature PR

  • I have checked readme and add important infos to this PR.
  • I have added thorough tests.

Axmol 3.x ------------------------------------------------------------

For each 3.x PR

  • Check the '#include "axmol.h"' and replace it with the needed headers.

- Added DWriteTextRenderer implementation for Windows platform
- Updated Device::getTextureDataForText to use DirectWrite instead of BitmapDC
- Adjusted Label and Texture2D to enable stroke support on Windows
- Removed legacy BitmapDC and SafeRelease helpers
- Updated cpp-tests to validate DirectWrite text rendering with '&' character

This patch modernizes Windows text rendering by switching from GDI to DirectWrite,
providing consistent alignment, stroke, and shadow support across platforms.
@halx99 halx99 linked an issue Apr 3, 2026 that may be closed by this pull request
@halx99 halx99 added this to the 3.0.0 milestone Apr 3, 2026
@halx99 halx99 added the enhancement New feature or request label Apr 3, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a new DirectWrite and Direct2D based text renderer for the Win32 platform, replacing the legacy GDI-based BitmapDC implementation. This change enables support for text stroke and shadow effects on Windows. The feedback provided addresses a potential memory leak in geometry combination, suggests optimizing the font-shrinking algorithm via binary search, and identifies several outdated log and assertion messages that need to be updated to reflect the new platform support.

Comment thread axmol/platform/win32/DWriteTextRenderer.cpp Outdated
Comment thread axmol/2d/Label.cpp Outdated
Comment thread axmol/platform/win32/DWriteTextRenderer.cpp Outdated
Comment thread axmol/platform/win32/DWriteTextRenderer.cpp Outdated
Comment thread axmol/platform/win32/DWriteTextRenderer.cpp Outdated
Comment thread axmol/renderer/Texture2D.cpp Outdated
@halx99

halx99 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

/clang-format

@halx99

halx99 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request replaces the legacy GDI-based text rendering on Windows with a modern DirectWrite and Direct2D implementation via the new DWriteTextRenderer class. This change enables support for text stroke on Win32 and improves rendering quality. However, several critical issues were identified in the implementation: the color conversion logic incorrectly swaps color channels, the shadow effect uses the wrong color, and there is a type mismatch in the pixel data copying logic. Furthermore, the static renderer instance is not thread-safe, and the COM initialization strategy may lead to crashes when text is rendered on worker threads. Improvements are also needed for the inefficient geometry combination logic and the removal of compiler-specific pragmas in favor of CMake configuration.

Comment thread axmol/platform/msw/DWriteTextRenderer.cpp
Comment thread axmol/platform/win32/DWriteTextRenderer.cpp Outdated
Comment thread axmol/platform/win32/DWriteTextRenderer.cpp Outdated
Comment thread axmol/platform/win32/Device-win32.cpp Outdated
Comment thread axmol/platform/msw/DWriteTextRenderer.cpp
Comment thread axmol/platform/win32/DWriteTextRenderer.cpp Outdated
Comment thread axmol/platform/win32/DWriteTextRenderer.cpp Outdated
Comment thread axmol/platform/win32/DWriteTextRenderer.cpp Outdated
@halx99

halx99 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

/clang-format

@halx99 halx99 changed the title win32: integrate DirectWrite text renderer and remove legacy GDI path Improve label rendering with system font Apr 3, 2026
@halx99

halx99 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request implements text stroke support for WASM and replaces the legacy GDI-based text rendering on Win32 with a modern DirectWrite/Direct2D implementation, enabling stroke and shadow effects on Windows. A bug was identified in the Win32 renderer where the shadow color is incorrectly derived from the font fill color instead of the intended shadow color.

Comment thread axmol/platform/win32/DWriteTextRenderer.cpp Outdated
@halx99
halx99 marked this pull request as draft April 3, 2026 12:45
@halx99

halx99 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

/clang-format

@halx99
halx99 marked this pull request as ready for review April 3, 2026 14:34
@halx99

halx99 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request replaces the legacy GDI-based text rendering on Windows with a new DirectWrite and Direct2D implementation via the DWriteTextRenderer class. It also removes the FontShadow feature from the engine across all platforms and introduces stroke support for the WebAssembly platform. The review feedback highlights a functional issue where the text brush color is not updated when a render target is reused, as well as a copy-paste error in the Lua bindings where a stroke property is incorrectly mapped to a shadow key. Other improvements include removing unused variables, addressing potential integer overflows during buffer resizing, and correcting outdated documentation regarding removed features.

Comment thread axmol/platform/msw/DWriteTextRenderer.cpp
Comment thread extensions/scripting/lua-bindings/manual/LuaBasicConversions.cpp Outdated
Comment thread axmol/platform/msw/DWriteTextRenderer.cpp Outdated
Comment thread axmol/platform/msw/DWriteTextRenderer.cpp Outdated
Comment thread axmol/platform/msw/DWriteTextRenderer.h Outdated
halx99 and others added 2 commits April 3, 2026 22:46
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@halx99

halx99 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request replaces the legacy GDI-based text rendering on Windows with a new DWriteTextRenderer utilizing DirectWrite and Direct2D, enabling features like text stroke and improved overflow handling. Concurrently, the FontShadow implementation has been removed across all platforms, and the WASM platform has been updated to support text strokes. Review feedback highlights a layering violation in the platform code, a performance optimization for the font-shrinking logic, and a minor documentation duplication.

Comment thread axmol/platform/msw/DWriteTextRenderer.cpp Outdated
Comment thread axmol/platform/msw/DWriteTextRenderer.cpp Outdated
Comment thread axmol/platform/msw/DWriteTextRenderer.h Outdated
halx99 and others added 4 commits April 3, 2026 23:01
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@halx99

halx99 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors text rendering across all supported platforms by removing the FontShadow property from FontDefinition and its associated implementations. A major highlight is the introduction of DWriteTextRenderer for Windows platforms, which utilizes DirectWrite and Direct2D to replace the legacy GDI-based text rendering. Additionally, the PR updates Android, iOS, macOS, and WASM implementations to support text strokes while removing shadow support, and it consolidates Windows-specific utilities like ComPtr.h into a shared directory. I have no feedback to provide.

@halx99
halx99 merged commit 56b13bd into dev Apr 4, 2026
27 checks passed
@halx99
halx99 deleted the direct-write-text-rendering branch April 4, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug init Label::createWithSystemFont and EditBox at runtime.

2 participants