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.
pull/141/head
Steven Kirk 11 years ago
parent
commit
3d845f9527
  1. 19
      src/Gtk/Perspex.Cairo/CairoPlatform.cs
  2. 4
      src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs
  3. BIN
      tests/TestFiles/Cairo/Controls/Border/Border_Bottom_Aligns_Content.expected.png
  4. BIN
      tests/TestFiles/Cairo/Controls/Border/Border_Centers_Content_Horizontally.expected.png
  5. BIN
      tests/TestFiles/Cairo/Controls/Border/Border_Centers_Content_Vertically.expected.png
  6. BIN
      tests/TestFiles/Cairo/Controls/Border/Border_Left_Aligns_Content.expected.png
  7. BIN
      tests/TestFiles/Cairo/Controls/Border/Border_Right_Aligns_Content.expected.png
  8. BIN
      tests/TestFiles/Cairo/Controls/Border/Border_Top_Aligns_Content.expected.png

19
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();
}
}
}

4
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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 797 B

After

Width:  |  Height:  |  Size: 761 B

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 830 B

After

Width:  |  Height:  |  Size: 760 B

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 811 B

After

Width:  |  Height:  |  Size: 771 B

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 838 B

After

Width:  |  Height:  |  Size: 743 B

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 800 B

After

Width:  |  Height:  |  Size: 734 B

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 801 B

After

Width:  |  Height:  |  Size: 758 B

Loading…
Cancel
Save