@@ -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 ) ;
0 commit comments