Honor Config.ConversionForUnit at the per-call conversion sites - #349
Open
youdie006 wants to merge 1 commit into
Open
Honor Config.ConversionForUnit at the per-call conversion sites#349youdie006 wants to merge 1 commit into
youdie006 wants to merge 1 commit into
Conversation
Rect and Box each have two conversion helpers: the exported UnitsToPoints(t int), which builds a defaultUnitConfig from the unit alone and so always sees ConversionForUnit as 0, and the unexported unitsToPoints(unitConfigurator), which takes the whole Config. Start already uses the config-aware form for Config.PageSize and Config.TrimBox. Nine other call sites pass only gp.config.Unit and silently drop the option, so a document configured with ConversionForUnit renders per-call rects at the built-in factor. Image is the clearest case: the line above converts x and y through UnitsToPointsVar, which honors the option, and the next line converts the rect without it. Reported as signintech#323.
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.
Closes #323.
RectandBoxeach have two conversion helpers:UnitsToPoints(t int)-- builds adefaultUnitConfig{Unit: t}from the unit alone, soConversionForUnitis always 0 inside it (rect.go:27,box.go:9)unitsToPoints(unitConfigurator)-- takes the wholeConfig, so the option is honoured (rect.go:42,box.go:29)Startuses the config-aware form:Nine other call sites pass only
gp.config.Unitand drop the option.Imageis the clearest, because both forms sit on adjacent lines:so position and size disagree inside one call:
Same effect on page geometry -- the same
Rect{W:100,H:200}gives200.00 400.00throughConfig.PageSizeand100.00 200.00throughPageOption.PageSize, byte-identical to settingConversionForUnit: 0.The field's doc comment (
config.go:39) promises the opposite: "If this variable is not 0. This value will be used to calculate the unit conversion instead of the existing const value in the system. And if this variable is not 0. Value in Config.Unit will not be used."Why here and not in
UnitsToPoints#323 points at
Rect.UnitsToPointsitself. That function takes anintand cannot seeConversionForUnit, so fixing it there means changing an exported signature. The call sites already have the wholeConfigin hand, andStartshows the intended form -- so this changes the nine call sites and leaves the public API alone.Behaviour change
Only for documents that set
ConversionForUnit. With it at 0 both helpers take the identicalswitchbranch, so output is byte-identical -- which is why the whole existing suite passes unmodified and no existing test row changes.Verification
go test ./...-- 4 packages ok, before and after (the run needstest/out/to exist).go vet .clean.gofmt -l .lists onlyarabic_alphabet.go, which is pre-existing and not in this diff.Tests added covering
Image,ImageByHolder,ImageByHolderWithOptions, andAddPageWithOptionfor bothPageSizeandTrimBox.ConversionForUnithad zero occurrences in any_test.gobefore this.I mutation-checked each of the nine changed lines separately, anchored to its enclosing function, since
.UnitsToPoints(gp.config.Unit)is textually identical at all nine and a plain substitution hits the wrong one. Five of the nine are killed by the new tests:Image(:735)ImageByHolder(:491)ImageByHolderWithOptionsrect (:505)AddPageWithOptionTrimBox (:807)AddPageWithOptionPageSize (:808)ImageByHolderWithOptionsmask rect (:527)ImageFromWithOption(:765)CellWithOption(:1131)Cell(:1146)I would rather say that than imply full coverage. The four unpinned ones are the same one-line change on the same kind of site -- each takes a caller-supplied
*Rectand converts it with the unit alone -- and I could not get a stable output diff for them inside this pass: the mask path needs a second image with an alpha channel, and the cell paths render through the font metrics, where I could not isolate the rect's contribution from the text layout. If you would rather I either cover them properly or drop them from this PR, say which and I will.What I did not change
Rect.UnitsToPoints/Box.UnitsToPointssignatures (see above).Config.K(config.go:44). It is read nowhere in the repo and its comment is "Not sure", so a fix would be choosing semantics rather than restoring them -- that belongs in an issue, not here.unitOverrideprecedence:unitsToPointsstill short-circuits torect.unitOverridewhen set, exactly as the exported form does.Disclosure: AI-assisted. I found and prepared this with an AI assistant, and I ran and verified everything above myself.