Browse Source

Fix grip visualbrush tests.

pull/2115/head
Steven Kirk 8 years ago
parent
commit
41f201bec8
  1. 4
      src/Avalonia.Visuals/Media/PixelSize.cs
  2. 4
      src/Avalonia.Visuals/Rendering/Utilities/TileBrushCalculator.cs
  3. 8
      src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs
  4. 3
      src/Windows/Avalonia.Direct2D1/Media/ImageBrushImpl.cs
  5. BIN
      tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_Grip_144_Dpi.expected.png

4
src/Avalonia.Visuals/Media/PixelSize.cs

@ -159,8 +159,8 @@ namespace Avalonia
/// <param name="dpi">The dots per inch.</param>
/// <returns>The device-independent size.</returns>
public static PixelSize FromSize(Size size, Vector dpi) => new PixelSize(
(int)(size.Width * (dpi.X / 96)),
(int)(size.Height * (dpi.Y / 96)));
(int)Math.Ceiling(size.Width * (dpi.X / 96)),
(int)Math.Ceiling(size.Height * (dpi.Y / 96)));
/// <summary>
/// Returns the string representation of the size.

4
src/Avalonia.Visuals/Rendering/Utilities/TileBrushCalculator.cs

@ -116,8 +116,8 @@ namespace Avalonia.Rendering.Utilities
return true;
if (SourceRect.Size.AspectRatio == _imageSize.AspectRatio)
return false;
if ((int)SourceRect.Width != _imageSize.Width ||
(int)SourceRect.Height != _imageSize.Height)
if (SourceRect.Width != _imageSize.Width ||
SourceRect.Height != _imageSize.Height)
return true;
return false;
}

8
src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs

@ -434,10 +434,16 @@ namespace Avalonia.Direct2D1.Media
if (intermediateSize.Width >= 1 && intermediateSize.Height >= 1)
{
// We need to ensure the size we're requesting is an integer pixel size, otherwise
// D2D alters the DPI of the render target, which messes stuff up. PixelSize.FromSize
// will do the rounding for us.
var dpi = new Vector(_deviceContext.DotsPerInch.Width, _deviceContext.DotsPerInch.Height);
var pixelSize = PixelSize.FromSize(intermediateSize, dpi);
using (var intermediate = new BitmapRenderTarget(
_deviceContext,
CompatibleRenderTargetOptions.None,
intermediateSize.ToSharpDX()))
pixelSize.ToSize(dpi).ToSharpDX()))
{
using (var ctx = new RenderTarget(intermediate).CreateDrawingContext(_visualBrushRenderer))
{

3
src/Windows/Avalonia.Direct2D1/Media/ImageBrushImpl.cs

@ -100,7 +100,8 @@ namespace Avalonia.Direct2D1.Media
using (var context = new RenderTarget(result).CreateDrawingContext(null))
{
var rect = new Rect(0, 0, bitmap.PixelSize.Width, bitmap.PixelSize.Height);
var dpi = new Vector(target.DotsPerInch.Width, target.DotsPerInch.Height);
var rect = new Rect(bitmap.PixelSize.ToSize(dpi));
context.Clear(Colors.Transparent);
context.PushClip(calc.IntermediateClip);

BIN
tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_Grip_144_Dpi.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 B

After

Width:  |  Height:  |  Size: 271 B

Loading…
Cancel
Save