Refactor: Extract image processing logic from DocumentAssembler into ImageHelper#166
Refactor: Extract image processing logic from DocumentAssembler into ImageHelper#166
Conversation
- Created new ImageHelper.cs class with all image-related methods - Moved AddImagePart, CreateImageElement, GetNextDocPrId, TryGetJustification, TryParseLengthToEmu, ConvertJustificationToString, TryCalculateImageDimensions, TryGetPixelSize, TryReadPngDimensions, TryReadJpegDimensions, TryReadGifDimensions to ImageHelper - Updated DocumentAssembler.cs to call methods from ImageHelper - Removed duplicate image code from DocumentAssembler.cs - All 789 tests passing Co-authored-by: stesee <168659+stesee@users.noreply.github.com>
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
There was a problem hiding this comment.
Pull Request Overview
This PR extracts approximately 430 lines of image-specific functionality from DocumentAssembler.cs into a dedicated ImageHelper.cs class, improving code organization and maintainability. The refactoring addresses review feedback from PR #165.
Key changes:
- Created new
ImageHelperstatic class with 12 image-related methods - Added support for
<Image>template element with alignment and dimension attributes - Updated
DocumentAssemblerto useImageHelpermethods and passowningPartparameter through the transformation pipeline
Reviewed Changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| OpenXmlPowerTools/DocumentAssembler/ImageHelper.cs | New helper class containing all image processing logic including dimension calculations, format detection, and XML element generation |
| OpenXmlPowerTools/DocumentAssembler/DocumentAssembler.cs | Refactored to delegate image operations to ImageHelper and added Image element processing |
| OpenXmlPowerTools/DocumentAssembler/PA.cs | Added Image-related attribute name constants |
| OpenXmlPowerTools/HtmlToWmlConverterCore.cs | Enhanced font size handling with validation and rounding |
| OpenXmlPowerTools.Tests/DocumentAssemblerTests.cs | Added comprehensive test coverage for image functionality |
| OpenXmlPowerToolsExamples/DocumentAssembler04/* | New example demonstrating Image template element usage |
| DOCUMENT_ASSEMBLER.md | New documentation file for DocumentAssembler features |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| catch | ||
| { | ||
| // ignore and fall back to header-based detection |
There was a problem hiding this comment.
Generic catch clause.
| catch | |
| { | |
| // ignore and fall back to header-based detection | |
| catch (Exception ex) | |
| { | |
| errorMessage = $"Image: Failed to decode image using SKBitmap. Exception: {ex.Message}"; | |
| // fall back to header-based detection |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Replaced custom PNG, JPEG, and GIF header-based dimension detection with exception handling. Now, if image dimensions cannot be determined via SkiaSharp, the error message is set from the exception, simplifying the code and error reporting.
Addresses review feedback from PR #165 to extract ~430 lines of image-specific functionality from
DocumentAssembler.csinto a dedicated helper class.Changes
Created
ImageHelper.csAddImagePart)CreateImageElement)Updated
DocumentAssembler.csImageHelper.*callsSkiaSharp,System.Globalization)Example
All 789 tests pass without modification.
Original prompt
💡 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.