public Text (string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null) : base (pen, brush) { Frame = frame; Font = font; Alignment = alignment; Spans = new List<TextSpan> { new TextSpan (text) }; }
public Text (Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null) : base (pen, brush) { Frame = frame; Font = font; Alignment = alignment; Spans = new List<TextSpan> (); }
public Text(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null) : base(pen, brush) { String = text; Frame = frame; Font = font; Alignment = alignment; }
public static TextMetrics GlobalMeasureText (string text, Font font) { var paint = GlobalGetFontPaint(font, TextAlignment.Left); var w = paint.MeasureText (text); var fm = paint.GetFontMetrics (); return new TextMetrics { Width = w, Ascent = -fm.Ascent, Descent = fm.Descent }; }
public static TextPaint GlobalGetFontPaint (Font font, TextAlignment alignment) { var paint = new TextPaint (PaintFlags.AntiAlias); paint.TextAlign = Paint.Align.Left; if (alignment == TextAlignment.Center) paint.TextAlign = Paint.Align.Center; else if (alignment == TextAlignment.Right) paint.TextAlign = Paint.Align.Right; paint.TextSize = (float)font.Size; var typeface = Typeface.Create (font.Family, TypefaceStyle.Normal); paint.SetTypeface (typeface); return paint; }
public Size MeasureText(string text, Font font) { var tt = new TextBlock(); tt.FontFamily = new FontFamily(font.Family); tt.FontSize = font.Size; tt.Text = text; return new Size(tt.ActualWidth, tt.ActualWidth); }
void DrawValue(ICanvas canvas, NGraphics.Point center, double radius, NGraphics.Font font, NGraphics.Color textColor, double middleRadian) { var valueCenter = new NGraphics.Point(center.X, center.Y); DrawText(Value.ToString("N"), canvas, valueCenter, radius, font, textColor, middleRadian); }
/// <summary> /// Draws text /// </summary> /// <param name="text"></param> /// <param name="frame"></param> /// <param name="font"></param> /// <param name="alignment"></param> /// <param name="pen"></param> /// <param name="brush"></param> public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, NGraphics.Brush brush = null) { var textBlock = new TextBlock(); textBlock.Text = text; textBlock.Width = frame.Width; textBlock.Height = frame.Height; Canvas.SetLeft(textBlock, frame.X); Canvas.SetTop(textBlock, frame.Y); textBlock.FontFamily = new FontFamily(font.Family); textBlock.FontSize = font.Size; switch (alignment) { case TextAlignment.Left: textBlock.TextAlignment = Windows.UI.Xaml.TextAlignment.Left; break; case TextAlignment.Center: textBlock.TextAlignment = Windows.UI.Xaml.TextAlignment.Center; break; case TextAlignment.Right: textBlock.TextAlignment = Windows.UI.Xaml.TextAlignment.Right; break; } if (pen != null) textBlock.Foreground = new SolidColorBrush(new Windows.UI.Color { A = pen.Color.A, R = pen.Color.R, G = pen.Color.G, B = pen.Color.B }); textBlock.RenderTransform = Conversions.GetTransform(CurrentTransform); _canvas.Children.Add(textBlock); }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null) { if (brush == null) return; var paint = GetFontPaint (font, alignment); var w = paint.MeasureText (text); var fm = paint.GetFontMetrics (); var h = fm.Ascent + fm.Descent; var point = frame.Position; var fr = new Rect (point, new Size (w, h)); AddBrushPaint (paint, brush, fr); graphics.DrawText (text, (float)point.X, (float)point.Y, paint); }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null) { }
public Size MeasureText(string text, Font font) { throw new NotImplementedException(); }
void DrawPercent(ICanvas canvas, NGraphics.Point center, double radius, NGraphics.Font font, NGraphics.Color textColor, double middleRadian) { var percentCenter = new NGraphics.Point(center.X, center.Y + 20); DrawText(Percent.ToString("P1"), canvas, percentCenter, radius, font, textColor, middleRadian); }
public static void DrawText(this ICanvas canvas, string text, Point point, Font font, Brush brush) { canvas.DrawText (text, new Rect (point, Size.MaxValue), font, brush: brush); }
void AddElement (IList<Element> list, XElement e, Pen inheritPen, Brush inheritBrush) { // // Style // Element r = null; Style eStyle = new Style(); ApplyStyle (e.Attributes ().ToDictionary (k => k.Name.LocalName, v => v.Value), eStyle); var style = ReadString (e.Attribute ("style")); if (!string.IsNullOrWhiteSpace (style)) { ApplyStyle (style, eStyle); } if (!eStyle.hasPen) eStyle.pen = inheritPen; if (!eStyle.hasBrush) eStyle.brush = inheritBrush; //var id = ReadString (e.Attribute ("id")); // // Elements // switch (e.Name.LocalName) { case "text": { var x = ReadNumber (e.Attribute ("x")); var y = ReadNumber (e.Attribute ("y")); var font = new Font (); var fontFamily = ReadTextFontFamily(e); if (!string.IsNullOrEmpty(fontFamily)) font.Family = fontFamily; var fontSize = ReadTextFontSize(e); if (fontSize >= 0) font.Size = fontSize; TextAlignment textAlignment = ReadTextAlignment(e); var txt = new Text (new Rect (new Point (x, y), new Size (double.MaxValue, double.MaxValue)), font, textAlignment, eStyle.pen, eStyle.brush); ReadTextSpans (txt, e); r = txt; } break; case "rect": { var x = ReadNumber (e.Attribute ("x")); var y = ReadNumber (e.Attribute ("y")); var width = ReadNumber (e.Attribute ("width")); var height = ReadNumber (e.Attribute ("height")); var rx = ReadNumber (e.Attribute ("rx")); var ry = ReadNumber (e.Attribute ("ry")); if (ry == 0) { ry = rx; } r = new Rectangle (new Rect (new Point (x, y), new Size (width, height)), new Size (rx, ry), eStyle.pen, eStyle.brush); } break; case "ellipse": { var cx = ReadNumber (e.Attribute ("cx")); var cy = ReadNumber (e.Attribute ("cy")); var rx = ReadNumber (e.Attribute ("rx")); var ry = ReadNumber (e.Attribute ("ry")); r = new Ellipse (new Point (cx - rx, cy - ry), new Size (2 * rx, 2 * ry), eStyle.pen, eStyle.brush); } break; case "circle": { var cx = ReadNumber (e.Attribute ("cx")); var cy = ReadNumber (e.Attribute ("cy")); var rr = ReadNumber (e.Attribute ("r")); r = new Ellipse (new Point (cx - rr, cy - rr), new Size (2 * rr, 2 * rr), eStyle.pen, eStyle.brush); } break; case "path": { var dA = e.Attribute ("d"); if (dA != null && !string.IsNullOrWhiteSpace (dA.Value)) { var p = new Path (eStyle.pen, eStyle.brush); ReadPath (p, dA.Value); r = p; } } break; case "polygon": { var pA = e.Attribute ("points"); if (pA != null && !string.IsNullOrWhiteSpace (pA.Value)) { var path = new Path (eStyle.pen, eStyle.brush); ReadPoints (path, pA.Value, true); r = path; } } break; case "polyline": { var pA = e.Attribute ("points"); if (pA != null && !string.IsNullOrWhiteSpace (pA.Value)) { var path = new Path (eStyle.pen, eStyle.brush); ReadPoints (path, pA.Value, false); r = path; } } break; case "g": { var g = new Group (); var groupId = e.Attribute("id"); if (groupId != null && !string.IsNullOrEmpty(groupId.Value)) g.Id = groupId.Value; AddElements (g.Children, e.Elements (), eStyle.pen, eStyle.brush); r = g; } break; case "use": { var href = ReadString (e.Attributes ().FirstOrDefault (x => x.Name.LocalName == "href")); if (!string.IsNullOrWhiteSpace (href)) { XElement useE; if (defs.TryGetValue (href.Trim ().Replace ("#", ""), out useE)) { var useList = new List<Element> (); AddElement (useList, useE, eStyle.pen, eStyle.brush); r = useList.FirstOrDefault (); } } } break; case "title": Graphic.Title = ReadString (e); break; case "desc": case "description": Graphic.Description = ReadString (e); break; case "defs": // Already read in earlier pass break; case "namedview": case "metadata": case "image": // Ignore break; case "line": { var x1 = ReadNumber ( e.Attribute("x1") ); var x2 = ReadNumber ( e.Attribute("x2") ); var y1 = ReadNumber ( e.Attribute("y1") ); var y2 = ReadNumber ( e.Attribute("y2") ); var p = new Path (eStyle.pen, null); p.MoveTo (x1, y1); p.LineTo (x2, y2); r = p; } break; case "foreignObject": { var x = ReadNumber ( e.Attribute("x") ); var y = ReadNumber ( e.Attribute("y") ); var width = ReadNumber ( e.Attribute("width") ); var height = ReadNumber ( e.Attribute("height") ); r = new ForeignObject(new Point(x, y), new Size(width, height)); } break; case "pgf": { var id = e.Attribute("id"); System.Diagnostics.Debug.WriteLine("Ignoring pgf element" + (id != null ? ": '" + id.Value + "'" : "")); } break; case "switch": { // Evaluate requiredFeatures, requiredExtensions and systemLanguage foreach (var ee in e.Elements()) { var requiredFeatures = ee.Attribute("requiredFeatures"); var requiredExtensions = ee.Attribute("requiredExtensions"); var systemLanguage = ee.Attribute("systemLanguage"); // currently no support for any of these restrictions if (requiredFeatures == null && requiredExtensions == null && systemLanguage == null) AddElement (list, ee, eStyle.pen, eStyle.brush); } } break; // color definition that can be referred to by other elements case "linearGradient": break; default: throw new NotSupportedException ("SVG element \"" + e.Name.LocalName + "\" is not supported"); } if (r != null) { eStyle.Apply(r); r.Transform = ReadTransform (ReadString (e.Attribute ("transform"))); var ida = e.Attribute("id"); if (ida != null && !string.IsNullOrEmpty (ida.Value)) { r.Id = ida.Value.Trim (); } list.Add (r); } }
public void DrawText (string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null) { if (brush == null) return; var paint = AndroidPlatform.GlobalGetFontPaint (font, alignment); var w = paint.MeasureText (text); var fm = paint.GetFontMetrics (); var h = fm.Ascent + fm.Descent; var point = alignment == TextAlignment.Left ? frame.TopLeft : alignment == TextAlignment.Center ? (frame.TopLeft + frame.TopRight) / 2 : frame.TopRight; var fr = new Rect (point, new Size (w, h)); AddBrushPaint (paint, brush, fr); graphics.DrawText (text, (float)point.X, (float)point.Y, paint); }
public TextMetrics MeasureText(string text, Font font) { return new TextMetrics (); }
public TextMetrics MeasureText (string text, Font font) { return AndroidPlatform.GlobalMeasureText (text, font); }
public virtual Size MeasureText(string text, Font font) { return NextCanvas.MeasureText(text, font); }
public virtual void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null) { NextCanvas.DrawText (text, frame, font, alignment, GetPen (pen), GetBrush (brush)); }
public double DrawSegment(NGraphics.ICanvas canvas, NGraphics.Point center, double radius, double startRadian, double pullLength, NGraphics.Font font, NGraphics.Color textColor, bool isNameVisible, NGraphics.Color percentColor, bool isPercentVisible, NGraphics.Color valueColor, bool isValueVisible) { double middleRadian = startRadian + Radian / 2.0; if (IsPull) { center = new NGraphics.Point( center.X + pullLength * Math.Cos(middleRadian), center.Y + pullLength * Math.Sin(middleRadian)); } var brush = new SolidBrush((Color ?? NGraphics.Colors.Black)); var pen = new Pen(PenColor, PenWidth); canvas.DrawPath((path) => { const double shardRadian = 0.02; path.MoveTo(center); path.LineTo(center.X + Math.Cos(startRadian) * radius, center.Y + Math.Sin(startRadian) * radius); for (var addRadian = 0.0; addRadian < Radian; addRadian += shardRadian) { path.LineTo(center.X + Math.Cos(startRadian + addRadian) * radius, center.Y + Math.Sin(startRadian + addRadian) * radius); } path.LineTo(center.X + Math.Cos(startRadian + Radian) * radius, center.Y + Math.Sin(startRadian + Radian) * radius); path.Close(); }, pen, brush); if (isNameVisible) { DrawName(canvas, center, radius, font, TitleColor ?? textColor, middleRadian); } if (isValueVisible) { DrawValue(canvas, center, radius, font, ValueColor ?? valueColor, middleRadian); } if (isPercentVisible) { DrawPercent(canvas, center, radius, font, PercentColor ?? percentColor, middleRadian); } return(startRadian + Radian); }
void DrawText(string text, ICanvas canvas, NGraphics.Point center, double radius, NGraphics.Font font, NGraphics.Color textColor, double middleRadian) { if (!string.IsNullOrWhiteSpace(text)) { double textRadius = radius * 0.67; NGraphics.Point centerText = new NGraphics.Point(center.X + Math.Cos(middleRadian) * textRadius, center.Y + Math.Sin(middleRadian) * textRadius); const double width = 40; const double height = 5; Rect rect = new Rect(centerText.X - width / 2.0, centerText.Y, width, height); canvas.DrawText(text, rect, font, NGraphics.TextAlignment.Center, new Pen(textColor), new SolidBrush(textColor)); } }
public static void DrawText(this ICanvas canvas, string text, Point point, Font font, Color color) { canvas.DrawText (text, new Rect (point, Size.MaxValue), font, brush: new SolidBrush (color)); }
public TextMetrics MeasureText (string text, Font font) { return GlobalMeasureText (text, font); }
void AddElement(IList<IDrawable> list, XElement e, Pen inheritPen, Brush inheritBrush) { // // Style // Element r = null; Pen pen = null; Brush brush = null; bool hasPen, hasBrush; ApplyStyle (e.Attributes ().ToDictionary (k => k.Name.LocalName, v => v.Value), ref pen, out hasPen, ref brush, out hasBrush); var style = ReadString (e.Attribute ("style")); if (!string.IsNullOrWhiteSpace (style)) { ApplyStyle (style, ref pen, out hasPen, ref brush, out hasBrush); } pen = hasPen ? pen : inheritPen; brush = hasBrush ? brush : inheritBrush; //var id = ReadString (e.Attribute ("id")); // // Elements // switch (e.Name.LocalName) { case "text": { var x = ReadNumber (e.Attribute ("x")); var y = ReadNumber (e.Attribute ("y")); var text = e.Value.Trim (); var fontFamilyAttribute = e.Attribute("font-family"); var font = new Font (); //if (fontFamilyAttribute != null) // font.Family = fontFamilyAttribute.Value.Trim('\''); var fontSizeAttribute = e.Attribute("font-size"); if (fontSizeAttribute != null) font.Size = ReadNumber(fontSizeAttribute.Value); r = new Text (text, new Rect (new Point (x, y), new Size (double.MaxValue, double.MaxValue)), font, TextAlignment.Left, pen, brush); } break; case "rect": { var x = ReadNumber (e.Attribute ("x")); var y = ReadNumber (e.Attribute ("y")); var width = ReadNumber (e.Attribute ("width")); var height = ReadNumber (e.Attribute ("height")); r = new Rectangle (new Point (x, y), new Size (width, height), pen, brush); } break; case "ellipse": { var cx = ReadNumber (e.Attribute ("cx")); var cy = ReadNumber (e.Attribute ("cy")); var rx = ReadNumber (e.Attribute ("rx")); var ry = ReadNumber (e.Attribute ("ry")); r = new Ellipse (new Point (cx - rx, cy - ry), new Size (2 * rx, 2 * ry), pen, brush); } break; case "circle": { var cx = ReadNumber (e.Attribute ("cx")); var cy = ReadNumber (e.Attribute ("cy")); var rr = ReadNumber (e.Attribute ("r")); r = new Ellipse (new Point (cx - rr, cy - rr), new Size (2 * rr, 2 * rr), pen, brush); } break; case "path": { var dA = e.Attribute ("d"); if (dA != null && !string.IsNullOrWhiteSpace (dA.Value)) { var p = new Path (pen, brush); ReadPath (p, dA.Value); r = p; } } break; case "polygon": { var pA = e.Attribute ("points"); if (pA != null && !string.IsNullOrWhiteSpace (pA.Value)) { var path = new Path (pen, brush); ReadPolygon (path, pA.Value); r = path; } } break; case "g": { var g = new Group (); AddElements (g.Children, e.Elements (), pen, brush); r = g; } break; case "use": { var href = ReadString (e.Attributes ().FirstOrDefault (x => x.Name.LocalName == "href")); if (!string.IsNullOrWhiteSpace (href)) { XElement useE; if (defs.TryGetValue (href.Trim ().Replace ("#", ""), out useE)) { var useList = new List<IDrawable> (); AddElement (useList, useE, pen, brush); r = useList.OfType<Element> ().FirstOrDefault (); } } } break; case "title": Graphic.Title = ReadString (e); break; case "desc": case "description": Graphic.Description = ReadString (e); break; case "defs": // Already read in earlier pass break; case "namedview": case "metadata": case "image": // Ignore break; case "line": { var x1 = ReadNumber ( e.Attribute("x1") ); var x2 = ReadNumber ( e.Attribute("x2") ); var y1 = ReadNumber ( e.Attribute("y1") ); var y2 = ReadNumber ( e.Attribute("y2") ); r = new Line(new Point(x1, y1), new Point(x2, y2), pen); } break; // color definition that can be referred to by other elements case "linearGradient": break; default: throw new NotSupportedException ("SVG element \"" + e.Name.LocalName + "\" is not supported"); } if (r != null) { r.Transform = ReadTransform (ReadString (e.Attribute ("transform"))); list.Add (r); } }
public Size MeasureText(string text, Font font) { float maxWidth = float.MaxValue; float maxHeight = float.MaxValue; var layout = new DW.TextLayout (factories.DWFactory, text, GetTextFormat (font), maxWidth, maxHeight); return new Size (layout.Metrics.Width, layout.Metrics.Height); }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null) { Graphic.Children.Add (new Text (text, frame, font, alignment, pen, brush)); }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null) { if (string.IsNullOrEmpty (text)) return; if (font == null) throw new ArgumentNullException ("font"); SetBrush (brush); // string fontName = font.Name; // context.SelectFont (font.Name, (nfloat)font.Size, CGTextEncoding.MacRoman); // // context.ShowTextAtPoint ((nfloat)frame.X, (nfloat)frame.Y, text); var pt = frame.TopLeft; using (var atext = new NSMutableAttributedString (text)) { atext.AddAttributes (new CTStringAttributes { ForegroundColorFromContext = true, Font = font.GetCTFont (), }, new NSRange (0, text.Length)); using (var l = new CTLine (atext)) { nfloat asc, desc, lead; var width = l.GetTypographicBounds (out asc, out desc, out lead); context.SaveState (); context.TranslateCTM ((nfloat)(pt.X - width / 2), (nfloat)(pt.Y + desc)); context.TextPosition = CGPoint.Empty; l.Draw (context); context.RestoreState (); } } }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null) { var layout = new DW.TextLayout (factories.DWFactory, text, GetTextFormat (font), (float)frame.Width, (float)frame.Height); var h = layout.Metrics.Height; renderTarget.DrawTextLayout ((frame.TopLeft - h*Point.OneY).ToVector2 (), layout, GetBrush (frame, brush)); }
void DrawName(ICanvas canvas, NGraphics.Point center, double radius, NGraphics.Font font, NGraphics.Color textColor, double middleRadian) { var percentCenter = new NGraphics.Point(center.X, center.Y - 20); DrawText(Title ?? "", canvas, percentCenter, radius, font, textColor, middleRadian); }
private DW.TextFormat GetTextFormat(Font font) { return new DW.TextFormat (factories.DWFactory, font.Family, (float)font.Size); }
TextPaint GetFontPaint(Font font, TextAlignment alignment) { var paint = new TextPaint (PaintFlags.AntiAlias); paint.TextAlign = Paint.Align.Left; if (alignment == TextAlignment.Center) paint.TextAlign = Paint.Align.Left; else if (alignment == TextAlignment.Right) paint.TextAlign = Paint.Align.Right; // paint.TextSize = (float)font.Size; // var typeface = Typeface.Create (font.Family, TypefaceStyle.Normal); // paint.SetTypeface (typeface); var typeface = Typeface.Default; paint.SetTypeface (typeface); float androidFontSize = AndroidPlatform.SizeToAndroid ((float)font.Size); paint.TextSize = androidFontSize; return paint; }
public Size MeasureText(string text, Font font) { if (string.IsNullOrEmpty(text)) return Size.Zero; if (font == null) throw new ArgumentNullException("font"); string fontName = font.Name; Array availableFonts = #if __IOS__ UIKit.UIFont.FontNamesForFamilyName(fontName); #else AppKit.NSFontManager.SharedFontManager.AvailableMembersOfFontFamily (fontName).ToArray (); #endif #if __IOS__ UIKit.UIFont nsFont; if (availableFonts != null && availableFonts.Length > 0) nsFont = UIKit.UIFont.FromName(font.Name, (nfloat)font.Size); else nsFont = UIKit.UIFont.FromName("Georgia", (nfloat)font.Size); #else AppKit.NSFont nsFont; if (availableFonts != null && availableFonts.Length > 0) nsFont = AppKit.NSFont.FromFontName(font.Name, (nfloat)font.Size); else nsFont = AppKit.NSFont.FromFontName("Georgia", (nfloat)font.Size); #endif using (var s = new NSAttributedString(text, font: nsFont)) using (nsFont) { #if __IOS__ var result = s.GetBoundingRect(new CGSize(float.MaxValue, float.MaxValue), NSStringDrawingOptions.UsesDeviceMetrics, null); #else var result = s.BoundingRectWithSize(new CGSize(float.MaxValue, float.MaxValue), NSStringDrawingOptions.UsesDeviceMetrics); #endif return new Size(result.Width, result.Height); } }
private async Task <string> CreateBadge(CancellationToken token) { //Get the badge icon IImage badgeIcon = null; if (_mode == Mode.File) { badgeIcon = await _canvasService.GetImage(FileIcon, token); } else if (_mode == Mode.Svg) { badgeIcon = await _canvasService.GetSvgImage(SvgIcon, SvgWidth, SvgHeight, token); } if (badgeIcon == null) { return(null); } token.ThrowIfCancellationRequested(); IImageCanvas canvas = null; if (IsBadgeVisible) { //InitializeCache frames var font = new Font(null, BadgeFontSize); var metrics = _canvasService.MeasureText(BadgeCount.ToString(), font); var textSize = metrics.Size; var badgeSize = new Size(BadgePadding.Left + BadgePadding.Right + textSize.Width, BadgePadding.Top + BadgePadding.Bottom + textSize.Height); var canvasSize = new Size(badgeIcon.Size.Width + badgeSize.Width - BadgeInsets.Width, badgeIcon.Size.Height + badgeSize.Height - BadgeInsets.Height); //Create canvas canvas = _canvasService.GetCanvas(canvasSize); token.ThrowIfCancellationRequested(); //Draw icon var imageFrame = new Rect(0, badgeSize.Height - BadgeInsets.Height, badgeIcon.Size.Width, badgeIcon.Size.Height); canvas.DrawImage(badgeIcon, imageFrame); token.ThrowIfCancellationRequested(); //Draw the badge rounded rect var badgeFrame = new Rect(badgeIcon.Size.Width - BadgeInsets.Width, 0, badgeSize.Width, badgeSize.Height); var color = GetColor(BadgeColor); var badgeImage = _canvasService.GetRoundedImage(badgeFrame.Size, color, BadgeRadius); canvas.DrawImage(badgeImage, badgeFrame); token.ThrowIfCancellationRequested(); //Draw badge text var textFrame = new Rect(badgeFrame.X + BadgePadding.Left, badgeFrame.Y + BadgePadding.Top + metrics.Ascent, textSize.Width, textSize.Height); canvas.DrawText(BadgeCount.ToString(), textFrame, font, TextAlignment.Center, GetColor(BadgeTextColor)); } else { //Create canvas canvas = _canvasService.GetCanvas(badgeIcon.Size); token.ThrowIfCancellationRequested(); //Draw icon var imageFrame = new Rect(0, 0, badgeIcon.Size.Width, badgeIcon.Size.Height); canvas.DrawImage(badgeIcon, imageFrame); } token.ThrowIfCancellationRequested(); //Get the result image var image = canvas.GetImage(); //Save the image to cache var filename = GetBadgeCacheFileName(); var path = PortablePath.Combine(_cacheFolder.Path, filename); await _canvasService.SaveImage(image, _cacheFolder.Path, filename, token); return(path); }
public Size MeasureText(string text, Font font) { var paint = GetFontPaint(font, TextAlignment.Left); var w = paint.MeasureText (text); var fm = paint.GetFontMetrics (); var h = fm.Ascent + fm.Descent; return new Size(w, h); }
public void DrawText (string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null) { var ch = GetChild (ChildType.Text); var s = (Shapes.Rectangle)ch.Shape; FormatShape (s, pen, brush); }
public Size MeasureText(string text, Font font) { return Size.Zero; }
public TextMetrics MeasureText(string text, Font font) { return(_platform.MeasureText(text, font)); }