public MeasureText ( |
||
buffer | ||
length | ||
return | float |
public static void MeasureTextSample (SKCanvas canvas, int width, int height) { canvas.DrawColor (SKColors.White); using (var paint = new SKPaint ()) { paint.TextSize = 64.0f; paint.IsAntialias = true; paint.Color = new SKColor (0x42, 0x81, 0xA4); paint.TextEncoding = SKTextEncoding.Utf32; canvas.DrawText ("Skia (UTF-32)", 0, 64.0f, paint); var bounds = new SKRect(); paint.MeasureText ("Skia (UTF-32)", ref bounds); bounds.Top += 64.0f; bounds.Bottom += 64.0f; paint.IsStroke = true; paint.Color = SKColors.Red; canvas.DrawRect (bounds, paint); } using (var paint = new SKPaint ()) { paint.TextSize = 64.0f; paint.IsAntialias = true; paint.Color = new SKColor (0x9C, 0xAF, 0xB7); paint.TextEncoding = SKTextEncoding.Utf16; canvas.DrawText ("Skia (UTF-16)", 0, 144.0f, paint); var bounds = new SKRect(); paint.MeasureText ("Skia (UTF-16)", ref bounds); bounds.Top += 144.0f; bounds.Bottom += 144.0f; paint.IsStroke = true; paint.Color = SKColors.Red; canvas.DrawRect (bounds, paint); } using (var paint = new SKPaint ()) { paint.TextSize = 64.0f; paint.IsAntialias = true; paint.Color = new SKColor (0xE6, 0xB8, 0x9C); paint.TextEncoding = SKTextEncoding.Utf8; canvas.DrawText ("Skia (UTF-8)", 0, 224.0f, paint); var bounds = new SKRect(); paint.MeasureText ("Skia (UTF-8)", ref bounds); bounds.Top += 224.0f; bounds.Bottom += 224.0f; paint.IsStroke = true; paint.Color = SKColors.Red; canvas.DrawRect (bounds, paint); } }
private void ReadTextSpans(XElement e, SKCanvas canvas, SKPoint location, SKPaint stroke, SKPaint fill) { var nodes = e.Nodes().ToArray(); for (int i = 0; i < nodes.Length; i++) { var c = nodes[i]; bool isFirst = i == 0; bool isLast = i == nodes.Length - 1; if (c.NodeType == XmlNodeType.Text) { // TODO: check for preserve whitespace var textSegments = ((XText)c).Value.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); var count = textSegments.Length; if (count > 0) { if (isFirst) { textSegments[0] = textSegments[0].TrimStart(); } if (isLast) { textSegments[count - 1] = textSegments[count - 1].TrimEnd(); } var text = WSRe.Replace(string.Concat(textSegments), " "); canvas.DrawText(text, location.X, location.Y, fill); location.X += fill.MeasureText(text); } } else if (c.NodeType == XmlNodeType.Element) { var ce = (XElement)c; if (ce.Name.LocalName == "tspan") { var spanFill = fill.Clone(); // the current span may want to change the cursor position location.X = ReadOptionalNumber(ce.Attribute("x")) ?? location.X; location.Y = ReadOptionalNumber(ce.Attribute("y")) ?? location.Y; ReadFontAttributes(ce, spanFill); var text = ce.Value.Trim(); canvas.DrawText(text, location.X, location.Y, spanFill); location.X += spanFill.MeasureText(text); } } } }
private static SKBitmap CreateLabelAsBitmap(LabelStyle style, string text, SKPaint paint) { var rect = new SKRect(); paint.MeasureText(text, ref rect); var backRect = new SKRect(0, 0, rect.Width + 6, rect.Height + 6); var bitmap = new SKBitmap((int)backRect.Width, (int)backRect.Height); using (var target = new SKCanvas(bitmap)) { target.Clear(); DrawBackground(style, backRect, target); target.DrawText(text, -rect.Left + 3, -rect.Top +3, paint); return bitmap; } }
public static void MeasureTextSample(SKCanvas canvas, int width, int height) { canvas.DrawColor(SKColors.White); using (var paint = new SKPaint()) { paint.TextSize = 64.0f; paint.IsAntialias = true; paint.Color = new SKColor(0x42, 0x81, 0xA4); paint.TextEncoding = SKTextEncoding.Utf32; canvas.DrawText("Skia (UTF-32)", 0, 64.0f, paint); var bounds = new SKRect(); paint.MeasureText("Skia (UTF-32)", ref bounds); bounds.Top += 64.0f; bounds.Bottom += 64.0f; paint.IsStroke = true; paint.Color = SKColors.Red; canvas.DrawRect(bounds, paint); } using (var paint = new SKPaint()) { paint.TextSize = 64.0f; paint.IsAntialias = true; paint.Color = new SKColor(0x9C, 0xAF, 0xB7); paint.TextEncoding = SKTextEncoding.Utf16; canvas.DrawText("Skia (UTF-16)", 0, 144.0f, paint); var bounds = new SKRect(); paint.MeasureText("Skia (UTF-16)", ref bounds); bounds.Top += 144.0f; bounds.Bottom += 144.0f; paint.IsStroke = true; paint.Color = SKColors.Red; canvas.DrawRect(bounds, paint); } using (var paint = new SKPaint()) { paint.TextSize = 64.0f; paint.IsAntialias = true; paint.Color = new SKColor(0xE6, 0xB8, 0x9C); paint.TextEncoding = SKTextEncoding.Utf8; canvas.DrawText("Skia (UTF-8)", 0, 224.0f, paint); var bounds = new SKRect(); paint.MeasureText("Skia (UTF-8)", ref bounds); bounds.Top += 224.0f; bounds.Bottom += 224.0f; paint.IsStroke = true; paint.Color = SKColors.Red; canvas.DrawRect(bounds, paint); } }