private void ProcessTextFormat(NSStringAttributes attributes) { var str = new NSString("A"); var bounds = str.BoundingRectWithSize( new CGSize(1000, 1000), 0, attributes.Dictionary); if ((nfloat)CharacterWidth != bounds.Width || (nfloat)CharacterHeight != bounds.Height) { CharacterWidth = bounds.Right; CharacterHeight = //bounds.Bottom attributes.Font.Ascender - attributes.Font.Descender; } int columns = Convert.ToInt32(Math.Floor(Frame.Width / CharacterWidth)); int rows = Convert.ToInt32(Math.Floor(Frame.Height / CharacterHeight)); if (Columns != columns || Rows != rows) { Columns = columns; Rows = rows; ResizeTerminal(); if (VtConnection != null) { VtConnection.SetTerminalWindowSize(columns, rows, 800, 600); } } }
private static void RenderSolutionNameIcon(string name) { if (!string.IsNullOrWhiteSpace(name)) { const float margin = 4; NSString text = (NSString)name; var paragraphStyle = (NSParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy(); paragraphStyle.Alignment = NSTextAlignment.Center; var attributes = new NSStringAttributes() { Font = NSFont.SystemFontOfSize(19, NSFontWeight.Regular), ForegroundColor = NSColor.White, ParagraphStyle = paragraphStyle }; var textRect = new CGSize(_defaultImage.Size.Width - margin * 2, _defaultImage.Size.Height - 2 * margin); var rect = text.BoundingRectWithSize(textRect, NSStringDrawingOptions.UsesLineFragmentOrigin, attributes.Dictionary); var centerAdjustment = _defaultImage.Size.Width - rect.Width - 2 * margin; rect.Offset(margin + centerAdjustment / 2, margin); var brandedImage = NSImage.ImageWithSize(_defaultImage.Size, false, (dstRect) => { _defaultImage.Draw(dstRect); DrawBackgroundInRect(rect); text.DrawInRect(rect, attributes); return(true); }); NSApplication.SharedApplication.ApplicationIconImage = brandedImage; } else { NSApplication.SharedApplication.ApplicationIconImage = _defaultImage; } }
public void NSString_BoundingRectWithSize() { NSString input = new NSString("Hey\nHow\nYou\nDoing"); CGRect rect = input.BoundingRectWithSize(new CGSize(20, 30), NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading, new NSDictionary()); Assert.IsTrue(rect.Width > 0); Assert.IsTrue(rect.Height > 0); }