11use ecow:: eco_format;
2- use pdf_writer:: types:: { ActionType , AnnotationType , ColorSpaceOperand } ;
2+ use pdf_writer:: types:: {
3+ ActionType , AnnotationType , ColorSpaceOperand , LineCapStyle , LineJoinStyle ,
4+ } ;
35use pdf_writer:: writers:: ColorSpace ;
46use pdf_writer:: { Content , Filter , Finish , Name , Rect , Ref , Str } ;
57
68use super :: { deflate, AbsExt , EmExt , PdfContext , RefExt , D65_GRAY , SRGB } ;
79use crate :: doc:: { Destination , Frame , FrameItem , GroupItem , Meta , TextItem } ;
810use crate :: font:: Font ;
911use crate :: geom:: {
10- self , Abs , Color , Em , Geometry , Numeric , Paint , Point , Ratio , Shape , Size , Stroke ,
11- Transform ,
12+ self , Abs , Color , Em , Geometry , LineCap , LineJoin , Numeric , Paint , Point , Ratio ,
13+ Shape , Size , Stroke , Transform ,
1214} ;
1315use crate :: image:: Image ;
1416
@@ -250,8 +252,17 @@ impl PageContext<'_, '_> {
250252
251253 fn set_stroke ( & mut self , stroke : & Stroke ) {
252254 if self . state . stroke . as_ref ( ) != Some ( stroke) {
255+ let Stroke {
256+ paint,
257+ thickness,
258+ line_cap,
259+ line_join,
260+ dash_pattern,
261+ miter_limit,
262+ } = stroke;
263+
253264 let f = |c| c as f32 / 255.0 ;
254- let Paint :: Solid ( color) = stroke . paint ;
265+ let Paint :: Solid ( color) = paint;
255266 match color {
256267 Color :: Luma ( c) => {
257268 self . set_stroke_color_space ( D65_GRAY ) ;
@@ -267,7 +278,26 @@ impl PageContext<'_, '_> {
267278 }
268279 }
269280
270- self . content . set_line_width ( stroke. thickness . to_f32 ( ) ) ;
281+ self . content . set_line_width ( thickness. to_f32 ( ) ) ;
282+ if self . state . stroke . as_ref ( ) . map ( |s| & s. line_cap ) != Some ( line_cap) {
283+ self . content . set_line_cap ( line_cap. into ( ) ) ;
284+ }
285+ if self . state . stroke . as_ref ( ) . map ( |s| & s. line_join ) != Some ( line_join) {
286+ self . content . set_line_join ( line_join. into ( ) ) ;
287+ }
288+ if self . state . stroke . as_ref ( ) . map ( |s| & s. dash_pattern ) != Some ( dash_pattern) {
289+ if let Some ( pattern) = dash_pattern {
290+ self . content . set_dash_pattern (
291+ pattern. array . iter ( ) . map ( |l| l. to_f32 ( ) ) ,
292+ pattern. phase . to_f32 ( ) ,
293+ ) ;
294+ } else {
295+ self . content . set_dash_pattern ( [ ] , 0.0 ) ;
296+ }
297+ }
298+ if self . state . stroke . as_ref ( ) . map ( |s| & s. miter_limit ) != Some ( miter_limit) {
299+ self . content . set_miter_limit ( miter_limit. 0 as f32 ) ;
300+ }
271301 self . state . stroke = Some ( stroke. clone ( ) ) ;
272302 }
273303 }
@@ -486,3 +516,23 @@ fn write_link(ctx: &mut PageContext, pos: Point, dest: &Destination, size: Size)
486516
487517 ctx. links . push ( ( dest. clone ( ) , rect) ) ;
488518}
519+
520+ impl From < & LineCap > for LineCapStyle {
521+ fn from ( line_cap : & LineCap ) -> Self {
522+ match line_cap {
523+ LineCap :: Butt => LineCapStyle :: ButtCap ,
524+ LineCap :: Round => LineCapStyle :: RoundCap ,
525+ LineCap :: Square => LineCapStyle :: ProjectingSquareCap ,
526+ }
527+ }
528+ }
529+
530+ impl From < & LineJoin > for LineJoinStyle {
531+ fn from ( line_join : & LineJoin ) -> Self {
532+ match line_join {
533+ LineJoin :: Miter => LineJoinStyle :: MiterJoin ,
534+ LineJoin :: Round => LineJoinStyle :: RoundJoin ,
535+ LineJoin :: Bevel => LineJoinStyle :: BevelJoin ,
536+ }
537+ }
538+ }
0 commit comments