Skip to content

Commit

Permalink
(#63, #338, #339, #340, #341) Code review changes
Browse files Browse the repository at this point in the history
Clarify docs, change type visibility, fix namespaces, connect TODOs with
the issues.
  • Loading branch information
ForNeVeR committed Jan 25, 2023
1 parent 7a4dc3e commit 1054067
Show file tree
Hide file tree
Showing 21 changed files with 195 additions and 201 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- `RenderGlyphRun` has been replaced with `RenderCharacter` method (not reliant on any WPF-specific types),
- `RenderRectangle` now receives an instance of a new `WpfMath.Rendering.Rectangle` type (decoupled from WPF).
- `WpfMath.TexRenderer` is now obsolete. Consult the documentation on new recommended ways to perform custom rendering. There are new extension methods in two classes (`WpfMath.Rendering.WpfTeXFormulaExtensions` and `WpfMath.Rendering.TeXFormulaExtensions`) that are the main way to render formulae now.
- **(Breaking change.)** `WpfMath.TexFormnula::GetRenderer` is gone. Create a `TexRenderer` using constructor (obsolete) or use the aforementioned extension methods instead.

### Added
- `WpfMath.CharInfo`: a new public type to work with a font character. Use `WpfMath.Fonts.WpfCharInfoEx::GetGlyphRun` if you need to get a `System.Windows.Media.GlyphRun` from it.
- `WpfMath.Rendering.WpfTeXFormulaExtensions` to render a `WpfMath.TexFormula` into a `System.Windows.Media.Imaging.BitmapSource` or `System.Windows.Media.Geometry`.
- New classes for WPF-Math porting to platforms other than WPF (consult the `WpfMath.Rendering.IElementRenderer` interface and `TexFormulaParser` constructor parameters to know more).

- `WpfMath.Colors.RgbaColor` as a new portable color representation.
- `WpfMath.Fonts.IFontProvider`: implement this interface to provide alternate font reading functionality.
- `WpfMath.Fonts.ITeXFont`: implement this interface to provide access to a platform-specific font resource.
- `WpfMath.Rendering.IBrushFactory`: implement this interface to provide access to creation of platform-specific solid-colored brushes.
- `WpfMath.TeXFontMetrics` that contains some measurements of a font glyph.
- An utility `Result` struct is now public.

## [0.12.0] - 2023-01-07
### Added
Expand Down
95 changes: 44 additions & 51 deletions src/WpfMath.ApiTest/api/WpfMath.Shared.net452.verified.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,6 @@ public partial class FormulaNotFoundException : System.Exception
{
internal FormulaNotFoundException() { }
}
public partial interface ITeXFont
{
double Size { get; }
bool SupportsMetrics { get; }
double GetAxisHeight(WpfMath.TexStyle style);
double GetBigOpSpacing1(WpfMath.TexStyle style);
double GetBigOpSpacing2(WpfMath.TexStyle style);
double GetBigOpSpacing3(WpfMath.TexStyle style);
double GetBigOpSpacing4(WpfMath.TexStyle style);
double GetBigOpSpacing5(WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(char character, string textStyle, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(string name, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(WpfMath.CharFont charFont, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetDefaultCharInfo(char character, WpfMath.TexStyle style);
double GetDefaultLineThickness(WpfMath.TexStyle style);
double GetDenom1(WpfMath.TexStyle style);
double GetDenom2(WpfMath.TexStyle style);
WpfMath.ExtensionChar GetExtension(WpfMath.CharInfo charInfo, WpfMath.TexStyle style);
double GetKern(WpfMath.CharFont leftChar, WpfMath.CharFont rightChar, WpfMath.TexStyle style);
WpfMath.CharFont? GetLigature(WpfMath.CharFont leftChar, WpfMath.CharFont rightChar);
int GetMuFontId();
WpfMath.CharInfo GetNextLargerCharInfo(WpfMath.CharInfo charInfo, WpfMath.TexStyle style);
double GetNum1(WpfMath.TexStyle style);
double GetNum2(WpfMath.TexStyle style);
double GetNum3(WpfMath.TexStyle style);
double GetQuad(int fontId, WpfMath.TexStyle style);
double GetSkew(WpfMath.CharFont charFont, WpfMath.TexStyle style);
double GetSpace(WpfMath.TexStyle style);
double GetSub1(WpfMath.TexStyle style);
double GetSub2(WpfMath.TexStyle style);
double GetSubDrop(WpfMath.TexStyle style);
double GetSup1(WpfMath.TexStyle style);
double GetSup2(WpfMath.TexStyle style);
double GetSup3(WpfMath.TexStyle style);
double GetSupDrop(WpfMath.TexStyle style);
double GetXHeight(WpfMath.TexStyle style, int fontId);
bool HasNextLarger(WpfMath.CharInfo charInfo);
bool HasSpace(int fontId);
bool IsExtensionChar(WpfMath.CharInfo charInfo);
}
public enum MatrixCellAlignment
{
Left = 0,
Expand Down Expand Up @@ -152,14 +112,14 @@ public enum TexDelimiter
}
public sealed partial class TexEnvironment : System.IEquatable<WpfMath.TexEnvironment>
{
public TexEnvironment(WpfMath.TexStyle Style, WpfMath.ITeXFont MathFont, WpfMath.ITeXFont TextFont, WpfMath.Rendering.IBrush? Background = null, WpfMath.Rendering.IBrush? Foreground = null) { }
public TexEnvironment(WpfMath.TexStyle Style, WpfMath.Fonts.ITeXFont MathFont, WpfMath.Fonts.ITeXFont TextFont, WpfMath.Rendering.IBrush? Background = null, WpfMath.Rendering.IBrush? Foreground = null) { }
public WpfMath.Rendering.IBrush? Background { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.Rendering.IBrush? Foreground { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.ITeXFont MathFont { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.Fonts.ITeXFont MathFont { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.TexStyle Style { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.ITeXFont TextFont { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.Fonts.ITeXFont TextFont { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public void Deconstruct(out WpfMath.TexStyle Style, out WpfMath.ITeXFont MathFont, out WpfMath.ITeXFont TextFont, out WpfMath.Rendering.IBrush? Background, out WpfMath.Rendering.IBrush? Foreground) { throw null; }
public void Deconstruct(out WpfMath.TexStyle Style, out WpfMath.Fonts.ITeXFont MathFont, out WpfMath.Fonts.ITeXFont TextFont, out WpfMath.Rendering.IBrush? Background, out WpfMath.Rendering.IBrush? Foreground) { throw null; }
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public override bool Equals(object? obj) { throw null; }
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
Expand Down Expand Up @@ -189,7 +149,6 @@ public TexFormula() { }
public WpfMath.SourceSpan? Source { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public string? TextStyle { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public void Add(WpfMath.TexFormula formula, WpfMath.SourceSpan? source = null) { }
public WpfMath.Boxes.Box CreateBox(WpfMath.TexEnvironment environment) { throw null; }
public void SetBackground(WpfMath.Rendering.IBrush brush) { }
public void SetForeground(WpfMath.Rendering.IBrush brush) { }
}
Expand Down Expand Up @@ -290,12 +249,6 @@ public static partial class StandardColorParsers
public static System.Collections.Generic.IReadOnlyDictionary<string, WpfMath.Colors.IColorParser> Dictionary;
}
}
namespace WpfMath.Data
{
public static partial class WpfMathResourceMarker
{
}
}
namespace WpfMath.Exceptions
{
public partial class TexCharacterMappingNotFoundException : WpfMath.Exceptions.TexException
Expand Down Expand Up @@ -334,6 +287,46 @@ public partial interface IFontProvider
public partial interface IFontTypeface
{
}
public partial interface ITeXFont
{
double Size { get; }
bool SupportsMetrics { get; }
double GetAxisHeight(WpfMath.TexStyle style);
double GetBigOpSpacing1(WpfMath.TexStyle style);
double GetBigOpSpacing2(WpfMath.TexStyle style);
double GetBigOpSpacing3(WpfMath.TexStyle style);
double GetBigOpSpacing4(WpfMath.TexStyle style);
double GetBigOpSpacing5(WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(char character, string textStyle, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(string name, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(WpfMath.CharFont charFont, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetDefaultCharInfo(char character, WpfMath.TexStyle style);
double GetDefaultLineThickness(WpfMath.TexStyle style);
double GetDenom1(WpfMath.TexStyle style);
double GetDenom2(WpfMath.TexStyle style);
WpfMath.ExtensionChar GetExtension(WpfMath.CharInfo charInfo, WpfMath.TexStyle style);
double GetKern(WpfMath.CharFont leftChar, WpfMath.CharFont rightChar, WpfMath.TexStyle style);
WpfMath.CharFont? GetLigature(WpfMath.CharFont leftChar, WpfMath.CharFont rightChar);
int GetMuFontId();
WpfMath.CharInfo GetNextLargerCharInfo(WpfMath.CharInfo charInfo, WpfMath.TexStyle style);
double GetNum1(WpfMath.TexStyle style);
double GetNum2(WpfMath.TexStyle style);
double GetNum3(WpfMath.TexStyle style);
double GetQuad(int fontId, WpfMath.TexStyle style);
double GetSkew(WpfMath.CharFont charFont, WpfMath.TexStyle style);
double GetSpace(WpfMath.TexStyle style);
double GetSub1(WpfMath.TexStyle style);
double GetSub2(WpfMath.TexStyle style);
double GetSubDrop(WpfMath.TexStyle style);
double GetSup1(WpfMath.TexStyle style);
double GetSup2(WpfMath.TexStyle style);
double GetSup3(WpfMath.TexStyle style);
double GetSupDrop(WpfMath.TexStyle style);
double GetXHeight(WpfMath.TexStyle style, int fontId);
bool HasNextLarger(WpfMath.CharInfo charInfo);
bool HasSpace(int fontId);
bool IsExtensionChar(WpfMath.CharInfo charInfo);
}
}
namespace WpfMath.Rendering
{
Expand Down
95 changes: 44 additions & 51 deletions src/WpfMath.ApiTest/api/WpfMath.Shared.netcoreapp3.1.verified.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,6 @@ public partial class FormulaNotFoundException : System.Exception
{
internal FormulaNotFoundException() { }
}
public partial interface ITeXFont
{
double Size { get; }
bool SupportsMetrics { get; }
double GetAxisHeight(WpfMath.TexStyle style);
double GetBigOpSpacing1(WpfMath.TexStyle style);
double GetBigOpSpacing2(WpfMath.TexStyle style);
double GetBigOpSpacing3(WpfMath.TexStyle style);
double GetBigOpSpacing4(WpfMath.TexStyle style);
double GetBigOpSpacing5(WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(char character, string textStyle, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(string name, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(WpfMath.CharFont charFont, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetDefaultCharInfo(char character, WpfMath.TexStyle style);
double GetDefaultLineThickness(WpfMath.TexStyle style);
double GetDenom1(WpfMath.TexStyle style);
double GetDenom2(WpfMath.TexStyle style);
WpfMath.ExtensionChar GetExtension(WpfMath.CharInfo charInfo, WpfMath.TexStyle style);
double GetKern(WpfMath.CharFont leftChar, WpfMath.CharFont rightChar, WpfMath.TexStyle style);
WpfMath.CharFont? GetLigature(WpfMath.CharFont leftChar, WpfMath.CharFont rightChar);
int GetMuFontId();
WpfMath.CharInfo GetNextLargerCharInfo(WpfMath.CharInfo charInfo, WpfMath.TexStyle style);
double GetNum1(WpfMath.TexStyle style);
double GetNum2(WpfMath.TexStyle style);
double GetNum3(WpfMath.TexStyle style);
double GetQuad(int fontId, WpfMath.TexStyle style);
double GetSkew(WpfMath.CharFont charFont, WpfMath.TexStyle style);
double GetSpace(WpfMath.TexStyle style);
double GetSub1(WpfMath.TexStyle style);
double GetSub2(WpfMath.TexStyle style);
double GetSubDrop(WpfMath.TexStyle style);
double GetSup1(WpfMath.TexStyle style);
double GetSup2(WpfMath.TexStyle style);
double GetSup3(WpfMath.TexStyle style);
double GetSupDrop(WpfMath.TexStyle style);
double GetXHeight(WpfMath.TexStyle style, int fontId);
bool HasNextLarger(WpfMath.CharInfo charInfo);
bool HasSpace(int fontId);
bool IsExtensionChar(WpfMath.CharInfo charInfo);
}
public enum MatrixCellAlignment
{
Left = 0,
Expand Down Expand Up @@ -152,14 +112,14 @@ public enum TexDelimiter
}
public sealed partial class TexEnvironment : System.IEquatable<WpfMath.TexEnvironment>
{
public TexEnvironment(WpfMath.TexStyle Style, WpfMath.ITeXFont MathFont, WpfMath.ITeXFont TextFont, WpfMath.Rendering.IBrush? Background = null, WpfMath.Rendering.IBrush? Foreground = null) { }
public TexEnvironment(WpfMath.TexStyle Style, WpfMath.Fonts.ITeXFont MathFont, WpfMath.Fonts.ITeXFont TextFont, WpfMath.Rendering.IBrush? Background = null, WpfMath.Rendering.IBrush? Foreground = null) { }
public WpfMath.Rendering.IBrush? Background { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.Rendering.IBrush? Foreground { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.ITeXFont MathFont { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.Fonts.ITeXFont MathFont { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.TexStyle Style { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.ITeXFont TextFont { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public WpfMath.Fonts.ITeXFont TextFont { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public void Deconstruct(out WpfMath.TexStyle Style, out WpfMath.ITeXFont MathFont, out WpfMath.ITeXFont TextFont, out WpfMath.Rendering.IBrush? Background, out WpfMath.Rendering.IBrush? Foreground) { throw null; }
public void Deconstruct(out WpfMath.TexStyle Style, out WpfMath.Fonts.ITeXFont MathFont, out WpfMath.Fonts.ITeXFont TextFont, out WpfMath.Rendering.IBrush? Background, out WpfMath.Rendering.IBrush? Foreground) { throw null; }
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public override bool Equals(object? obj) { throw null; }
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
Expand Down Expand Up @@ -189,7 +149,6 @@ public TexFormula() { }
public WpfMath.SourceSpan? Source { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public string? TextStyle { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public void Add(WpfMath.TexFormula formula, WpfMath.SourceSpan? source = null) { }
public WpfMath.Boxes.Box CreateBox(WpfMath.TexEnvironment environment) { throw null; }
public void SetBackground(WpfMath.Rendering.IBrush brush) { }
public void SetForeground(WpfMath.Rendering.IBrush brush) { }
}
Expand Down Expand Up @@ -290,12 +249,6 @@ public static partial class StandardColorParsers
public static System.Collections.Generic.IReadOnlyDictionary<string, WpfMath.Colors.IColorParser> Dictionary;
}
}
namespace WpfMath.Data
{
public static partial class WpfMathResourceMarker
{
}
}
namespace WpfMath.Exceptions
{
public partial class TexCharacterMappingNotFoundException : WpfMath.Exceptions.TexException
Expand Down Expand Up @@ -334,6 +287,46 @@ public partial interface IFontProvider
public partial interface IFontTypeface
{
}
public partial interface ITeXFont
{
double Size { get; }
bool SupportsMetrics { get; }
double GetAxisHeight(WpfMath.TexStyle style);
double GetBigOpSpacing1(WpfMath.TexStyle style);
double GetBigOpSpacing2(WpfMath.TexStyle style);
double GetBigOpSpacing3(WpfMath.TexStyle style);
double GetBigOpSpacing4(WpfMath.TexStyle style);
double GetBigOpSpacing5(WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(char character, string textStyle, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(string name, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetCharInfo(WpfMath.CharFont charFont, WpfMath.TexStyle style);
WpfMath.Utils.Result<WpfMath.CharInfo> GetDefaultCharInfo(char character, WpfMath.TexStyle style);
double GetDefaultLineThickness(WpfMath.TexStyle style);
double GetDenom1(WpfMath.TexStyle style);
double GetDenom2(WpfMath.TexStyle style);
WpfMath.ExtensionChar GetExtension(WpfMath.CharInfo charInfo, WpfMath.TexStyle style);
double GetKern(WpfMath.CharFont leftChar, WpfMath.CharFont rightChar, WpfMath.TexStyle style);
WpfMath.CharFont? GetLigature(WpfMath.CharFont leftChar, WpfMath.CharFont rightChar);
int GetMuFontId();
WpfMath.CharInfo GetNextLargerCharInfo(WpfMath.CharInfo charInfo, WpfMath.TexStyle style);
double GetNum1(WpfMath.TexStyle style);
double GetNum2(WpfMath.TexStyle style);
double GetNum3(WpfMath.TexStyle style);
double GetQuad(int fontId, WpfMath.TexStyle style);
double GetSkew(WpfMath.CharFont charFont, WpfMath.TexStyle style);
double GetSpace(WpfMath.TexStyle style);
double GetSub1(WpfMath.TexStyle style);
double GetSub2(WpfMath.TexStyle style);
double GetSubDrop(WpfMath.TexStyle style);
double GetSup1(WpfMath.TexStyle style);
double GetSup2(WpfMath.TexStyle style);
double GetSup3(WpfMath.TexStyle style);
double GetSupDrop(WpfMath.TexStyle style);
double GetXHeight(WpfMath.TexStyle style, int fontId);
bool HasNextLarger(WpfMath.CharInfo charInfo);
bool HasSpace(int fontId);
bool IsExtensionChar(WpfMath.CharInfo charInfo);
}
}
namespace WpfMath.Rendering
{
Expand Down
1 change: 1 addition & 0 deletions src/WpfMath.Shared/Atoms/CharAtom.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using WpfMath.Fonts;
using WpfMath.Utils;

namespace WpfMath.Atoms
Expand Down
1 change: 1 addition & 0 deletions src/WpfMath.Shared/Atoms/CharSymbol.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using WpfMath.Boxes;
using WpfMath.Fonts;
using WpfMath.Utils;

namespace WpfMath.Atoms
Expand Down
1 change: 1 addition & 0 deletions src/WpfMath.Shared/Atoms/DummyAtom.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using WpfMath.Boxes;
using WpfMath.Fonts;
using WpfMath.Utils;

namespace WpfMath.Atoms
Expand Down
1 change: 1 addition & 0 deletions src/WpfMath.Shared/Atoms/FixedCharAtom.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using WpfMath.Fonts;
using WpfMath.Utils;

namespace WpfMath.Atoms
Expand Down
Loading

0 comments on commit 1054067

Please sign in to comment.