public CanvasSizeF MeasureText(string text, IFont font) { text = text.RemoveReturns(); SKRect bounds = new SKRect(); var size = new CanvasSizeF(); if (text.IsMultiline()) { var fontHeight = font.Size.FontSizePointsToPixels(); foreach (var line in text.GetLines()) { GetSKPaint(font).MeasureText(line, ref bounds); size.Width = Math.Max(size.Width, bounds.Width); size.Height += fontHeight; } } else { GetSKPaint(font).MeasureText(text, ref bounds); size.Width = bounds.Width; size.Height = bounds.Height; } return(size); }
private AnnotationPolygon AnnotationPolygon(IDisplay display, CanvasSizeF size, float x, float y, TextSymbolAlignment alignment) { float x1 = 0, y1 = 0; switch (alignment) { case TextSymbolAlignment.rightAlignOver: x1 = x - size.Width; y1 = y - size.Height; break; case TextSymbolAlignment.rightAlignCenter: x1 = x - size.Width; y1 = y - size.Height / 2; break; case TextSymbolAlignment.rightAlignUnder: x1 = x - size.Width; y1 = y; break; case TextSymbolAlignment.Over: x1 = x - size.Width / 2; y1 = y - size.Height; break; case TextSymbolAlignment.Center: x1 = x - size.Width / 2; y1 = y - size.Height / 2; break; case TextSymbolAlignment.Under: x1 = x - size.Width / 2; y1 = y; break; case TextSymbolAlignment.leftAlignOver: x1 = x; y1 = y - size.Height; break; case TextSymbolAlignment.leftAlignCenter: x1 = x; y1 = y - size.Height / 2; break; case TextSymbolAlignment.leftAlignUnder: x1 = x; y1 = y; break; } return(new AnnotationPolygon(x1, y1, size.Width, size.Height)); }
private CanvasSizeF MeasureStringSize(IDisplay display, string text) { if (text == _text && _measureStringSize.HasValue) { return(_measureStringSize.Value); } else { CanvasSizeF size = display.Canvas.MeasureText(text, _font); if (text == _text) { _measureStringSize = size; } return(size); } }