@@ -532,8 +532,6 @@ pub mod path {
532
532
let r = clamp_rounding ( rounding, rect) ;
533
533
534
534
if r == Rounding :: ZERO {
535
- let min = rect. min ;
536
- let max = rect. max ;
537
535
path. reserve ( 4 ) ;
538
536
path. push ( pos2 ( min. x , min. y ) ) ; // left top
539
537
path. push ( pos2 ( max. x , min. y ) ) ; // right top
@@ -868,6 +866,21 @@ fn fill_closed_path_with_uv(
868
866
}
869
867
}
870
868
869
+ /// Translate a point according to the stroke kind.
870
+ fn translate_stroke_point ( p : & PathPoint , stroke : & PathStroke ) -> PathPoint {
871
+ match stroke. kind {
872
+ stroke:: StrokeKind :: Middle => p. clone ( ) ,
873
+ stroke:: StrokeKind :: Outside => PathPoint {
874
+ pos : p. pos + p. normal * stroke. width * 0.5 ,
875
+ normal : p. normal ,
876
+ } ,
877
+ stroke:: StrokeKind :: Inside => PathPoint {
878
+ pos : p. pos - p. normal * stroke. width * 0.5 ,
879
+ normal : p. normal ,
880
+ } ,
881
+ }
882
+ }
883
+
871
884
/// Tessellate the given path as a stroke with thickness.
872
885
fn stroke_path (
873
886
feathering : f32 ,
@@ -885,8 +898,13 @@ fn stroke_path(
885
898
let idx = out. vertices . len ( ) as u32 ;
886
899
887
900
// expand the bounding box to include the thickness of the path
888
- let bbox = Rect :: from_points ( & path. iter ( ) . map ( |p| p. pos ) . collect :: < Vec < Pos2 > > ( ) )
889
- . expand ( ( stroke. width / 2.0 ) + feathering) ;
901
+ let bbox = Rect :: from_points (
902
+ & path
903
+ . iter ( )
904
+ . map ( |p| translate_stroke_point ( p, & stroke) . pos )
905
+ . collect :: < Vec < Pos2 > > ( ) ,
906
+ )
907
+ . expand ( ( stroke. width / 2.0 ) + feathering) ;
890
908
891
909
let get_color = |col : & ColorMode , pos : Pos2 | match col {
892
910
ColorMode :: Solid ( col) => * col,
@@ -920,7 +938,7 @@ fn stroke_path(
920
938
let mut i0 = n - 1 ;
921
939
for i1 in 0 ..n {
922
940
let connect_with_previous = path_type == PathType :: Closed || i1 > 0 ;
923
- let p1 = & path[ i1 as usize ] ;
941
+ let p1 = translate_stroke_point ( & path[ i1 as usize ] , & stroke ) ;
924
942
let p = p1. pos ;
925
943
let n = p1. normal ;
926
944
out. colored_vertex ( p + n * feathering, color_outer) ;
@@ -962,7 +980,7 @@ fn stroke_path(
962
980
963
981
let mut i0 = n - 1 ;
964
982
for i1 in 0 ..n {
965
- let p1 = & path[ i1 as usize ] ;
983
+ let p1 = translate_stroke_point ( & path[ i1 as usize ] , & stroke ) ;
966
984
let p = p1. pos ;
967
985
let n = p1. normal ;
968
986
out. colored_vertex ( p + n * outer_rad, color_outer) ;
@@ -1007,7 +1025,7 @@ fn stroke_path(
1007
1025
out. reserve_vertices ( 4 * n as usize ) ;
1008
1026
1009
1027
{
1010
- let end = & path[ 0 ] ;
1028
+ let end = translate_stroke_point ( & path[ 0 ] , & stroke ) ;
1011
1029
let p = end. pos ;
1012
1030
let n = end. normal ;
1013
1031
let back_extrude = n. rot90 ( ) * feathering;
@@ -1028,7 +1046,7 @@ fn stroke_path(
1028
1046
1029
1047
let mut i0 = 0 ;
1030
1048
for i1 in 1 ..n - 1 {
1031
- let point = & path[ i1 as usize ] ;
1049
+ let point = translate_stroke_point ( & path[ i1 as usize ] , & stroke ) ;
1032
1050
let p = point. pos ;
1033
1051
let n = point. normal ;
1034
1052
out. colored_vertex ( p + n * outer_rad, color_outer) ;
@@ -1056,7 +1074,7 @@ fn stroke_path(
1056
1074
1057
1075
{
1058
1076
let i1 = n - 1 ;
1059
- let end = & path[ i1 as usize ] ;
1077
+ let end = translate_stroke_point ( & path[ i1 as usize ] , & stroke ) ;
1060
1078
let p = end. pos ;
1061
1079
let n = end. normal ;
1062
1080
let back_extrude = -n. rot90 ( ) * feathering;
@@ -1120,7 +1138,7 @@ fn stroke_path(
1120
1138
return ;
1121
1139
}
1122
1140
}
1123
- for p in path {
1141
+ for p in path. iter ( ) . map ( |p| translate_stroke_point ( p , & stroke ) ) {
1124
1142
out. colored_vertex (
1125
1143
p. pos + radius * p. normal ,
1126
1144
mul_color (
@@ -1138,7 +1156,7 @@ fn stroke_path(
1138
1156
}
1139
1157
} else {
1140
1158
let radius = stroke. width / 2.0 ;
1141
- for p in path {
1159
+ for p in path. iter ( ) . map ( |p| translate_stroke_point ( p , & stroke ) ) {
1142
1160
out. colored_vertex (
1143
1161
p. pos + radius * p. normal ,
1144
1162
get_color ( & stroke. color , p. pos + radius * p. normal ) ,
@@ -1403,8 +1421,11 @@ impl Tessellator {
1403
1421
self . scratchpad_path . clear ( ) ;
1404
1422
self . scratchpad_path . add_circle ( center, radius) ;
1405
1423
self . scratchpad_path . fill ( self . feathering , fill, out) ;
1406
- self . scratchpad_path
1407
- . stroke_closed ( self . feathering , & stroke. into ( ) , out) ;
1424
+ self . scratchpad_path . stroke_closed (
1425
+ self . feathering ,
1426
+ & PathStroke :: from ( stroke) . outside ( ) ,
1427
+ out,
1428
+ ) ;
1408
1429
}
1409
1430
1410
1431
/// Tessellate a single [`EllipseShape`] into a [`Mesh`].
@@ -1470,8 +1491,11 @@ impl Tessellator {
1470
1491
self . scratchpad_path . clear ( ) ;
1471
1492
self . scratchpad_path . add_line_loop ( & points) ;
1472
1493
self . scratchpad_path . fill ( self . feathering , fill, out) ;
1473
- self . scratchpad_path
1474
- . stroke_closed ( self . feathering , & stroke. into ( ) , out) ;
1494
+ self . scratchpad_path . stroke_closed (
1495
+ self . feathering ,
1496
+ & PathStroke :: from ( stroke) . outside ( ) ,
1497
+ out,
1498
+ ) ;
1475
1499
}
1476
1500
1477
1501
/// Tessellate a single [`Mesh`] into a [`Mesh`].
@@ -1661,7 +1685,7 @@ impl Tessellator {
1661
1685
path. fill ( self . feathering , fill, out) ;
1662
1686
}
1663
1687
1664
- path. stroke_closed ( self . feathering , & stroke. into ( ) , out) ;
1688
+ path. stroke_closed ( self . feathering , & PathStroke :: from ( stroke) . outside ( ) , out) ;
1665
1689
}
1666
1690
1667
1691
self . feathering = old_feathering; // restore
@@ -1700,8 +1724,8 @@ impl Tessellator {
1700
1724
// The contents of the galley is already snapped to pixel coordinates,
1701
1725
// but we need to make sure the galley ends up on the start of a physical pixel:
1702
1726
let galley_pos = pos2 (
1703
- self . round_to_pixel ( galley_pos. x ) ,
1704
- self . round_to_pixel ( galley_pos. y ) ,
1727
+ self . round_to_pixel ( galley_pos. x ) - 0.0 ,
1728
+ self . round_to_pixel ( galley_pos. y ) - 0.0 ,
1705
1729
) ;
1706
1730
1707
1731
let uv_normalizer = vec2 (
0 commit comments