Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Merge pull request #22833 from mellinoe/system.drawing.netcoreapp20
Browse files Browse the repository at this point in the history
Change System.Drawing.Common's target to netcoreapp2.0
  • Loading branch information
mellinoe committed Aug 2, 2017
2 parents 91f993e + 17130d8 commit 87b5a4e
Show file tree
Hide file tree
Showing 33 changed files with 404 additions and 197 deletions.
1 change: 1 addition & 0 deletions external/dir.proj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<!-- Build for all configurations -->
<ItemGroup>
<Project Include="netcoreapp/netcoreapp.depproj" />
<Project Include="netstandard/netstandard.depproj" />
<Project Include="netfx/netfx.depproj" />
<Project Include="runtime/runtime.depproj" />
Expand Down
8 changes: 8 additions & 0 deletions external/netcoreapp/Configurations.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp2.0
</BuildConfigurations>
</PropertyGroup>
</Project>
27 changes: 27 additions & 0 deletions external/netcoreapp/netcoreapp.depproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<!-- This project restores and publishes the targeting pack for specific versions of .NET Core.
With this, we are able to compile assemblies against shipped, stable versions of .NET Core. -->
<PropertyGroup>
<BinPlaceRef>true</BinPlaceRef>
<NuGetDeploySourceItem>Reference</NuGetDeploySourceItem>
<NETCoreAppPackageVersion>2.0.0</NETCoreAppPackageVersion>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App">
<Version>$(NETCoreAppPackageVersion)</Version>
</PackageReference>
</ItemGroup>

<ItemGroup>
<!-- for all configurations this project provides refs for that configuration -->
<BinPlaceConfiguration Include="$(Configuration)">
<RefPath>$(RefPath)</RefPath>
</BinPlaceConfiguration>
</ItemGroup>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
98 changes: 98 additions & 0 deletions src/Common/src/System/Drawing/ColorUtil.netcoreapp20.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Reflection;

namespace System.Drawing
{
// System.Drawing.Common uses several members on System.Drawing.Common which are implemented in .NET Core 2.0, but
// not exposed. This is a helper class which allows System.Drawing.Common to access those members through reflection.
internal static class ColorUtil
{
private const short StateKnownColorValid = 0x0001;
private const short StateNameValid = 0x0008;
private const long NotDefinedValue = 0;

private static readonly ConstructorInfo s_ctorKnownColor; // internal Color(KnownColor knownColor)
private static readonly ConstructorInfo s_ctorAllValues; // private Color(long value, short state, string name, KnownColor knownColor)
private static readonly FieldInfo s_fieldKnownColor; // private readonly short knownColor
private static readonly FieldInfo s_fieldState; // private readonly short state

static ColorUtil()
{
Type colorType = typeof(Color);
Type knownColorType = colorType.Assembly.GetType("System.Drawing.KnownColor", true);
Debug.Assert(knownColorType != null);
const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;
s_ctorKnownColor = colorType.GetConstructor(bindingFlags, null, new Type[] { knownColorType }, null);
Debug.Assert(s_ctorKnownColor != null);

s_ctorAllValues = colorType.GetConstructor(bindingFlags, null, new Type[] { typeof(long), typeof(short), typeof(string), knownColorType }, null);
Debug.Assert(s_ctorAllValues != null);

s_fieldKnownColor = colorType.GetField("knownColor", bindingFlags);
Debug.Assert(s_fieldKnownColor != null);

s_fieldState = colorType.GetField("state", bindingFlags);
Debug.Assert(s_fieldState != null);
}

public static Color FromKnownColor(KnownColor color)
{
var value = (int)color;
if (value < (int)KnownColor.ActiveBorder || value > (int)KnownColor.MenuHighlight)
{
return FromName(color.ToString());
}

return (Color)s_ctorKnownColor.Invoke(new object[] { value });
}

public static Color FromName(string name)
{
// try to get a known color first
Color color;
if (ColorTable.TryGetNamedColor(name, out color))
{
return color;
}
// otherwise treat it as a named color
return (Color)s_ctorAllValues.Invoke(new object[] { NotDefinedValue, StateNameValid, name, 0 });
}

public static bool IsSystemColor(this Color color)
{
short knownColor = GetKnownColor(color);
return GetIsKnownColor(color) && ((((KnownColor)knownColor) <= KnownColor.WindowText) || (((KnownColor)knownColor) > KnownColor.YellowGreen));
}

public static short GetKnownColor(this Color color)
{
return (short)s_fieldKnownColor.GetValue(color);
}

public static short GetState(this Color color)
{
return (short)s_fieldState.GetValue(color);
}

public static bool GetIsSystemColor(this Color color)
{
short knownColor = color.GetKnownColor();
return GetIsKnownColor(color) && ((((KnownColor)knownColor) <= KnownColor.WindowText) || (((KnownColor)knownColor) > KnownColor.YellowGreen));
}

public static bool GetIsKnownColor(this Color color)
{
short state = GetState(color);
return ((state & StateKnownColorValid) != 0);
}

public static KnownColor ToKnownColor(this Color c)
{
return (KnownColor)GetKnownColor(c);
}
}
}
15 changes: 15 additions & 0 deletions src/Common/src/System/Drawing/ColorUtil.netcoreapp21.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Reflection;

