From 50d96a35c8f450b5abcd3ee6549e21ec44921c6c Mon Sep 17 00:00:00 2001 From: Lluis Sanchez Date: Thu, 28 Mar 2013 18:42:54 +0100 Subject: [PATCH] [WPF] Implement new Font api --- Testing/Tests/FontTests.cs | 4 ++-- Xwt.WPF/Xwt.WPFBackend/ContextBackendHandler.cs | 4 ---- Xwt.WPF/Xwt.WPFBackend/FontBackendHandler.cs | 16 ++++++++++++++++ .../Xwt.WPFBackend/TextLayoutBackendHandler.cs | 11 +---------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Testing/Tests/FontTests.cs b/Testing/Tests/FontTests.cs index 97931b28..257e1c22 100644 --- a/Testing/Tests/FontTests.cs +++ b/Testing/Tests/FontTests.cs @@ -44,8 +44,8 @@ namespace Xwt public void WithFamily () { var f1 = Font.SystemFont; - var f2 = f1.WithFamily ("Courier"); - Assert.AreEqual ("Courier", f2.Family); + var f2 = f1.WithFamily ("Arial"); + Assert.AreEqual ("Arial", f2.Family); Assert.AreEqual (f1.Size, f2.Size); Assert.AreEqual (f1.Stretch, f2.Stretch); Assert.AreEqual (f1.Style, f2.Style); diff --git a/Xwt.WPF/Xwt.WPFBackend/ContextBackendHandler.cs b/Xwt.WPF/Xwt.WPFBackend/ContextBackendHandler.cs index ac2893e4..cf8f8690 100644 --- a/Xwt.WPF/Xwt.WPFBackend/ContextBackendHandler.cs +++ b/Xwt.WPF/Xwt.WPFBackend/ContextBackendHandler.cs @@ -245,10 +245,6 @@ namespace Xwt.WPFBackend c.SetPattern ((System.Windows.Media.Brush)p); } - public override void SetFont (object backend, Font font) - { - } - public override void DrawTextLayout (object backend, TextLayout layout, double x, double y) { var c = (DrawingContext) backend; diff --git a/Xwt.WPF/Xwt.WPFBackend/FontBackendHandler.cs b/Xwt.WPF/Xwt.WPFBackend/FontBackendHandler.cs index 4ba6f009..a532a594 100644 --- a/Xwt.WPF/Xwt.WPFBackend/FontBackendHandler.cs +++ b/Xwt.WPF/Xwt.WPFBackend/FontBackendHandler.cs @@ -26,6 +26,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System.Linq; using SW = System.Windows; using Xwt.Backends; @@ -37,6 +38,21 @@ namespace Xwt.WPFBackend { public class WpfFontBackendHandler : FontBackendHandler { + public override object GetSystemDefaultFont () + { + double size = WpfFontBackendHandler.GetPointsFromDeviceUnits (SW.SystemFonts.MessageFontSize); + + return new FontData (SW.SystemFonts.MessageFontFamily, size) { + Style = SW.SystemFonts.MessageFontStyle, + Weight = SW.SystemFonts.MessageFontWeight + }; + } + + public override System.Collections.Generic.IEnumerable GetInstalledFonts () + { + return System.Windows.Media.Fonts.SystemFontFamilies.Select (f => f.Source); + } + public override object Create (string fontName, double size, FontStyle style, FontWeight weight, FontStretch stretch) { return new FontData (new FontFamily (fontName), size) { diff --git a/Xwt.WPF/Xwt.WPFBackend/TextLayoutBackendHandler.cs b/Xwt.WPF/Xwt.WPFBackend/TextLayoutBackendHandler.cs index 3bc8d92b..bd3c37ce 100644 --- a/Xwt.WPF/Xwt.WPFBackend/TextLayoutBackendHandler.cs +++ b/Xwt.WPF/Xwt.WPFBackend/TextLayoutBackendHandler.cs @@ -38,17 +38,8 @@ namespace Xwt.WPFBackend public class WpfTextLayoutBackendHandler : TextLayoutBackendHandler { - public override object Create (Context context) + public override object Create () { - var drawingContext = (DrawingContext)Toolkit.GetBackend (context); - return new TextLayoutBackend () { - Context = drawingContext - }; - } - - public override object Create (ICanvasBackend canvas) - { - var backend = (WidgetBackend)canvas; return new TextLayoutBackend (); }