[ColorPicker]Use the new custom formats when picking colors without editor (#22552)

* ColorPicker fixing 'old' formats still represented in the old pre-defined format in color picker module.

* Fixing color picker tests, adding format strings
This commit is contained in:
Laszlo Nemeth
2022-12-09 12:21:59 +01:00
committed by GitHub
parent d8b92662ba
commit bb92b03156
2 changed files with 11 additions and 20 deletions

View File

@@ -34,26 +34,16 @@ namespace ColorPicker.Helpers
/// <param name="colorRepresentationType">The type of the representation</param>
/// <returns>A <see cref="string"/> representation of a color</returns>
internal static string GetStringRepresentation(Color color, string colorRepresentationType, string colorFormat)
=> colorRepresentationType switch
{
if (string.IsNullOrEmpty(colorFormat))
{
"CMYK" => ColorToCMYK(color),
"HEX" => ColorToHex(color),
"HSB" => ColorToHSB(color),
"HSI" => ColorToHSI(color),
"HSL" => ColorToHSL(color),
"HSV" => ColorToHSV(color),
"HWB" => ColorToHWB(color),
"NCol" => ColorToNCol(color),
"RGB" => ColorToRGB(color),
"CIELAB" => ColorToCIELAB(color),
"CIEXYZ" => ColorToCIEXYZ(color),
"VEC4" => ColorToFloat(color),
"Decimal" => ColorToDecimal(color),
"HEX Int" => ColorToHexInteger(color),
// Fall-back value, when "_userSettings.CopiedColorRepresentation.Value" is incorrect
_ => string.IsNullOrEmpty(colorFormat) ? ColorToHex(color) : ColorFormatHelper.GetStringRepresentation(color, colorFormat),
};
return ColorToHex(color);
}
else
{
return ColorFormatHelper.GetStringRepresentation(color, colorFormat);
}
}
/// <summary>
/// Return a <see cref="string"/> representation of a CMYK color

View File

@@ -4,6 +4,7 @@
using System.Drawing;
using ColorPicker.Helpers;
using ManagedCommon;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.ColorPicker.UnitTests
@@ -29,7 +30,7 @@ namespace Microsoft.ColorPicker.UnitTests
public void GetStringRepresentationTest(string type, string expected)
{
var result = ColorRepresentationHelper.GetStringRepresentation(Color.Black, type, string.Empty);
var result = ColorRepresentationHelper.GetStringRepresentation(Color.Black, type, ColorFormatHelper.GetDefaultFormat(type));
Assert.AreEqual(result, expected);
}
}