|
|
|
@ -15,10 +15,10 @@ namespace Avalonia.Skia |
|
|
|
public FormattedTextImpl(string text, string fontFamilyName, double fontSize, FontStyle fontStyle, |
|
|
|
TextAlignment textAlignment, FontWeight fontWeight, TextWrapping wrapping) |
|
|
|
{ |
|
|
|
_text = text ?? string.Empty; |
|
|
|
Text = text ?? string.Empty; |
|
|
|
|
|
|
|
// Replace 0 characters with zero-width spaces (200B)
|
|
|
|
_text = _text.Replace((char)0, (char)0x200B); |
|
|
|
Text = Text.Replace((char)0, (char)0x200B); |
|
|
|
|
|
|
|
var typeface = TypefaceCache.GetTypeface(fontFamilyName, fontStyle, fontWeight); |
|
|
|
|
|
|
|
@ -98,7 +98,7 @@ namespace Avalonia.Skia |
|
|
|
{ |
|
|
|
IsInside = false, |
|
|
|
TextPosition = line.Start + offset, |
|
|
|
IsTrailing = _text.Length == (line.Start + offset + 1) |
|
|
|
IsTrailing = Text.Length == (line.Start + offset + 1) |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
@ -108,7 +108,7 @@ namespace Avalonia.Skia |
|
|
|
{ |
|
|
|
IsInside = false, |
|
|
|
IsTrailing = end, |
|
|
|
TextPosition = end ? _text.Length - 1 : 0 |
|
|
|
TextPosition = end ? Text.Length - 1 : 0 |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
@ -182,7 +182,7 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
{ |
|
|
|
return _text; |
|
|
|
return Text; |
|
|
|
} |
|
|
|
|
|
|
|
internal void Draw(DrawingContextImpl context, |
|
|
|
@ -231,7 +231,7 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
if (!hasCusomFGBrushes) |
|
|
|
{ |
|
|
|
var subString = _text.Substring(line.Start, line.Length); |
|
|
|
var subString = Text.Substring(line.Start, line.Length); |
|
|
|
canvas.DrawText(subString, x, origin.Y + line.Top + _lineOffset, paint); |
|
|
|
} |
|
|
|
else |
|
|
|
@ -255,7 +255,7 @@ namespace Avalonia.Skia |
|
|
|
currentWrapper = foreground; |
|
|
|
} |
|
|
|
|
|
|
|
subStr = _text.Substring(i, len); |
|
|
|
subStr = Text.Substring(i, len); |
|
|
|
|
|
|
|
if (currFGPaint != currentWrapper.Paint) |
|
|
|
{ |
|
|
|
@ -284,7 +284,7 @@ namespace Avalonia.Skia |
|
|
|
private readonly List<FormattedTextLine> _lines = new List<FormattedTextLine>(); |
|
|
|
private readonly SKPaint _paint; |
|
|
|
private readonly List<Rect> _rects = new List<Rect>(); |
|
|
|
private readonly string _text; |
|
|
|
public string Text { get; } |
|
|
|
private readonly TextWrapping _wrapping; |
|
|
|
private Size _constraint = new Size(double.PositiveInfinity, double.PositiveInfinity); |
|
|
|
private float _lineHeight = 0; |
|
|
|
@ -434,7 +434,7 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
for (int i = line.Start; i < line.Start + line.TextLength; i++) |
|
|
|
{ |
|
|
|
float w = _paint.MeasureText(_text[i].ToString()); |
|
|
|
float w = _paint.MeasureText(Text[i].ToString()); |
|
|
|
|
|
|
|
_rects.Add(new Rect( |
|
|
|
prevRight, |
|
|
|
@ -490,7 +490,7 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
private List<Rect> GetRects() |
|
|
|
{ |
|
|
|
if (_text.Length > _rects.Count) |
|
|
|
if (Text.Length > _rects.Count) |
|
|
|
{ |
|
|
|
BuildRects(); |
|
|
|
} |
|
|
|
@ -500,7 +500,7 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
private void Rebuild() |
|
|
|
{ |
|
|
|
var length = _text.Length; |
|
|
|
var length = Text.Length; |
|
|
|
|
|
|
|
_lines.Clear(); |
|
|
|
_rects.Clear(); |
|
|
|
@ -536,7 +536,7 @@ namespace Avalonia.Skia |
|
|
|
int measured; |
|
|
|
int trailingnumber = 0; |
|
|
|
|
|
|
|
subString = _text.Substring(curOff); |
|
|
|
subString = Text.Substring(curOff); |
|
|
|
|
|
|
|
float constraint = -1; |
|
|
|
|
|
|
|
@ -547,12 +547,12 @@ namespace Avalonia.Skia |
|
|
|
constraint = MAX_LINE_WIDTH; |
|
|
|
} |
|
|
|
|
|
|
|
measured = LineBreak(_text, curOff, length, _paint, constraint, out trailingnumber); |
|
|
|
measured = LineBreak(Text, curOff, length, _paint, constraint, out trailingnumber); |
|
|
|
|
|
|
|
AvaloniaFormattedTextLine line = new AvaloniaFormattedTextLine(); |
|
|
|
line.TextLength = measured; |
|
|
|
|
|
|
|
subString = _text.Substring(line.Start, line.TextLength); |
|
|
|
subString = Text.Substring(line.Start, line.TextLength); |
|
|
|
lineWidth = _paint.MeasureText(subString); |
|
|
|
line.Start = curOff; |
|
|
|
line.Length = measured - trailingnumber; |
|
|
|
|