using Cairo; using Pango; // Create a Cairo surface and context object using (var surface = new ImageSurface(Format.Argb32, 100, 100)) using (var cr = new Context(surface)) { // Create a Pango layout object and set the text to display var layout = new Layout(new Pango.Context()); layout.SetText("Hello, World!"); // Set the font and font size for the Pango layout var desc = FontDescription.FromString("Arial 12"); layout.FontDescription = desc; // Specify the position to display the Pango layout cr.Translate(20, 20); // Call ShowLayout to display the Pango layout using the Cairo context Pango.CairoHelper.ShowLayout(cr, layout); // Save the image to a file surface.WriteToPng("output.png"); }
using Cairo; using Pango; // Create a Cairo surface and context object using (var surface = new ImageSurface(Format.Argb32, 200, 200)) using (var cr = new Context(surface)) { // Create a Pango layout object and set the text to display var layout = new Layout(new Pango.Context()); layout.SetText("Hello, World!"); // Set the font and font size for the Pango layout var desc = FontDescription.FromString("Arial 18"); layout.FontDescription = desc; // Specify the position and alignment of the Pango layout cr.Translate(100, 100); Pango.CairoHelper.ShowLayout(cr, layout, Pango.Alignment.Center); // Save the image to a file surface.WriteToPng("output.png"); }This example is similar to the previous example, but it adds an alignment option to the ShowLayout method to center the text within the specified location. Package Library: Mono.Cairo Overall, the examples are using the Mono.Cairo package library to create and display Pango layouts using Cairo context.