Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 34 additions & 67 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,81 +1,48 @@
# This file is the top-most EditorConfig file
# This file is the top-most EditorConfig file. Do not inherit from outside folders.
root = true

#############################
# Deviates from the default .editorconfig file:
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options#example-editorconfig-file
#############################

# C# files
[*.cs]

#### Core EditorConfig Options ####

charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = false
trim_trailing_whitespace = true
indent_size = 2

#############################
# Deviates from .NET Formatting Conventions
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#formatting-conventions
#############################
#### .NET Coding Conventions ####

# Organize usings
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#usings
dotnet_sort_system_directives_first = true
# C# formatting settings
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#c-formatting-settings

#### C# Coding Conventions ####

# var preferences
csharp_style_var_elsewhere = true
csharp_style_var_for_built_in_types = true
csharp_style_var_when_type_is_apparent = true

# Expression-bodied members
csharp_style_expression_bodied_constructors = true
csharp_style_expression_bodied_methods = true
csharp_style_expression_bodied_operators = true

# Code-block preferences
csharp_prefer_braces = false
csharp_style_namespace_declarations = file_scoped

#### C# Formatting Rules ####

# New line preferences
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_open_brace = none
csharp_new_line_between_query_expression_clauses = false

# Indentation options
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#indent
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
# Spacing options
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#spacing
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
# Wrapping options
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#wrapping
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true
# More Indentation options (Undocumented)
csharp_indent_block_contents = true
csharp_indent_braces = false
# Spacing Options (Undocumented)
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_declaration_statements = do_not_ignore
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_before_open_square_brackets = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_square_brackets = false
# Expression-level preferences
csharp_prefer_braces = false
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
# var preferences
csharp_style_var_for_built_in_types = true:none
csharp_style_var_when_type_is_apparent = true:none
csharp_style_var_elsewhere = true:none
# Expression-bodied members
csharp_style_expression_bodied_methods = true:none
csharp_style_expression_bodied_constructors = true:none
csharp_style_expression_bodied_operators = true:none
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none
csharp_new_line_between_query_expression_clauses = false
3 changes: 2 additions & 1 deletion .github/workflows/Benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Benchmark

on: push
on: [push, pull_request]
jobs:
Rendering:
if: (github.event_name == 'pull_request') == github.event.pull_request.head.repo.fork
runs-on: windows-latest
steps:
- uses: actions/checkout@v6
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/Format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Check format

on: [push, pull_request]
jobs:
Excluding_Typography:
if: (github.event_name == 'pull_request') == github.event.pull_request.head.repo.fork
runs-on: windows-latest
steps:
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.x'
- uses: actions/checkout@v6
with:
submodules: 'recursive'
- run: dotnet workload restore
- name: Check formatting (Fix with "dotnet format --exclude Typography" at repository root)
run: dotnet format --exclude Typography --verify-no-changes --severity error --verbosity diagnostic
3 changes: 2 additions & 1 deletion .github/workflows/Nightly.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Upload test results and nightly builds

on: push
on: [push, pull_request]
jobs:
Everything:
if: (github.event_name == 'pull_request') == github.event.pull_request.head.repo.fork
runs-on: windows-latest
steps:
- name: Update draft on GitHub Releases
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/Test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Build and Test

on: push
on: [push, pull_request]
jobs:
Everything:
if: (github.event_name == 'pull_request') == github.event.pull_request.head.repo.fork
strategy:
fail-fast: false # Don't cancel other os builds if one fails
matrix:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CSharpMath.Xaml.Tests.NuGet/Test.*.png
/.benchmarkresults
/.nupkgs
/.testcoverage
/.vscode
## END Specifically added for CSharpMath

