Skip to content

Commit 19393e4

Browse files
committed
Day 3 of Sprint 1 (see #15 (comment))
1 parent 258769d commit 19393e4

File tree

16 files changed

+154
-72
lines changed

16 files changed

+154
-72
lines changed

.editorconfig

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
# This file is the top-most EditorConfig file
12
root = true
23

34
[*.cs]
5+
charset = utf-8
46
indent_style = space
57
indent_size = 2
8+
insert_final_newline = false
9+
trim_trailing_whitespace = true
10+
11+
#############################
12+
# Deviates from .NET Formatting Conventions
13+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#formatting-conventions
14+
#############################
15+
16+
# Organize usings
17+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#usings
18+
dotnet_sort_system_directives_first = true
19+
# C# formatting settings
20+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#c-formatting-settings
621
csharp_new_line_before_open_brace = none
722
csharp_new_line_before_else = false
823
csharp_new_line_before_catch = false
@@ -11,18 +26,40 @@ csharp_new_line_before_members_in_object_initializers = true
1126
csharp_new_line_before_members_in_anonymous_types = true
1227
csharp_new_line_between_query_expression_clauses = false
1328

29+
# Indentation options
30+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#indent
1431
csharp_indent_case_contents = true
1532
csharp_indent_switch_labels = true
1633
csharp_indent_labels = false
17-
34+
# Spacing options
35+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#spacing
1836
csharp_space_after_cast = false
1937
csharp_space_after_keywords_in_control_flow_statements = true
20-
csharp_space_between_method_call_parameter_list_parenteses = true
38+
csharp_space_between_method_declaration_parameter_list_parentheses = false
39+
csharp_space_between_method_call_parameter_list_parentheses = true
2140
csharp_space_between_parentheses = false
22-
41+
csharp_space_before_colon_in_inheritance_clause = true
42+
csharp_space_after_colon_in_inheritance_clause = true
43+
csharp_space_around_binary_operators = before_and_after
44+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
45+
csharp_space_between_method_call_name_and_opening_parenthesis = false
46+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
47+
# Wrapping options
48+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#wrapping
2349
csharp_preserve_single_line_statements = true
2450
csharp_preserve_single_line_blocks = true
25-
26-
dotnet_sort_system_directives_first = true
27-
28-
51+
# More Indentation options (Undocumented)
52+
csharp_indent_block_contents = true
53+
csharp_indent_braces = false
54+
# Spacing Options (Undocumented)
55+
csharp_space_after_comma = true
56+
csharp_space_after_dot = false
57+
csharp_space_after_semicolon_in_for_statement = true
58+
csharp_space_around_declaration_statements = do_not_ignore
59+
csharp_space_before_comma = false
60+
csharp_space_before_dot = false
61+
csharp_space_before_semicolon_in_for_statement = false
62+
csharp_space_before_open_square_brackets = false
63+
csharp_space_between_empty_square_brackets = false
64+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
65+
csharp_space_between_square_brackets = false

CSharpMath.Forms.Example/CSharpMath.Forms.Example/LayoutPage.xaml.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,22 @@ namespace CSharpMath.Forms.Example
1111
{
1212
[XamlCompilation(XamlCompilationOptions.Compile)]
1313
public partial class LayoutPage : ContentPage {
14-
SkiaSharp.TextPainter painter = new SkiaSharp.TextPainter { Text = @"Here are some text. This text is made to be long enough to have the TextPainter of CSharpMath (hopefully) add a line break to this text automatically. To demonstrate the capabilities of the TextPainter, here are some math content: First, a fraction in inline mode: $\frac34$ Next, a summation in inline mode: $\sum_{i=0}^3i^i$ Then, a summation in display mode: $$\sum_{i=0}^3i^i$$ (ah, bugs.) After that, an integral in display mode: $$\int^6_{-56}x\ dx$$ Finally, an escaped dollar sign \$ that represents the start/end of math mode when it is unescaped. Even though colours are currently unsupported, it can be done via math mode with the \\color command with the help of the \\text command. It looks like this: $\color{#F00}{\text{some red text}}$, which is nearly indistinguishable from non-math mode aside from not being able to automatically break up when spaces are inside the coloured text. The SkiaSharp version of this is located at CSharpMath.SkiaSharp.TextPainter; and the Xamarin.Forms version of this is located at CSharpMath.Forms.TextView. Was added in 0.1.0-pre4; working in 0.1.0-pre5." };
14+
SkiaSharp.TextPainter painter = new SkiaSharp.TextPainter { Text = @"Here are some text.
15+
This text is made to be long enough to have the TextPainter of CSharpMath add a line break to this text automatically.
16+
To demonstrate the capabilities of the TextPainter,
17+
here are some math content:
18+
First, a fraction in inline mode: $\frac34$
19+
Next, a summation in inline mode: $\sum_{i=0}^3i^i$
20+
Then, a summation in display mode: $$\sum_{i=0}^3i^i$$
21+
After that, an integral in display mode: $$\int^6_{-56}x\ dx$$
22+
Finally, an escaped dollar sign \$ that represents the start/end of math mode when it is unescaped.
23+
Colors can be achieved via \backslash color{color}{content}, or \backslash \textit{color}{content},
24+
where \textit{color} stands for one of the LaTeX standard colors.
25+
\red{Colored text in text mode are able to automatically break up when spaces are inside the colored text, which the equivalent in math mode cannot do.}
26+
\textbf{Styled} \texttt{text} can be achieved via the LaTeX styling commands.
27+
The SkiaSharp version of this is located at CSharpMath.SkiaSharp.TextPainter;
28+
and the Xamarin.Forms version of this is located at CSharpMath.Forms.TextView.
29+
Was added in 0.1.0-pre4; working in 0.1.0-pre5; fully tested in 0.1.0-pre6." };
1530
bool reset;
1631
double x, y, w;
1732

@@ -22,13 +37,26 @@ private void Canvas_PaintSurface(object sender, SKPaintSurfaceEventArgs e) {
2237
var measure = painter.Measure((float)w).Value;
2338
e.Surface.Canvas.Clear();
2439
e.Surface.Canvas.DrawRect((float)x + measure.X, (float)y + measure.Y, measure.Width, measure.Height, new global::SkiaSharp.SKPaint { Color = global::SkiaSharp.SKColors.Orange });
25-
painter.Draw(e.Surface.Canvas, new System.Drawing.PointF((float)x, (float)y), (float)w);
40+
/*measure = painter._absoluteXCoordDisplay.ComputeDisplayBounds();
41+
e.Surface.Canvas.DrawRect((float)x + measure.X, (float)y + measure.Y, measure.Width, measure.Height, new global::SkiaSharp.SKPaint { Color = global::SkiaSharp.SKColors.Red, IsStroke = true });
42+
measure = painter._relativeXCoordDisplay.ComputeDisplayBounds();
43+
e.Surface.Canvas.DrawRect((float)x + measure.X, (float)y + measure.Y, measure.Width, measure.Height, new global::SkiaSharp.SKPaint { Color = global::SkiaSharp.SKColors.Blue, IsStroke = true });
44+
*/painter.Draw(e.Surface.Canvas, new System.Drawing.PointF((float)x, (float)y), (float)w);
2645
}
2746

28-
private void SliderX_ValueChanged(object sender, ValueChangedEventArgs e) { x = e.NewValue; SliderW.Maximum = SliderX.Maximum - x; Canvas.InvalidateSurface(); }
47+
//Add Epsilon to prevent SliderW.Minimum == SiderW.Maximum == 0
48+
private void SliderX_ValueChanged(object sender, ValueChangedEventArgs e) { x = e.NewValue; SliderW.Maximum = SliderX.Maximum - x + float.Epsilon; Canvas.InvalidateSurface(); }
2949

3050
private void SliderY_ValueChanged(object sender, ValueChangedEventArgs e) { y = e.NewValue; Canvas.InvalidateSurface(); }
3151

3252
private void SliderW_ValueChanged(object sender, ValueChangedEventArgs e) { w = e.NewValue; Canvas.InvalidateSurface(); }
53+
54+
protected override void OnSizeAllocated(double width, double height) {
55+
base.OnSizeAllocated(width, height);
56+
//+1 to avoid Maximum == Minimum == 0 (which throws) but allow for sliding
57+
//Add Epsilon to prevent SliderW.Minimum == SiderW.Maximum == 0
58+
(SliderX.Maximum, SliderY.Maximum, SliderW.Maximum) = (Canvas.CanvasSize.Width + 1, Canvas.CanvasSize.Height + 1, Canvas.CanvasSize.Width + 1 - SliderX.Value + float.Epsilon);
59+
SliderX.Minimum = SliderY.Minimum = SliderW.Minimum = 0;
60+
}
3361
}
3462
}

CSharpMath.Forms.Example/CSharpMath.Forms.Example/SlidePage.xaml.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,12 @@ private void Canvas_Touch(object sender, SKTouchEventArgs e) {
3232
private void SliderX_ValueChanged(object sender, ValueChangedEventArgs e) { x = e.NewValue; Canvas.InvalidateSurface(); }
3333

3434
private void SliderY_ValueChanged(object sender, ValueChangedEventArgs e) { y = e.NewValue; Canvas.InvalidateSurface(); }
35+
36+
protected override void OnSizeAllocated(double width, double height) {
37+
base.OnSizeAllocated(width, height);
38+
//+1 to avoid Maximum == Minimum == 0 (which throws) but allow for sliding
39+
(SliderX.Maximum, SliderY.Maximum) = (Canvas.CanvasSize.Width + 1, Canvas.CanvasSize.Height + 1);
40+
SliderX.Minimum = SliderY.Minimum = 0;
41+
}
3542
}
3643
}

CSharpMath.Forms/CSharpMath.Forms.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<LangVersion>latest</LangVersion>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<PackageVersion>0.1.0-pre5</PackageVersion>
7-
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie)</Authors>
6+
<PackageVersion>0.1.0-pre6</PackageVersion>
7+
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
88
<PackageReleaseNotes>The 0.1.0 SkiaSharp Update brings the SkiaSharp and Xamarin.Forms front ends to CSharpMath.</PackageReleaseNotes>
99
<RepositoryType>git</RepositoryType>
1010
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
1111
<RepositoryBranch>master</RepositoryBranch>
12-
<RepositoryCommit>aff4172bd424bbd66a47e028bdff96c30573bc12</RepositoryCommit>
12+
<RepositoryCommit>258769db65d722bb29110896d9356d4a88c60d38</RepositoryCommit>
1313
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
1414
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1515
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>

