void DrawAlphaBetaMarker(Cairo.Context c, ref Cairo.PointD bottomRight, string text) { c.SelectFontFace(SplashFontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Bold); c.SetFontSize(SplashFontSize); // Create a rectangle larger than the text so we can have a nice border // And round the value so we don't have a blurry rectangle. var extents = c.TextExtents(text); var x = Math.Round(bottomRight.X - extents.Width * 1.3); var y = Math.Round(bottomRight.Y - extents.Height * 2.8); var rectangle = new Cairo.Rectangle(x, y, bottomRight.X - x, bottomRight.Y - y); // Draw the background color the text will be overlaid on DrawRectangle(c, rectangle); // Calculate the offset the text will need to be at to be centralised // in the border x = x + extents.XBearing + (rectangle.Width - extents.Width) / 2; y = y - extents.YBearing + (rectangle.Height - extents.Height) / 2; c.MoveTo(x, y); // Draw the text c.SetSourceRGB(1, 1, 1); c.ShowText(text); bottomRight.Y -= rectangle.Height - 2; }
void OnExpose(object sender, EventArgs eventArgs) { DrawingArea drawingArea = this.tree; // Get drawing context Cairo.Context ctx = Gdk.CairoHelper.Create(drawingArea.GdkWindow); // Set initial point Cairo.PointD point = new Cairo.PointD() { X = 150.0, Y = 100.0, }; //Setup text style ctx.SelectFontFace("Sans", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); ctx.SetFontSize(15.0); // Set current and next point Cairo.PointD currentPoint = new Cairo.PointD { X = 200, Y = 125, }; Cairo.PointD newPoint = new Cairo.PointD { X = 125, Y = 225, }; this.DisplayTree(this.ast, ctx, currentPoint, 0, true, false); }
/// <summary> /// Creates a bitmap for each character in the font. /// Characters that the font does not include will not be assigned a bitmap. /// </summary> private void CreateBitmaps() { characters = new Dictionary <char, PixelSet>(); ImageSurface surface = new ImageSurface(Format.RGB24, 1, 1); Context context = new Context(surface); context.SelectFontFace(FontName, FontSlant.Normal, FontWeight.Normal); context.SetFontSize(Font.Size); TextExtents ext = context.TextExtents("@"); int charW = (int)Math.Ceiling(ext.Width); int charH = (int)Math.Ceiling(ext.Height); context.Dispose(); surface.Dispose(); surface = new ImageSurface(Format.RGB24, charW, charH); context = new Context(surface); PixelSet missingChar = null; for (int i = 0; i < asciiString.Length; i++) { // Render one character into a PixelSet string asciiChar = string.Empty + asciiString[i]; context.SelectFontFace(FontName, FontSlant.Normal, FontWeight.Normal); context.SetFontSize(Font.Size); context.SetSourceRGB(0.067, 0.067, 0.067); context.Paint(); context.SetSourceRGB(1, 1, 1); ext = context.TextExtents(asciiChar); context.MoveTo(ext.XBearing, ext.YBearing * -1); context.ShowText(asciiChar); PixelSet ch = new PixelSet(surface); // Filter out characters the font doesn't include // The first character is always unprintable, and serves as // a reference for what unprintable characters look like in this font if (i == 0) { missingChar = ch; continue; } else if (ch == missingChar) { continue; } characters.Add(asciiString[i], ch); } context.Dispose(); surface.Dispose(); // Add the space manually if it wasn't included if (!characters.ContainsKey(' ')) { var en = characters.Values.GetEnumerator(); en.MoveNext(); characters.Add(' ', new PixelSet(en.Current.Width, en.Current.Height)); } }
public override void DrawText(FormattedText formattedText, Point origin) { cr.Color = new Cairo.Color(formattedText.Foreground.R, formattedText.Foreground.G, formattedText.Foreground.B, formattedText.Foreground.Alfa); cr.MoveTo(origin.X, origin.Y + formattedText.Height); cr.SelectFontFace(formattedText.FontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); cr.SetFontSize(formattedText.FontSize); cr.ShowText(formattedText.Text); }
void DrawVersionNumber(Cairo.Context c, ref Cairo.PointD bottomRight, string text) { c.SelectFontFace(SplashFontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); c.SetFontSize(SplashFontSize); var extents = c.TextExtents(text); c.MoveTo(bottomRight.X - extents.Width - 1, bottomRight.Y - extents.Height); c.SetSourceRGB(1, 1, 1); c.ShowText(text); }
private void Measure() { var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 1, 1); using (Cairo.Context cr = new Cairo.Context(surface)) { cr.SelectFontFace(FontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); cr.SetFontSize(FontSize); var textExtents = cr.TextExtents(Text); Width = textExtents.Width; Height = Math.Abs(textExtents.YBearing); Extent = textExtents.Height; } }
private void Measure () { var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1); using (Cairo.Context cr = new Cairo.Context(surface)) { cr.SelectFontFace (FontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); cr.SetFontSize (FontSize); var textExtents = cr.TextExtents (Text); Width = textExtents.Width; Height = Math.Abs (textExtents.YBearing); Extent = textExtents.Height; } }
public static void SelectFont(this Cairo.Context ctx, Font font) { Cairo.FontSlant slant; switch (font.Style) { case FontStyle.Oblique: slant = Cairo.FontSlant.Oblique; break; case FontStyle.Italic: slant = Cairo.FontSlant.Italic; break; default: slant = Cairo.FontSlant.Normal; break; } Cairo.FontWeight w = font.Weight >= FontWeight.Bold ? Cairo.FontWeight.Bold : Cairo.FontWeight.Normal; ctx.SelectFontFace(font.Family, slant, w); }
void DrawInfos(Cairo.Context context) { context.Save(); context.SelectFontFace("Tahoma 10", Cairo.FontSlant.Normal, Cairo.FontWeight.Bold); // cairo.SetFontSize(10); for (int i = 0; i < m_Nodes.Count - 1; i++) { var a = m_Nodes[i]; var b = m_Nodes[i + 1]; var c = Coord.Center(a, b); double angle = Coord.AngleRad(a, b); double len = Coord.Length(a, b); string text = string.Format("{0:F1} {1:F1}°", len, Coord.Rad2Degree(angle)); Drawing.DrawText(context, (int)c.X, (int)c.Y, angle, text); } context.Restore(); }
public static void DrawCaption(DrawingArea da, int width, int height, string text, double posX, double posY, double size = 3.75) { if (posX <= 1 && posY <= 1) { posX *= width; posY *= height; } Cairo.Context texTcr = Gdk.CairoHelper.Create(da.GdkWindow); texTcr.SelectFontFace("", Cairo.FontSlant.Normal, Cairo.FontWeight.Bold); texTcr.SetFontSize(size * width / 100f); texTcr.MoveTo(posX, posY); texTcr.TextPath(text); texTcr.SetSourceRGB(1, 1, 1); texTcr.FillPreserve(); texTcr.LineWidth = width / 100f / 3; texTcr.SetSourceRGB(0, 0, 0); texTcr.Stroke(); texTcr.Dispose(); return; }
protected override void onDraw(Cairo.Context gr) { base.onDraw(gr); if (lines == null) { return; } gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); Rectangle r = ClientRectangle; Foreground.SetAsSource(gr); double y = ClientRectangle.Y; double x = ClientRectangle.X; for (int i = 0; i < visibleLines; i++) { if (i + ScrollY >= Lines.Count) { break; } //if ((lines [i + Scroll] as string).StartsWith ("error", StringComparison.OrdinalIgnoreCase)) { // errorFill.SetAsSource (gr); // gr.Rectangle (x, y, (double)r.Width, fe.Height); // gr.Fill (); // Foreground.SetAsSource (gr); //} gr.MoveTo(x, y + fe.Ascent); gr.ShowText(lines[i + ScrollY] as string); y += fe.Height; gr.Fill(); } }
protected override void onDraw(Cairo.Context gr) { base.onDraw(gr); Rectangle cb = new Rectangle(0, 0, designWidth, designHeight); gr.Save(); double z = zoom / 100.0; gr.Scale(z, z); if (drawGrid) { double gridLineWidth = 0.2 / z; double glhw = gridLineWidth / 2.0; int nbLines = cb.Width / gridSpacing; double d = cb.Left + gridSpacing; for (int i = 0; i < nbLines; i++) { gr.MoveTo(d - glhw, cb.Y); gr.LineTo(d - glhw, cb.Bottom); d += gridSpacing; } nbLines = cb.Height / gridSpacing; d = cb.Top + gridSpacing; for (int i = 0; i < nbLines; i++) { gr.MoveTo(cb.X, d - glhw); gr.LineTo(cb.Right, d - glhw); d += gridSpacing; } gr.LineWidth = gridLineWidth; Foreground.SetAsSource(gr, cb); gr.Stroke(); } lock (imlVE.RenderMutex) { gr.SetSourceSurface(imlVE.surf, cb.Left, cb.Top); gr.Paint(); imlVE.IsDirty = false; } /*if (Error == null) { * gr.SetSourceColor (Color.Black); * gr.Rectangle (cb, 1.0 / z); * } else { * gr.SetSourceColor (Color.LavenderBlush); * gr.Rectangle (cb, 2.0 / z); * string[] lerrs = Error.ToString ().Split ('\n'); * Point p = cb.Center; * p.Y -= lerrs.Length * 20; * foreach (string le in lerrs) { * drawCenteredTextLine(gr, p, le); * p.Y += 20; * * } * } * gr.Stroke ();*/ Rectangle hr; if (SelectedItem?.Parent != null) { gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); gr.FontOptions = Interface.FontRenderingOptions; gr.Antialias = Interface.Antialias; Widget g = SelectedItem; hr = g.ScreenCoordinates(g.getSlot()); // Rectangle rIcons = new Rectangle (iconSize); // rIcons.Width *= 4; // rIcons.Top = hr.Bottom; // rIcons.Left = hr.Right - rIcons.Width + iconSize.Width; Rectangle rIcoMove = new Rectangle(hr.BottomRight, iconSize); // Rectangle rIcoStyle = rIcoMove; // rIcoStyle.Left += iconSize.Width + 4; using (Surface mask = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) { using (Context ctx = new Context(mask)) { ctx.Save(); ctx.SetSourceRGBA(1.0, 1.0, 1.0, 0.4); ctx.Paint(); ctx.Rectangle(hr); ctx.Operator = Operator.Clear; ctx.Fill(); } gr.SetSourceSurface(mask, 0, 0); gr.Paint(); using (Surface ol = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) { using (Context ctx = new Context(ol)) { ctx.SetSourceColor(Colors.Black); drawDesignOverlay(ctx, g, cb, hr, 0.4 / z, 6.5); } gr.SetSourceSurface(ol, 0, 0); gr.Paint(); } drawIcon(gr, icoMove, rIcoMove); //drawIcon (gr, icoStyle, rIcoStyle); } } if (HoverWidget != null) { hr = HoverWidget.ScreenCoordinates(HoverWidget.getSlot()); gr.SetSourceColor(Colors.SkyBlue); //gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0); gr.Rectangle(hr, 0.4 / z); } gr.Restore(); }
public static void SelectTagOverlayFont(this Cairo.Context cr) { cr.SelectFontFace("Noto Mono", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); cr.SetFontSize(12.0); cr.Antialias = Cairo.Antialias.Gray; }
protected override bool OnExposeEvent(Gdk.EventExpose args) { //base.OnPaint(pe); Cairo.Context dc = Gdk.CairoHelper.Create(args.Window); // Draw white background //Graphics dc = pe.Graphics; dc.IdentityMatrix(); dc.SetSourceRGB(1.0, 1.0, 1.0); dc.Rectangle(0, 0, Allocation.Width, Allocation.Height); dc.Fill(); // Draw the raster Cairo.Matrix t = TheRasterModel.GetTikzToScreenTransform().ToCairoMatrix(); //t.Freeze(); dc.Save(); dc.LineWidth = 0.01; // todo: always 1 pixel dc.SetSourceRGB(0.7, 0.7, 0.7); // whitesmoke? { dc.Transform(t); TheRasterModel.DrawRaster( (p1, p2) => { dc.MoveTo(p1.X, p1.Y); dc.LineTo(p2.X, p2.Y); dc.Stroke(); }, (r1, r2) => { dc.DrawEllipse(0, 0, 2 * r1, 2 * r2); }); } dc.Restore(); // draw unavailable note if (TheDisplayModel.IsUnavailable) { dc.SetSourceRGB(0, 0, 0); dc.SelectFontFace("Arial", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); //StringFormat f = new StringFormat(); //f.Alignment = StringAlignment.Center; //f.LineAlignment = StringAlignment.Center; //dc.DrawString("<Unavailable>", new Font("Arial", 16), Brushes.Black, ClientRectangle, f); dc.MoveTo(Allocation.Width / 2, Allocation.Height / 2); //todo dc.ShowText("<Unavailable>"); } // draw the pdf image if (TheDisplayModel.IsImageVisible && TheDisplayModel.Bmp != null) { Point p = new Point((Allocation.Width - TheDisplayModel.Bmp.Width) / 2, (Allocation.Height - TheDisplayModel.Bmp.Height) / 2); //dc.DrawImageUnscaled(TheDisplayModel.Bmp, p); dc.SetSource(TheDisplayModel.Bmp, p.X, p.Y); //dc.Rectangle(p.X, p.Y, TheDisplayModel.Bmp.Width, TheDisplayModel.Bmp.Height); dc.Paint(); } // draw the overlay if (ShowOverlay) { dc.SetSourceRGB(0, 0, 0); // draw shapes from parsetree foreach (var osv in OSViews) { osv.Draw(dc); } // draw (visible) auxiliary shapes foreach (var ps in PreviewShapes.Where(o => o.Visible)) { ps.Draw(dc); } } // draw adorner(s) foreach (var scope in this.OSViews.OfType <OverlayScopeView>().Where(v => v.IsAdornerVisible)) { dc.SetSourceRGB(0.5, 0.5, 0.5); dc.LineWidth = 5; System.Windows.Rect ShowAt = scope.GetBB(Allocation.Height); ShowAt.Inflate(6, 6); dc.Rectangle(ShowAt.ToCairoRectangle()); //(PensAndBrushes.AdornerPen, ShowAt.ToRectangleF()); dc.Stroke(); } // draw the object marker if (MarkObject_ShowMarker && MarkObject_Marked != null) { System.Windows.Rect ShowAt = MarkObject_Marked.GetBB(Allocation.Height); ShowAt.Inflate(15, 15); //using (Pen p = new Pen(Brushes.Red, 6)) { dc.SetSourceRGB(1, 0, 0); dc.LineWidth = 6; dc.DrawEllipse(ShowAt);//p, } } ((IDisposable)dc.Target).Dispose(); ((IDisposable)dc).Dispose(); return(true); }
protected override void onDraw(Cairo.Context gr) { base.onDraw(gr); if (events == null) { return; } gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); Rectangle r = ClientRectangle; double y = ClientRectangle.Y; double x = ClientRectangle.X; int spaces = 0; uint [] evts; lock (eventsDic) evts = eventsDic.ToArray(); int idx = Array.BinarySearch(evts, (uint)ScrollY); if (idx < 0) { idx = ~idx - 1; } if (idx < 0) { return; } int diff = ScrollY - (int)evts [idx]; int i = 0; while (i < visibleLines) { if (idx >= events.Count) { break; } //if ((lines [i + Scroll] as string).StartsWith ("error", StringComparison.OrdinalIgnoreCase)) { // errorFill.SetAsSource (gr); // gr.Rectangle (x, y, (double)r.Width, fe.Height); // gr.Fill (); // Foreground.SetAsSource (gr); //} BuildEventArgs evt = events[idx] as BuildEventArgs; if (evt is BuildMessageEventArgs) { BuildMessageEventArgs msg = evt as BuildMessageEventArgs; switch (msg.Importance) { case MessageImportance.High: gr.SetSourceColor(Colors.White); break; case MessageImportance.Normal: gr.SetSourceColor(Colors.Grey); break; case MessageImportance.Low: gr.SetSourceColor(Colors.Jet); break; } } else if (evt is BuildStartedEventArgs) { gr.SetSourceColor(Colors.White); } else if (evt is BuildFinishedEventArgs) { gr.SetSourceColor(Colors.White); } else if (evt is BuildErrorEventArgs) { gr.SetSourceColor(Colors.Red); } else if (evt is BuildEventArgs) { gr.SetSourceColor(Colors.Yellow); } else if (evt is BuildStatusEventArgs) { gr.SetSourceColor(Colors.Green); } string[] lines = Regex.Split(evt.Message, "\r\n|\r|\n|\\\\n"); for (int j = diff; j < lines.Length; j++) { gr.MoveTo(x, y + fe.Ascent); gr.ShowText(new string (' ', spaces) + lines[j]); y += fe.Height; i++; if (y > ClientRectangle.Bottom) { break; } } diff = 0; idx++; gr.Fill(); } }
public static void SetFont(this Cairo.Context cr, FontInfo fontInfo) { cr.SetSourceRGB(fontInfo.Color.Red, fontInfo.Color.Green, fontInfo.Color.Blue); cr.SelectFontFace(fontInfo.Family, fontInfo.Slant, fontInfo.Weight); cr.SetFontSize(fontInfo.Scale); }