public void NSLayoutManager_DrawGlyphsForGlyphRange() { #if NET manager.DrawGlyphs(new NSRange(0, 4), new CGPoint(10, 10)); #else manager.DrawGlyphsForGlyphRange(new NSRange(0, 4), new CGPoint(10, 10)); #endif }
public override void DrawRect(CGRect rect) { _drawRect = GetDrawRect(rect); if (UseLayoutManager) { // DrawGlyphsForGlyphRange is the method we want to use here since DrawBackgroundForGlyphRange is intended for something different. // While DrawBackgroundForGlyphRange will draw the background mark for specified Glyphs DrawGlyphsForGlyphRange will draw the actual Glyphs. // Note: This part of the code is called only under very specific situations. For most of the scenarios DrawString is used to draw the text. _layoutManager?.DrawGlyphsForGlyphRange(new NSRange(0, (nint)_layoutManager.NumberOfGlyphs), _drawRect.Location); } else { _attributedString?.DrawString(_drawRect, NSStringDrawingOptions.UsesLineFragmentOrigin); } }
public void Draw(CGContext ctx, CGColor foregroundColor, double x, double y) { bool tempForegroundSet = false; // if no color attribute is set for the whole string, // NSLayoutManager will use the default control foreground color. // To override the default color we need to apply the current CGContext stroke color // before all other attributes are set, otherwise it will remove all other foreground colors. if (foregroundColor != null && !Attributes.Any(a => a is ColorTextAttribute && a.StartIndex == 0 && a.Count == Text.Length)) { // FIXME: we need to find a better way to accomplish this without the need to reset all attributes. ResetAttributes(NSColor.FromCGColor(foregroundColor)); tempForegroundSet = true; } ctx.SaveState(); NSGraphicsContext.GlobalSaveGraphicsState(); var nsContext = NSGraphicsContext.FromCGContext(ctx, true); NSGraphicsContext.CurrentContext = nsContext; using (var TextLayout = new NSLayoutManager()) { TextLayout.AddTextContainer(TextContainer); TextStorage.AddLayoutManager(TextLayout); TextLayout.DrawBackgroundForGlyphRange(new NSRange(0, Text.Length), new CGPoint(x, y)); TextLayout.DrawGlyphsForGlyphRange(new NSRange(0, Text.Length), new CGPoint(x, y)); TextStorage.RemoveLayoutManager(TextLayout); TextLayout.RemoveTextContainer(0); } // reset foreground color change if (tempForegroundSet) { ResetAttributes(); } NSGraphicsContext.GlobalRestoreGraphicsState(); ctx.RestoreState(); }
public override void DrawRect(CGRect rect) { _drawRect = GetDrawRect(rect); _layoutManager?.DrawGlyphsForGlyphRange(new NSRange(0, (nint)_layoutManager.NumberOfGlyphs), _drawRect.Location); }
public void NSLayoutManager_DrawGlyphsForGlyphRange() { manager.DrawGlyphsForGlyphRange(new NSRange(0, 4), new CGPoint(10, 10)); }