CSharpMath.Ios/CSharpMath.Ios.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<NuGetPackageImportStamp></NuGetPackageImportStamp>
1515
<PackOnBuild>true</PackOnBuild>
1616
<PackageId>CSharpMath.Ios</PackageId>
17-
<PackageVersion>0.1.0-pre5</PackageVersion>
18-
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie)</Authors>
17+
<PackageVersion>0.1.0-pre6</PackageVersion>
18+
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
1919
<NeutralLanguage>en</NeutralLanguage>
2020
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
2121
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
@@ -28,7 +28,7 @@
2828
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
2929
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
3030
<RepositoryBranch>master</RepositoryBranch>
31-
<RepositoryCommit>aff4172bd424bbd66a47e028bdff96c30573bc12</RepositoryCommit>
31+
<RepositoryCommit>258769db65d722bb29110896d9356d4a88c60d38</RepositoryCommit>
3232
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
3333
<PackageIconUrl>https://raw.githubusercontent.com/verybadcat/CSharpMath/master/Icon.png</PackageIconUrl>
3434
</PropertyGroup>

CSharpMath.Rendering/CSharpMath.Rendering.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<!--NuGet Properties-->
1212
<PackOnBuild>true</PackOnBuild>
1313
<PackageId>CSharpMath.Rendering</PackageId>
14-
<PackageVersion>0.1.0-pre5</PackageVersion>
15-
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie)</Authors>
14+
<PackageVersion>0.1.0-pre6</PackageVersion>
15+
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
1616
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
1717
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
1818
<PackageReleaseNotes>The 0.1.0 SkiaSharp Update brings the SkiaSharp and Xamarin.Forms front ends to CSharpMath.</PackageReleaseNotes>
@@ -24,7 +24,7 @@
2424
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2525
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
2626
<RepositoryBranch>master</RepositoryBranch>
27-
<RepositoryCommit>aff4172bd424bbd66a47e028bdff96c30573bc12</RepositoryCommit>
27+
<RepositoryCommit>258769db65d722bb29110896d9356d4a88c60d38</RepositoryCommit>
2828
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
2929
<PackageIconUrl>https://raw.githubusercontent.com/verybadcat/CSharpMath/master/Icon.png</PackageIconUrl>
3030
</PropertyGroup>

