Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use old layout code for non-Gtk3 #15

Merged
merged 1 commit into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Source/OxyPlot.GtkSharp.Shared/GraphicsRenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public class GraphicsRenderContext : RenderContextBase
/// </summary>
private Cairo.Context g;

#if GTKSHARP3
/// <summary>
/// The text layout context
/// </summary>
private Pango.Context c;
#endif

/// <summary>
/// Sets the graphics target.
Expand All @@ -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
}

/// <summary>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -364,6 +378,9 @@ public override void CleanUp()
}

this.imagesInUse.Clear();
#if GTKSHARP3
this.c.Dispose();
#endif
}

/// <summary>
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Source/OxyPlot.GtkSharp3/OxyPlot.GtkSharp3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<RepositoryUrl>https://github.com/oxyplot/oxyplot-gtksharp.git</RepositoryUrl>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>OxyPlot.snk</AssemblyOriginatorKeyFile>
<DefineConstants>GTKSHARP3</DefineConstants>
</PropertyGroup>
<Import Project="..\OxyPlot.GtkSharp.Shared\OxyPlot.GtkSharp.Shared.projitems" Label="Shared" />
<ItemGroup>
Expand Down