fix(sch): align add_schematic_text as KiCad does instead of centring it - #308
Open
anyn99 wants to merge 1 commit into
Open
fix(sch): align add_schematic_text as KiCad does instead of centring it#308anyn99 wants to merge 1 commit into
anyn99 wants to merge 1 commit into
Conversation
The handler wrote no `(justify ...)` clause, so KiCad centred the text on `x`. A long line then crosses the page edge and is dropped from the PDF export while the .kicad_sch still holds it intact and the tool reports success. Measured on KiCad 10.0.4 with the reproduction from the issue: a 61-character annotation at x = 27.94 lands with its left edge at -84.65 mm. Add a `justify` argument, defaulting to `left bottom`. Alignment is per axis and an axis left out is centred, which is how KiCad encodes it; `center` centres both and writes no clause, the behaviour before this change. Unknown tokens and two tokens on one axis are refused rather than guessed at. `left bottom` is what KiCad itself writes: every `(text ...)` block in the current format version of its bundled demos carries that clause. Closes mixelpixx#286 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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 #286.
Verified against KiCad 10.0.4 by re-running the reproduction from the issue — an
A3 sheet, one 61-character annotation at
x = 27.94,size 5, exported withkicad-cli sch export svg. Today the text is anchoredmiddleand its left edgelands at -84.65 mm, 84 mm off the page. With
(justify left bottom)it isanchored
startand starts at 27.94 mm, where the caller asked for it.left bottomis what KiCad 10 itself writes: in its bundled demo projects, every(text ...)block in the current format version carries a justify clause, andall of them are
left bottom. That is the default this PR adopts.The change
add_schematic_textgains ajustifyargument. It takes at most one horizontaltoken (
left,right) and one vertical token (top,bottom), in eitherorder and any case, and writes them in KiCad's order — horizontal first. An
unknown token, or two tokens on one axis, is refused rather than guessed at.
Alignment is per axis, and an axis left out is centred:
"left"isleft-aligned and vertically centred,
"bottom"is horizontally centred andbottom-aligned.
"center"centres both and so writes no clause. It isalso the behaviour before this change, which callers who want it keep by
asking.
This changes existing behaviour
Text placed through this tool is centred on
xtoday and will be left-bottomaligned after this PR. That is the point of the fix, but it is not a pure
addition: an existing caller's annotation moves.
"center"is the opt-out.There is no
docs/API_MIGRATIONS.mdonmainyet — #278 adds one — so thisnote is here instead.
Tests
Six: the new default, token order,
"center"emitting nothing, the tworefusals, and a parser test over the shapes KiCad's own demos contain.
cargo test --no-fail-fast --workspacegreen, fmt and clippy clean.tool-directory.mdgains the parameter on the tool's row.