feat(api): LineBuilder.lineCap — round/square caps and dotted lines#229
Merged
Conversation
LineBuilder gains lineCap(DocumentLineCap), bringing the round/square end-caps PathBuilder already exposed to plain lines. Pairing ROUND with a short dash draws a dotted line — line.dashed(0.1, 4).lineCap(ROUND) renders round dots, the classic table-of-contents leader/separator. A lineCap component is threaded through LineNode, LineFragmentPayload, LineDefinition and PdfLineFragmentRenderHandler the same way dashPattern was; the BUTT default emits no cap operator (applyStrokeStyle short-circuits), so existing line output is byte-identical. No lineJoin is added — a single line segment has no corners. Verified: ./mvnw test -pl . — 1501 tests, 0 baselines changed. PdfLineStrokeStyleTest asserts ROUND/SQUARE emit the J operator and BUTT emits none; a runnable LineCapExample ships with a committed preview.
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.
Why
LineBuildercould draw dashed lines but not control the stroke end-cap, so a dotted line — round dots, the classic table-of-contents leader / separator — was impossible: a zero-length on-dash renders nothing without a round cap.PathBuilderalready hadlineCap(...); plain lines did not.What changed
LineBuilder.lineCap(DocumentLineCap)— round / square / butt end-caps for lines, reusing the already-publicDocumentLineCapenum (no new type).lineCapcomponent is threaded throughLineNode,LineFragmentPayload,LineDefinition.emitFragments, andPdfLineFragmentRenderHandler(oneapplyStrokeStylecall, inside the existing save/restore-graphics-state block so the cap never leaks to later strokes) — the same waydashPatternwas added in 1.7.0. Back-compat constructors are preserved on both records.BUTTdefault emits no cap operator (applyStrokeStyleshort-circuits on the PDF default), so existing line output is byte-identical.lineJoin— a single line segment has no corners, so a join setter would be dead API.The dotted idiom:
line.dashed(0.1, 4).lineCap(DocumentLineCap.ROUND)(a tiny on-dash, becauseDocumentDashPattern.ofrejects a literal zero-length segment).Lane: canonical public DSL (
LineBuilder/LineNode) + shared-engine (payload / definition / render handler).Verification
./mvnw test -pl .— 1501 tests, 0 failures, 0 visual baselines changed.PdfLineStrokeStyleTest(render-level):ROUNDemits theJcap operator with value 1,SQUAREvalue 2, theBUTTdefault emits none (byte-identity), anddashed + ROUNDemitsJ 1(the dotted composition).LineBuilderTest: cap defaults toBUTT, carries into the node, andlineCap(null)resets toBUTT.LineCapExample(solid / dashed / dotted rules + a thick round-vs-butt comparison) with a committed preview and an examples README row.@since 1.9.0on the new public method.