CSharpMath.Rendering/MathPainter.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public MathPainter(float fontSize = DefaultFontSize) : base(fontSize) { }
1313
public IMathList MathList { get => Source.MathList; set => Source = new MathSource(value); }
1414
public string LaTeX { get => Source.LaTeX; set => Source = new MathSource(value); }
1515

16-
protected override RectangleF? MeasureCore(float canvasWidth = float.NaN) => _display?.ComputeDisplayBounds();
16+
protected override RectangleF? MeasureCore(float canvasWidth = float.NaN) =>
17+
_display?.ComputeDisplayBounds(!CoordinatesFromBottomLeftInsteadOfTopLeft);
1718
public RectangleF? Measure {
1819
get {
1920
UpdateDisplay();
@@ -34,21 +35,9 @@ public override void Draw(TCanvas canvas, TextAlignment alignment = TextAlignmen
3435
if (!Source.IsValid) DrawError(c);
3536
else {
3637
UpdateDisplay(c.Width);
37-
Draw(c, _display, IPainterExtensions.GetDisplayPosition(_display.Width, _display.Ascent, _display.Descent, FontSize, CoordinatesFromBottomLeftInsteadOfTopLeft, c.Width, c.Height, alignment, padding, offsetX, offsetY));
38+
DrawCore(c, _display, IPainterExtensions.GetDisplayPosition(_display.Width, _display.Ascent, _display.Descent, FontSize, CoordinatesFromBottomLeftInsteadOfTopLeft, c.Width, c.Height, alignment, padding, offsetX, offsetY));
3839
}
3940
}
40-
41-
public void Draw(TCanvas canvas, float x, float y) {
42-
var c = WrapCanvas(canvas);
43-
UpdateDisplay(c.Width);
44-
Draw(c, _display, new PointF(x, CoordinatesFromBottomLeftInsteadOfTopLeft ? y : -y));
45-
}
46-
47-
public void Draw(TCanvas canvas, PointF position) {
48-
var c = WrapCanvas(canvas);
49-
if (CoordinatesFromBottomLeftInsteadOfTopLeft) position.Y *= -1;
50-
UpdateDisplay(c.Width);
51-
Draw(c, _display, position);
52-
}
41+
public void Draw(TCanvas canvas, float x, float y) => Draw(canvas, TextAlignment.TopLeft, default, x, y);
5342
}
5443
}

