From daf7bba6c1755c84d2ca074d78500cb98b5467f1 Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Mon, 5 Jul 2021 09:32:05 +0100 Subject: [PATCH] Use old layout code for non-Gtk3 --- .../GraphicsRenderContext.cs | 19 ++++++++++++++++++- .../OxyPlot.GtkSharp3.csproj | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Source/OxyPlot.GtkSharp.Shared/GraphicsRenderContext.cs b/Source/OxyPlot.GtkSharp.Shared/GraphicsRenderContext.cs index 02cb6a0..2c6a22c 100644 --- a/Source/OxyPlot.GtkSharp.Shared/GraphicsRenderContext.cs +++ b/Source/OxyPlot.GtkSharp.Shared/GraphicsRenderContext.cs @@ -39,10 +39,12 @@ public class GraphicsRenderContext : RenderContextBase /// private Cairo.Context g; +#if GTKSHARP3 /// /// The text layout context /// private Pango.Context c; +#endif /// /// Sets the graphics target. @@ -52,7 +54,9 @@ public void SetGraphicsTarget(Cairo.Context graphics) { this.g = graphics; this.g.Antialias = Antialias.Subpixel; // TODO .TextRenderingHint = TextRenderingHint.AntiAliasGridFit; +#if GTKSHARP3 this.c = Pango.CairoHelper.CreateContext(this.g); +#endif } /// @@ -264,7 +268,11 @@ public override void DrawText( VerticalAlignment valign, OxySize? maxSize) { +#if GTKSHARP3 Pango.Layout layout = new Layout(this.c); +#else + Pango.Layout layout = Pango.CairoHelper.CreateLayout(this.g); +#endif Pango.FontDescription font = new Pango.FontDescription(); font.Family = fontFamily; font.Weight = (fontWeight >= 700) ? Pango.Weight.Bold : Pango.Weight.Normal; @@ -318,6 +326,7 @@ public override void DrawText( g.Clip(); this.g.SetSourceColor(fill); Pango.CairoHelper.ShowLayout(this.g, layout); + layout.Dispose(); this.g.Restore(); } @@ -336,7 +345,11 @@ public override OxySize MeasureText(string text, string fontFamily, double fontS return OxySize.Empty; } this.g.Save(); +#if GTKSHARP3 Pango.Layout layout = new Layout(this.c); +#else + Pango.Layout layout = Pango.CairoHelper.CreateLayout(this.g); +#endif Pango.FontDescription font = new Pango.FontDescription(); font.Family = fontFamily; font.Weight = (fontWeight >= 700) ? Pango.Weight.Bold : Pango.Weight.Normal; @@ -347,6 +360,7 @@ public override OxySize MeasureText(string text, string fontFamily, double fontS Pango.Rectangle logicalRect; layout.GetExtents(out inkRect, out logicalRect); this.g.Restore(); + layout.Dispose(); return new OxySize(logicalRect.Width / Pango.Scale.PangoScale, logicalRect.Height / Pango.Scale.PangoScale); } @@ -364,6 +378,9 @@ public override void CleanUp() } this.imagesInUse.Clear(); +#if GTKSHARP3 + this.c.Dispose(); +#endif } /// @@ -424,7 +441,7 @@ public override void DrawImage( // Pixbuf imageScaled = new Pixbuf(image.Colorspace, image.HasAlpha, image.BitsPerSample, (int)w, (int)h); // image.Composite(image, 0, 0, (int)w, (int)h, srcX, srcY, scalex, scaley, interpolate ? InterpType.Bilinear : InterpType.Nearest, (int)(opacity * 255)); // image = imageScaled; - + if (!interpolate) { image = image.ScaleSimple((int)w, (int)h, InterpType.Nearest); diff --git a/Source/OxyPlot.GtkSharp3/OxyPlot.GtkSharp3.csproj b/Source/OxyPlot.GtkSharp3/OxyPlot.GtkSharp3.csproj index c37dc69..a07b963 100644 --- a/Source/OxyPlot.GtkSharp3/OxyPlot.GtkSharp3.csproj +++ b/Source/OxyPlot.GtkSharp3/OxyPlot.GtkSharp3.csproj @@ -14,6 +14,7 @@ https://github.com/oxyplot/oxyplot-gtksharp.git True OxyPlot.snk + GTKSHARP3