-
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.
(#63) TexEnvironment: convert to a public record
- Loading branch information
Showing
2 changed files
with
32 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,39 @@ | ||
using System.Windows.Media; | ||
|
||
namespace WpfMath | ||
namespace WpfMath; | ||
|
||
/// <summary>Specifies current graphical parameters used to create boxes.</summary> | ||
public sealed record TexEnvironment( | ||
TexStyle Style, | ||
ITeXFont MathFont, | ||
ITeXFont TextFont, | ||
Brush? Background = null, | ||
Brush? Foreground = null) | ||
{ | ||
/// <summary>Specifies current graphical parameters used to create boxes.</summary> | ||
public sealed class TexEnvironment | ||
{ | ||
// ID of font that was last used. | ||
private int lastFontId = TexFontUtilities.NoFontId; | ||
|
||
internal TexEnvironment( | ||
TexStyle style, | ||
ITeXFont mathFont, | ||
ITeXFont textFont, | ||
Brush? background = null, | ||
Brush? foreground = null) | ||
{ | ||
if (style == TexStyle.Display || style == TexStyle.Text || | ||
style == TexStyle.Script || style == TexStyle.ScriptScript) | ||
this.Style = style; | ||
else | ||
this.Style = TexStyle.Display; | ||
|
||
this.MathFont = mathFont; | ||
TextFont = textFont; | ||
this.Background = background; | ||
this.Foreground = foreground; | ||
} | ||
|
||
internal TexStyle Style | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
internal ITeXFont MathFont | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
internal ITeXFont TextFont { get; } | ||
|
||
internal Brush? Background | ||
{ | ||
get; | ||
set; | ||
} | ||
// ID of font that was last used. | ||
private int lastFontId = TexFontUtilities.NoFontId; | ||
|
||
internal Brush? Foreground | ||
{ | ||
get; | ||
set; | ||
} | ||
|
||
internal int LastFontId | ||
{ | ||
get { return this.lastFontId == TexFontUtilities.NoFontId ? this.MathFont.GetMuFontId() : this.lastFontId; } | ||
set { this.lastFontId = value; } | ||
} | ||
|
||
internal TexEnvironment GetCrampedStyle() | ||
{ | ||
var newEnvironment = Clone(); | ||
newEnvironment.Style = (int)this.Style % 2 == 1 ? this.Style : this.Style + 1; | ||
return newEnvironment; | ||
} | ||
|
||
internal TexEnvironment GetNumeratorStyle() | ||
{ | ||
var newEnvironment = Clone(); | ||
newEnvironment.Style = this.Style + 2 - 2 * ((int)this.Style / 6); | ||
return newEnvironment; | ||
} | ||
internal int LastFontId | ||
{ | ||
get { return this.lastFontId == TexFontUtilities.NoFontId ? this.MathFont.GetMuFontId() : this.lastFontId; } | ||
set { this.lastFontId = value; } | ||
} | ||
|
||
internal TexEnvironment GetDenominatorStyle() | ||
{ | ||
var newEnvironment = Clone(); | ||
newEnvironment.Style = (TexStyle)(2 * ((int)this.Style / 2) + 1 + 2 - 2 * ((int)this.Style / 6)); | ||
return newEnvironment; | ||
} | ||
internal TexEnvironment GetCrampedStyle() => | ||
this with { Style = (int)this.Style % 2 == 1 ? this.Style : this.Style + 1 }; | ||
|
||
internal TexEnvironment GetRootStyle() | ||
{ | ||
var newEnvironment = Clone(); | ||
newEnvironment.Style = TexStyle.ScriptScript; | ||
return newEnvironment; | ||
} | ||
internal TexEnvironment GetNumeratorStyle() => | ||
this with { Style = this.Style + 2 - 2 * ((int)this.Style / 6) }; | ||
|
||
internal TexEnvironment GetSubscriptStyle() | ||
{ | ||
var newEnvironment = Clone(); | ||
newEnvironment.Style = (TexStyle)(2 * ((int)this.Style / 4) + 4 + 1); | ||
return newEnvironment; | ||
} | ||
internal TexEnvironment GetDenominatorStyle() => | ||
this with { Style = (TexStyle)(2 * ((int)this.Style / 2) + 1 + 2 - 2 * ((int)this.Style / 6)) }; | ||
|
||
internal TexEnvironment GetSuperscriptStyle() | ||
{ | ||
var newEnvironment = Clone(); | ||
newEnvironment.Style = (TexStyle)(2 * ((int)this.Style / 4) + 4 + ((int)this.Style % 2)); | ||
return newEnvironment; | ||
} | ||
internal TexEnvironment GetRootStyle() => | ||
this with { Style = TexStyle.ScriptScript }; | ||
|
||
internal TexEnvironment Clone() | ||
{ | ||
return new TexEnvironment(Style, MathFont, TextFont, Background, Foreground); | ||
} | ||
internal TexEnvironment GetSubscriptStyle() => | ||
this with { Style = (TexStyle)(2 * ((int)this.Style / 4) + 4 + 1) }; | ||
|
||
internal void Reset() | ||
{ | ||
this.Background = null; | ||
this.Foreground = null; | ||
} | ||
} | ||
internal TexEnvironment GetSuperscriptStyle() => | ||
this with { Style = (TexStyle)(2 * ((int)this.Style / 4) + 4 + (int)this.Style % 2) }; | ||
} |