namespace System.Drawing
{
internal static class ColorUtil
{
public static Color FromKnownColor(KnownColor color) => Color.FromKnownColor(color);
public static bool IsSystemColor(this Color color) => color.IsSystemColor;
}
}
4 changes: 2 additions & 2 deletions src/Common/src/System/Drawing/KnownColorTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static Color ArgbToKnownColor(int targetARGB)
int argb = s_colorTable[index];
if (argb == targetARGB)
{
Color color = Color.FromKnownColor((KnownColor)index);
if (!color.IsSystemColor)
Color color = ColorUtil.FromKnownColor((KnownColor)index);
if (!ColorUtil.IsSystemColor(color))
return color;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/System.Drawing.Common/System.Drawing.Common.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ Global
{4B93E684-0630-45F4-8F63-6C7788C9892F}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
{4B93E684-0630-45F4-8F63-6C7788C9892F}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
{4B93E684-0630-45F4-8F63-6C7788C9892F}.Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU
{191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Debug|Any CPU.ActiveCfg = netcoreapp-Unix-Debug|Any CPU
{191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Debug|Any CPU.Build.0 = netcoreapp-Unix-Debug|Any CPU
{191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
{191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU
{D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
{191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Debug|Any CPU.ActiveCfg = netcoreapp2.0-Windows_NT-Debug|Any CPU
{191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Debug|Any CPU.Build.0 = netcoreapp2.0-Windows_NT-Debug|Any CPU
{191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Release|Any CPU.ActiveCfg = netcoreapp2.0-Windows_NT-Release|Any CPU
{191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Release|Any CPU.Build.0 = netcoreapp2.0-Windows_NT-Release|Any CPU
{D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Debug|Any CPU.ActiveCfg = netcoreapp2.0-Debug|Any CPU
{D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Debug|Any CPU.Build.0 = netcoreapp2.0-Debug|Any CPU
{D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Release|Any CPU.ActiveCfg = netcoreapp2.0-Release|Any CPU
{D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Release|Any CPU.Build.0 = netcoreapp2.0-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion src/System.Drawing.Common/ref/Configurations.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp;
netcoreapp2.0;
</BuildConfigurations>
</PropertyGroup>
</Project>
20 changes: 10 additions & 10 deletions src/System.Drawing.Common/ref/System.Drawing.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
<PropertyGroup>
<ProjectGuid>{D7AEA698-275D-441F-B7A7-8491D1F0EFF0}</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="System.Drawing.Common.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
<ProjectReference Include="..\..\System.Runtime.Extensions\ref\System.Runtime.Extensions.csproj" />
<ProjectReference Include="..\..\System.Runtime.InteropServices\ref\System.Runtime.InteropServices.csproj" />
<ProjectReference Include="..\..\System.Collections.NonGeneric\ref\System.Collections.NonGeneric.csproj" />
<ProjectReference Include="..\..\System.ComponentModel\ref\System.ComponentModel.csproj" />
<ProjectReference Include="..\..\System.ComponentModel.Primitives\ref\System.ComponentModel.Primitives.csproj" />
<ProjectReference Include="..\..\System.Diagnostics.Debug\ref\System.Diagnostics.Debug.csproj" />
<ProjectReference Include="..\..\System.Drawing.Primitives\ref\System.Drawing.Primitives.csproj" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Collections.NonGeneric" />
<Reference Include="System.ComponentModel" />
<Reference Include="System.ComponentModel.Primitives" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.Drawing.Primitives" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
4 changes: 2 additions & 2 deletions src/System.Drawing.Common/src/Configurations.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp-Windows_NT;
netcoreapp-Unix;
netcoreapp2.0-Windows_NT;
netcoreapp2.0-Unix;
</BuildConfigurations>
</PropertyGroup>
</Project>
23 changes: 17 additions & 6 deletions src/System.Drawing.Common/src/System.Drawing.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
<DefineConstants Condition="'$(TargetsWindows)' == 'true'">$(DefineConstants);FEATURE_WINDOWS_SYSTEM_COLORS</DefineConstants>
<DefineConstants Condition="'$(TargetsUnix)' == 'true'">$(DefineConstants);CORECLR;NETCORE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Unix-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Unix-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Windows_NT-Release|AnyCPU'" />
<ItemGroup>
<Reference Include="Microsoft.Win32.Primitives" />
<Reference Include="System.Collections" />
<Reference Include="System.Collections.NonGeneric" />
<Reference Include="System.Collections.Specialized" />
<Reference Include="System.Configuration.ConfigurationManager" />
<Reference Include="System.Diagnostics.Contracts" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.Diagnostics.StackTrace" />
Expand All @@ -41,6 +40,7 @@
</ItemGroup>
<ItemGroup>
<!-- Shared source code, all configurations -->
<Compile Include="misc\InvalidEnumArgumentException.cs" />
<Compile Include="System\Drawing\BitmapSuffixInSameAssemblyAttribute.cs" />
<Compile Include="System\Drawing\BitmapSuffixInSatelliteAssemblyAttribute.cs" />
<Compile Include="System\Drawing\IDeviceContext.cs" />
Expand Down Expand Up @@ -166,6 +166,12 @@
<Compile Include="$(CommonPath)\System\Drawing\ColorTable.cs">
<Link>System\Drawing\ColorTable.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Drawing\ColorUtil.netcoreapp20.cs">
<Link>System\Drawing\ColorUtil.netcoreapp20.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Drawing\KnownColor.cs">
<Link>System\Drawing\KnownColor.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Drawing\KnownColorTable.cs">
<Link>System\Drawing\KnownColorTable.cs</Link>
</Compile>
Expand Down Expand Up @@ -212,7 +218,9 @@
<Compile Include="System\Drawing\Printing\PageSettings.cs" />
<Compile Include="System\Drawing\Printing\PreviewPrintController.cs" />
<Compile Include="System\Drawing\Printing\PrintController.cs" />
<Compile Include="System\Drawing\Printing\PrintDocument.cs" />
<Compile Include="System\Drawing\Printing\PrintDocument.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="System\Drawing\Printing\PrinterSettings.cs" />
<Compile Include="System\Drawing\Printing\PrintEvent.cs" />
<Compile Include="System\Drawing\Printing\PrintPageEvent.cs" />
Expand Down Expand Up @@ -241,6 +249,9 @@
<Compile Include="misc\GDI\WindowsRegion.cs" />
<Compile Include="misc\GDI\WindowsRegionCombineMode.cs" />
<Compile Include="$(CommonPath)\System\LocalAppContext.cs" />
<Compile Include="$(CommonPath)\System\Numerics\Hashing\HashHelpers.cs">
<Link>Common\System\Numerics\Hashing\HashHelpers.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
<Link>Common\Interop\Windows\Interop.Libraries.cs</Link>
</Compile>
Expand Down
18 changes: 3 additions & 15 deletions src/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace System.Drawing
{
using System.Configuration;
using System.Drawing.Configuration;
using System.IO;
using System.Reflection;

Expand All @@ -27,19 +25,9 @@ internal static string Suffix
{
get
{
if (s_suffix == null)
{
s_suffix = string.Empty;
var section = ConfigurationManager.GetSection("system.drawing") as SystemDrawingSection;
if (section != null)
{
var value = section.BitmapSuffix;
if (value != null && value is string)
{
s_suffix = (string)value;
}
}
}
// NOTE: This value is read from the "SystemDrawingSection" of the ConfigurationManager on
// the .NET Framework. To avoid pulling in a direct dependency to that assembly, we are not
// reading the value in this implementation.
return s_suffix;
}
set
Expand Down
Loading

0 comments on commit 87b5a4e

Please sign in to comment.