Browse Source

Fixed failing Border render tests.

They were failing because passing a Pango.Context to FormattedTextImpl
was a hack. Create a pango context on startup that can be used for all
FormattedTextImpls. Fix the expected test output for tests containing
text as the expected output came from the Direct2D renderer where text
rendering is slightly different.
Steven Kirk 10 years ago
parent
commit
3d845f9527

+ 6 - 13
src/Gtk/Perspex.Cairo/CairoPlatform.cs

@@ -17,6 +17,8 @@ namespace Perspex.Cairo
     {
         private static readonly CairoPlatform s_instance = new CairoPlatform();
 
+        private static Pango.Context s_pangoContext = CreatePangoContext();
+
         public static void Initialize()
         {
             var locator = Locator.CurrentMutable;
@@ -36,12 +38,11 @@ namespace Perspex.Cairo
             TextAlignment textAlignment,
             Perspex.Media.FontWeight fontWeight)
         {
-            return new FormattedTextImpl(text, fontFamily, fontSize, fontStyle, textAlignment, fontWeight);
+            return new FormattedTextImpl(s_pangoContext, text, fontFamily, fontSize, fontStyle, textAlignment, fontWeight);
         }
 
         public IRenderer CreateRenderer(IPlatformHandle handle, double width, double height)
         {
-            Locator.CurrentMutable.RegisterConstant(GetPangoContext(handle), typeof(Pango.Context));
             return new Renderer(handle, width, height);
         }
 
@@ -69,18 +70,10 @@ namespace Perspex.Cairo
             return new BitmapImpl(pixbuf);
         }
 
-        private Pango.Context GetPangoContext(IPlatformHandle handle)
+        private static Pango.Context CreatePangoContext()
         {
-            switch (handle.HandleDescriptor)
-            {
-                case "GtkWindow":
-                    var window = GLib.Object.GetObject(handle.Handle) as Gtk.Window;
-                    return window.PangoContext;
-                default:
-                    throw new NotSupportedException(string.Format(
-                        "Don't know how to get a Pango Context from a '{0}'.",
-                        handle.HandleDescriptor));
-            }
+            Gtk.Application.Init();
+            return new Gtk.Invisible().CreatePangoContext();
         }
     }
 }

+ 3 - 1
src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs

@@ -15,6 +15,7 @@ namespace Perspex.Cairo.Media
         private Size _size;
 
         public FormattedTextImpl(
+            Pango.Context context,
             string text,
             string fontFamily,
             double fontSize,
@@ -22,7 +23,8 @@ namespace Perspex.Cairo.Media
             TextAlignment textAlignment,
             FontWeight fontWeight)
         {
-            var context = Locator.Current.GetService<Pango.Context>();
+            Contract.Requires<NullReferenceException>(context != null);
+
             Layout = new Pango.Layout(context);
             Layout.SetText(text);
             Layout.FontDescription = new Pango.FontDescription

BIN
tests/TestFiles/Cairo/Controls/Border/Border_Bottom_Aligns_Content.expected.png


BIN
tests/TestFiles/Cairo/Controls/Border/Border_Centers_Content_Horizontally.expected.png


BIN
tests/TestFiles/Cairo/Controls/Border/Border_Centers_Content_Vertically.expected.png


BIN
tests/TestFiles/Cairo/Controls/Border/Border_Left_Aligns_Content.expected.png


BIN
tests/TestFiles/Cairo/Controls/Border/Border_Right_Aligns_Content.expected.png


BIN
tests/TestFiles/Cairo/Controls/Border/Border_Top_Aligns_Content.expected.png