Beispiel #1
0
        public void Should_Measure_Expander_Triangle_With_Stroke_Correctly()
        {
            using (AvaloniaLocator.EnterScope())
            {
                Direct2D1Platform.Initialize();

                var target = new Path
                {
                    Data                = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"),
                    Stroke              = Brushes.Black,
                    StrokeThickness     = 2,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top,
                    UseLayoutRounding   = false,
                };

                target.Measure(new Size(100, 100));
                target.Arrange(new Rect(0, 0, 100, 100));

                // Measured geometry with stroke of 2px is:
                //
                //     {-1, -0.414, 6.414, 12.828} (see GeometryTests)
                //
                // With origin at 0,0 the bounds should equal:
                //
                //     Assert.Equal(new Rect(0, 0, 5.414, 12.414), target.Bounds, compare);
                //
                // However Path.Measure doesn't correctly handle strokes currently, so testing for
                // the (incorrect) current output for now...
                Assert.Equal(new Rect(0, 0, 4, 10), target.Bounds, Compare);
            }
        }
Beispiel #2
0
 public App()
     : base(new DefaultTheme())
 {
     this.RegisterServices();
     Direct2D1Platform.Initialize();
     WindowsPlatform.Initialize();
 }
Beispiel #3
0
        static TestBase()
        {
#if PERSPEX_CAIRO
            CairoPlatform.Initialize();
#else
            Direct2D1Platform.Initialize();
#endif
        }
Beispiel #4
0
        static TestBase()
        {
#if AVALONIA_CAIRO
            CairoPlatform.Initialize();
#elif AVALONIA_SKIA
            SkiaPlatform.Initialize();
#else
            Direct2D1Platform.Initialize();
#endif
        }
Beispiel #5
0
        static TestBase()
        {
#if AVALONIA_SKIA
            SkiaPlatform.Initialize();
#else
            Direct2D1Platform.Initialize();
#endif
            AvaloniaLocator.CurrentMutable
            .Bind <IPlatformThreadingInterface>()
            .ToConstant(threadingInterface);
        }
Beispiel #6
0
        public void Should_Measure_Expander_Triangle_With_Stroke_Correctly()
        {
            using (AvaloniaLocator.EnterScope())
            {
                Direct2D1Platform.Initialize();

                var target = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z");

                Assert.Equal(new Rect(-1, -0.414, 6.414, 12.828), target.GetRenderBounds(2), Compare);
            }
        }
Beispiel #7
0
        public void Should_Measure_Expander_Triangle_Correctly()
        {
            using (AvaloniaLocator.EnterScope())
            {
                Direct2D1Platform.Initialize();

                var target = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z");

                Assert.Equal(new Rect(0, 2, 4, 8), target.Bounds, Compare);
            }
        }
Beispiel #8
0
        public void Should_Measure_Expander_Triangle_Correctly()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                Direct2D1Platform.Initialize();

                var target = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z");

                Assert.Equal(new Rect(0, 2, 4, 8), target.Bounds, Compare);
            }
        }
Beispiel #9
0
        public App()
            : base(new DefaultTheme())
        {
            this.RegisterServices();
#if PERSPEX_CAIRO
            CairoPlatform.Initialize();
#else
            Direct2D1Platform.Initialize();
#endif

#if PERSPEX_GTK
            GtkPlatform.Initialize();
#else
            Win32Platform.Initialize();
#endif
        }
Beispiel #10
0
        public void Should_Load_Nearest_Matching_Font()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                Direct2D1Platform.Initialize();

                var fontManager = new FontManagerImpl();

                var glyphTypeface = (GlyphTypefaceImpl)fontManager.CreateGlyphTypeface(
                    new Typeface(s_fontUri, FontStyle.Italic, FontWeight.Black));

                var font = glyphTypeface.DWFont;

                Assert.Equal("Noto Mono", font.FontFamily.FamilyNames.GetString(0));
            }
        }
Beispiel #11
0
        public void Should_Load_Typeface_From_Resource()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                Direct2D1Platform.Initialize();

                var fontManager = new FontManagerImpl();

                var glyphTypeface = (GlyphTypefaceImpl)fontManager.CreateGlyphTypeface(
                    new Typeface(s_fontUri));

                var font = glyphTypeface.DWFont;

                Assert.Equal("Noto Mono", font.FontFamily.FamilyNames.GetString(0));
            }
        }
Beispiel #12
0
        public void Should_Create_Typeface_From_Fallback_Bold()
        {
            using (AvaloniaLocator.EnterScope())
            {
                Direct2D1Platform.Initialize();

                var fontManager = new FontManagerImpl();

                var glyphTypeface = (GlyphTypefaceImpl)fontManager.CreateGlyphTypeface(
                    new Typeface(new FontFamily("A, B, Arial"), weight: FontWeight.Bold));

                var font = glyphTypeface.DWFont;

                Assert.Equal("Arial", font.FontFamily.FamilyNames.GetString(0));

                Assert.Equal(SharpDX.DirectWrite.FontWeight.Bold, font.Weight);

                Assert.Equal(SharpDX.DirectWrite.FontStyle.Normal, font.Style);
            }
        }
Beispiel #13
0
        public void Should_Measure_Expander_Triangle_Correctly()
        {
            using (AvaloniaLocator.EnterScope())
            {
                Direct2D1Platform.Initialize();

                var target = new Path
                {
                    Data                = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"),
                    StrokeThickness     = 0,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top,
                    UseLayoutRounding   = false,
                };

                target.Measure(new Size(100, 100));
                target.Arrange(new Rect(0, 0, 100, 100));

                Assert.Equal(new Rect(0, 0, 4, 10), target.Bounds, Compare);
            }
        }
Beispiel #14
0
        public void Should_Load_Nearest_Matching_Font()
        {
            using (AvaloniaLocator.EnterScope())
            {
                Direct2D1Platform.Initialize();

                var assetLoaderType = typeof(TestRoot).Assembly.GetType("Avalonia.Shared.PlatformSupport.AssetLoader");

                var assetLoader = (IAssetLoader)Activator.CreateInstance(assetLoaderType, (Assembly)null);

                AvaloniaLocator.CurrentMutable.Bind <IAssetLoader>().ToConstant(assetLoader);

                var fontManager = new FontManagerImpl();

                var glyphTypeface = (GlyphTypefaceImpl)fontManager.CreateGlyphTypeface(
                    new Typeface(new FontFamily(s_fontUri), FontWeight.Black, FontStyle.Italic));

                var font = glyphTypeface.DWFont;

                Assert.Equal("Noto Mono", font.FontFamily.FamilyNames.GetString(0));
            }
        }
Beispiel #15
0
        public void Should_Create_Typeface_For_Unknown_Font()
        {
            using (AvaloniaLocator.EnterScope())
            {
                Direct2D1Platform.Initialize();

                var fontManager = new FontManagerImpl();

                var glyphTypeface = (GlyphTypefaceImpl)fontManager.CreateGlyphTypeface(
                    new Typeface(new FontFamily("Unknown")));

                var font = glyphTypeface.DWFont;

                var defaultName = fontManager.GetDefaultFontFamilyName();

                Assert.Equal(defaultName, font.FontFamily.FamilyNames.GetString(0));

                Assert.Equal(SharpDX.DirectWrite.FontWeight.Normal, font.Weight);

                Assert.Equal(SharpDX.DirectWrite.FontStyle.Normal, font.Style);
            }
        }
Beispiel #16
0
 static TestBase()
 {
     Direct2D1Platform.Initialize();
 }