Skip to content

Commit 7fc171b

Browse files
committed
Update Direct2D to new interfaces
1 parent f0c7772 commit 7fc171b

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

NGraphics/ICanvas.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface ICanvas
1010
void Transform (Transform transform);
1111
void RestoreState ();
1212

13-
Size MeasureText(string text, Font font);
13+
Size MeasureText (string text, Font font);
1414
void DrawText (string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null);
1515
void DrawPath (IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null);
1616
void DrawRectangle (Rect frame, Pen pen = null, Brush brush = null);

NGraphics/SvgReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ void ReadPath (Path p, string pathDescriptor)
503503
match = match.Replace("-", " -");
504504
var args = match.Substring(1).Split(WSC, StringSplitOptions.RemoveEmptyEntries);
505505

506-
Point previousPoint;
506+
Point previousPoint = new Point ();
507507
if (p.Operations.Count > 0 && !(p.Operations.Last() is ClosePath))
508508
previousPoint = p.Operations.Last().EndPoint;
509509

Platforms/NGraphics.WindowsStore/Direct2DCanvas.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public WICBitmapCanvas (WIC.Bitmap bmp, D2D1.RenderTargetProperties properties,
4242
public IImage GetImage ()
4343
{
4444
renderTarget.EndDraw ();
45-
return new WICBitmapSourceImage (Bmp, factories);
45+
return new WICBitmapSourceImage (Bmp, scale, factories);
4646
}
4747

4848
public Size Size
@@ -60,14 +60,19 @@ public class WICBitmapSourceImage : IImage
6060
{
6161
readonly WIC.BitmapSource bmp;
6262
readonly Direct2DFactories factories;
63+
readonly double scale;
6364

6465
public WIC.BitmapSource Bitmap { get { return bmp; } }
6566

66-
public WICBitmapSourceImage (WIC.BitmapSource bmp, Direct2DFactories factories = null)
67+
public Size Size { get { return Conversions.ToSize (bmp.Size); } }
68+
public double Scale { get { return scale; } }
69+
70+
public WICBitmapSourceImage (WIC.BitmapSource bmp, double scale, Direct2DFactories factories = null)
6771
{
6872
if (bmp == null)
6973
throw new ArgumentNullException ("bmp");
7074
this.bmp = bmp;
75+
this.scale = scale;
7176
this.factories = factories ?? Direct2DFactories.Shared;
7277
}
7378

@@ -173,6 +178,14 @@ public void RestoreState ()
173178
}
174179
}
175180

181+
public Size MeasureText (string text, Font font)
182+
{
183+
float maxWidth = float.MaxValue;
184+
float maxHeight = float.MaxValue;
185+
var layout = new DW.TextLayout (factories.DWFactory, text, GetTextFormat (font), maxWidth, maxHeight);
186+
return new Size (layout.Metrics.Width, layout.Metrics.Height);
187+
}
188+
176189
public void DrawText (string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
177190
{
178191
var layout = new DW.TextLayout (factories.DWFactory, text, GetTextFormat (font), (float)frame.Width, (float)frame.Height);
@@ -435,6 +448,16 @@ public static Size2F ToSize2F (this Size size)
435448
return new Size2F ((float)size.Width, (float)size.Height);
436449
}
437450

451+
public static Size ToSize (this Size2F size)
452+
{
453+
return new Size (size.Width, size.Height);
454+
}
455+
456+
public static Size ToSize (this Size2 size)
457+
{
458+
return new Size (size.Width, size.Height);
459+
}
460+
438461
public static RectangleF ToRectangleF (this Rect rect)
439462
{
440463
return new RectangleF ((float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);

Platforms/NGraphics.WindowsStore/WinRTPlatform.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public IImage CreateImage (Color[] colors, int width, double scale = 1.0)
3434
DataPointer = (IntPtr)p,
3535
};
3636
var bmp = new WIC.Bitmap (factories.WICFactory, width, colors.Length / width, pf, data);
37-
return new WICBitmapSourceImage (bmp, factories);
37+
return new WICBitmapSourceImage (bmp, scale, factories);
3838
}
3939
}
4040
}
@@ -55,7 +55,7 @@ public IImage LoadImage (Stream stream)
5555
}
5656

5757
// Convert the BitmapSource to a Bitmap so we can allow the decoder to go out of memory
58-
return new WICBitmapSourceImage (new WIC.Bitmap (factories.WICFactory, b, WIC.BitmapCreateCacheOption.CacheOnLoad), factories);
58+
return new WICBitmapSourceImage (new WIC.Bitmap (factories.WICFactory, b, WIC.BitmapCreateCacheOption.CacheOnLoad), 1.0, factories);
5959
}
6060

6161
public IImage LoadImage (string path)

0 commit comments

Comments
 (0)