-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
\cancel
, \bcancel
and \xcancel
.
- Loading branch information
Showing
15 changed files
with
240 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Avalonia.Media; | ||
using XamlMath.Rendering; | ||
using IBrush = XamlMath.Rendering.IBrush; | ||
|
||
namespace AvaloniaMath.Rendering | ||
{ | ||
public static class AvaloniaExtensions | ||
{ | ||
[return: NotNullIfNotNull(nameof(brush))] | ||
public static IBrush? ToPlatform(this Brush? brush) => brush == null ? null : AvaloniaBrush.FromBrush(brush); | ||
|
||
[return: NotNullIfNotNull(nameof(brush))] | ||
public static Avalonia.Media.IBrush? ToAvalonia(this IBrush? brush) => ((AvaloniaBrush?)brush)?.Value; | ||
|
||
public static Avalonia.Point ToAvalonia(this Point point) => new(point.X, point.Y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
src/WpfMath/Rendering/WpfBrushExtensions.cs → src/WpfMath/Rendering/WpfExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Windows.Media; | ||
using XamlMath.Rendering; | ||
using WpfPoint = System.Windows.Point; | ||
|
||
namespace WpfMath.Rendering; | ||
|
||
public static class WpfBrushExtensions | ||
public static class WpfExtensions | ||
{ | ||
public static Brush? ToWpf(this IBrush? brush) => ((WpfBrush?)brush)?.Value; | ||
[return: NotNullIfNotNull(nameof(brush))] | ||
public static IBrush? ToPlatform(this Brush? brush) => brush == null ? null : WpfBrush.FromBrush(brush); | ||
|
||
[return: NotNullIfNotNull(nameof(brush))] | ||
public static Brush? ToWpf(this IBrush? brush) => ((WpfBrush?)brush)?.Value; | ||
|
||
public static WpfPoint ToWpf(this Point point) => new(point.X, point.Y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using XamlMath.Boxes; | ||
|
||
namespace XamlMath.Atoms | ||
{ | ||
internal record CancelAtom : Atom | ||
{ | ||
private readonly Atom? _contentAtom; | ||
private readonly StrokeBoxMode _strokeBoxMode; | ||
|
||
public CancelAtom(SourceSpan atomSource, Atom? contentAtom, StrokeBoxMode strokeBoxMode) : base(atomSource) | ||
{ | ||
_contentAtom = contentAtom; | ||
_strokeBoxMode = strokeBoxMode; | ||
} | ||
|
||
protected override Box CreateBoxCore(TexEnvironment environment) | ||
{ | ||
var contentBox = _contentAtom is null ? StrutBox.Empty : _contentAtom.CreateBox(environment); | ||
var lineBox = new StrokeBox(_strokeBoxMode) | ||
{ | ||
Height = contentBox.Height, | ||
Depth = contentBox.Depth, | ||
Width = contentBox.Width | ||
}; | ||
|
||
var box = new ZBox(); | ||
box.Add(contentBox); | ||
box.Add(lineBox); | ||
|
||
return box; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using XamlMath.Rendering; | ||
|
||
namespace XamlMath.Boxes; | ||
|
||
public class StrokeBox : Box | ||
{ | ||
private readonly StrokeBoxMode _mode; | ||
|
||
public StrokeBox(StrokeBoxMode mode) | ||
{ | ||
_mode = mode; | ||
} | ||
|
||
public override void RenderTo(IElementRenderer renderer, double x, double y) | ||
{ | ||
if (_mode.HasFlag(StrokeBoxMode.Normal)) | ||
renderer.RenderLine(new Point(x, y + Depth), new Point(x + Width, y - Height), Foreground); | ||
|
||
if (_mode.HasFlag(StrokeBoxMode.Back)) | ||
renderer.RenderLine(new Point(x, y - Height), new Point(x + Width, y + Depth), Foreground); | ||
} | ||
|
||
public override int GetLastFontId() | ||
{ | ||
var fontId = TexFontUtilities.NoFontId; | ||
foreach (var child in Children) | ||
{ | ||
fontId = child.GetLastFontId(); | ||
if (fontId == TexFontUtilities.NoFontId) | ||
break; | ||
} | ||
return fontId; | ||
} | ||
} | ||
|
||
[Flags] | ||
public enum StrokeBoxMode | ||
{ | ||
None = 0, | ||
Normal = 1, | ||
Back = 2, | ||
Both = 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Linq; | ||
using XamlMath.Rendering; | ||
|
||
namespace XamlMath.Boxes | ||
{ | ||
public class ZBox : Box | ||
{ | ||
public override void Add(Box box) | ||
{ | ||
base.Add(box); | ||
|
||
Width = Children.Select(c => c.Width).DefaultIfEmpty(0).Max(); | ||
Height = Children.Select(c => c.Height - c.Shift).DefaultIfEmpty(double.NegativeInfinity).Max(); | ||
Depth = Children.Select(c => c.Depth + c.Shift).DefaultIfEmpty(double.NegativeInfinity).Max(); ; | ||
Italic = Children.Select(c => c.Italic).DefaultIfEmpty(double.NegativeInfinity).Max(); ; | ||
} | ||
|
||
public override void RenderTo(IElementRenderer renderer, double x, double y) | ||
{ | ||
foreach (var box in Children) | ||
{ | ||
renderer.RenderElement(box, x, y + box.Shift); | ||
} | ||
} | ||
|
||
public override int GetLastFontId() | ||
{ | ||
var fontId = TexFontUtilities.NoFontId; | ||
foreach (var child in Children) | ||
{ | ||
fontId = child.GetLastFontId(); | ||
if (fontId == TexFontUtilities.NoFontId) | ||
break; | ||
} | ||
return fontId; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.