public FormattedTextImpl(string text, string fontFamilyName, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight, TextWrapping wrapping) { _text = text ?? string.Empty; // Replace 0 characters with zero-width spaces (200B) _text = _text.Replace((char)0, (char)0x200B); var typeface = TypefaceCache.GetTypeface(fontFamilyName, fontStyle, fontWeight); _paint = new SKPaint(); //currently Skia does not measure properly with Utf8 !!! //Paint.TextEncoding = SKTextEncoding.Utf8; _paint.TextEncoding = SKTextEncoding.Utf16; _paint.IsStroke = false; _paint.IsAntialias = true; _paint.LcdRenderText = true; _paint.SubpixelText = true; _paint.Typeface = typeface; _paint.TextSize = (float)fontSize; _paint.TextAlign = textAlignment.ToSKTextAlign(); _wrapping = wrapping; Rebuild(); }
public FormattedTextImpl(string text, string fontFamilyName, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight, TextWrapping wrapping) { _text = text ?? string.Empty; // Replace 0 characters with zero-width spaces (200B) _text = _text.Replace((char)0, (char)0x200B); var typeface = TypefaceCache.GetTypeface(fontFamilyName, fontStyle, fontWeight); _paint = new SKPaint(); //currently Skia does not measure properly with Utf8 !!! //Paint.TextEncoding = SKTextEncoding.Utf8; _paint.TextEncoding = SKTextEncoding.Utf16; _paint.IsStroke = false; _paint.IsAntialias = true; _paint.Typeface = typeface; _paint.TextSize = (float)fontSize; _paint.TextAlign = textAlignment.ToSKTextAlign(); _wrapping = wrapping; Rebuild(); }
public static FormattedTextImpl Create(string text, string fontFamilyName, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight) { var typeface = TypefaceCache.GetTypeface(fontFamilyName, fontStyle, fontWeight); FormattedTextImpl instance = new FormattedTextImpl(text); instance.Paint.Typeface = typeface; instance.Paint.TextSize = (float)fontSize; instance.Paint.TextAlign = textAlignment.ToSKTextAlign(); instance.Rebuild(); return(instance); }
public FormattedTextImpl( string text, Typeface typeface, double fontSize, TextAlignment textAlignment, TextWrapping wrapping, Size constraint, IReadOnlyList <FormattedTextStyleSpan> spans) { Text = text ?? string.Empty; // Replace 0 characters with zero-width spaces (200B) Text = Text.Replace((char)0, (char)0x200B); var glyphTypeface = (GlyphTypefaceImpl)typeface.GlyphTypeface.PlatformImpl; _paint = new SKPaint { TextEncoding = SKTextEncoding.Utf16, IsStroke = false, IsAntialias = true, LcdRenderText = true, SubpixelText = true, IsLinearText = true, Typeface = glyphTypeface.Typeface, TextSize = (float)fontSize, TextAlign = textAlignment.ToSKTextAlign() }; //currently Skia does not measure properly with Utf8 !!! //Paint.TextEncoding = SKTextEncoding.Utf8; _wrapping = wrapping; _constraint = constraint; if (spans != null) { foreach (var span in spans) { if (span.ForegroundBrush != null) { SetForegroundBrush(span.ForegroundBrush, span.StartIndex, span.Length); } } } Rebuild(); }
public FormattedTextImpl( string text, Typeface typeface, TextAlignment textAlignment, TextWrapping wrapping, Size constraint, IReadOnlyList <FormattedTextStyleSpan> spans) { Text = text ?? string.Empty; // Replace 0 characters with zero-width spaces (200B) Text = Text.Replace((char)0, (char)0x200B); var skiaTypeface = TypefaceCache.GetTypeface( typeface?.FontFamilyName ?? "monospace", typeface?.Style ?? FontStyle.Normal, typeface?.Weight ?? FontWeight.Normal); _paint = new SKPaint(); //currently Skia does not measure properly with Utf8 !!! //Paint.TextEncoding = SKTextEncoding.Utf8; _paint.TextEncoding = SKTextEncoding.Utf16; _paint.IsStroke = false; _paint.IsAntialias = true; _paint.LcdRenderText = true; _paint.SubpixelText = true; _paint.Typeface = skiaTypeface; _paint.TextSize = (float)(typeface?.FontSize ?? 12); _paint.TextAlign = textAlignment.ToSKTextAlign(); _paint.BlendMode = SKBlendMode.Src; _wrapping = wrapping; _constraint = constraint; if (spans != null) { foreach (var span in spans) { if (span.ForegroundBrush != null) { SetForegroundBrush(span.ForegroundBrush, span.StartIndex, span.Length); } } } Rebuild(); }
public FormattedTextImpl( string text, Typeface typeface, TextAlignment textAlignment, TextWrapping wrapping, Size constraint, IReadOnlyList <FormattedTextStyleSpan> spans) { Text = text ?? string.Empty; // Replace 0 characters with zero-width spaces (200B) Text = Text.Replace((char)0, (char)0x200B); SKTypeface skiaTypeface = TypefaceCache.Default; if (typeface.FontFamily.Key != null) { var typefaces = SKTypefaceCollectionCache.GetOrAddTypefaceCollection(typeface.FontFamily); skiaTypeface = typefaces.GetTypeFace(typeface); } else { if (typeface.FontFamily.FamilyNames.HasFallbacks) { foreach (var familyName in typeface.FontFamily.FamilyNames) { skiaTypeface = TypefaceCache.GetTypeface( familyName, typeface.Style, typeface.Weight); if (skiaTypeface != TypefaceCache.Default) { break; } } } else { skiaTypeface = TypefaceCache.GetTypeface( typeface.FontFamily.Name, typeface.Style, typeface.Weight); } } _paint = new SKPaint(); //currently Skia does not measure properly with Utf8 !!! //Paint.TextEncoding = SKTextEncoding.Utf8; _paint.TextEncoding = SKTextEncoding.Utf16; _paint.IsStroke = false; _paint.IsAntialias = true; _paint.LcdRenderText = true; _paint.SubpixelText = true; _paint.Typeface = skiaTypeface; _paint.TextSize = (float)typeface.FontSize; _paint.TextAlign = textAlignment.ToSKTextAlign(); _wrapping = wrapping; _constraint = constraint; if (spans != null) { foreach (var span in spans) { if (span.ForegroundBrush != null) { SetForegroundBrush(span.ForegroundBrush, span.StartIndex, span.Length); } } } Rebuild(); }