internal static void Draw (CGContext ctx, object layout, double x, double y) { LayoutInfo li = (LayoutInfo)layout; using (CTFrame frame = CreateFrame (li)) { if (frame == null) return; CTLine ellipsis = null; bool ellipsize = li.Width.HasValue && li.TextTrimming == TextTrimming.WordElipsis; if (ellipsize) ellipsis = new CTLine (CreateAttributedString (li, "...")); float lineHeight = li.Font.Ascender - li.Font.Descender + li.Font.Leading; ctx.SaveState (); ctx.TextMatrix = CGAffineTransform.MakeScale (1f, -1f); ctx.TranslateCTM ((float)x, (float)y + li.Font.Ascender); foreach (var line in frame.GetLines ()) { ctx.TextPosition = PointF.Empty; if (ellipsize) // we need to create a new CTLine here because the framesetter already truncated the text for the line new CTLine (CreateAttributedString (li, li.Text.Substring (line.StringRange.Location))) .GetTruncatedLine (li.Width.Value, CTLineTruncation.End, ellipsis).Draw (ctx); else line.Draw (ctx); ctx.TranslateCTM (0, lineHeight); } ctx.RestoreState (); } }
public static void DrawText(CGContext context, string text, string fontName, float fontSize, float translateHeight, float x, float y) { context.SaveState(); context.SelectFont(fontName, fontSize, CGTextEncoding.MacRoman); context.SetTextDrawingMode(CGTextDrawingMode.Fill); context.SetFillColor(new CGColor(1, 1)); context.SetStrokeColor(new CGColor(1.0f, 1.0f)); //context.AddRect(rectText); //context.Clip(); context.TextMatrix = CGAffineTransform.MakeScale(1.0f, -1.0f); context.TranslateCTM(0, translateHeight); context.ScaleCTM(1, -1); context.ShowTextAtPoint(x, y, text); context.RestoreState(); }
internal static void Draw(CGContext ctx, object layout, double x, double y) { LayoutInfo li = (LayoutInfo)layout; if (li.Framesetter == null) return; CGPath path = new CGPath (); path.AddRect (new RectangleF (0, 0, li.Width ?? float.MaxValue, li.Height ?? float.MaxValue)); CTFrame frame = li.Framesetter.GetFrame (new NSRange (0, li.Text.Length), path, null); CTLine ellipsis = null; bool ellipsize = li.Width.HasValue && li.TextTrimming == TextTrimming.WordElipsis; if (ellipsize) ellipsis = new CTLine (CreateAttributedString (li, "...")); float lineHeight = layoutManager.DefaultLineHeightForFont (li.Font); ctx.SaveState (); ctx.TextMatrix = CGAffineTransform.MakeScale (1f, -1f); ctx.TranslateCTM ((float)x, (float)y + li.Font.Ascender); foreach (var line in frame.GetLines ()) { ctx.TextPosition = PointF.Empty; if (ellipsize) // we need to create a new CTLine here because the framesetter already truncated the text for the line new CTLine (CreateAttributedString (li, li.Text.Substring (line.StringRange.Location))) .GetTruncatedLine (li.Width.Value, CTLineTruncation.End, ellipsis).Draw (ctx); else line.Draw (ctx); ctx.TranslateCTM (0, lineHeight); } ctx.RestoreState (); }