This closes #2217: Preserve editAs positioning when copying pictures with twoCellAnchor - #2378
Open
blankInPajamas wants to merge 1 commit into
Open
This closes #2217: Preserve editAs positioning when copying pictures with twoCellAnchor#2378blankInPajamas wants to merge 1 commit into
blankInPajamas wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2217
Problem
Copying a picture via
AddPictureFromBytesproduced a visibly stretched/distorted copy when the source picture was anchored with a
twoCellAnchorelement carrying an explicit
editAs="oneCell"attribute. This is a valid,spec-compliant anchor pattern commonly produced by WPS Office (and other
third-party tools), distinct from excelize's own writer, which always emits
a true
oneCellAnchorelement for size-locked pictures.Root cause
Two issues compounded to cause this:
extractPictureFromAnchorandextractPictureFromDecodeAnchoronlyinferred
Format.Positioning = "oneCell"when the anchor had no<to>element at all. They never checked the anchor's own
editAsattribute,so a
twoCellAnchorwitheditAs="oneCell"(which does have a<to>)was never recognized as size-locked.
For anchors that fall through to the fallback decode path
(
extractDecodeCellAnchor, used when a drawing part mixes chart/graphicFrame anchors together with picture anchors), the re-parse of the
anchor's inner content did not preserve the parent anchor's
editAsattribute, so it was lost even when correctly read initially.
The end result:
Format.Positioningcame back empty for these pictures, soAddPictureFromByteswrote a plaintwoCellAnchorwith noeditAsoncopy — making the copied picture resize with its cells instead of keeping
its original locked size.
Fix
editAsdirectly when reading a picture's anchor, falling backto the existing "oneCell when no
to" inference only wheneditAsisabsent.
editAswhen the decode-fallback pathre-parses anchor content.
Testing
TestGetPicturecovering atwoCellAnchorwitheditAs="oneCell"and atoelement present, assertingGetPicturesreturns
Format.Positioning == "oneCell"..xlsxfile produced by WPS Office: before thefix, copying the picture dropped
editAs="oneCell"from the resultingdrawing*.xml(becoming a plaintwoCellAnchor, which visibly stretchedthe picture); after the fix, the copy correctly writes a proper
size-locked
oneCellAnchor, matching the source picture's appearance.go test ./...) with no regressions.