CSharpMath.Rendering/Painter.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ public Painter(float fontSize = DefaultFontSize) {
7373
protected abstract void UpdateDisplay(float canvasWidth);
7474

7575
protected abstract RectangleF? MeasureCore(float canvasWidth);
76-
77-
protected void Draw(ICanvas canvas, IDisplay<TFonts, Glyph> display, PointF? position = null) {
76+
77+
protected RectangleF? InvertRect(RectangleF? r) { if (r.HasValue) return new RectangleF(r.Value.X, r.Value.Y, r.Value.Width, r.Value.Height * -1); return r; }
78+
79+
protected void DrawCore(ICanvas canvas, IDisplay<TFonts, Glyph> display, PointF? position = null) {
7880
if (Source.IsValid) {
7981
if(position != null) display.Position = position.Value;
8082
canvas.Save();
@@ -87,7 +89,7 @@ protected void Draw(ICanvas canvas, IDisplay<TFonts, Glyph> display, PointF? pos
8789
canvas.CurrentColor = WrapColor(HighlightColor);
8890
canvas.CurrentStyle = PaintStyle;
8991
var measure = MeasureCore(canvas.Width) ??
90-
throw new InvalidOperationException($"{nameof(MeasureCore)} returned null. Any conditions leading to this should have already been checked via {nameof(Source)}.{nameof(Source.IsValid)}.");
92+
throw new InvalidCodePathException($"{nameof(MeasureCore)} returned null. Any conditions leading to this should have already been checked via {nameof(Source)}.{nameof(Source.IsValid)}.");
9193
canvas.FillRect(display.Position.X + measure.X, display.Position.Y -
9294
(CoordinatesFromBottomLeftInsteadOfTopLeft ? display.Ascent : display.Descent),
9395
measure.Width, measure.Height);

CSharpMath.Rendering/Text/TextBuilder.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ string ReadInsideBrackets() {
3737
#warning Support single-char arguments
3838
(startAt, endAt, endingChar) = ObtainRange(++i);
3939
if (endingChar != '{') { error = "Missing {"; return null; }
40-
var endingIndex = text.IndexOf('}', endAt);
40+
int numOfBrackets = 0;
41+
int endingIndex = -1;
42+
//+1 to not start at the { we started at
43+
for (int j = startAt + 1; j < text.Length; j++) { if (text[j] == '{') numOfBrackets++; else if (text[j] == '}') if (numOfBrackets > 0) numOfBrackets--; else { endingIndex = j; break; } }
4144
if (endingIndex == -1) { error = "Missing }"; return null; }
4245
var resultText = text.Substring(endAt, endingIndex - endAt);
4346
while (startAt < endingIndex) (startAt, endAt, endingChar) = ObtainRange(++i);

0 commit comments

Comments
 (0)