1
1
use ecow:: eco_format;
2
- use pdf_writer:: types:: { ActionType , AnnotationType , ColorSpaceOperand } ;
2
+ use pdf_writer:: types:: {
3
+ ActionType , AnnotationType , ColorSpaceOperand , LineCapStyle , LineJoinStyle ,
4
+ } ;
3
5
use pdf_writer:: writers:: ColorSpace ;
4
6
use pdf_writer:: { Content , Filter , Finish , Name , Rect , Ref , Str } ;
5
7
6
8
use super :: { deflate, AbsExt , EmExt , PdfContext , RefExt , D65_GRAY , SRGB } ;
7
9
use crate :: doc:: { Destination , Frame , FrameItem , GroupItem , Meta , TextItem } ;
8
10
use crate :: font:: Font ;
9
11
use 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 ,
12
14
} ;
13
15
use crate :: image:: Image ;
14
16
@@ -250,8 +252,17 @@ impl PageContext<'_, '_> {
250
252
251
253
fn set_stroke ( & mut self , stroke : & Stroke ) {
252
254
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
+
253
264
let f = |c| c as f32 / 255.0 ;
254
- let Paint :: Solid ( color) = stroke . paint ;
265
+ let Paint :: Solid ( color) = paint;
255
266
match color {
256
267
Color :: Luma ( c) => {
257
268
self . set_stroke_color_space ( D65_GRAY ) ;
@@ -267,7 +278,26 @@ impl PageContext<'_, '_> {
267
278
}
268
279
}
269
280
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
+ }
271
301
self . state . stroke = Some ( stroke. clone ( ) ) ;
272
302
}
273
303
}
@@ -486,3 +516,23 @@ fn write_link(ctx: &mut PageContext, pos: Point, dest: &Destination, size: Size)
486
516
487
517
ctx. links . push ( ( dest. clone ( ) , rect) ) ;
488
518
}
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