## Ignore Visual Studio temporary files, build results, and
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Avalonia.Example/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ public static AppBuilder BuildAvaloniaApp() =>
public static int Main(string[] args) =>
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
}
}
2 changes: 1 addition & 1 deletion CSharpMath.Avalonia.Example/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ private void InitializeComponent() {
AvaloniaXamlLoader.Load(this);
}
}
}
}
2 changes: 1 addition & 1 deletion CSharpMath.Avalonia.Example/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ private void InitializeComponent() {
AvaloniaXamlLoader.Load(this);
}
}
}
}
2 changes: 1 addition & 1 deletion CSharpMath.Avalonia.Example/Pages/MathButtonPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ private void InitializeComponent() {
AvaloniaXamlLoader.Load(this);
}
}
}
}
2 changes: 1 addition & 1 deletion CSharpMath.Avalonia.Example/Pages/MathViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ private void InitializeComponent() {
AvaloniaXamlLoader.Load(this);
}
}
}
}
2 changes: 1 addition & 1 deletion CSharpMath.Avalonia.Example/Pages/TextViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ I mean I started doing videos like these just over a year ago and i would have n
AvaloniaXamlLoader.Load(this);
}
}
}
}
2 changes: 1 addition & 1 deletion CSharpMath.Avalonia/AvaloniaCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ public void Translate(float dx, float dy) =>
PushState(DrawingContext.PushTransform(Matrix.CreateTranslation(dx, dy)));
private void PushState(DrawingContext.PushedState state) => _states.Peek().Push(state);
}
}
}
7 changes: 3 additions & 4 deletions CSharpMath.Avalonia/AvaloniaPath.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using CSharpMath.Rendering.FrontEnd;
using CSharpMathColor = System.Drawing.Color;

using Avalonia;
using Avalonia.Media;
using CSharpMath.Rendering.FrontEnd;
using CSharpMathColor = System.Drawing.Color;

namespace CSharpMath.Avalonia {
public sealed class AvaloniaPath : Path {
Expand Down Expand Up @@ -36,4 +35,4 @@ public override void Dispose() {
_canvas.DrawingContext.DrawGeometry(brush, pen, _path);
}
}
}
}
8 changes: 3 additions & 5 deletions CSharpMath.Avalonia/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Avalonia;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using CSharpMath.Rendering.FrontEnd;
using AvaloniaColor = Avalonia.Media.Color;
using AvaloniaTextAlignment = Avalonia.Media.TextAlignment;

using CSharpMath.Rendering.FrontEnd;
using CSharpMathTextAlignment = CSharpMath.Rendering.FrontEnd.TextAlignment;

namespace CSharpMath.Avalonia {
Expand All @@ -16,8 +15,7 @@ internal static System.Drawing.Color ToCSharpMathColor(this AvaloniaColor color)
System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);

internal static CSharpMathTextAlignment ToCSharpMathTextAlignment(this AvaloniaTextAlignment alignment) =>
alignment switch
{
alignment switch {
AvaloniaTextAlignment.Left => CSharpMathTextAlignment.TopLeft,
AvaloniaTextAlignment.Center => CSharpMathTextAlignment.Top,
AvaloniaTextAlignment.Right => CSharpMathTextAlignment.TopRight,
Expand Down Expand Up @@ -59,4 +57,4 @@ public static void DrawAsPng<TContent>
bitmap.Save(target, quality);
}
}
}
}
5 changes: 2 additions & 3 deletions CSharpMath.Avalonia/MathPainter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AvaloniaColor = Avalonia.Media.Color;

using CSharpMath.Rendering.FrontEnd;
using AvaloniaColor = Avalonia.Media.Color;
using CSharpMathColor = System.Drawing.Color;

namespace CSharpMath.Avalonia {
Expand All @@ -11,4 +10,4 @@ public sealed class MathPainter : MathPainter<AvaloniaCanvas, AvaloniaColor> {

public override CSharpMathColor WrapColor(AvaloniaColor color) => color.ToCSharpMathColor();
}
}
}
5 changes: 2 additions & 3 deletions CSharpMath.Avalonia/TextPainter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AvaloniaColor = Avalonia.Media.Color;

using CSharpMath.Rendering.FrontEnd;
using AvaloniaColor = Avalonia.Media.Color;
using CSharpMathColor = System.Drawing.Color;

namespace CSharpMath.Avalonia {
Expand All @@ -11,4 +10,4 @@ public sealed class TextPainter : TextPainter<AvaloniaCanvas, AvaloniaColor> {

public override CSharpMathColor WrapColor(AvaloniaColor color) => color.ToCSharpMathColor();
}
}
}
4 changes: 2 additions & 2 deletions CSharpMath.Core.Example/BackEnd/JsonMathTable.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using CSharpMath.Display;
using CSharpMath.Display.FrontEnd;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;

