11package com .demcha .compose .document .backend .fixed .pdf .handlers ;
22
3+ import com .demcha .compose .document .style .DocumentDashPattern ;
34import com .demcha .compose .document .style .DocumentPathSegment ;
45import com .demcha .compose .document .style .ShapePoint ;
56import com .demcha .compose .engine .components .content .shape .Stroke ;
@@ -28,6 +29,20 @@ static void fillAndStrokePath(PDPageContentStream stream,
2829 Color fillColor ,
2930 Stroke stroke ,
3031 PathEmitter path ) throws IOException {
32+ fillAndStrokePath (stream , fillColor , stroke , null , path );
33+ }
34+
35+ /**
36+ * Variant of {@link #fillAndStrokePath(PDPageContentStream, Color, Stroke, PathEmitter)}
37+ * with an optional dash pattern applied to the stroke inside the saved
38+ * graphics state ({@code null} or {@link DocumentDashPattern#NONE} keeps
39+ * the stroke solid).
40+ */
41+ static void fillAndStrokePath (PDPageContentStream stream ,
42+ Color fillColor ,
43+ Stroke stroke ,
44+ DocumentDashPattern dashPattern ,
45+ PathEmitter path ) throws IOException {
3146 boolean hasFill = fillColor != null ;
3247 boolean hasStroke = stroke != null
3348 && stroke .strokeColor () != null
@@ -42,6 +57,7 @@ static void fillAndStrokePath(PDPageContentStream stream,
4257 PdfAlphaSupport .applyStrokeAlpha (stream , stroke .strokeColor ().color ());
4358 stream .setStrokingColor (stroke .strokeColor ().color ());
4459 stream .setLineWidth ((float ) stroke .width ());
60+ applyDashPattern (stream , dashPattern );
4561 }
4662 if (hasFill ) {
4763 PdfAlphaSupport .applyFillAlpha (stream , fillColor );
@@ -168,6 +184,23 @@ static void roundedRectPath(PDPageContentStream stream,
168184 stream .closePath ();
169185 }
170186
187+ /**
188+ * Applies a dash pattern to the stream's stroking state. No-op for
189+ * {@code null} or solid patterns. Shared by the line and path renderers
190+ * so both emit identical dash arrays.
191+ */
192+ static void applyDashPattern (PDPageContentStream stream , DocumentDashPattern dash ) throws IOException {
193+ if (dash == null || dash .isSolid ()) {
194+ return ;
195+ }
196+ List <Double > segments = dash .segments ();
197+ float [] dashArray = new float [segments .size ()];
198+ for (int i = 0 ; i < dashArray .length ; i ++) {
199+ dashArray [i ] = segments .get (i ).floatValue ();
200+ }
201+ stream .setLineDashPattern (dashArray , 0f );
202+ }
203+
171204 /**
172205 * A path contribution: the caller adds the geometry (ellipse, rectangle,
173206 * polygon, …) so the fill/stroke wrapper can be shared.
0 commit comments