|
@@ -50,38 +50,40 @@ namespace Avalonia.Direct2D1.RenderTests.Media
|
|
|
FontStyle fontStyle,
|
|
FontStyle fontStyle,
|
|
|
TextAlignment textAlignment,
|
|
TextAlignment textAlignment,
|
|
|
FontWeight fontWeight,
|
|
FontWeight fontWeight,
|
|
|
- TextWrapping wrapping)
|
|
|
|
|
|
|
+ TextWrapping wrapping,
|
|
|
|
|
+ double widthConstraint)
|
|
|
{
|
|
{
|
|
|
var r = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
|
|
var r = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
|
|
|
return r.CreateFormattedText(text,
|
|
return r.CreateFormattedText(text,
|
|
|
- fontFamily,
|
|
|
|
|
- fontSize,
|
|
|
|
|
- fontStyle,
|
|
|
|
|
|
|
+ new Typeface(fontFamily, fontSize, fontStyle, fontWeight),
|
|
|
textAlignment,
|
|
textAlignment,
|
|
|
- fontWeight,
|
|
|
|
|
wrapping,
|
|
wrapping,
|
|
|
- Size.Infinity);
|
|
|
|
|
|
|
+ widthConstraint == -1 ? Size.Infinity : new Size(widthConstraint, double.PositiveInfinity),
|
|
|
|
|
+ null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private IFormattedTextImpl Create(string text, double fontSize)
|
|
private IFormattedTextImpl Create(string text, double fontSize)
|
|
|
{
|
|
{
|
|
|
return Create(text, FontName, fontSize,
|
|
return Create(text, FontName, fontSize,
|
|
|
FontStyle.Normal, TextAlignment.Left,
|
|
FontStyle.Normal, TextAlignment.Left,
|
|
|
- FontWeight.Normal, TextWrapping.NoWrap);
|
|
|
|
|
|
|
+ FontWeight.Normal, TextWrapping.NoWrap,
|
|
|
|
|
+ -1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private IFormattedTextImpl Create(string text, double fontSize, TextAlignment alignment)
|
|
|
|
|
|
|
+ private IFormattedTextImpl Create(string text, double fontSize, TextAlignment alignment, double widthConstraint)
|
|
|
{
|
|
{
|
|
|
return Create(text, FontName, fontSize,
|
|
return Create(text, FontName, fontSize,
|
|
|
FontStyle.Normal, alignment,
|
|
FontStyle.Normal, alignment,
|
|
|
- FontWeight.Normal, TextWrapping.NoWrap);
|
|
|
|
|
|
|
+ FontWeight.Normal, TextWrapping.NoWrap,
|
|
|
|
|
+ widthConstraint);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private IFormattedTextImpl Create(string text, double fontSize, TextWrapping wrap)
|
|
|
|
|
|
|
+ private IFormattedTextImpl Create(string text, double fontSize, TextWrapping wrap, double widthConstraint)
|
|
|
{
|
|
{
|
|
|
return Create(text, FontName, fontSize,
|
|
return Create(text, FontName, fontSize,
|
|
|
FontStyle.Normal, TextAlignment.Left,
|
|
FontStyle.Normal, TextAlignment.Left,
|
|
|
- FontWeight.Normal, wrap);
|
|
|
|
|
|
|
+ FontWeight.Normal, wrap,
|
|
|
|
|
+ widthConstraint);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#if AVALONIA_CAIRO
|
|
#if AVALONIA_CAIRO
|
|
@@ -134,14 +136,9 @@ namespace Avalonia.Direct2D1.RenderTests.Media
|
|
|
double widthConstraint,
|
|
double widthConstraint,
|
|
|
TextWrapping wrap)
|
|
TextWrapping wrap)
|
|
|
{
|
|
{
|
|
|
- var fmt = Create(input, FontSize, wrap);
|
|
|
|
|
|
|
+ var fmt = Create(input, FontSize, wrap, widthConstraint);
|
|
|
var constrained = fmt;
|
|
var constrained = fmt;
|
|
|
|
|
|
|
|
- if (widthConstraint != -1)
|
|
|
|
|
- {
|
|
|
|
|
- constrained = fmt.WithConstraint(new Size(widthConstraint, 10000));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
var lines = constrained.GetLines().ToArray();
|
|
var lines = constrained.GetLines().ToArray();
|
|
|
Assert.Equal(linesCount, lines.Count());
|
|
Assert.Equal(linesCount, lines.Count());
|
|
|
}
|
|
}
|
|
@@ -224,14 +221,8 @@ namespace Avalonia.Direct2D1.RenderTests.Media
|
|
|
double x, double y, double width, double height)
|
|
double x, double y, double width, double height)
|
|
|
{
|
|
{
|
|
|
//parse expected
|
|
//parse expected
|
|
|
- var fmt = Create(input, FontSize, TextAlignment.Right);
|
|
|
|
|
|
|
+ var fmt = Create(input, FontSize, TextAlignment.Right, widthConstraint);
|
|
|
var constrained = fmt;
|
|
var constrained = fmt;
|
|
|
-
|
|
|
|
|
- if (widthConstraint != -1)
|
|
|
|
|
- {
|
|
|
|
|
- constrained = fmt.WithConstraint(new Size(widthConstraint, 100));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
var r = constrained.HitTestTextPosition(index);
|
|
var r = constrained.HitTestTextPosition(index);
|
|
|
|
|
|
|
|
Assert.Equal(x, r.X, 2);
|
|
Assert.Equal(x, r.X, 2);
|
|
@@ -253,14 +244,8 @@ namespace Avalonia.Direct2D1.RenderTests.Media
|
|
|
double x, double y, double width, double height)
|
|
double x, double y, double width, double height)
|
|
|
{
|
|
{
|
|
|
//parse expected
|
|
//parse expected
|
|
|
- var fmt = Create(input, FontSize, TextAlignment.Center);
|
|
|
|
|
|
|
+ var fmt = Create(input, FontSize, TextAlignment.Center, widthConstraint);
|
|
|
var constrained = fmt;
|
|
var constrained = fmt;
|
|
|
-
|
|
|
|
|
- if (widthConstraint != -1)
|
|
|
|
|
- {
|
|
|
|
|
- constrained = fmt.WithConstraint(new Size(widthConstraint, 100));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
var r = constrained.HitTestTextPosition(index);
|
|
var r = constrained.HitTestTextPosition(index);
|
|
|
|
|
|
|
|
Assert.Equal(x, r.X, 2);
|
|
Assert.Equal(x, r.X, 2);
|