diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs index 463ccfd5d00e00..ca1dd612121086 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs @@ -268,9 +268,7 @@ public enum CopyPixelOperation Whiteness = 16711778, CaptureBlt = 1073741824, } -#if NETCOREAPP - [System.ComponentModel.TypeConverterAttribute("System.Drawing.FontConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")] -#endif + [System.ComponentModel.TypeConverterAttribute(typeof(System.Drawing.FontConverter))] public sealed partial class Font : System.MarshalByRefObject, System.ICloneable, System.IDisposable, System.Runtime.Serialization.ISerializable { public Font(System.Drawing.Font prototype, System.Drawing.FontStyle newStyle) { } @@ -301,6 +299,7 @@ public Font(string familyName, float emSize, System.Drawing.GraphicsUnit unit) { [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)] public bool Italic { get { throw null; } } [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)] + [System.ComponentModel.TypeConverterAttribute(typeof(System.Drawing.FontConverter.FontNameConverter))] public string Name { get { throw null; } } [System.ComponentModel.BrowsableAttribute(false)] public string? OriginalFontName { get { throw null; } } @@ -315,6 +314,7 @@ public Font(string familyName, float emSize, System.Drawing.GraphicsUnit unit) { public string SystemFontName { get { throw null; } } [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)] public bool Underline { get { throw null; } } + [System.ComponentModel.TypeConverterAttribute(typeof(System.Drawing.FontConverter.FontUnitConverter))] public System.Drawing.GraphicsUnit Unit { get { throw null; } } public object Clone() { throw null; } public void Dispose() { } @@ -334,6 +334,33 @@ public void ToLogFont(object logFont) { } public void ToLogFont(object logFont, System.Drawing.Graphics graphics) { } public override string ToString() { throw null; } } + public partial class FontConverter : System.ComponentModel.TypeConverter + { + public FontConverter() { } + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) { throw null; } + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) { throw null; } + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) { throw null; } + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) { throw null; } + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext? context, System.Collections.IDictionary propertyValues) { throw null; } + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext? context) { throw null; } + public override System.ComponentModel.PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext? context, object? value, System.Attribute[]? attributes) { throw null; } + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { throw null; } + public sealed partial class FontNameConverter : System.ComponentModel.TypeConverter, System.IDisposable + { + public FontNameConverter() { } + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) { throw null; } + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) { throw null; } + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext? context) { throw null; } + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext? context) { throw null; } + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext? context) { throw null; } + void System.IDisposable.Dispose() { } + } + public partial class FontUnitConverter : System.ComponentModel.EnumConverter + { + public FontUnitConverter() : base (default(System.Type)) { } + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext? context) { throw null; } + } + } public sealed partial class FontFamily : System.MarshalByRefObject, System.IDisposable { public FontFamily(System.Drawing.Text.GenericFontFamilies genericFamily) { } @@ -629,9 +656,7 @@ public enum GraphicsUnit Document = 5, Millimeter = 6, } -#if NETCOREAPP - [System.ComponentModel.TypeConverterAttribute("System.Drawing.IconConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")] -#endif + [System.ComponentModel.TypeConverterAttribute(typeof(System.Drawing.IconConverter))] public sealed partial class Icon : System.MarshalByRefObject, System.ICloneable, System.IDisposable, System.Runtime.Serialization.ISerializable { public Icon(System.Drawing.Icon original, System.Drawing.Size size) { } @@ -660,15 +685,21 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public System.Drawing.Bitmap ToBitmap() { throw null; } public override string ToString() { throw null; } } + public partial class IconConverter : System.ComponentModel.ExpandableObjectConverter + { + public IconConverter() { } + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) { throw null; } + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { throw null; } + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { throw null; } + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { throw null; } + } public partial interface IDeviceContext : System.IDisposable { System.IntPtr GetHdc(); void ReleaseHdc(); } [System.ComponentModel.ImmutableObjectAttribute(true)] -#if NETCOREAPP - [System.ComponentModel.TypeConverterAttribute("System.Drawing.ImageConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")] -#endif + [System.ComponentModel.TypeConverterAttribute(typeof(System.Drawing.ImageConverter))] public abstract partial class Image : System.MarshalByRefObject, System.ICloneable, System.IDisposable, System.Runtime.Serialization.ISerializable { internal Image() { } @@ -742,6 +773,26 @@ public static void StopAnimate(System.Drawing.Image image, System.EventHandler o public static void UpdateFrames() { } public static void UpdateFrames(System.Drawing.Image image) { } } + public partial class ImageConverter : System.ComponentModel.TypeConverter + { + public ImageConverter() { } + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) { throw null; } + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) { throw null; } + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) { throw null; } + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) { throw null; } + public override System.ComponentModel.PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext? context, object? value, System.Attribute[]? attributes) { throw null; } + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext? context) { throw null; } + } + public partial class ImageFormatConverter : System.ComponentModel.TypeConverter + { + public ImageFormatConverter() { } + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) { throw null; } + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) { throw null; } + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) { throw null; } + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) { throw null; } + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext? context) { throw null; } + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext? context) { throw null; } + } public sealed partial class Pen : System.MarshalByRefObject, System.ICloneable, System.IDisposable { public Pen(System.Drawing.Brush brush) { } @@ -961,7 +1012,7 @@ public void Intersect(System.Drawing.Region region) { } public bool IsVisible(System.Drawing.Rectangle rect, System.Drawing.Graphics? g) { throw null; } public bool IsVisible(System.Drawing.RectangleF rect) { throw null; } public bool IsVisible(System.Drawing.RectangleF rect, System.Drawing.Graphics? g) { throw null; } - public bool IsVisible(int x, int y, System.Drawing.Graphics g) { throw null; } + public bool IsVisible(int x, int y, System.Drawing.Graphics? g) { throw null; } public bool IsVisible(int x, int y, int width, int height) { throw null; } public bool IsVisible(int x, int y, int width, int height, System.Drawing.Graphics? g) { throw null; } public bool IsVisible(float x, float y) { throw null; } @@ -2292,9 +2343,7 @@ public enum ImageFlags ReadOnly = 65536, Caching = 131072, } -#if NETCOREAPP - [System.ComponentModel.TypeConverterAttribute("System.Drawing.ImageFormatConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")] -#endif + [System.ComponentModel.TypeConverterAttribute(typeof(System.Drawing.ImageFormatConverter))] public sealed partial class ImageFormat { public ImageFormat(System.Guid guid) { } @@ -2491,9 +2540,7 @@ public InvalidPrinterException(System.Drawing.Printing.PrinterSettings settings) protected InvalidPrinterException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } } -#if NETCOREAPP - [System.ComponentModel.TypeConverterAttribute("System.Drawing.Printing.MarginsConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")] -#endif + [System.ComponentModel.TypeConverterAttribute(typeof(System.Drawing.Printing.MarginsConverter))] public partial class Margins : System.ICloneable { public Margins() { } @@ -2505,10 +2552,20 @@ public Margins(int left, int right, int top, int bottom) { } public object Clone() { throw null; } public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } - public static bool operator ==(System.Drawing.Printing.Margins m1, System.Drawing.Printing.Margins m2) { throw null; } - public static bool operator !=(System.Drawing.Printing.Margins m1, System.Drawing.Printing.Margins m2) { throw null; } + public static bool operator ==(System.Drawing.Printing.Margins? m1, System.Drawing.Printing.Margins? m2) { throw null; } + public static bool operator !=(System.Drawing.Printing.Margins? m1, System.Drawing.Printing.Margins? m2) { throw null; } public override string ToString() { throw null; } } + public partial class MarginsConverter : System.ComponentModel.ExpandableObjectConverter + { + public MarginsConverter() { } + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) { throw null; } + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) { throw null; } + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) { throw null; } + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) { throw null; } + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext? context, System.Collections.IDictionary propertyValues) { throw null; } + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext? context) { throw null; } + } public partial class PageSettings : System.ICloneable { public PageSettings() { } diff --git a/src/libraries/System.Drawing.Common/src/Resources/Strings.resx b/src/libraries/System.Drawing.Common/src/Resources/Strings.resx index f5ba77ee8ed377..1b718caf5ad6c8 100644 --- a/src/libraries/System.Drawing.Common/src/Resources/Strings.resx +++ b/src/libraries/System.Drawing.Common/src/Resources/Strings.resx @@ -262,6 +262,9 @@ Value of '{1}' is not valid for '{0}'. + + + Value of '{0}' is not valid for font size unit. Value of '{1}' is not valid for '{0}'. '{0}' should be greater than {2} and less than or equal to {3}. @@ -437,6 +440,9 @@ Operation not implemented under X11 + + (none) + No valid icon image found diff --git a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj index a2a3625642527b..516a194705c08d 100644 --- a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj +++ b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj @@ -25,7 +25,10 @@ + + + @@ -116,6 +119,7 @@ + @@ -130,6 +134,7 @@ + @@ -158,6 +163,8 @@ Link="Common\Interop\Windows\User32\Interop.LOGFONT.cs" /> + System.Drawing.DefaultComponent.bmp diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs index 3b0665b32c5f87..106653389c38f8 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs @@ -13,9 +13,7 @@ namespace System.Drawing /// /// Defines a particular format for text, including font face, size, and style attributes. /// -#if NETCOREAPP - [TypeConverter("System.Drawing.FontConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")] -#endif + [TypeConverter(typeof(FontConverter))] [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public sealed partial class Font : MarshalByRefObject, ICloneable, IDisposable, ISerializable @@ -76,11 +74,13 @@ public sealed partial class Font : MarshalByRefObject, ICloneable, IDisposable, /// Gets the face name of this . /// [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(FontConverter.FontNameConverter))] public string Name => FontFamily.Name; /// /// Gets the unit of measure for this . /// + [TypeConverter(typeof(FontConverter.FontUnitConverter))] public GraphicsUnit Unit => _fontUnit; /// diff --git a/src/libraries/System.Windows.Extensions/src/System/Drawing/FontConverter.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs similarity index 88% rename from src/libraries/System.Windows.Extensions/src/System/Drawing/FontConverter.cs rename to src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs index 0a1032379848cf..99a327b2ba5041 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Drawing/FontConverter.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs @@ -4,6 +4,7 @@ using System.Collections; using System.ComponentModel; using System.ComponentModel.Design.Serialization; +using System.Diagnostics; using System.Drawing.Text; using System.Globalization; using System.Reflection; @@ -15,17 +16,17 @@ public class FontConverter : TypeConverter { private const string StylePrefix = "style="; - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + public override bool CanConvertFrom(ITypeDescriptorContext? context, Type? sourceType) { - return sourceType == typeof(string) ? true : base.CanConvertFrom(context, sourceType); + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); } - public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType) { return (destinationType == typeof(string)) || (destinationType == typeof(InstanceDescriptor)); } - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) { if (value is Font font) { @@ -86,7 +87,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul if (destinationType == typeof(InstanceDescriptor)) { - ConstructorInfo met = typeof(Font).GetTypeInfo().GetConstructor(new Type[] { typeof(string), typeof(float), typeof(FontStyle), typeof(GraphicsUnit) }); + ConstructorInfo? met = typeof(Font).GetTypeInfo().GetConstructor(new Type[] { typeof(string), typeof(float), typeof(FontStyle), typeof(GraphicsUnit) }); object[] args = new object[4]; args[0] = font.Name; args[1] = font.Size; @@ -100,7 +101,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul return base.ConvertTo(context, culture, value, destinationType); } - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) { if (!(value is string font)) { @@ -123,8 +124,8 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c char separator = culture.TextInfo.ListSeparator[0]; // For vi-VN: ',' string fontName = font; // start with the assumption that only the font name was provided. - string style = null; - string sizeStr = null; + string? style = null; + string? sizeStr = null; float fontSize = 8.25f; FontStyle fontStyle = FontStyle.Regular; GraphicsUnit units = GraphicsUnit.Point; @@ -161,7 +162,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c } // Parse size. - (string size, string unit) unitTokens = ParseSizeTokens(sizeStr, separator); + (string? size, string? unit) unitTokens = ParseSizeTokens(sizeStr, separator); if (unitTokens.size != null) { @@ -208,10 +209,10 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c return new Font(fontName, fontSize, fontStyle, units); } - private (string, string) ParseSizeTokens(string text, char separator) + private (string?, string?) ParseSizeTokens(string text, char separator) { - string size = null; - string units = null; + string? size = null; + string? units = null; text = text.Trim(); @@ -259,18 +260,23 @@ private GraphicsUnit ParseGraphicsUnits(string units) => "mm" => GraphicsUnit.Millimeter, "px" => GraphicsUnit.Pixel, "world" => GraphicsUnit.World, - _ => throw new ArgumentException(SR.Format(SR.InvalidArgumentValue, units), nameof(units)), + _ => throw new ArgumentException(SR.Format(SR.InvalidArgumentValueFontConverter, units), nameof(units)), }; - public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) + public override object CreateInstance(ITypeDescriptorContext? context, IDictionary propertyValues) { - object value; + if (propertyValues == null) + { + throw new ArgumentNullException(nameof(propertyValues)); + } + + object? value; byte charSet = 1; float size = 8; - string name = null; + string? name = null; bool vertical = false; FontStyle style = FontStyle.Regular; - FontFamily fontFamily = null; + FontFamily? fontFamily = null; GraphicsUnit unit = GraphicsUnit.Point; if ((value = propertyValues["GdiCharSet"]) != null) @@ -352,12 +358,12 @@ public override object CreateInstance(ITypeDescriptorContext context, IDictionar return new Font(fontFamily, size, style, unit, charSet, vertical); } - public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) => true; + public override bool GetCreateInstanceSupported(ITypeDescriptorContext? context) => true; public override PropertyDescriptorCollection GetProperties( - ITypeDescriptorContext context, - object value, - Attribute[] attributes) + ITypeDescriptorContext? context, + object? value, + Attribute[]? attributes) { return value is Font ? TypeDescriptor.GetProperties(value, attributes) : base.GetProperties(context, value, attributes); } @@ -377,17 +383,17 @@ void IDisposable.Dispose() { } - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + public override bool CanConvertFrom(ITypeDescriptorContext? context, Type? sourceType) { return sourceType == typeof(string) ? true : base.CanConvertFrom(context, sourceType); } - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) { return value is string strValue ? MatchFontName(strValue, context) : base.ConvertFrom(context, culture, value); } - public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) + public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context) { string[] values = new string[_fonts.Length]; for (int i = 0; i < _fonts.Length; i++) @@ -400,18 +406,20 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex } // We allow other values other than those in the font list. - public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => false; + public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context) => false; // Yes, we support picking an element from the list. - public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true; + public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) => true; - private string MatchFontName(string name, ITypeDescriptorContext context) + private string MatchFontName(string name, ITypeDescriptorContext? context) { // Try a partial match - string bestMatch = null; + string? bestMatch = null; - foreach (string fontName in GetStandardValues(context)) + // setting fontName as nullable since IEnumerable.Current returned nullable in 3.0 + foreach (string? fontName in GetStandardValues(context)) { + Debug.Assert(fontName != null); if (fontName.Equals(name, StringComparison.InvariantCultureIgnoreCase)) { // For an exact match, return immediately @@ -435,12 +443,13 @@ public class FontUnitConverter : EnumConverter { public FontUnitConverter() : base(typeof(GraphicsUnit)) { } - public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) + public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context) { // display graphic unit is not supported. if (Values == null) { base.GetStandardValues(context); // sets "values" + Debug.Assert(Values != null); ArrayList filteredValues = new ArrayList(Values); filteredValues.Remove(GraphicsUnit.Display); Values = new StandardValuesCollection(filteredValues); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Unix.cs index 04ed13140fdbe4..c5288cc6744d98 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Unix.cs @@ -44,9 +44,7 @@ namespace System.Drawing { -#if NETCOREAPP - [System.ComponentModel.TypeConverter("System.Drawing.IconConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")] -#endif + [System.ComponentModel.TypeConverter(typeof(IconConverter))] [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public sealed partial class Icon : MarshalByRefObject, ISerializable, ICloneable, IDisposable diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.cs index 34c84087194cc7..6ade4a7267cd5d 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.cs @@ -13,9 +13,7 @@ namespace System.Drawing { -#if NETCOREAPP - [TypeConverter("System.Drawing.IconConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")] -#endif + [TypeConverter(typeof(IconConverter))] [Serializable] [TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public sealed partial class Icon : MarshalByRefObject, ICloneable, IDisposable, ISerializable diff --git a/src/libraries/System.Windows.Extensions/src/System/Drawing/IconConverter.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/IconConverter.cs similarity index 97% rename from src/libraries/System.Windows.Extensions/src/System/Drawing/IconConverter.cs rename to src/libraries/System.Drawing.Common/src/System/Drawing/IconConverter.cs index b1c01da338b7e0..48803c35261d9c 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Drawing/IconConverter.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/IconConverter.cs @@ -35,7 +35,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul } else if (value is Icon) { - return value.ToString(); + return value.ToString()!; } } else if (destinationType == typeof(byte[])) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs index 23f795b4e94759..d6b2d3cc91ddff 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs @@ -17,9 +17,7 @@ namespace System.Drawing [ImmutableObject(true)] [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] -#if NETCOREAPP - [TypeConverter("System.Drawing.ImageConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")] -#endif + [TypeConverter(typeof(ImageConverter))] public abstract partial class Image : MarshalByRefObject, IDisposable, ICloneable, ISerializable { // The signature of this delegate is incorrect. The signature of the corresponding diff --git a/src/libraries/System.Windows.Extensions/src/System/Drawing/ImageConverter.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageConverter.cs similarity index 90% rename from src/libraries/System.Windows.Extensions/src/System/Drawing/ImageConverter.cs rename to src/libraries/System.Drawing.Common/src/System/Drawing/ImageConverter.cs index 4b6f0194ab4387..710ce1d4381b5a 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Drawing/ImageConverter.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageConverter.cs @@ -17,17 +17,17 @@ public class ImageConverter : TypeConverter private static ReadOnlySpan BMBytes => new byte[] { (byte)'B', (byte)'M' }; - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + public override bool CanConvertFrom(ITypeDescriptorContext? context, Type? sourceType) { return sourceType == typeof(byte[]) || sourceType == typeof(Icon); } - public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType) { return destinationType == typeof(byte[]) || destinationType == typeof(string); } - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) { if (value is Icon icon) { @@ -47,7 +47,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c } } - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) { if (destinationType == typeof(string)) { @@ -57,7 +57,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul } else if (value is Image) { - return value.ToString(); + return value.ToString()!; } } else if (destinationType == typeof(byte[])) @@ -79,7 +79,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul // If we don't find an Encoder (for things like Icon), we // just switch back to PNG. - ImageCodecInfo codec = FindEncoder(dest) ?? FindEncoder(ImageFormat.Png); + ImageCodecInfo codec = FindEncoder(dest) ?? FindEncoder(ImageFormat.Png)!; image.Save(ms, codec, null); return ms.ToArray(); } @@ -90,7 +90,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul } // Find any random encoder which supports this format. - private static ImageCodecInfo FindEncoder(ImageFormat imageformat) + private static ImageCodecInfo? FindEncoder(ImageFormat imageformat) { ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); foreach (ImageCodecInfo codec in codecs) @@ -101,14 +101,14 @@ private static ImageCodecInfo FindEncoder(ImageFormat imageformat) return null; } - public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) + public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext? context, object? value, Attribute[]? attributes) { return TypeDescriptor.GetProperties(typeof(Image), attributes); } - public override bool GetPropertiesSupported(ITypeDescriptorContext context) => true; + public override bool GetPropertiesSupported(ITypeDescriptorContext? context) => true; - private unsafe Stream GetBitmapStream(ReadOnlySpan rawData) + private unsafe Stream? GetBitmapStream(ReadOnlySpan rawData) { try { diff --git a/src/libraries/System.Windows.Extensions/src/System/Drawing/ImageFormatConverter.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageFormatConverter.cs similarity index 89% rename from src/libraries/System.Windows.Extensions/src/System/Drawing/ImageFormatConverter.cs rename to src/libraries/System.Drawing.Common/src/System/Drawing/ImageFormatConverter.cs index 02ab96eaacf48d..908477d27beb47 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Drawing/ImageFormatConverter.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageFormatConverter.cs @@ -11,12 +11,12 @@ namespace System.Drawing { public class ImageFormatConverter : TypeConverter { - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + public override bool CanConvertFrom(ITypeDescriptorContext? context, Type? sourceType) { - return sourceType == typeof(string) ? true : base.CanConvertFrom(context, sourceType); + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); } - public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType) { if ((destinationType == typeof(string)) || (destinationType == typeof(InstanceDescriptor))) { @@ -25,10 +25,10 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati return base.CanConvertTo(context, destinationType); } - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) { // we must be able to convert from short names and long names - string strFormat = value as string; + string? strFormat = value as string; if (strFormat == null) { // case #1, this is not a string @@ -66,7 +66,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c throw new FormatException(SR.Format(SR.ConvertInvalidPrimitive, strFormat, nameof(ImageFormat))); } - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) { if (value is ImageFormat imgFormat) { @@ -77,7 +77,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul if (destinationType == typeof(InstanceDescriptor)) { - string strFormat = null; + string? strFormat = null; if (imgFormat.Guid.Equals(ImageFormat.Bmp.Guid)) strFormat = "Bmp"; else if (imgFormat.Guid.Equals(ImageFormat.Emf.Guid)) @@ -105,7 +105,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul } else { - ConstructorInfo ctor = typeof(ImageFormat).GetTypeInfo().GetConstructor(new Type[] { typeof(Guid) }); + ConstructorInfo? ctor = typeof(ImageFormat).GetTypeInfo().GetConstructor(new Type[] { typeof(Guid) }); return new InstanceDescriptor(ctor, new object[] { imgFormat.Guid }); } } @@ -114,7 +114,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul return base.ConvertTo(context, culture, value, destinationType); } - public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) + public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context) { return new TypeConverter.StandardValuesCollection(new ImageFormat[] { @@ -131,6 +131,6 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex }); } - public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true; + public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) => true; } } diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs index 34c55614f6a8e8..7107d21b9b6f42 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs @@ -8,9 +8,7 @@ namespace System.Drawing.Imaging /// /// Specifies the format of the image. /// -#if NETCOREAPP - [TypeConverter("System.Drawing.ImageFormatConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")] -#endif + [TypeConverter(typeof(ImageFormatConverter))] public sealed class ImageFormat { // Format IDs diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/Margins.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/Margins.cs index 011b543ddb6881..48415cc0b3bfbd 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/Margins.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/Margins.cs @@ -10,9 +10,7 @@ namespace System.Drawing.Printing /// /// Specifies the margins of a printed page. /// -#if NETCOREAPP - [TypeConverter("System.Drawing.Printing.MarginsConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")] -#endif + [TypeConverter(typeof(MarginsConverter))] public partial class Margins : ICloneable { private int _left; diff --git a/src/libraries/System.Windows.Extensions/src/System/Drawing/Printing/MarginsConverter.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/MarginsConverter.cs similarity index 90% rename from src/libraries/System.Windows.Extensions/src/System/Drawing/Printing/MarginsConverter.cs rename to src/libraries/System.Drawing.Common/src/System/Drawing/Printing/MarginsConverter.cs index f693df719d9f40..2431fde5eac15e 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Drawing/Printing/MarginsConverter.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/MarginsConverter.cs @@ -19,7 +19,7 @@ public class MarginsConverter : ExpandableObjectConverter /// Determines if a converter can convert an object of the given source /// type to the native type of the converter. /// - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + public override bool CanConvertFrom(ITypeDescriptorContext? context, Type? sourceType) { if (sourceType == typeof(string)) { @@ -32,7 +32,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT /// Gets a value indicating whether this converter can /// convert an object to the given destination type using the context. /// - public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType) { if (destinationType == typeof(InstanceDescriptor)) { @@ -44,7 +44,7 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati /// /// Converts the given object to the converter's native type. /// - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) { if (value is string strValue) { @@ -87,7 +87,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c /// type is string. If this cannot convert to the desitnation type, this will /// throw a NotSupportedException. /// - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) { if (destinationType == null) { @@ -116,7 +116,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul } if (destinationType == typeof(InstanceDescriptor)) { - ConstructorInfo ctor = typeof(Margins).GetConstructor(new Type[] { + ConstructorInfo? ctor = typeof(Margins).GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(int)}); if (ctor != null) @@ -133,24 +133,24 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul /// Determines if changing a value on this object should require a call to /// CreateInstance to create a new value. /// - public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) => true; + public override bool GetCreateInstanceSupported(ITypeDescriptorContext? context) => true; /// /// Creates an instance of this type given a set of property values /// for the object. This is useful for objects that are immutable, but still /// want to provide changable properties. /// - public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) + public override object CreateInstance(ITypeDescriptorContext? context, IDictionary propertyValues) { if (propertyValues == null) { throw new ArgumentNullException(nameof(propertyValues)); } - object left = propertyValues["Left"]; - object right = propertyValues["Right"]; - object top = propertyValues["Top"]; - object bottom = propertyValues["Bottom"]; + object? left = propertyValues["Left"]; + object? right = propertyValues["Right"]; + object? top = propertyValues["Top"]; + object? bottom = propertyValues["Bottom"]; if (left == null || right == null || bottom == null || top == null || !(left is int) || !(right is int) || !(bottom is int) || !(top is int)) diff --git a/src/libraries/System.Drawing.Common/tests/System.Drawing.Common.Tests.csproj b/src/libraries/System.Drawing.Common/tests/System.Drawing.Common.Tests.csproj index 5537f87099e4ad..1371f91e3d1a08 100644 --- a/src/libraries/System.Drawing.Common/tests/System.Drawing.Common.Tests.csproj +++ b/src/libraries/System.Drawing.Common/tests/System.Drawing.Common.Tests.csproj @@ -72,6 +72,11 @@ + + + + + @@ -89,6 +94,8 @@ + + System.Drawing.Tests.48x48_multiple_entries_4bit.ico diff --git a/src/libraries/System.Drawing.Common/tests/System/Drawing/FontConverterTests.cs b/src/libraries/System.Drawing.Common/tests/System/Drawing/FontConverterTests.cs new file mode 100644 index 00000000000000..38f56c80f0d1d1 --- /dev/null +++ b/src/libraries/System.Drawing.Common/tests/System/Drawing/FontConverterTests.cs @@ -0,0 +1,201 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Drawing; +using System.Drawing.Text; +using System.Globalization; +using System.Linq; +using Xunit; +using static System.Drawing.FontConverter; + +namespace System.ComponentModel.TypeConverterTests +{ + public class FontNameConverterTest + { + [ConditionalFact(Helpers.IsDrawingSupported)] + public void TestConvertFrom() + { + FontConverter.FontNameConverter converter = new FontConverter.FontNameConverter(); + // returns "Times" under Linux and "Times New Roman" under Windows + if (PlatformDetection.IsWindows) + { + Assert.Equal("Times New Roman", converter.ConvertFrom("Times") as string); + } + else + { + Assert.Equal("Times", converter.ConvertFrom("Times") as string); + } + Assert.True(converter.GetStandardValuesSupported(), "standard values supported"); + Assert.False(converter.GetStandardValuesExclusive(), "standard values exclusive"); + } + + [ConditionalFact(Helpers.IsDrawingSupported)] + public void ExTestConvertFrom_ThrowsNotSupportedException() + { + FontConverter.FontNameConverter converter = new FontConverter.FontNameConverter(); + Assert.Throws(() => converter.ConvertFrom(null)); + Assert.Throws(() => converter.ConvertFrom(1)); + } + } + + public class FontConverterTest + { + public static char s_Separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator[0]; + + [ConditionalTheory(Helpers.IsDrawingSupported)] + [MemberData(nameof(TestConvertFormData))] + [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Full Framework doesn't support inputs without units")] + public void TestConvertFrom(string input, string expectedName, float expectedSize, GraphicsUnit expectedUnits, FontStyle expectedFontStyle) + { + FontConverter converter = new FontConverter(); + Font font = (Font)converter.ConvertFrom(input); + + // Unix fonts + Assert.Equal(expectedName, font.Name); + Assert.Equal(expectedSize, font.Size); + Assert.Equal(expectedUnits, font.Unit); + Assert.Equal(expectedFontStyle, font.Style); + } + + [ConditionalTheory(Helpers.IsDrawingSupported)] + [MemberData(nameof(ArgumentExceptionFontConverterData))] + public void InvalidInputThrowsArgumentException(string input, string paramName, string netfxParamName) + { + FontConverter converter = new FontConverter(); + AssertExtensions.Throws(paramName, netfxParamName, () => converter.ConvertFrom(input)); + } + + [ConditionalTheory(Helpers.IsDrawingSupported)] + [MemberData(nameof(InvalidEnumArgumentExceptionFontConverterData))] + public void InvalidInputThrowsInvalidEnumArgumentException(string input, string paramName) + { + FontConverter converter = new FontConverter(); + Assert.Throws(paramName, () => converter.ConvertFrom(input)); + } + + [ConditionalFact(Helpers.IsDrawingSupported)] + public void EmptyStringInput() + { + FontConverter converter = new FontConverter(); + Font font = (Font)converter.ConvertFrom(string.Empty); + Assert.Null(font); + } + + public static TheoryData TestConvertFormData() + { + var data = PlatformDetection.IsWindows ? + new TheoryData() + { + { $"Courier New", "Courier New", 8.25f, GraphicsUnit.Point, FontStyle.Regular }, + { $"Courier New{s_Separator} 11", "Courier New", 11f, GraphicsUnit.Point, FontStyle.Regular }, + { $"Arial{s_Separator} 11px", "Arial", 11f, GraphicsUnit.Pixel, FontStyle.Regular }, + { $"Courier New{s_Separator} 11 px", "Courier New", 11f, GraphicsUnit.Pixel, FontStyle.Regular }, + { $"Courier New{s_Separator} 11 px{s_Separator} style=Regular", "Courier New", 11f, GraphicsUnit.Pixel, FontStyle.Regular }, + { $"Courier New{s_Separator} style=Bold", "Courier New", 8.25f, GraphicsUnit.Point, FontStyle.Bold }, + { $"Courier New{s_Separator} 11 px{s_Separator} style=Bold{s_Separator} Italic", "Courier New", 11f, GraphicsUnit.Pixel, FontStyle.Bold | FontStyle.Italic }, + { $"Courier New{s_Separator} 11 px{s_Separator} style=Regular, Italic", "Courier New", 11f, GraphicsUnit.Pixel, FontStyle.Regular | FontStyle.Italic }, + { $"Courier New{s_Separator} 11 px{s_Separator} style=Bold{s_Separator} Italic{s_Separator} Strikeout", "Courier New", 11f, GraphicsUnit.Pixel, FontStyle.Bold | FontStyle.Italic | FontStyle.Strikeout }, + { $"Arial{s_Separator} 11 px{s_Separator} style=Bold, Italic, Strikeout", "Arial", 11f, GraphicsUnit.Pixel, FontStyle.Bold | FontStyle.Italic | FontStyle.Strikeout }, + { $"11px", "Microsoft Sans Serif", 8.25f, GraphicsUnit.Point, FontStyle.Regular }, + { $"Style=Bold", "Microsoft Sans Serif", 8.25f, GraphicsUnit.Point, FontStyle.Regular }, + { $"arIAL{s_Separator} 10{s_Separator} style=bold", "Arial", 10f, GraphicsUnit.Point, FontStyle.Bold }, + { $"Arial{s_Separator} 10{s_Separator}", "Arial", 10f, GraphicsUnit.Point, FontStyle.Regular }, + { $"Arial{s_Separator}", "Arial", 8.25f, GraphicsUnit.Point, FontStyle.Regular }, + { $"Arial{s_Separator} 10{s_Separator} style=12", "Arial", 10f, GraphicsUnit.Point, FontStyle.Underline | FontStyle.Strikeout }, + { $"Courier New{s_Separator} Style=Bold", "Courier New", 8.25f, GraphicsUnit.Point, FontStyle.Bold }, // FullFramework style keyword is case sensitive. + { $"11px{s_Separator} Style=Bold", "Microsoft Sans Serif", 8.25f, GraphicsUnit.Point, FontStyle.Bold} + } + : new TheoryData() + { + // Unix has different fonts installed, let's use a default one. + { FontFamily.GenericSansSerif.Name, FontFamily.GenericSansSerif.Name, 8.25f, GraphicsUnit.Point, FontStyle.Regular }, + { $"{FontFamily.GenericSansSerif.Name}{s_Separator} 11", FontFamily.GenericSansSerif.Name, 11f, GraphicsUnit.Point, FontStyle.Regular }, + { $"{FontFamily.GenericSansSerif.Name}{s_Separator} 11 px", FontFamily.GenericSansSerif.Name, 11f, GraphicsUnit.Pixel, FontStyle.Regular }, + { $"{FontFamily.GenericSansSerif.Name}{s_Separator} 11 px{s_Separator} style=Regular", FontFamily.GenericSansSerif.Name, 11f, GraphicsUnit.Pixel, FontStyle.Regular }, + { $"{FontFamily.GenericSansSerif.Name}{s_Separator} style=Bold", FontFamily.GenericSansSerif.Name, 8.25f, GraphicsUnit.Point, FontStyle.Bold }, + { $"{FontFamily.GenericSansSerif.Name}{s_Separator} 11 px{s_Separator} style=Bold{s_Separator} Italic", FontFamily.GenericSansSerif.Name, 11f, GraphicsUnit.Pixel, FontStyle.Bold | FontStyle.Italic }, + { $"{FontFamily.GenericSansSerif.Name}{s_Separator} 11 px{s_Separator} style=Regular, Italic", FontFamily.GenericSansSerif.Name, 11f, GraphicsUnit.Pixel, FontStyle.Regular | FontStyle.Italic }, + { $"{FontFamily.GenericSansSerif.Name}{s_Separator} 11 px{s_Separator} style=Bold{s_Separator} Italic{s_Separator} Strikeout", FontFamily.GenericSansSerif.Name, 11f, GraphicsUnit.Pixel, FontStyle.Bold | FontStyle.Italic | FontStyle.Strikeout }, + { $"{FontFamily.GenericSansSerif.Name}{s_Separator} Style=Bold", FontFamily.GenericSansSerif.Name, 8.25f, GraphicsUnit.Point, FontStyle.Bold }, // FullFramework style keyword is case sensitive. + }; + + if (PlatformDetection.IsWindows) + { + // FullFramework disregards all arguments if the font name is an empty string. + // Empty string is not an installed font on Windows 7, windows 8 and some versions of windows 10. + if (EmptyFontPresent) + { + data.Add($"{s_Separator} 10{s_Separator} style=bold", "", 10f, GraphicsUnit.Point, FontStyle.Bold); + } + else + { + data.Add($"{s_Separator} 10{s_Separator} style=bold", "Microsoft Sans Serif", 10f, GraphicsUnit.Point, FontStyle.Bold); + } + } + + return data; + } + + private static bool EmptyFontPresent + { + get + { + using (var installedFonts = new InstalledFontCollection()) + { + return installedFonts.Families.Select(t => t.Name).Contains(string.Empty); + } + } + } + + public static TheoryData ArgumentExceptionFontConverterData() => new TheoryData() + { + { $"Courier New{s_Separator} 11 px{s_Separator} type=Bold{s_Separator} Italic", "units", null }, + { $"Courier New{s_Separator} {s_Separator} Style=Bold", "value", null }, + { $"Courier New{s_Separator} 11{s_Separator} Style=", "value", null }, + { $"Courier New{s_Separator} 11{s_Separator} Style=RandomEnum", null, null }, + { $"Arial{s_Separator} 10{s_Separator} style=bold{s_Separator}", "value", null }, + { $"Arial{s_Separator} 10{s_Separator} style=null", null, null }, + { $"Arial{s_Separator} 10{s_Separator} style=abc#", null, null }, + { $"Arial{s_Separator} 10{s_Separator} style=##", null, null }, + { $"Arial{s_Separator} 10display{s_Separator} style=bold", null, null }, + { $"Arial{s_Separator} 10style{s_Separator} style=bold", "units", null }, + }; + + public static TheoryData InvalidEnumArgumentExceptionFontConverterData() => new TheoryData() + { + { $"Arial{s_Separator} 10{s_Separator} style=56", "style" }, + { $"Arial{s_Separator} 10{s_Separator} style=-1", "style" }, + }; + } + + public class FontUnitConverterTest + { + [ConditionalFact(Helpers.IsDrawingSupported)] + public void GetStandardValuesTest() + { + FontUnitConverter converter = new FontUnitConverter(); + var values = converter.GetStandardValues(); + Assert.Equal(6, values.Count); // The six supported values of Graphics unit: World, Pixel, Point, Inch, Document, Millimeter. + + foreach (var item in values) + { + Assert.NotEqual(GraphicsUnit.Display, (GraphicsUnit)item); + } + } + + [ConditionalTheory(Helpers.IsDrawingSupported)] + [InlineData("Display", GraphicsUnit.Display)] + [InlineData("Document", GraphicsUnit.Document)] + [InlineData("Inch", GraphicsUnit.Inch)] + [InlineData("Millimeter", GraphicsUnit.Millimeter)] + [InlineData("Pixel", GraphicsUnit.Pixel)] + [InlineData("Point", GraphicsUnit.Point)] + [InlineData("World", GraphicsUnit.World)] + public void CanConvertFrom(string input, GraphicsUnit expected) + { + FontUnitConverter converter = new FontUnitConverter(); + GraphicsUnit value = (GraphicsUnit)converter.ConvertFrom(input); + Assert.Equal(expected, value); + } + } +} diff --git a/src/libraries/System.Windows.Extensions/tests/System/Drawing/IconConverterTests.cs b/src/libraries/System.Drawing.Common/tests/System/Drawing/IconConverterTests.cs similarity index 100% rename from src/libraries/System.Windows.Extensions/tests/System/Drawing/IconConverterTests.cs rename to src/libraries/System.Drawing.Common/tests/System/Drawing/IconConverterTests.cs diff --git a/src/libraries/System.Windows.Extensions/tests/System/Drawing/ImageConverterTests.cs b/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageConverterTests.cs similarity index 100% rename from src/libraries/System.Windows.Extensions/tests/System/Drawing/ImageConverterTests.cs rename to src/libraries/System.Drawing.Common/tests/System/Drawing/ImageConverterTests.cs diff --git a/src/libraries/System.Windows.Extensions/tests/System/Drawing/ImageFormatConverterTests.cs b/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageFormatConverterTests.cs similarity index 100% rename from src/libraries/System.Windows.Extensions/tests/System/Drawing/ImageFormatConverterTests.cs rename to src/libraries/System.Drawing.Common/tests/System/Drawing/ImageFormatConverterTests.cs diff --git a/src/libraries/System.Windows.Extensions/tests/System/Drawing/Printing/MarginsConverterTests.cs b/src/libraries/System.Drawing.Common/tests/System/Drawing/Printing/MarginsConverterTests.cs similarity index 100% rename from src/libraries/System.Windows.Extensions/tests/System/Drawing/Printing/MarginsConverterTests.cs rename to src/libraries/System.Drawing.Common/tests/System/Drawing/Printing/MarginsConverterTests.cs diff --git a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.Forwards.cs b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.Forwards.cs new file mode 100644 index 00000000000000..c64d5ead3990bf --- /dev/null +++ b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.Forwards.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// ------------------------------------------------------------------------------ +// Changes to this file must follow the https://aka.ms/api-review process. +// ------------------------------------------------------------------------------ + +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.FontConverter))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.IconConverter))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.ImageConverter))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.ImageFormatConverter))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.Printing.MarginsConverter))] diff --git a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs index c3dd8dc7ecca7d..ac07897be2c886 100644 --- a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs +++ b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs @@ -4,77 +4,6 @@ // Changes to this file must follow the https://aka.ms/api-review process. // ------------------------------------------------------------------------------ -namespace System.Drawing -{ - public partial class FontConverter : System.ComponentModel.TypeConverter - { - public FontConverter() { } - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) { throw null; } - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { throw null; } - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { throw null; } - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { throw null; } - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary propertyValues) { throw null; } - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { throw null; } - public override System.ComponentModel.PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributes) { throw null; } - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { throw null; } - public sealed partial class FontNameConverter : System.ComponentModel.TypeConverter, System.IDisposable - { - public FontNameConverter() { } - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) { throw null; } - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { throw null; } - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { throw null; } - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { throw null; } - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { throw null; } - void System.IDisposable.Dispose() { } - } - public partial class FontUnitConverter : System.ComponentModel.EnumConverter - { - public FontUnitConverter() : base (default(System.Type)) { } - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { throw null; } - } - } - public partial class IconConverter : System.ComponentModel.ExpandableObjectConverter - { - public IconConverter() { } - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) { throw null; } - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { throw null; } - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { throw null; } - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { throw null; } - } - public partial class ImageConverter : System.ComponentModel.TypeConverter - { - public ImageConverter() { } - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) { throw null; } - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { throw null; } - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { throw null; } - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { throw null; } - public override System.ComponentModel.PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributes) { throw null; } - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { throw null; } - } - public partial class ImageFormatConverter : System.ComponentModel.TypeConverter - { - public ImageFormatConverter() { } - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) { throw null; } - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { throw null; } - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { throw null; } - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { throw null; } - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { throw null; } - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { throw null; } - } -} -namespace System.Drawing.Printing -{ - public partial class MarginsConverter : System.ComponentModel.ExpandableObjectConverter - { - public MarginsConverter() { } - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) { throw null; } - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { throw null; } - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { throw null; } - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { throw null; } - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary propertyValues) { throw null; } - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { throw null; } - } -} namespace System.Media { public partial class SoundPlayer : System.ComponentModel.Component, System.Runtime.Serialization.ISerializable diff --git a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.csproj b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.csproj index d8548ee597d3a6..e015f136522256 100644 --- a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.csproj +++ b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.csproj @@ -5,6 +5,10 @@ + + + + diff --git a/src/libraries/System.Windows.Extensions/src/ExcludeApiList.PNSE.txt b/src/libraries/System.Windows.Extensions/src/ExcludeApiList.PNSE.txt new file mode 100644 index 00000000000000..4537903f66bee8 --- /dev/null +++ b/src/libraries/System.Windows.Extensions/src/ExcludeApiList.PNSE.txt @@ -0,0 +1,7 @@ +T:System.Drawing.FontConverter +T:System.Drawing.FontConverter.FontNameConverter +T:System.Drawing.FontConverter.FontUnitConverter +T:System.Drawing.IconConverter +T:System.Drawing.ImageConverter +T:System.Drawing.ImageFormatConverter +T:System.Drawing.Printing.MarginsConverter diff --git a/src/libraries/System.Windows.Extensions/src/Resources/Strings.resx b/src/libraries/System.Windows.Extensions/src/Resources/Strings.resx index 0d363ab629fbc7..bafdb5f343cd8b 100644 --- a/src/libraries/System.Windows.Extensions/src/Resources/Strings.resx +++ b/src/libraries/System.Windows.Extensions/src/Resources/Strings.resx @@ -125,12 +125,6 @@ Enumeration value '{0}' specified in condition mapping is not valid. - - (none) - - - Value of '{0}' is not valid for font size unit. - System.Windows.Extensions types are not supported on this platform. diff --git a/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj b/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj index 7e4df72fa5eb68..178344cc5fe472 100644 --- a/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj +++ b/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj @@ -1,10 +1,16 @@ - SR.PlatformNotSupported_System_Windows_Extensions true $(NetCoreAppCurrent)-Windows_NT;netcoreapp3.0-Windows_NT;$(NetCoreAppCurrent);netcoreapp3.0 true + + SR.PlatformNotSupported_System_Windows_Extensions + --exclude-api-list ExcludeApiList.PNSE.txt + + + + @@ -40,23 +46,16 @@ Link="Common\Interop\Windows\Interop.Libraries.cs" /> - - - - - - - - + + diff --git a/src/libraries/System.Windows.Extensions/src/TypeForwards.cs b/src/libraries/System.Windows.Extensions/src/TypeForwards.cs new file mode 100644 index 00000000000000..f3974c73b75060 --- /dev/null +++ b/src/libraries/System.Windows.Extensions/src/TypeForwards.cs @@ -0,0 +1,8 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.FontConverter))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.IconConverter))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.ImageConverter))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.ImageFormatConverter))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.Printing.MarginsConverter))] diff --git a/src/libraries/System.Windows.Extensions/tests/System.Windows.Extensions.Tests.csproj b/src/libraries/System.Windows.Extensions/tests/System.Windows.Extensions.Tests.csproj index f41f912cb05b7d..f0f105858a701c 100644 --- a/src/libraries/System.Windows.Extensions/tests/System.Windows.Extensions.Tests.csproj +++ b/src/libraries/System.Windows.Extensions/tests/System.Windows.Extensions.Tests.csproj @@ -12,11 +12,6 @@ Link="Common\System\Drawing\Helpers.cs" /> - - - - - diff --git a/src/libraries/System.Windows.Extensions/tests/System/Drawing/FontConverterTests.cs b/src/libraries/System.Windows.Extensions/tests/System/Drawing/FontConverterTests.cs deleted file mode 100644 index 3f9a9da40efa00..00000000000000 --- a/src/libraries/System.Windows.Extensions/tests/System/Drawing/FontConverterTests.cs +++ /dev/null @@ -1,166 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Drawing; -using System.Drawing.Text; -using System.Globalization; -using System.Linq; -using Xunit; -using static System.Drawing.FontConverter; - -namespace System.ComponentModel.TypeConverterTests -{ - public class FontNameConverterTest - { - [ConditionalFact(Helpers.IsDrawingSupported)] - public void TestConvertFrom() - { - FontConverter.FontNameConverter converter = new FontConverter.FontNameConverter(); - // returns "Times" under Linux and "Times New Roman" under Windows - if (PlatformDetection.IsWindows) - { - Assert.Equal("Times New Roman", converter.ConvertFrom("Times") as string); - } - else - { - Assert.Equal("Times", converter.ConvertFrom("Times") as string); - } - Assert.True(converter.GetStandardValuesSupported(), "standard values supported"); - Assert.False(converter.GetStandardValuesExclusive(), "standard values exclusive"); - } - - [ConditionalFact(Helpers.IsDrawingSupported)] - public void ExTestConvertFrom_ThrowsNotSupportedException() - { - FontConverter.FontNameConverter converter = new FontConverter.FontNameConverter(); - Assert.Throws(() => converter.ConvertFrom(null)); - Assert.Throws(() => converter.ConvertFrom(1)); - } - } - - public class FontConverterTest - { - public static char s_Separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator[0]; - - [ConditionalTheory(Helpers.IsDrawingSupported)] - [MemberData(nameof(TestConvertFormData))] - public void TestConvertFrom(string input, string expectedName, float expectedSize, GraphicsUnit expectedUnits, FontStyle expectedFontStyle) - { - FontConverter converter = new FontConverter(); - Font font = (Font)converter.ConvertFrom(input); - Assert.Equal(expectedName, font.Name); - Assert.Equal(expectedSize, font.Size); - Assert.Equal(expectedUnits, font.Unit); - Assert.Equal(expectedFontStyle, font.Style); - } - - [ConditionalTheory(Helpers.IsDrawingSupported)] - [MemberData(nameof(ArgumentExceptionFontConverterData))] - public void InvalidInputThrowsArgumentException(string input, string paramName, string netfxParamName) - { - FontConverter converter = new FontConverter(); - AssertExtensions.Throws(paramName, netfxParamName, () => converter.ConvertFrom(input)); - } - - [ConditionalTheory(Helpers.IsDrawingSupported)] - [MemberData(nameof(InvalidEnumArgumentExceptionFontConverterData))] - public void InvalidInputThrowsInvalidEnumArgumentException(string input, string paramName) - { - FontConverter converter = new FontConverter(); - Assert.Throws(paramName, () => converter.ConvertFrom(input)); - } - - [ConditionalFact(Helpers.IsDrawingSupported)] - public void EmptyStringInput() - { - FontConverter converter = new FontConverter(); - Font font = (Font)converter.ConvertFrom(string.Empty); - Assert.Null(font); - } - - public static TheoryData TestConvertFormData() - { - var data = new TheoryData() - { - { $"Courier New", "Courier New", 8.25f, GraphicsUnit.Point, FontStyle.Regular }, - { $"Courier New{s_Separator} 11", "Courier New", 11f, GraphicsUnit.Point, FontStyle.Regular }, - { $"Arial{s_Separator} 11px", "Arial", 11f, GraphicsUnit.Pixel, FontStyle.Regular }, - { $"Courier New{s_Separator} 11 px", "Courier New", 11f, GraphicsUnit.Pixel, FontStyle.Regular }, - { $"Courier New{s_Separator} 11 px{s_Separator} style=Regular", "Courier New", 11f, GraphicsUnit.Pixel, FontStyle.Regular }, - { $"Courier New{s_Separator} style=Bold", "Courier New", 8.25f, GraphicsUnit.Point, FontStyle.Bold }, - { $"Courier New{s_Separator} 11 px{s_Separator} style=Bold{s_Separator} Italic", "Courier New", 11f, GraphicsUnit.Pixel, FontStyle.Bold | FontStyle.Italic }, - { $"Courier New{s_Separator} 11 px{s_Separator} style=Regular, Italic", "Courier New", 11f, GraphicsUnit.Pixel, FontStyle.Regular | FontStyle.Italic }, - { $"Courier New{s_Separator} 11 px{s_Separator} style=Bold{s_Separator} Italic{s_Separator} Strikeout", "Courier New", 11f, GraphicsUnit.Pixel, FontStyle.Bold | FontStyle.Italic | FontStyle.Strikeout }, - { $"Arial{s_Separator} 11 px{s_Separator} style=Bold, Italic, Strikeout", "Arial", 11f, GraphicsUnit.Pixel, FontStyle.Bold | FontStyle.Italic | FontStyle.Strikeout }, - { $"11px", "Microsoft Sans Serif", 8.25f, GraphicsUnit.Point, FontStyle.Regular }, - { $"Style=Bold", "Microsoft Sans Serif", 8.25f, GraphicsUnit.Point, FontStyle.Regular }, - { $"arIAL{s_Separator} 10{s_Separator} style=bold", "Arial", 10f, GraphicsUnit.Point, FontStyle.Bold }, - { $"Arial{s_Separator} 10{s_Separator}", "Arial", 10f, GraphicsUnit.Point, FontStyle.Regular }, - { $"Arial{s_Separator}", "Arial", 8.25f, GraphicsUnit.Point, FontStyle.Regular }, - { $"Arial{s_Separator} 10{s_Separator} style=12", "Arial", 10f, GraphicsUnit.Point, FontStyle.Underline | FontStyle.Strikeout }, - { $"Courier New{s_Separator} Style=Bold", "Courier New", 8.25f, GraphicsUnit.Point, FontStyle.Bold }, // FullFramework style keyword is case sensitive. - { $"11px{s_Separator} Style=Bold", "Microsoft Sans Serif", 8.25f, GraphicsUnit.Point, FontStyle.Bold} - }; - - // FullFramework disregards all arguments if the font name is an empty string. - // Empty string is not an installed font on Windows 7, windows 8 and some versions of windows 10. - if (EmptyFontPresent) - { - data.Add($"{s_Separator} 10{s_Separator} style=bold", "", 10f, GraphicsUnit.Point, FontStyle.Bold); - } - else - { - data.Add($"{s_Separator} 10{s_Separator} style=bold", "Microsoft Sans Serif", 10f, GraphicsUnit.Point, FontStyle.Bold); - } - - return data; - } - - private static bool EmptyFontPresent - { - get - { - using (var installedFonts = new InstalledFontCollection()) - { - return installedFonts.Families.Select(t => t.Name).Contains(string.Empty); - } - } - } - - public static TheoryData ArgumentExceptionFontConverterData() => new TheoryData() - { - { $"Courier New{s_Separator} 11 px{s_Separator} type=Bold{s_Separator} Italic", "units", null }, - { $"Courier New{s_Separator} {s_Separator} Style=Bold", "value", null }, - { $"Courier New{s_Separator} 11{s_Separator} Style=", "value", null }, - { $"Courier New{s_Separator} 11{s_Separator} Style=RandomEnum", null, null }, - { $"Arial{s_Separator} 10{s_Separator} style=bold{s_Separator}", "value", null }, - { $"Arial{s_Separator} 10{s_Separator} style=null", null, null }, - { $"Arial{s_Separator} 10{s_Separator} style=abc#", null, null }, - { $"Arial{s_Separator} 10{s_Separator} style=##", null, null }, - { $"Arial{s_Separator} 10display{s_Separator} style=bold", null, null }, - { $"Arial{s_Separator} 10style{s_Separator} style=bold", "units", null }, - }; - - public static TheoryData InvalidEnumArgumentExceptionFontConverterData() => new TheoryData() - { - { $"Arial{s_Separator} 10{s_Separator} style=56", "style" }, - { $"Arial{s_Separator} 10{s_Separator} style=-1", "style" }, - }; - } - - public class FontUnitConverterTest - { - [ConditionalFact(Helpers.IsDrawingSupported)] - public void GetStandardValuesTest() - { - FontUnitConverter converter = new FontUnitConverter(); - var values = converter.GetStandardValues(); - Assert.Equal(6, values.Count); // The six supported values of Graphics unit: World, Pixel, Point, Inch, Document, Millimeter. - - foreach (var item in values) - { - Assert.NotEqual(GraphicsUnit.Display, (GraphicsUnit)item); - } - } - } -}