Skip to content

Commit 6337812

Browse files
authored
Enable CSharpMath.Rendering.Tests.TextPainterSettings (#139)
* Fix iOS tests * Enable TextPainterSettings * For some reason SkiaSharp produces an errornous image only on Ubuntu?? * i catn spel * Append OS to tests
1 parent 8cca3cc commit 6337812

File tree

13 files changed

+28
-14
lines changed

13 files changed

+28
-14
lines changed

.github/workflows/Test all projects.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
- uses: actions/upload-artifact@v2
5151
if: always() # Run even when a previous step failed: https://stackoverflow.com/a/58859404/5429648
5252
with:
53-
name: CSharpMath.Rendering.Tests results
53+
name: CSharpMath.Rendering.Tests results (${{ matrix.os }})
5454
path: CSharpMath.Rendering.Tests/*/*.png
5555
Ios:
5656
runs-on: macos-latest

CSharpMath.Apple/AppleMathView.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ public class AppleMathView : NView {
2323
public float FontSize { get; set; } = 20f;
2424
public ColumnAlignment TextAlignment { get; set; } = ColumnAlignment.Left;
2525
public NContentInsets ContentInsets { get; set; }
26+
private LineStyle _style = LineStyle.Display;
27+
public LineStyle LineStyle {
28+
get => _style;
29+
set {
30+
_style = value;
31+
if (_mathList != null) {
32+
_displayList = Typesetter.CreateLine(_mathList,
33+
TFont.LatinMath(FontSize), _typesettingContext, _style);
34+
}
35+
InvalidateIntrinsicContentSize();
36+
SetNeedsLayout();
37+
}
38+
}
2639
private MathList _mathList = new MathList();
2740
public MathList MathList {
2841
get => _mathList;
@@ -41,7 +54,7 @@ public string LaTeX {
4154
(_mathList, ErrorMessage) = LaTeXParser.MathListFromLaTeX(value);
4255
if (_mathList != null) {
4356
_displayList = Typesetter.CreateLine(_mathList,
44-
TFont.LatinMath(FontSize), _typesettingContext, LineStyle.Display);
57+
TFont.LatinMath(FontSize), _typesettingContext, _style);
4558
}
4659
InvalidateIntrinsicContentSize();
4760
SetNeedsLayout();

CSharpMath.Ios.Tests/Tests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ public class Tests {
1010
const double FileSizeTolerance = 0.95; // This is too large... We need to devise an alternative test mechanism
1111
static readonly Func<string, System.IO.Stream> GetManifestResourceStream =
1212
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream;
13-
async Task Test(string directory, string file, string latex) {
13+
async Task Test(string directory, Action<Apple.AppleMathView> init, string file, string latex) {
1414
var source = new TaskCompletionSource<UIKit.UIImage>();
1515
Foundation.NSRunLoop.Main.BeginInvokeOnMainThread(() => {
1616
try {
1717
using var v = IosMathLabels.MathView(latex, 50);
18+
init(v);
1819
var size = v.SizeThatFits(default);
1920
v.Frame = new CoreGraphics.CGRect(default, size);
2021
UIKit.UIGraphics.BeginImageContext(size);
@@ -54,10 +55,10 @@ async Task Test(string directory, string file, string latex) {
5455
[Theory]
5556
[ClassData(typeof(TestData))]
5657
public Task MathInline(string file, string latex) =>
57-
Test(nameof(MathInline), file, latex);
58+
Test(nameof(MathInline), v => v.LineStyle = Atom.LineStyle.Text, file, latex);
5859
[Theory]
5960
[ClassData(typeof(TestData))]
6061
public Task MathDisplay(string file, string latex) =>
61-
Test(nameof(MathDisplay), file, latex);
62+
Test(nameof(MathDisplay), v => { }, file, latex);
6263
}
6364
}

CSharpMath.Rendering.Tests/TestRendering.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,14 @@ protected void Run<TContent>(
137137
{ "Stroke", new TPainter { PaintStyle = PaintStyle.Stroke } },
138138
#warning For some reason the Avalonia front end behaves correctly for TextPainter Magnification test but not the SkiaSharp front end??
139139
{ "Magnification", new TPainter { Magnification = 2 } },
140-
{ "LocalTypeface", new TPainter {
141-
LocalTypefaces = new[] {
142-
new Typography.OpenFont.OpenFontReader().Read(
143-
TestRenderingFixture.ThisDirectory.EnumerateFiles("ComicNeue_Bold.otf").Single().OpenRead()
144-
) ?? throw new Structures.InvalidCodePathException("Invalid font!")
145-
}
146-
} },
140+
#warning For some reason SkiaSharp produces an erroneous image only on Ubuntu??
141+
//{ "LocalTypeface", new TPainter {
142+
// LocalTypefaces = new[] {
143+
// new Typography.OpenFont.OpenFontReader().Read(
144+
// TestRenderingFixture.ThisDirectory.EnumerateFiles("ComicNeue_Bold.otf").Single().OpenRead()
145+
// ) ?? throw new Structures.InvalidCodePathException("Invalid font!")
146+
// }
147+
//} },
147148
{ "TextLineStyle", new TPainter { LineStyle = Atom.LineStyle.Text } },
148149
{ "ScriptLineStyle", new TPainter { LineStyle = Atom.LineStyle.Script } },
149150
{ "ScriptScriptLineStyle", new TPainter { LineStyle = Atom.LineStyle.ScriptScript } },
@@ -160,8 +161,7 @@ protected void Run<TContent>(
160161
[MemberData(nameof(MathPainterSettingsData))]
161162
public virtual void MathPainterSettings(string file, TMathPainter painter) =>
162163
Run(file, @"\sqrt[3]\frac\color{#F00}a\mathbb C", painter);
163-
#warning Awaiting CI fix
164-
[SkippableTheory(Skip="Awaiting CI fix")]
164+
[SkippableTheory]
165165
[MemberData(nameof(TextPainterSettingsData))]
166166
public void TextPainterSettings(string file, TTextPainter painter) =>
167167
Run(file, @"Inline \color{red}{Maths}: $\int_{a_1^2}^{a_2^2}\color{green}\sqrt\frac x2dx$Display \color{red}{Maths}: $$\int_{a_1^2}^{a_2^2}\color{green}\sqrt\frac x2dx$$", painter);
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)