From 114bfceca302c76a83056bda7ab4cd2ebf7f3371 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Sun, 17 Jan 2021 23:01:44 +0100 Subject: [PATCH] First working Android, UWP samples --- .../CSharpMath.UWPUno.Example.Droid.csproj | 21 +- .../Properties/AndroidManifest.xml | 6 +- ...CSharpMath.UWPUno.Example.Shared.projitems | 15 + .../ClockPage.xaml | 18 + .../ClockPage.xaml.cs | 126 +++++ .../MainPage.xaml | 8 +- .../MoreExamples.cs | 492 ++++++++++++++++++ .../MoreExamplesPage.xaml | 16 + .../MoreExamplesPage.xaml.cs | 27 + .../TryPage.xaml | 2 +- .../CSharpMath.UWPUno.Example.UWP.csproj | 3 + ....GeneratedMSBuildEditorConfig.editorconfig | 5 + .../CSharpMath.UWPUno.Example.iOS.csproj | 3 + .../CSharpMath.UWPUno.Example.macOS.csproj | 3 + CSharpMath.UWPUno/CSharpMath.UWPUno.csproj | 2 +- CSharpMath.Xaml/Views.cs | 2 +- CSharpMath.sln | 1 + 17 files changed, 739 insertions(+), 11 deletions(-) create mode 100644 CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/ClockPage.xaml create mode 100644 CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/ClockPage.xaml.cs create mode 100644 CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamples.cs create mode 100644 CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamplesPage.xaml create mode 100644 CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamplesPage.xaml.cs diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Droid/CSharpMath.UWPUno.Example.Droid.csproj b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Droid/CSharpMath.UWPUno.Example.Droid.csproj index b90effbc..6e071d99 100644 --- a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Droid/CSharpMath.UWPUno.Example.Droid.csproj +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Droid/CSharpMath.UWPUno.Example.Droid.csproj @@ -17,7 +17,7 @@ true Off False - v10.0 + v11.0 Properties\AndroidManifest.xml True ..\CSharpMath.UWPUno.Example.Shared\Strings @@ -65,6 +65,9 @@ + + 2.4.22 + @@ -89,10 +92,26 @@ + + {38f58489-ede4-4289-8acf-a9756977a7a6} + CSharpMath.Editor + + + {65016a61-2125-4e0c-90e8-a915230c7826} + CSharpMath.Rendering + + + {35b4bb5b-2202-436e-9afe-00997ca2cc65} + CSharpMath.SkiaSharp + {5c46ca75-fa31-4281-80eb-a07750e1fecb} CSharpMath.UWPUno + + {5157367b-f03e-4acb-83a1-0de414a3bfca} + CSharpMath + diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Droid/Properties/AndroidManifest.xml b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Droid/Properties/AndroidManifest.xml index 71ff6316..6df21a40 100644 --- a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Droid/Properties/AndroidManifest.xml +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Droid/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - - - + + + \ No newline at end of file diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/CSharpMath.UWPUno.Example.Shared.projitems b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/CSharpMath.UWPUno.Example.Shared.projitems index 246b2e6e..8a28a577 100644 --- a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/CSharpMath.UWPUno.Example.Shared.projitems +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/CSharpMath.UWPUno.Example.Shared.projitems @@ -18,18 +18,33 @@ App.xaml + + ClockPage.xaml + MainPage.xaml + + + MoreExamplesPage.xaml + TryPage.xaml + + Designer + MSBuild:Compile + Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/ClockPage.xaml b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/ClockPage.xaml new file mode 100644 index 00000000..16dd4b83 --- /dev/null +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/ClockPage.xaml @@ -0,0 +1,18 @@ + + + + + + diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/ClockPage.xaml.cs b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/ClockPage.xaml.cs new file mode 100644 index 00000000..a10d54bc --- /dev/null +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/ClockPage.xaml.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using CSharpMath.SkiaSharp; +using SkiaSharp; +using SkiaSharp.Views.UWP; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; +using static System.Math; + +namespace CSharpMath.UWPUno.Example { + public sealed partial class ClockPage : Page { + private readonly DispatcherTimer _timer; + + public ClockPage() { + this.InitializeComponent(); + _timer = new DispatcherTimer(); + _timer.Interval = TimeSpan.FromMilliseconds(200); + _timer.Tick += (s, e) => { + canvasView.Invalidate(); + }; + this.Loaded += ClockPage_Loaded; + this.Unloaded += ClockPage_Unloaded; + } + + private void ClockPage_Loaded(object sender, RoutedEventArgs e) { + _timer.Start(); + } + + private void ClockPage_Unloaded(object sender, RoutedEventArgs e) { + _timer.Stop(); + } + + readonly SKPaint blackFillPaint = new SKPaint { + Style = SKPaintStyle.Fill, + Color = SKColors.Black + }; + readonly SKPaint whiteFillPaint = new SKPaint { + Style = SKPaintStyle.Fill, + Color = SKColors.White + }; + readonly SKPaint whiteStrokePaint = new SKPaint { + Style = SKPaintStyle.Stroke, + Color = SKColors.White, + StrokeCap = SKStrokeCap.Round, + IsAntialias = true + }; + readonly SKPaint redStrokePaint = new SKPaint { + Style = SKPaintStyle.Stroke, + Color = SKColors.Red, + StrokeCap = SKStrokeCap.Round, + IsAntialias = true + }; + readonly string[] labels = { + // Four 4s make 1 to 12 using different operations + @"$\frac{44+4}{4}$", + @"$\frac{44}{44}$", + @"$\frac{4}{4}+\frac{4}{4}$", + @"$\frac{4+4+4}{4}$", + @"$4+\frac{4-4}{4}$", + @"$4+4^{4-4}$", + @"$4+\frac{4+4}{4}$", + @"$\frac{44}{4}-4$", + @"$\sqrt{4}^{4-\frac{4}{4}}$", + @"$\:\:(4-\frac{4}{4})^{\sqrt{4}}$", + @"$\frac{44-4}{4}$", + @"$\frac{4!}{\sqrt{4}}-\frac{4}{4}$" + }; + private void CanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e) { + var canvas = e.Surface.Canvas; + canvas.Clear(SKColors.CornflowerBlue); + canvas.Translate(e.Info.Width / 2, e.Info.Height / 2); + canvas.Scale(e.Info.Width / 210f); + canvas.DrawCircle(0, 0, 100, blackFillPaint); + var painter = new TextPainter { FontSize = 8, TextColor = SKColors.White }; + for (int i = 0; i < 60; i++) { + // Dots + canvas.Save(); + canvas.RotateDegrees(6 * i); + canvas.DrawCircle(0, -90, i % 5 == 0 ? 4 : 2, whiteFillPaint); + canvas.Restore(); + // Maths + if (i % 5 == 0) { + painter.LaTeX = labels[i / 5]; + if (!(painter.Measure(e.Info.Width) is { } measure)) + throw new Structures.InvalidCodePathException("Invalid LaTeX"); + var θ = (90 - 6 * i) / 180f * PI; + var sinθ = (float)Sin(θ); + var cosθ = (float)Cos(θ); + painter.Draw(canvas, + new System.Drawing.PointF(75 * cosθ - (float)measure.Width / 2, + -75 * sinθ - (float)measure.Height / 2), + float.PositiveInfinity); + } + } + var dateTime = DateTime.Now; + // H + canvas.Save(); + canvas.RotateDegrees(30 * dateTime.Hour + dateTime.Minute / 2f); + whiteStrokePaint.StrokeWidth = 12; + canvas.DrawLine(0, 0, 0, -50, whiteStrokePaint); + canvas.Restore(); + // M + canvas.Save(); + canvas.RotateDegrees(6 * dateTime.Minute + dateTime.Second / 10f); + whiteStrokePaint.StrokeWidth = 6; + canvas.DrawLine(0, 0, 0, -65, whiteStrokePaint); + canvas.Restore(); + // S + canvas.Save(); + canvas.RotateDegrees(6f * (dateTime.Second + dateTime.Millisecond / 1000f)); + redStrokePaint.StrokeWidth = 2; + canvas.DrawLine(0, 0, 0, -75, redStrokePaint); + canvas.Restore(); + } + } +} diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MainPage.xaml b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MainPage.xaml index f39e6c88..734ae005 100644 --- a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MainPage.xaml +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MainPage.xaml @@ -12,12 +12,12 @@ - + + diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamples.cs b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamples.cs new file mode 100644 index 00000000..52242c87 --- /dev/null +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamples.cs @@ -0,0 +1,492 @@ +//Do not modify this file directly. Instead, modify this at +//CSharpMath\CSharpMath.Playground\iosMathDemo\ToFormsMoreExamples.cs and re-generate +//this file by executing the method in that file in the CSharpMath.Utils project. + +using CSharpMath.Atom; +using CSharpMath.Rendering.FrontEnd; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using Windows.UI; +using Windows.UI.Xaml.Media; +using Color = Windows.UI.Color; + +namespace CSharpMath.UWPUno.Example { + [System.Diagnostics.DebuggerNonUserCode, System.Runtime.CompilerServices.CompilerGenerated] + public static class MoreExamples { + public static ReadOnlyCollection Views { get; } + static MoreExamples() { + var demoLabels = new Dictionary(); + var labels = new Dictionary(); + + // Demo formulae + + // Quadratic formula + demoLabels[0] = new MathView { + LaTeX = @"\text{ваш вопрос: }x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}", + Height = 112.5, + FontSize = 22.5f + }; + demoLabels[0].FontSize = 15; + + // This is first label so set the height from the top + demoLabels[1] = new MathView { + LaTeX = @"\color{#ff3399}{(a_1+a_2)^2}=a_1^2+2a_1a_2+a_2^2", + Height = 75, + FontSize = 22.5f + }; + demoLabels[2] = new MathView { + LaTeX = @"\cos(\theta + \varphi) = + \cos(\theta)\cos(\varphi) - \sin(\theta)\sin(\varphi)", + Height = 75, + FontSize = 22.5f + }; + demoLabels[3] = new MathView { + LaTeX = @"\frac{1}{\left(\sqrt{\phi \sqrt{5}}-\phi\right) e^{\frac25 \pi}} + = 1+\frac{e^{-2\pi}} {1 +\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } }", + Height = 150, + FontSize = 22.5f + }; + demoLabels[4] = new MathView { + LaTeX = @"\sigma = \sqrt{\frac{1}{N}\sum_{i=1}^N (x_i - \mu)^2}", + Height = 112.5, + FontSize = 22.5f + }; + demoLabels[5] = new MathView { + LaTeX = @"\neg(P\land Q) \iff (\neg P)\lor(\neg Q)", + Height = 75, + FontSize = 22.5f + }; + demoLabels[6] = new MathView { + LaTeX = @"\log_b(x) = \frac{\log_a(x)}{\log_a(b)}", + Height = 75, + FontSize = 22.5f + }; + demoLabels[7] = new MathView { + LaTeX = @"\lim_{x\to\infty}\left(1 + \frac{k}{x}\right)^x = e^k", + Height = 75, + FontSize = 22.5f + }; + demoLabels[8] = new MathView { + LaTeX = @"\int_{-\infty}^\infty \! e^{-x^2} dx = \sqrt{\pi}", + Height = 75, + FontSize = 22.5f + }; + demoLabels[9] = new MathView { + LaTeX = @"\frac 1 n \sum_{i=1}^{n}x_i \geq \sqrt[n]{\prod_{i=1}^{n}x_i}", + Height = 112.5, + FontSize = 22.5f + }; + demoLabels[10] = new MathView { + LaTeX = @"f^{(n)}(z_0) = \frac{n!}{2\pi i}\oint_\gamma\frac{f(z)}{(z-z_0)^{n+1}}\,dz", + Height = 75, + FontSize = 22.5f + }; + demoLabels[11] = new MathView { + LaTeX = @"i\hbar\frac{\partial}{\partial t}\mathbf\Psi(\mathbf{x},t) = + -\frac{\hbar}{2m}\nabla^2\mathbf\Psi(\mathbf{x},t) + + V(\mathbf{x})\mathbf\Psi(\mathbf{x},t)", + Height = 75, + FontSize = 22.5f + }; + demoLabels[12] = new MathView { + LaTeX = @"\left(\sum_{k=1}^n a_k b_k \right)^2 \le \left(\sum_{k=1}^n a_k^2\right)\left(\sum_{k=1}^n b_k^2\right)", + Height = 112.5, + FontSize = 22.5f + }; + demoLabels[13] = new MathView { + LaTeX = @"{n \brace k} = \frac{1}{k!}\sum_{j=0}^k (-1)^{k-j}\binom{k}{j}(k-j)^n", + Height = 112.5, + FontSize = 22.5f + }; + demoLabels[14] = new MathView { + LaTeX = @"f(x) = \int\limits_{-\infty}^\infty\!\hat f(\xi)\,e^{2 \pi i \xi x}\,\mathrm{d}\xi", + Height = 112.5, + FontSize = 22.5f + }; + demoLabels[15] = new MathView { + LaTeX = @"\begin{gather} + \dot{x} = \sigma(y-x) \\ + \dot{y} = \rho x - y - xz \\ + \dot{z} = -\beta z + xy + \end{gather}", + Height = 131.25, + FontSize = 22.5f + }; + demoLabels[16] = new MathView { + LaTeX = @"\vec \bf V_1 \times \vec \bf V_2 = \begin{vmatrix} + \hat \imath &\hat \jmath &\hat k \\ + \frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\ + \frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0 + \end{vmatrix}", + Height = 131.25, + FontSize = 22.5f + }; + demoLabels[17] = new MathView { + LaTeX = @"\begin{eqalign} + \nabla \cdot \vec{\bf{E}} & = \frac {\rho} {\varepsilon_0} \\ + \nabla \cdot \vec{\bf{B}} & = 0 \\ + \nabla \times \vec{\bf{E}} &= - \frac{\partial\vec{\bf{B}}}{\partial t} \\ + \nabla \times \vec{\bf{B}} & = \mu_0\vec{\bf{J}} + \mu_0\varepsilon_0 \frac{\partial\vec{\bf{E}}}{\partial t} + \end{eqalign}", + Height = 262.5, + FontSize = 22.5f + }; + demoLabels[18] = new MathView { + LaTeX = @"\begin{pmatrix} + a & b\\ c & d + \end{pmatrix} + \begin{pmatrix} + \alpha & \beta \\ \gamma & \delta + \end{pmatrix} = + \begin{pmatrix} + a\alpha + b\gamma & a\beta + b \delta \\ + c\alpha + d\gamma & c\beta + d \delta + \end{pmatrix}", + Height = 112.5, + FontSize = 22.5f + }; + demoLabels[19] = new MathView { + LaTeX = @"\frak Q(\lambda,\hat{\lambda}) = + -\frac{1}{2} \mathbb P(O \mid \lambda ) \sum_s \sum_m \sum_t \gamma_m^{(s)} (t) +\\ + \quad \left( \log(2 \pi ) + \log \left| \cal C_m^{(s)} \right| + + \left( o_t - \hat{\mu}_m^{(s)} \right) ^T \cal C_m^{(s)-1} \right)", + Height = 168.75, + FontSize = 22.5f + }; + demoLabels[20] = new MathView { + LaTeX = @"f(x) = \begin{cases} + \frac{e^x}{2} & x \geq 0 \\ + 1 & x < 0 + \end{cases}", + Height = 112.5, + FontSize = 22.5f + }; + demoLabels[21] = new MathView { + LaTeX = @"\color{#ff3333}{c}\color{#9933ff}{o}\color{#ff0080}{l}+\color{#99ff33}{\frac{\color{#ff99ff}{o}}{\color{#990099}{r}}}-\color{#33ffff}{\sqrt[\color{#3399ff}{e}]{\color{#3333ff}{d}}}", + Height = 112.5, + FontSize = 22.5f + }; + + // Test formulae + labels[0] = new MathView { + LaTeX = @"3+2-5 = 0", + Height = 75, + FontSize = 22.5f + }; + labels[0].Background = new SolidColorBrush(Colors.Red); + + // Infix and prefix Operators + labels[1] = new MathView { + LaTeX = @"12+-3 > +14", + Height = 75, + FontSize = 22.5f + }; + labels[1].Background = new SolidColorBrush(Colors.Red); + labels[1].TextAlignment = TextAlignment.Center; + + // Punct, parens + labels[2] = new MathView { + LaTeX = @"(-3-5=-8, -6-7=-13)", + Height = 75, + FontSize = 22.5f + }; + + // Latex commands + labels[3] = new MathView { + LaTeX = @"5\times(-2 \div 1) = -10", + Height = 75, + FontSize = 22.5f + }; + labels[3].Background = new SolidColorBrush(Colors.Red); + labels[3].TextAlignment = TextAlignment.Right; + labels[4] = new MathView { + LaTeX = @"-h - (5xy+2) = z", + Height = 75, + FontSize = 22.5f + }; + + // Text mode fraction + labels[5] = new MathView { + LaTeX = @"\frac12x + \frac{3\div4}2y = 25", + Height = 112.5, + FontSize = 22.5f + }; + labels[5].LineStyle = LineStyle.Text; + + // Display mode fraction + labels[6] = new MathView { + LaTeX = @"\frac{x+\frac{12}{5}}{y}+\frac1z = \frac{xz+y+\frac{12}{5}z}{yz}", + Height = 112.5, + FontSize = 22.5f + }; + labels[6].Background = new SolidColorBrush(Colors.Red); + + // fraction in fraction in text mode + labels[7] = new MathView { + LaTeX = @"\frac{x+\frac{12}{5}}{y}+\frac1z = \frac{xz+y+\frac{12}{5}z}{yz}", + Height = 112.5, + FontSize = 22.5f + }; + labels[7].Background = new SolidColorBrush(Colors.Red); + labels[7].LineStyle = LineStyle.Text; + + // Exponents and subscripts + + // Large font + labels[8] = new MathView { + LaTeX = @"\frac{x^{2+3y}}{x^{2+4y}} = x^y \times \frac{z_1^{y+1}}{z_1^{y+1}}", + Height = 168.75, + FontSize = 22.5f + }; + labels[8].FontSize = 30; + labels[8].TextAlignment = TextAlignment.Center; + + // Small font + labels[9] = new MathView { + LaTeX = @"\frac{x^{2+3y}}{x^{2+4y}} = x^y \times \frac{z_1^{y+1}}{z_1^{y+1}}", + Height = 56.25, + FontSize = 22.5f + }; + labels[9].FontSize = 10; + labels[9].TextAlignment = TextAlignment.Center; + + // Square root + labels[10] = new MathView { + LaTeX = @"5+\sqrt{2}+3", + Height = 75, + FontSize = 22.5f + }; + + // Square root inside square roots and with fractions + labels[11] = new MathView { + LaTeX = @"\sqrt{\frac{\sqrt{\frac{1}{2}} + 3}{\sqrt5^x}}+\sqrt{3x}+x^{\sqrt2}", + Height = 168.75, + FontSize = 22.5f + }; + + // General root + labels[12] = new MathView { + LaTeX = @"\sqrt[3]{24} + 3\sqrt{2}24", + Height = 75, + FontSize = 22.5f + }; + + // Fractions and formulae in root + labels[13] = new MathView { + LaTeX = @"\sqrt[x+\frac{3}{4}]{\frac{2}{4}+1}", + Height = 112.5, + FontSize = 22.5f + }; + + // Non-symbol operators with no limits + labels[14] = new MathView { + LaTeX = @"\sin^2(\theta)=\log_3^2(\pi)", + Height = 112.5, + FontSize = 22.5f + }; + + // Non-symbol operators with limits + labels[15] = new MathView { + LaTeX = @"\lim_{x\to\infty}\frac{e^2}{1-x}=\limsup_{\sigma}5", + Height = 112.5, + FontSize = 22.5f + }; + + // Symbol operators with limits + labels[16] = new MathView { + LaTeX = @"\sum_{n=1}^{\infty}\frac{1+n}{1-n}=\bigcup_{A\in\Im}C\cup B", + Height = 112.5, + FontSize = 22.5f + }; + + // Symbol operators with limits text style + labels[17] = new MathView { + LaTeX = @"\sum_{n=1}^{\infty}\frac{1+n}{1-n}=\bigcup_{A\in\Im}C\cup B", + Height = 112.5, + FontSize = 22.5f + }; + labels[17].LineStyle = LineStyle.Text; + + // Non-symbol operators with limits text style + labels[18] = new MathView { + LaTeX = @"\lim_{x\to\infty}\frac{e^2}{1-x}=\limsup_{\sigma}5", + Height = 112.5, + FontSize = 22.5f + }; + labels[18].LineStyle = LineStyle.Text; + + // Symbol operators with no limits + labels[19] = new MathView { + LaTeX = @"\int_{0}^{\infty}e^x \,dx=\oint_0^{\Delta}5\Gamma", + Height = 112.5, + FontSize = 22.5f + }; + + // Test italic correction for large ops + labels[20] = new MathView { + LaTeX = @"\int\int\int^{\infty}\int_0\int^{\infty}_0\int", + Height = 112.5, + FontSize = 22.5f + }; + + // Test italic correction for superscript/subscript + labels[21] = new MathView { + LaTeX = @"U_3^2UY_3^2U_3Y^2f_1f^2ff", + Height = 112.5, + FontSize = 22.5f + }; + + // Error + labels[22] = new MathView { + LaTeX = @"\notacommand", + Height = 56.25, + FontSize = 22.5f + }; + labels[23] = new MathView { + LaTeX = @"\sqrt{1}", + Height = 37.5, + FontSize = 22.5f + }; + labels[24] = new MathView { + LaTeX = @"\sqrt[|]{1}", + Height = 37.5, + FontSize = 22.5f + }; + labels[25] = new MathView { + LaTeX = @"{n \choose k}", + Height = 112.5, + FontSize = 22.5f + }; + labels[26] = new MathView { + LaTeX = @"{n \choose k}", + Height = 56.25, + FontSize = 22.5f + }; + labels[26].LineStyle = LineStyle.Text; + labels[27] = new MathView { + LaTeX = @"\left({n \atop k}\right)", + Height = 75, + FontSize = 22.5f + }; + labels[28] = new MathView { + LaTeX = @"\left({n \atop k}\right)", + Height = 56.25, + FontSize = 22.5f + }; + labels[28].LineStyle = LineStyle.Text; + labels[29] = new MathView { + LaTeX = @"\underline{xyz}+\overline{abc}", + Height = 56.25, + FontSize = 22.5f + }; + labels[30] = new MathView { + LaTeX = @"\underline{\frac12}+\overline{\frac34}", + Height = 93.75, + FontSize = 22.5f + }; + labels[31] = new MathView { + LaTeX = @"\underline{x^\overline{y}_\overline{z}+5}", + Height = 93.75, + FontSize = 22.5f + }; + + // spacing examples from the TeX book + labels[32] = new MathView { + LaTeX = @"\int\!\!\!\int_D dx\,dy", + Height = 93.75, + FontSize = 22.5f + }; + + // no spacing + labels[33] = new MathView { + LaTeX = @"\int\int_D dxdy", + Height = 93.75, + FontSize = 22.5f + }; + labels[34] = new MathView { + LaTeX = @"y\,dx-x\,dy", + Height = 56.25, + FontSize = 22.5f + }; + labels[35] = new MathView { + LaTeX = @"y dx - x dy", + Height = 56.25, + FontSize = 22.5f + }; + + // large spaces + labels[36] = new MathView { + LaTeX = @"hello\ from \quad the \qquad other\ side", + Height = 56.25, + FontSize = 22.5f + }; + + // Accents + labels[37] = new MathView { + LaTeX = @"\vec x \; \hat y \; \breve {x^2} \; \tilde x \tilde x^2 x^2", + Height = 56.25, + FontSize = 22.5f + }; + labels[38] = new MathView { + LaTeX = @"\hat{xyz} \; \widehat{xyz}\; \vec{2ab}", + Height = 56.25, + FontSize = 22.5f + }; + labels[39] = new MathView { + LaTeX = @"\hat{\frac12} \; \hat{\sqrt 3}", + Height = 93.75, + FontSize = 22.5f + }; + + // large roots + labels[40] = new MathView { + LaTeX = @"\colorbox{#f0f0e0}{\sqrt{1+\colorbox{#d0c0d0}{\sqrt{1+\colorbox{#a080c0}{\sqrt{1+\colorbox{#7050a0}{\sqrt{1+\colorbox{403060}{\colorbox{#102000}{\sqrt{1+\cdots}}}}}}}}}}}", + Height = 150, + FontSize = 22.5f + }; + labels[41] = new MathView { + LaTeX = @"\begin{bmatrix} + a & b\\ c & d \\ e & f \\ g & h \\ i & j + \end{bmatrix}", + Height = 225, + FontSize = 22.5f + }; + labels[42] = new MathView { + LaTeX = @"x{\scriptstyle y}z", + Height = 56.25, + FontSize = 22.5f + }; + labels[43] = new MathView { + LaTeX = @"x \mathrm x \mathbf x \mathcal X \mathfrak x \mathsf x \bm x \mathtt x \mathit \Lambda \cal g", + Height = 56.25, + FontSize = 22.5f + }; + labels[44] = new MathView { + LaTeX = @"\mathrm{using\ mathrm}", + Height = 56.25, + FontSize = 22.5f + }; + labels[45] = new MathView { + LaTeX = @"\text{using text}", + Height = 56.25, + FontSize = 22.5f + }; + labels[46] = new MathView { + LaTeX = @"\text{Mary has }\$500 + \$200.", + Height = 56.25, + FontSize = 22.5f + }; + labels[47] = new MathView { + LaTeX = @"\colorbox{#888888}{\begin{pmatrix} + \colorbox{#ff0000}{a} & \colorbox{#00ff00}{b} \\ + \colorbox{#00aaff}{c} & \colorbox{#f0f0f0}{d} + \end{pmatrix}}", + Height = 131.25, + FontSize = 22.5f + }; + + Views = demoLabels.Concat(labels).Select(p => p.Value).ToList().AsReadOnly(); + } + } +} \ No newline at end of file diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamplesPage.xaml b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamplesPage.xaml new file mode 100644 index 00000000..82f98f5e --- /dev/null +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamplesPage.xaml @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamplesPage.xaml.cs b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamplesPage.xaml.cs new file mode 100644 index 00000000..8bb2d477 --- /dev/null +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MoreExamplesPage.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +namespace CSharpMath.UWPUno.Example { + public sealed partial class MoreExamplesPage : Page { + public MoreExamplesPage() { + this.InitializeComponent(); + foreach (var view in MoreExamples.Views) { + view.ErrorFontSize = view.FontSize * 0.8f; + view.TextColor = Windows.UI.Colors.White; + Stack.Children.Add(view); + } + } + } +} \ No newline at end of file diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/TryPage.xaml b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/TryPage.xaml index 32779027..9bb4bf0b 100644 --- a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/TryPage.xaml +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/TryPage.xaml @@ -32,6 +32,6 @@ HorizontalAlignment="Stretch" VerticalAlignment="Stretch" EnablePanning="True" - TextColor="{ThemeResource SystemBaseHighColor}" /> + TextColor="Black" /> diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.UWP/CSharpMath.UWPUno.Example.UWP.csproj b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.UWP/CSharpMath.UWPUno.Example.UWP.csproj index 54d27845..93f581b5 100644 --- a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.UWP/CSharpMath.UWPUno.Example.UWP.csproj +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.UWP/CSharpMath.UWPUno.Example.UWP.csproj @@ -14,6 +14,9 @@ + + 2.4.22 + diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.iOS/CSharpMath.UWPUno.Example.iOS.GeneratedMSBuildEditorConfig.editorconfig b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.iOS/CSharpMath.UWPUno.Example.iOS.GeneratedMSBuildEditorConfig.editorconfig index 291046a6..44a3556d 100644 --- a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.iOS/CSharpMath.UWPUno.Example.iOS.GeneratedMSBuildEditorConfig.editorconfig +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.iOS/CSharpMath.UWPUno.Example.iOS.GeneratedMSBuildEditorConfig.editorconfig @@ -29,6 +29,11 @@ build_property.IncludeXamlNamespacesProperty = xamarin,not_win,legacy,ios,not_an build_property.XamlGeneratorAnalyzerSuppressionsProperty = nventive.Usage-NV0056,nventive.Usage-NV0058,nventive.Usage-NV1003,nventive.Usage-NV0085,nventive.Usage-NV2001,nventive.Usage-NV2003,nventive.Usage-NV2004,nventive.Usage-NV2005 build_property.LegacyTypesProperty = +[C:/Martin/Dev/CSharpMath/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/ClockPage.xaml] +build_metadata.AdditionalFiles.SourceItemGroup = Page +build_metadata.AdditionalFiles.Link = ClockPage.xaml +build_metadata.AdditionalFiles.FullPath = C:\Martin\Dev\CSharpMath\CSharpMath.UWPUno.Example\CSharpMath.UWPUno.Example.Shared\ClockPage.xaml + [C:/Martin/Dev/CSharpMath/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MainPage.xaml] build_metadata.AdditionalFiles.SourceItemGroup = Page build_metadata.AdditionalFiles.Link = MainPage.xaml diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.iOS/CSharpMath.UWPUno.Example.iOS.csproj b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.iOS/CSharpMath.UWPUno.Example.iOS.csproj index b560bf75..03e50509 100644 --- a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.iOS/CSharpMath.UWPUno.Example.iOS.csproj +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.iOS/CSharpMath.UWPUno.Example.iOS.csproj @@ -119,6 +119,9 @@ + + 2.4.22 + diff --git a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.macOS/CSharpMath.UWPUno.Example.macOS.csproj b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.macOS/CSharpMath.UWPUno.Example.macOS.csproj index 4a89cad8..2da80fa8 100644 --- a/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.macOS/CSharpMath.UWPUno.Example.macOS.csproj +++ b/CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.macOS/CSharpMath.UWPUno.Example.macOS.csproj @@ -73,6 +73,9 @@ + + 2.4.22 + diff --git a/CSharpMath.UWPUno/CSharpMath.UWPUno.csproj b/CSharpMath.UWPUno/CSharpMath.UWPUno.csproj index dd3a50f4..1b80ef83 100644 --- a/CSharpMath.UWPUno/CSharpMath.UWPUno.csproj +++ b/CSharpMath.UWPUno/CSharpMath.UWPUno.csproj @@ -1,7 +1,7 @@ - xamarinmac20;MonoAndroid11.0;xamarinios10;netstandard2.0;uap10.0.17763 + xamarinmac20;MonoAndroid10.0;MonoAndroid11.0;xamarinios10;netstandard2.0;uap10.0.17763 The UWP and Uno Platform front end for CSharpMath using SkiaSharp rendering. $(PackageTags) unoplatform uwp wasm diff --git a/CSharpMath.Xaml/Views.cs b/CSharpMath.Xaml/Views.cs index b70c46fa..d312ba13 100644 --- a/CSharpMath.Xaml/Views.cs +++ b/CSharpMath.Xaml/Views.cs @@ -237,7 +237,7 @@ protected override void OnPaintSurface(global::SkiaSharp.Views.UWP.SKPaintSurfac canvas.Clear(); // SkiaSharp deals with raw pixels as opposed to Xamarin.Forms's device-independent units. // We should scale to occupy the full view size. - canvas.Scale(e.Info.Width / (float)Width); + canvas.Scale(e.Info.Width / (float)ActualWidth); #endif Painter.Draw(canvas, TextAlignment, Padding, (float)DisplacementX, (float)DisplacementY); } diff --git a/CSharpMath.sln b/CSharpMath.sln index 661ed67e..b442b623 100644 --- a/CSharpMath.sln +++ b/CSharpMath.sln @@ -140,6 +140,7 @@ Global CSharpMath.Wiki\CSharpMath.Wiki.projitems*{883bcfb1-3aa8-4ab7-8f82-27b849716373}*SharedItemsImports = 13 Typography\Typography.TextBreak\Typography.TextBreak\Typography.TextBreak.projitems*{9a99f103-b119-4a4d-8093-6a03baa6d36b}*SharedItemsImports = 13 CSharpMath.Xaml\CSharpMath.Xaml.projitems*{9bad6846-0b1d-4446-bf62-fcf85c6e9a9f}*SharedItemsImports = 5 + CSharpMath.UWPUno.Example\CSharpMath.UWPUno.Example.Shared\CSharpMath.UWPUno.Example.Shared.projitems*{b7759d42-229d-47cb-96a2-e99db18aa316}*SharedItemsImports = 4 CSharpMath.Xaml\CSharpMath.Xaml.projitems*{d37416fb-3025-4a64-81ce-89da21062acb}*SharedItemsImports = 13 Typography\Typography.GlyphLayout\Typography.GlyphLayout.projitems*{d8861cf8-c506-472b-8a57-632bd6ca6496}*SharedItemsImports = 13 EndGlobalSection