namespace CSharpMath.Core.BackEnd {
using TFont = TestFont;
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Core.Example/BackEnd/TestFontMeasurer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public class TestFontMeasurer {
public static TestFontMeasurer Instance { get; } = new TestFontMeasurer();
public int GetUnitsPerEm(TestFont font) => 1000;
}
}
}
8 changes: 4 additions & 4 deletions CSharpMath.Core.Example/BackEnd/TestGlyphBoundsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using TGlyph = System.Text.Rune;
using CSharpMath.Display;
using TGlyph = System.Text.Rune;

namespace CSharpMath.Core.BackEnd {
public class TestGlyphBoundsProvider : Display.FrontEnd.IGlyphBoundsProvider<TestFont, TGlyph> {
Expand All @@ -27,7 +27,7 @@ private int GetEffectiveLength(IEnumerable<TGlyph> enumerable) {

private int GetEffectiveLength(ReadOnlySpan<TGlyph> span) {
int length = 0;
for(int i = 0; i < span.Length; i++)
for (int i = 0; i < span.Length; i++)
if (M.Contains(span[i])) length += 2;
else length++;
return length;
Expand All @@ -54,12 +54,12 @@ public IEnumerable<RectangleF> GetBoundingRectsForGlyphs
var r = new float[nGlyphs];
var total = 0f;
int i = 0;
foreach(var glyph in glyphs) {
foreach (var glyph in glyphs) {
ReadOnlySpan<TGlyph> span = stackalloc[] { glyph };
total += r[i] = GetEffectiveLength(span) * font.PointSize * WidthPerCharacterPerFontSize;
i++;
}
return (r, total);
}
}
}
}
3 changes: 1 addition & 2 deletions CSharpMath.Core.Example/BackEnd/TestGlyphNameProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public string GetGlyphName(TGlyph glyph) =>
public TGlyph GetGlyph(string glyphName) {
// Variant glyphs have a dot in their name
var actualName = glyphName.IndexOf('.') switch { -1 => glyphName, var dotIndex => glyphName.Substring(0, dotIndex) };
return actualName.Length switch
{
return actualName.Length switch {
1 when actualName[0] >= 'a' && actualName[0] <= 'z' => new TGlyph(actualName[0] - 'a' + italic_a.Value),
1 when actualName[0] >= 'A' && actualName[0] <= 'Z' => new TGlyph(actualName[0] - 'A' + italic_A.Value),
5 => new TGlyph(int.Parse(actualName.Substring(1), System.Globalization.NumberStyles.AllowHexSpecifier)),
Expand Down
9 changes: 4 additions & 5 deletions CSharpMath.Core.Example/Checker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static int ReadInt(string message) {
Console.WriteLine("P: Re-inputs the cursor position.");
Console.WriteLine("Enter: Moves on to another test case.");
Console.WriteLine("");

ListDisplay? display = null;
void AssignDisplay() {
Console.Write("Input LaTeX: ");
Expand All @@ -60,10 +60,10 @@ void AssignDisplay() {
var y = ReadInt("Input Touch Y (integer): ");
Console.Clear();

if(OperatingSystem.IsWindows())
if (OperatingSystem.IsWindows())
Console.SetBufferSize(10000, Console.BufferHeight); // no line wrapping
display.Draw(context);
moveCursor:var pos = Adjust(new Rectangle(x, y, 0, 0));
moveCursor: var pos = Adjust(new Rectangle(x, y, 0, 0));
Console.Title = $"CSharpMath.Editor.Tests Visualizer - ({x}, {y}) in {latex}";
Console.SetCursorPosition(pos.X, pos.Y);
switch (Console.ReadKey(true).Key) {
Expand Down Expand Up @@ -100,8 +100,7 @@ public static void SetConsoleColor(Color? col) {
}
}
Console.ForegroundColor = ret;
}
else Console.ResetColor();
} else Console.ResetColor();
}
static Rectangle Adjust(Rectangle rect) =>
new Rectangle(
Expand Down
Loading
Loading