|
18 | 18 |
|
19 | 19 | using System; |
20 | 20 | using System.Collections.Generic; |
| 21 | +using System.Diagnostics; |
21 | 22 | using System.Linq; |
22 | 23 | using System.Windows; |
23 | 24 | using System.Windows.Controls.Primitives; |
@@ -46,14 +47,41 @@ public double CornerRadius { |
46 | 47 | } |
47 | 48 |
|
48 | 49 | /// <summary> |
49 | | - /// Gets/Sets whether to align the geometry to whole pixels. |
| 50 | + /// Gets/Sets whether to align to whole pixels. |
| 51 | + /// |
| 52 | + /// If BorderThickness is set to 0, the geometry is aligned to whole pixels. |
| 53 | + /// If BorderThickness is set to a non-zero value, the outer edge of the border is aligned |
| 54 | + /// to whole pixels. |
| 55 | + /// |
| 56 | + /// The default value is <c>false</c>. |
50 | 57 | /// </summary> |
51 | 58 | public bool AlignToWholePixels { get; set; } |
52 | 59 |
|
| 60 | + /// <summary> |
| 61 | + /// Gets/sets the border thickness. |
| 62 | + /// |
| 63 | + /// This property only has an effect if <c>AlignToWholePixels</c> is enabled. |
| 64 | + /// When using the resulting geometry to paint a border, set this property to the border thickness. |
| 65 | + /// Otherwise, leave the property set to the default value <c>0</c>. |
| 66 | + /// </summary> |
| 67 | + public double BorderThickness { get; set; } |
| 68 | + |
| 69 | + bool alignToMiddleOfPixels; |
| 70 | + |
53 | 71 | /// <summary> |
54 | 72 | /// Gets/Sets whether to align the geometry to the middle of pixels. |
55 | 73 | /// </summary> |
56 | | - public bool AlignToMiddleOfPixels { get; set; } |
| 74 | + [Obsolete("Use the AlignToWholePixels and BorderThickness properties instead. " |
| 75 | + + "Setting AlignToWholePixels=true and setting the BorderThickness to the pixel size " |
| 76 | + + "is equivalent to aligning the geometry to the middle of pixels.")] |
| 77 | + public bool AlignToMiddleOfPixels { |
| 78 | + get { |
| 79 | + return alignToMiddleOfPixels; |
| 80 | + } |
| 81 | + set { |
| 82 | + alignToMiddleOfPixels = value; |
| 83 | + } |
| 84 | + } |
57 | 85 |
|
58 | 86 | /// <summary> |
59 | 87 | /// Gets/Sets whether to extend the rectangles to full width at line end. |
@@ -96,17 +124,19 @@ public void AddRectangle(TextView textView, Rect rectangle) |
96 | 124 | void AddRectangle(Size pixelSize, Rect r) |
97 | 125 | { |
98 | 126 | if (AlignToWholePixels) { |
99 | | - AddRectangle(PixelSnapHelpers.Round(r.Left, pixelSize.Width), |
100 | | - PixelSnapHelpers.Round(r.Top + 1, pixelSize.Height), |
101 | | - PixelSnapHelpers.Round(r.Right, pixelSize.Width), |
102 | | - PixelSnapHelpers.Round(r.Bottom + 1, pixelSize.Height)); |
103 | | - } else if (AlignToMiddleOfPixels) { |
| 127 | + double halfBorder = 0.5 * BorderThickness; |
| 128 | + AddRectangle(PixelSnapHelpers.Round(r.Left - halfBorder, pixelSize.Width) + halfBorder, |
| 129 | + PixelSnapHelpers.Round(r.Top - halfBorder, pixelSize.Height) + halfBorder, |
| 130 | + PixelSnapHelpers.Round(r.Right + halfBorder, pixelSize.Width) - halfBorder, |
| 131 | + PixelSnapHelpers.Round(r.Bottom + halfBorder, pixelSize.Height) - halfBorder); |
| 132 | + //Debug.WriteLine(r.ToString() + " -> " + new Rect(lastLeft, lastTop, lastRight-lastLeft, lastBottom-lastTop).ToString()); |
| 133 | + } else if (alignToMiddleOfPixels) { |
104 | 134 | AddRectangle(PixelSnapHelpers.PixelAlign(r.Left, pixelSize.Width), |
105 | | - PixelSnapHelpers.PixelAlign(r.Top + 1, pixelSize.Height), |
| 135 | + PixelSnapHelpers.PixelAlign(r.Top, pixelSize.Height), |
106 | 136 | PixelSnapHelpers.PixelAlign(r.Right, pixelSize.Width), |
107 | | - PixelSnapHelpers.PixelAlign(r.Bottom + 1, pixelSize.Height)); |
| 137 | + PixelSnapHelpers.PixelAlign(r.Bottom, pixelSize.Height)); |
108 | 138 | } else { |
109 | | - AddRectangle(r.Left, r.Top + 1, r.Right, r.Bottom + 1); |
| 139 | + AddRectangle(r.Left, r.Top, r.Right, r.Bottom); |
110 | 140 | } |
111 | 141 | } |
112 | 142 |
|
|
0 commit comments