Skip to content

Conversation

Copy link

Copilot AI commented Nov 10, 2025

Addresses review feedback from PR #165 to extract ~430 lines of image-specific functionality from DocumentAssembler.cs into a dedicated helper class.

Changes

Created ImageHelper.cs

  • Static internal class handling all image operations:
    • Image part management (AddImagePart)
    • XML element generation (CreateImageElement)
    • Dimension calculations with unit conversions (px, pt, cm, mm, in, emu)
    • Format detection fallbacks (PNG, JPEG, GIF header parsing)
    • Alignment/justification processing

Updated DocumentAssembler.cs

  • Replaced 12 private static methods with ImageHelper.* calls
  • Removed image-specific imports (SkiaSharp, System.Globalization)
  • Reduced from 1404 to 969 lines

Example

// Before
var imagePart = AddImagePart(owningPart);
var docPrId = GetNextDocPrId(owningPart);
var imageElement = CreateImageElement(relationshipId, docPrId, widthEmu, heightEmu, justification);

// After  
var imagePart = ImageHelper.AddImagePart(owningPart);
var docPrId = ImageHelper.GetNextDocPrId(owningPart);
var imageElement = ImageHelper.CreateImageElement(relationshipId, docPrId, widthEmu, heightEmu, justification);

All 789 tests pass without modification.

Original prompt

can you address https://github.com/Codeuctivity/OpenXmlPowerTools/pull/165/files#r2498803135


💡 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.

- 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>
Copilot AI changed the title [WIP] Address code review comments from pull request #165 Refactor: Extract image processing logic from DocumentAssembler into ImageHelper Nov 10, 2025
Copilot AI requested a review from stesee November 10, 2025 18:33
@stesee stesee marked this pull request as ready for review November 10, 2025 23:53
Copilot AI review requested due to automatic review settings November 10, 2025 23:53
@github-actions
Copy link


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


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.

Copy link

Copilot AI left a 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 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 ImageHelper static class with 12 image-related methods
  • Added support for <Image> template element with alignment and dimension attributes
  • Updated DocumentAssembler to use ImageHelper methods and pass owningPart parameter 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.

Comment on lines 359 to 361
catch
{
// ignore and fall back to header-based detection
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Generic catch clause.

Suggested change
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

Copilot uses AI. Check for mistakes.
stesee and others added 2 commits November 11, 2025 00:58
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.
@stesee stesee closed this Nov 15, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Nov 15, 2025
@stesee stesee deleted the copilot/fix-code-review-comments branch November 15, 2025 20:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants