forked from ForNeVeR/xaml-math
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/color-support'
- Loading branch information
Showing
55 changed files
with
1,908 additions
and
69 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,88 @@ | ||
Color support in WPF-Math | ||
========================= | ||
|
||
WPF-Math supports standard LaTeX commands: `\color` for foreground color, and | ||
`\colorbox` for background color. | ||
|
||
The commands also support additional syntax for color definitions. Standard | ||
LaTeX only allows to use predefined colors or colors defined in the same | ||
document. WPF-Math allows immediate color definition in the command arguments | ||
instead. | ||
|
||
The full color command syntax is: | ||
|
||
``` | ||
\command [mode] {color} {text} | ||
``` | ||
|
||
Where: | ||
- `command` is either `color` or `colorbox` | ||
- `mode` is an optional argument that could be one of | ||
- `gray` | ||
- `RGB`, `rgb`, `ARGB`, `argb`, `RGBA`, `rgba` | ||
- `cmyk` | ||
- `HTML` | ||
- `color` is either a predefined color name if the `mode` argument wasn't | ||
provided, or a color definition according to the `mode` argument | ||
|
||
Some of the modes accepts multiple numbers separated by comma `,`; whitespace is | ||
allowed around the comma, before first and after the last element in the list. | ||
|
||
## Default mode (when no `mode` was provided) | ||
|
||
In the default mode, `color` should be a predefined color name. Predefined | ||
colors are stored in the `PredefinedColors.xml` file from the WPF-Math | ||
resources. Additionally, this mode accepts an opacity index in range from 0.0 to | ||
1.0. Examples: | ||
|
||
``` | ||
\color{red}{without opacity} | ||
\color{red, 0.5}{with opacity} | ||
``` | ||
|
||
## `gray` mode | ||
|
||
`gray` mode accepts a grayscale tone in range from 0.0 to 1.0. Additionally, | ||
this mode accepts an opacity index in range from 0.0 to 1.0. Examples: | ||
|
||
``` | ||
\color[gray]{0.5}{without opacity} | ||
\color[gray]{0.5,0.5}{with opacity} | ||
``` | ||
|
||
## RGB-based modes | ||
|
||
There're six RGB-based modes: capital ones (`RGB`, `RGBA`, `ARGB`) accept three | ||
(or four with opacity) comma-separated values in range from 0 to 255, lowercase | ||
ones (`rgb`, `rgba`, `argb`) accept three (or four) comma-separated values in | ||
range from 0.0 to 1.0. `ARGB` accepts opacity index first, `RGBA` accepts it | ||
last. Examples: | ||
|
||
``` | ||
\colorbox[rgb]{0,0,0}{text} | ||
\colorbox[rgba]{0,0,0, 0.5}{opacity = 0.5} | ||
\colorbox[argb]{0.5, 0,0,0}{opacity = 0.5} | ||
\colorbox[RGB]{255,255,255}{text} | ||
\colorbox[RGBA]{255,255,255,128}{opacity = 128} | ||
\colorbox[ARGB]{128, 255,255,255}{opacity = 128} | ||
``` | ||
|
||
## CMYK mode | ||
|
||
`cmyk` mode accepts four (or five with opacity) parameters in the range from 0 | ||
to 1 for the CMYK color model. Examples: | ||
|
||
``` | ||
\colorbox[cmyk]{0,0,0,0}{text} | ||
\colorbox[cmyk]{0,0,0,0, 0.5}{opacity = 0.5} | ||
``` | ||
|
||
## HTML mode | ||
|
||
`HTML` mode accepts six or eight hexadecimal digits, in the latter case last two | ||
should be opacity. Examples: | ||
|
||
``` | ||
\color[HTML]{FF0000}{red text} | ||
\color[HTML]{FF000000}{fully transparent red text} | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module WpfMath.Tests.PredefinedColorParserTests | ||
|
||
open System.Windows.Media | ||
|
||
open Xunit | ||
|
||
open WpfMath.Colors | ||
|
||
let parser = PredefinedColorParser.Instance | ||
|
||
[<Fact>] | ||
let ``PredefinedColorParser parses a correctly defined color``(): unit = | ||
Assert.Equal(Color.FromRgb(237uy, 27uy, 35uy), parser.Parse([| "red" |]).Value) | ||
|
||
[<Fact>] | ||
let ``PredefinedColorParser returns null for wrong input``(): unit = | ||
Assert.Null(parser.Parse([| "nonexistent-color" |])) | ||
|
||
[<Fact>] | ||
let ``PredefinedColorParser returns null for empty input``(): unit = | ||
Assert.Null(parser.Parse(Array.empty)) | ||
|
||
[<Fact>] | ||
let ``PredefinedColorParser returns null for too long input``(): unit = | ||
Assert.Null(parser.Parse([| "red"; "green" |])) |
39 changes: 39 additions & 0 deletions
39
src/WpfMath.Tests/TestResults/ParserTests.colorModels.(color (red) x).approved.txt
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,39 @@ | ||
{ | ||
"TextStyle": null, | ||
"RootAtom": { | ||
"RowAtom": { | ||
"PreviousAtom": null, | ||
"Elements": [ | ||
{ | ||
"Character": "x", | ||
"TextStyle": null, | ||
"IsDefaultTextStyle": true, | ||
"IsTextSymbol": false, | ||
"Type": "Ordinary", | ||
"Source": { | ||
"Start": 13, | ||
"End": 14, | ||
"Length": 1, | ||
"Source": "\\color {red} x" | ||
} | ||
} | ||
], | ||
"Type": "Ordinary", | ||
"Source": { | ||
"Start": 1, | ||
"End": 14, | ||
"Length": 13, | ||
"Source": "\\color {red} x" | ||
} | ||
}, | ||
"Background": null, | ||
"Foreground": "#FFED1B23", | ||
"Type": "Ordinary", | ||
"Source": { | ||
"Start": 1, | ||
"End": 14, | ||
"Length": 13, | ||
"Source": "\\color {red} x" | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/WpfMath.Tests/TestResults/ParserTests.colorModels.(color [HTML] (abcdef) x).approved.txt
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,39 @@ | ||
{ | ||
"TextStyle": null, | ||
"RootAtom": { | ||
"RowAtom": { | ||
"PreviousAtom": null, | ||
"Elements": [ | ||
{ | ||
"Character": "x", | ||
"TextStyle": null, | ||
"IsDefaultTextStyle": true, | ||
"IsTextSymbol": false, | ||
"Type": "Ordinary", | ||
"Source": { | ||
"Start": 23, | ||
"End": 24, | ||
"Length": 1, | ||
"Source": "\\color [HTML] {abcdef} x" | ||
} | ||
} | ||
], | ||
"Type": "Ordinary", | ||
"Source": { | ||
"Start": 1, | ||
"End": 24, | ||
"Length": 23, | ||
"Source": "\\color [HTML] {abcdef} x" | ||
} | ||
}, | ||
"Background": null, | ||
"Foreground": "#FFABCDEF", | ||
"Type": "Ordinary", | ||
"Source": { | ||
"Start": 1, | ||
"End": 24, | ||
"Length": 23, | ||
"Source": "\\color [HTML] {abcdef} x" | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...th.Tests/TestResults/ParserTests.colorModels.(color [RGB] (128, 128, 128) x).approved.txt
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,39 @@ | ||
{ | ||
"TextStyle": null, | ||
"RootAtom": { | ||
"RowAtom": { | ||
"PreviousAtom": null, | ||
"Elements": [ | ||
{ | ||
"Character": "x", | ||
"TextStyle": null, | ||
"IsDefaultTextStyle": true, | ||
"IsTextSymbol": false, | ||
"Type": "Ordinary", | ||
"Source": { | ||
"Start": 29, | ||
"End": 30, | ||
"Length": 1, | ||
"Source": "\\color [RGB] {128, 128, 128} x" | ||
} | ||
} | ||
], | ||
"Type": "Ordinary", | ||
"Source": { | ||
"Start": 1, | ||
"End": 30, | ||
"Length": 29, | ||
"Source": "\\color [RGB] {128, 128, 128} x" | ||
} | ||
}, | ||
"Background": null, | ||
"Foreground": "#FF808080", | ||
"Type": "Ordinary", | ||
"Source": { | ||
"Start": 1, | ||
"End": 30, | ||
"Length": 29, | ||
"Source": "\\color [RGB] {128, 128, 128} x" | ||
} | ||
} | ||
} |
Oops, something went wrong.