-
Notifications
You must be signed in to change notification settings - Fork 3
Add SVG decoding and rendering support to ImageCodec with optional scaling #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
yorkie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SVG can be scaled to the expected width and height, you need to add optional parameters to the ImageCodec::Decode() as the expected width and height.
…G scaling Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Added optional width and height parameters to ImageCodec::Decode for SVG scaling. The method now supports:
Maintains full backward compatibility with existing code. Commit f18cd37 |
…aling Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive SVG image decoding and rendering support to the ImageCodec module, enabling web content to display SVG images alongside existing raster formats. The implementation uses the nanosvg library for lightweight SVG parsing and rasterization with optional scaling parameters.
Key changes:
- Integrates nanosvg library for SVG parsing and rasterization to SkBitmap format
- Extends ImageCodec::Decode method with optional width/height parameters for SVG scaling
- Implements intelligent SVG format detection and size constraint handling
- Updates HTML image element to support dynamic SVG re-rendering based on layout changes
Reviewed Changes
Copilot reviewed 16 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| thirdparty/headers/nanosvg/nanosvgrast.h | Adds nanosvg rasterization library for SVG to bitmap conversion |
| src/client/canvas/image_codec.hpp | Extends ImageCodec interface with SVG format support and optional scaling parameters |
| src/client/canvas/image_codec.cpp | Implements SVG detection, parsing, and rasterization logic with size constraints |
| src/client/html/html_image_element.hpp | Adds SVG-aware image decoding with layout-based re-rendering capabilities |
| src/client/html/html_image_element.cpp | Implements dynamic SVG decoding based on element size changes |
| src/client/layout/layout_*.hpp/cpp | Updates layout system to notify elements of size changes for SVG re-rendering |
| tests/client/svg_image_codec_tests.cpp | Comprehensive test suite covering SVG decoding scenarios and edge cases |
| fixtures/html/images.html | Demo page showcasing SVG image rendering with dynamic resizing |
Comments suppressed due to low confidence (3)
src/client/canvas/image_codec.cpp:65
- The SkEncodedImageFormat::kJPEGXL enum value may not exist in older versions of Skia. Consider adding version checks or conditional compilation to ensure compatibility.
case SkEncodedImageFormat::kJPEGXL:
src/client/html/html_image_element.cpp:74
- The function parameter should use
std::shared_ptr<SkBitmap>instead ofshared_ptr<SkBitmap>for consistency and clarity, or ensure the appropriate using declaration is present.
{
tests/client/svg_image_codec_tests.cpp:25
- The test passes
nullptrfor the image_format parameter but doesn't verify that the format is correctly detected as SVG. Consider adding a test that captures and validates the detected format.
bool success = ImageCodec::Decode(svg_data, nullptr, decoded_bitmap, "test.svg");
This PR implements comprehensive SVG image decoding and rendering support in the client/canvas/image_codec module, with optional width and height parameters for flexible scaling, enabling richer image type support and improving canvas flexibility.
Changes Made
Core Implementation
SVG Scaling Features
The ImageCodec::Decode method now accepts optional target_width and target_height parameters for SVG images:
Smart SVG Detection
The implementation includes intelligent format detection that:
Size Constraint Handling
SVG images are subject to the same size constraints as other image formats:
Error Handling
Robust error handling for various edge cases:
Example Usage
The implementation maintains full backward compatibility and integrates seamlessly with the existing image processing pipeline, requiring no changes to existing calling code.
Fixes #168.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.