From 7ff58880ee946df244a5b7d6bbd6ee1e98ad5c26 Mon Sep 17 00:00:00 2001 From: Christiano Donke Date: Fri, 16 Mar 2018 13:40:27 -0300 Subject: [PATCH 1/7] Adding NetStandard Projects --- Core/Owl/Owl.NetStandard.csproj | 39 +++++++++++++ Owl.NetStandard.sln | 55 +++++++++++++++++++ .../ConExcelPlayground.NetStandard.csproj | 22 ++++++++ .../ConWordChunk.NetStandard.csproj | 22 ++++++++ .../ConWordPlayground.NetStandard.csproj | 22 ++++++++ 5 files changed, 160 insertions(+) create mode 100644 Core/Owl/Owl.NetStandard.csproj create mode 100644 Owl.NetStandard.sln create mode 100644 Playground/ConExcelPlayground/ConExcelPlayground.NetStandard.csproj create mode 100644 Playground/ConWordChunk/ConWordChunk.NetStandard.csproj create mode 100644 Playground/ConWordPlayground/ConWordPlayground.NetStandard.csproj diff --git a/Core/Owl/Owl.NetStandard.csproj b/Core/Owl/Owl.NetStandard.csproj new file mode 100644 index 0000000..85713bc --- /dev/null +++ b/Core/Owl/Owl.NetStandard.csproj @@ -0,0 +1,39 @@ + + + + netstandard2.0 + Owl + Owl + true + false + 1.5.0 + Fernando Henrique Inocêncio Borba Ferreira,Felipe Fujiy Pessoto + Owl.OpenXml.NetStandard + Owl OpenXml Office Word + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Owl.NetStandard.sln b/Owl.NetStandard.sln new file mode 100644 index 0000000..9eff5b3 --- /dev/null +++ b/Owl.NetStandard.sln @@ -0,0 +1,55 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2036 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{05447806-83E9-4413-BB87-26D5F5448BE6}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Playground", "Playground", "{5758B0BE-B15E-49D1-8AF4-A431840FE67C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Documents", ".Documents", "{D9C94C78-AAC7-4C9F-A47C-416E50014378}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Owl.NetStandard", "Core\Owl\Owl.NetStandard.csproj", "{C85FCBB9-BFDC-4AEC-B882-4A9FB3116783}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConWordPlayground.NetStandard", "Playground\ConWordPlayground\ConWordPlayground.NetStandard.csproj", "{103692A9-0976-444D-8482-3FABC07BF9F3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConWordChunk.NetStandard", "Playground\ConWordChunk\ConWordChunk.NetStandard.csproj", "{A37BB72B-69A8-4429-9472-E736799F9863}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConExcelPlayground.NetStandard", "Playground\ConExcelPlayground\ConExcelPlayground.NetStandard.csproj", "{025BE9E2-624C-48EA-90B8-3442E5E60B13}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C85FCBB9-BFDC-4AEC-B882-4A9FB3116783}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C85FCBB9-BFDC-4AEC-B882-4A9FB3116783}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C85FCBB9-BFDC-4AEC-B882-4A9FB3116783}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C85FCBB9-BFDC-4AEC-B882-4A9FB3116783}.Release|Any CPU.Build.0 = Release|Any CPU + {103692A9-0976-444D-8482-3FABC07BF9F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {103692A9-0976-444D-8482-3FABC07BF9F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {103692A9-0976-444D-8482-3FABC07BF9F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {103692A9-0976-444D-8482-3FABC07BF9F3}.Release|Any CPU.Build.0 = Release|Any CPU + {A37BB72B-69A8-4429-9472-E736799F9863}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A37BB72B-69A8-4429-9472-E736799F9863}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A37BB72B-69A8-4429-9472-E736799F9863}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A37BB72B-69A8-4429-9472-E736799F9863}.Release|Any CPU.Build.0 = Release|Any CPU + {025BE9E2-624C-48EA-90B8-3442E5E60B13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {025BE9E2-624C-48EA-90B8-3442E5E60B13}.Debug|Any CPU.Build.0 = Debug|Any CPU + {025BE9E2-624C-48EA-90B8-3442E5E60B13}.Release|Any CPU.ActiveCfg = Release|Any CPU + {025BE9E2-624C-48EA-90B8-3442E5E60B13}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {C85FCBB9-BFDC-4AEC-B882-4A9FB3116783} = {05447806-83E9-4413-BB87-26D5F5448BE6} + {103692A9-0976-444D-8482-3FABC07BF9F3} = {5758B0BE-B15E-49D1-8AF4-A431840FE67C} + {A37BB72B-69A8-4429-9472-E736799F9863} = {5758B0BE-B15E-49D1-8AF4-A431840FE67C} + {025BE9E2-624C-48EA-90B8-3442E5E60B13} = {5758B0BE-B15E-49D1-8AF4-A431840FE67C} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B3469F1C-ACA8-4C48-9011-AF0B8190704D} + EndGlobalSection +EndGlobal diff --git a/Playground/ConExcelPlayground/ConExcelPlayground.NetStandard.csproj b/Playground/ConExcelPlayground/ConExcelPlayground.NetStandard.csproj new file mode 100644 index 0000000..2cd8667 --- /dev/null +++ b/Playground/ConExcelPlayground/ConExcelPlayground.NetStandard.csproj @@ -0,0 +1,22 @@ + + + + netstandard2.0 + ConExcelPlayground + ConExcelPlayground + true + + + + + + + + + + + + + + + diff --git a/Playground/ConWordChunk/ConWordChunk.NetStandard.csproj b/Playground/ConWordChunk/ConWordChunk.NetStandard.csproj new file mode 100644 index 0000000..de86fcf --- /dev/null +++ b/Playground/ConWordChunk/ConWordChunk.NetStandard.csproj @@ -0,0 +1,22 @@ + + + + netstandard2.0 + ConWordChunk + ConWordChunk + true + + + + + + + + + + + + + + + diff --git a/Playground/ConWordPlayground/ConWordPlayground.NetStandard.csproj b/Playground/ConWordPlayground/ConWordPlayground.NetStandard.csproj new file mode 100644 index 0000000..1288684 --- /dev/null +++ b/Playground/ConWordPlayground/ConWordPlayground.NetStandard.csproj @@ -0,0 +1,22 @@ + + + + netstandard2.0 + ConWordPlayground + ConWordPlayground + true + + + + + + + + + + + + + + + From 62a8e01e722cf15b886eff786103aeed781c3fb0 Mon Sep 17 00:00:00 2001 From: Christiano Donke Date: Wed, 21 Mar 2018 14:40:33 -0300 Subject: [PATCH 2/7] System.Drawing Replacement --- Core/Owl/Drawing/Color.cs | 2191 +++++++++++++++++++++++++++ Core/Owl/Drawing/ColorConverter.cs | 100 ++ Core/Owl/Drawing/ColorTranslator.cs | 75 + Core/Owl/Drawing/KnownColor.cs | 894 +++++++++++ Core/Owl/Drawing/KnownColorTable.cs | 464 ++++++ Core/Owl/Drawing/SystemColors.cs | 418 +++++ 6 files changed, 4142 insertions(+) create mode 100644 Core/Owl/Drawing/Color.cs create mode 100644 Core/Owl/Drawing/ColorConverter.cs create mode 100644 Core/Owl/Drawing/ColorTranslator.cs create mode 100644 Core/Owl/Drawing/KnownColor.cs create mode 100644 Core/Owl/Drawing/KnownColorTable.cs create mode 100644 Core/Owl/Drawing/SystemColors.cs diff --git a/Core/Owl/Drawing/Color.cs b/Core/Owl/Drawing/Color.cs new file mode 100644 index 0000000..55693d1 --- /dev/null +++ b/Core/Owl/Drawing/Color.cs @@ -0,0 +1,2191 @@ +using System.Globalization; +using System.Text; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System; + +namespace Owl.Drawing +{ + + /// + /// + /// Represents an ARGB color. + /// + public struct Color + { + /// + /// + /// [To be supplied.] + /// + public static readonly Color Empty = new Color(); + + // ------------------------------------------------------------------- + // static list of "web" colors... + // + /// + /// + /// [To be supplied.] + /// + public static Color Transparent + { + get + { + return new Color(KnownColor.Transparent); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color AliceBlue + { + get + { + return new Color(KnownColor.AliceBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color AntiqueWhite + { + get + { + return new Color(KnownColor.AntiqueWhite); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Aqua + { + get + { + return new Color(KnownColor.Aqua); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Aquamarine + { + get + { + return new Color(KnownColor.Aquamarine); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Azure + { + get + { + return new Color(KnownColor.Azure); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Beige + { + get + { + return new Color(KnownColor.Beige); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Bisque + { + get + { + return new Color(KnownColor.Bisque); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Black + { + get + { + return new Color(KnownColor.Black); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color BlanchedAlmond + { + get + { + return new Color(KnownColor.BlanchedAlmond); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Blue + { + get + { + return new Color(KnownColor.Blue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color BlueViolet + { + get + { + return new Color(KnownColor.BlueViolet); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Brown + { + get + { + return new Color(KnownColor.Brown); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color BurlyWood + { + get + { + return new Color(KnownColor.BurlyWood); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color CadetBlue + { + get + { + return new Color(KnownColor.CadetBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Chartreuse + { + get + { + return new Color(KnownColor.Chartreuse); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Chocolate + { + get + { + return new Color(KnownColor.Chocolate); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Coral + { + get + { + return new Color(KnownColor.Coral); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color CornflowerBlue + { + get + { + return new Color(KnownColor.CornflowerBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Cornsilk + { + get + { + return new Color(KnownColor.Cornsilk); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Crimson + { + get + { + return new Color(KnownColor.Crimson); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Cyan + { + get + { + return new Color(KnownColor.Cyan); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkBlue + { + get + { + return new Color(KnownColor.DarkBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkCyan + { + get + { + return new Color(KnownColor.DarkCyan); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkGoldenrod + { + get + { + return new Color(KnownColor.DarkGoldenrod); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkGray + { + get + { + return new Color(KnownColor.DarkGray); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkGreen + { + get + { + return new Color(KnownColor.DarkGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkKhaki + { + get + { + return new Color(KnownColor.DarkKhaki); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkMagenta + { + get + { + return new Color(KnownColor.DarkMagenta); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkOliveGreen + { + get + { + return new Color(KnownColor.DarkOliveGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkOrange + { + get + { + return new Color(KnownColor.DarkOrange); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkOrchid + { + get + { + return new Color(KnownColor.DarkOrchid); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkRed + { + get + { + return new Color(KnownColor.DarkRed); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkSalmon + { + get + { + return new Color(KnownColor.DarkSalmon); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkSeaGreen + { + get + { + return new Color(KnownColor.DarkSeaGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkSlateBlue + { + get + { + return new Color(KnownColor.DarkSlateBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkSlateGray + { + get + { + return new Color(KnownColor.DarkSlateGray); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkTurquoise + { + get + { + return new Color(KnownColor.DarkTurquoise); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DarkViolet + { + get + { + return new Color(KnownColor.DarkViolet); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DeepPink + { + get + { + return new Color(KnownColor.DeepPink); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DeepSkyBlue + { + get + { + return new Color(KnownColor.DeepSkyBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DimGray + { + get + { + return new Color(KnownColor.DimGray); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color DodgerBlue + { + get + { + return new Color(KnownColor.DodgerBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Firebrick + { + get + { + return new Color(KnownColor.Firebrick); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color FloralWhite + { + get + { + return new Color(KnownColor.FloralWhite); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color ForestGreen + { + get + { + return new Color(KnownColor.ForestGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Fuchsia + { + get + { + return new Color(KnownColor.Fuchsia); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Gainsboro + { + get + { + return new Color(KnownColor.Gainsboro); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color GhostWhite + { + get + { + return new Color(KnownColor.GhostWhite); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Gold + { + get + { + return new Color(KnownColor.Gold); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Goldenrod + { + get + { + return new Color(KnownColor.Goldenrod); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Gray + { + get + { + return new Color(KnownColor.Gray); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Green + { + get + { + return new Color(KnownColor.Green); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color GreenYellow + { + get + { + return new Color(KnownColor.GreenYellow); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Honeydew + { + get + { + return new Color(KnownColor.Honeydew); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color HotPink + { + get + { + return new Color(KnownColor.HotPink); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color IndianRed + { + get + { + return new Color(KnownColor.IndianRed); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Indigo + { + get + { + return new Color(KnownColor.Indigo); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Ivory + { + get + { + return new Color(KnownColor.Ivory); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Khaki + { + get + { + return new Color(KnownColor.Khaki); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Lavender + { + get + { + return new Color(KnownColor.Lavender); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LavenderBlush + { + get + { + return new Color(KnownColor.LavenderBlush); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LawnGreen + { + get + { + return new Color(KnownColor.LawnGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LemonChiffon + { + get + { + return new Color(KnownColor.LemonChiffon); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightBlue + { + get + { + return new Color(KnownColor.LightBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightCoral + { + get + { + return new Color(KnownColor.LightCoral); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightCyan + { + get + { + return new Color(KnownColor.LightCyan); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightGoldenrodYellow + { + get + { + return new Color(KnownColor.LightGoldenrodYellow); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightGreen + { + get + { + return new Color(KnownColor.LightGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightGray + { + get + { + return new Color(KnownColor.LightGray); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightPink + { + get + { + return new Color(KnownColor.LightPink); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightSalmon + { + get + { + return new Color(KnownColor.LightSalmon); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightSeaGreen + { + get + { + return new Color(KnownColor.LightSeaGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightSkyBlue + { + get + { + return new Color(KnownColor.LightSkyBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightSlateGray + { + get + { + return new Color(KnownColor.LightSlateGray); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightSteelBlue + { + get + { + return new Color(KnownColor.LightSteelBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LightYellow + { + get + { + return new Color(KnownColor.LightYellow); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Lime + { + get + { + return new Color(KnownColor.Lime); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color LimeGreen + { + get + { + return new Color(KnownColor.LimeGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Linen + { + get + { + return new Color(KnownColor.Linen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Magenta + { + get + { + return new Color(KnownColor.Magenta); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Maroon + { + get + { + return new Color(KnownColor.Maroon); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MediumAquamarine + { + get + { + return new Color(KnownColor.MediumAquamarine); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MediumBlue + { + get + { + return new Color(KnownColor.MediumBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MediumOrchid + { + get + { + return new Color(KnownColor.MediumOrchid); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MediumPurple + { + get + { + return new Color(KnownColor.MediumPurple); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MediumSeaGreen + { + get + { + return new Color(KnownColor.MediumSeaGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MediumSlateBlue + { + get + { + return new Color(KnownColor.MediumSlateBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MediumSpringGreen + { + get + { + return new Color(KnownColor.MediumSpringGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MediumTurquoise + { + get + { + return new Color(KnownColor.MediumTurquoise); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MediumVioletRed + { + get + { + return new Color(KnownColor.MediumVioletRed); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MidnightBlue + { + get + { + return new Color(KnownColor.MidnightBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MintCream + { + get + { + return new Color(KnownColor.MintCream); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color MistyRose + { + get + { + return new Color(KnownColor.MistyRose); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Moccasin + { + get + { + return new Color(KnownColor.Moccasin); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color NavajoWhite + { + get + { + return new Color(KnownColor.NavajoWhite); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Navy + { + get + { + return new Color(KnownColor.Navy); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color OldLace + { + get + { + return new Color(KnownColor.OldLace); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Olive + { + get + { + return new Color(KnownColor.Olive); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color OliveDrab + { + get + { + return new Color(KnownColor.OliveDrab); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Orange + { + get + { + return new Color(KnownColor.Orange); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color OrangeRed + { + get + { + return new Color(KnownColor.OrangeRed); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Orchid + { + get + { + return new Color(KnownColor.Orchid); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color PaleGoldenrod + { + get + { + return new Color(KnownColor.PaleGoldenrod); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color PaleGreen + { + get + { + return new Color(KnownColor.PaleGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color PaleTurquoise + { + get + { + return new Color(KnownColor.PaleTurquoise); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color PaleVioletRed + { + get + { + return new Color(KnownColor.PaleVioletRed); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color PapayaWhip + { + get + { + return new Color(KnownColor.PapayaWhip); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color PeachPuff + { + get + { + return new Color(KnownColor.PeachPuff); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Peru + { + get + { + return new Color(KnownColor.Peru); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Pink + { + get + { + return new Color(KnownColor.Pink); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Plum + { + get + { + return new Color(KnownColor.Plum); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color PowderBlue + { + get + { + return new Color(KnownColor.PowderBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Purple + { + get + { + return new Color(KnownColor.Purple); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Red + { + get + { + return new Color(KnownColor.Red); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color RosyBrown + { + get + { + return new Color(KnownColor.RosyBrown); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color RoyalBlue + { + get + { + return new Color(KnownColor.RoyalBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color SaddleBrown + { + get + { + return new Color(KnownColor.SaddleBrown); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Salmon + { + get + { + return new Color(KnownColor.Salmon); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color SandyBrown + { + get + { + return new Color(KnownColor.SandyBrown); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color SeaGreen + { + get + { + return new Color(KnownColor.SeaGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color SeaShell + { + get + { + return new Color(KnownColor.SeaShell); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Sienna + { + get + { + return new Color(KnownColor.Sienna); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Silver + { + get + { + return new Color(KnownColor.Silver); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color SkyBlue + { + get + { + return new Color(KnownColor.SkyBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color SlateBlue + { + get + { + return new Color(KnownColor.SlateBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color SlateGray + { + get + { + return new Color(KnownColor.SlateGray); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Snow + { + get + { + return new Color(KnownColor.Snow); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color SpringGreen + { + get + { + return new Color(KnownColor.SpringGreen); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color SteelBlue + { + get + { + return new Color(KnownColor.SteelBlue); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Tan + { + get + { + return new Color(KnownColor.Tan); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Teal + { + get + { + return new Color(KnownColor.Teal); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Thistle + { + get + { + return new Color(KnownColor.Thistle); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Tomato + { + get + { + return new Color(KnownColor.Tomato); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Turquoise + { + get + { + return new Color(KnownColor.Turquoise); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Violet + { + get + { + return new Color(KnownColor.Violet); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Wheat + { + get + { + return new Color(KnownColor.Wheat); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color White + { + get + { + return new Color(KnownColor.White); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color WhiteSmoke + { + get + { + return new Color(KnownColor.WhiteSmoke); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color Yellow + { + get + { + return new Color(KnownColor.Yellow); + } + } + /// + /// + /// [To be supplied.] + /// + public static Color YellowGreen + { + get + { + return new Color(KnownColor.YellowGreen); + } + } + // + // end "web" colors + // ------------------------------------------------------------------- + + // NOTE : The "zero" pattern (all members being 0) must represent + // : "not set". This allows "Color c;" to be correct. + + private static short StateKnownColorValid = 0x0001; + private static short StateARGBValueValid = 0x0002; + private static short StateValueMask = (short)(StateARGBValueValid); + private static short StateNameValid = 0x0008; + private static long NotDefinedValue = 0; + + /** + * Shift count and bit mask for A, R, G, B components in ARGB mode! + */ + private const int ARGBAlphaShift = 24; + private const int ARGBRedShift = 16; + private const int ARGBGreenShift = 8; + private const int ARGBBlueShift = 0; + + /// WARNING!!! WARNING!!! WARNING!!! WARNING!!! + /// WARNING!!! WARNING!!! WARNING!!! WARNING!!! + /// We can never change the layout of this class (adding or removing or changing the + /// order of member variables) if you want to be compatible v1.0 version of the runtime. + /// This is so that we can push into the runtime a custom marshaller for OLE_COLOR to Color. + + // user supplied name of color. Will not be filled in if + // we map to a "knowncolor" + // + private readonly string name; + + // will contain standard 32bit sRGB (ARGB) + // + private readonly long value; + + // ignored, unless "state" says it is valid + // + private readonly short knownColor; + + // implementation specific information + // + private readonly short state; + + + internal Color(KnownColor knownColor) : this((long)knownColor, StateKnownColorValid, knownColor.ToString(), knownColor) + { } + + private Color(long value, short state, string name, KnownColor knownColor) + { + this.value = value; + this.state = state; + this.name = name; + this.knownColor = unchecked((short)knownColor); + } + + /// + /// + /// Gets the red component value for this . + /// + public byte R + { + get + { + return (byte)((Value >> ARGBRedShift) & 0xFF); + } + } + + /// + /// + /// Gets the green component value for this . + /// + public byte G + { + get + { + return (byte)((Value >> ARGBGreenShift) & 0xFF); + } + } + + /// + /// + /// + /// Gets the blue component value for this . + /// + /// + public byte B + { + get + { + return (byte)((Value >> ARGBBlueShift) & 0xFF); + } + } + + /// + /// + /// + /// Gets the alpha component value for this . + /// + /// + public byte A + { + get + { + return (byte)((Value >> ARGBAlphaShift) & 0xFF); + } + } + + /// + /// + /// + /// Specifies whether this is a known (predefined) color. + /// Predefined colors are defined in the + /// enum. + /// + /// + public bool IsKnownColor + { + get + { + return ((state & StateKnownColorValid) != 0); + } + } + + /// + /// + /// Specifies whether this is uninitialized. + /// + public bool IsEmpty + { + get + { + return state == 0; + } + } + + /// + /// + /// Specifies whether this has a name or is a . + /// + public bool IsNamedColor + { + get + { + return ((state & StateNameValid) != 0) || IsKnownColor; + } + } + + /// + /// + /// Determines if this color is a system color. + /// + public bool IsSystemColor + { + get + { + return IsKnownColor && ((((KnownColor)knownColor) <= KnownColor.WindowText) || (((KnownColor)knownColor) > KnownColor.YellowGreen)); + } + } + + // Not localized because it's only used for the DebuggerDisplayAttribute, and the values are + // programmatic items. + // Also, don't inline into the attribute for performance reasons. This way means the debugger + // does 1 func-eval instead of 5. + [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters")] + private string NameAndARGBValue + { + get + { + return string.Format(CultureInfo.CurrentCulture, + "{{Name={0}, ARGB=({1}, {2}, {3}, {4})}}", + Name, A, R, G, B); + } + } + + /// + /// + /// + /// Gets the name of this . This will either return the user + /// defined name of the color, if the color was created from a name, or + /// the name of the known color. For custom colors, the RGB value will + /// be returned. + /// + /// + public string Name + { + get + { + if ((state & StateNameValid) != 0) + { + return name; + } + + if (IsKnownColor) + { + // first try the table so we can avoid the (slow!) .ToString() + string tablename = KnownColorTable.KnownColorToName((KnownColor)knownColor); + if (tablename != null) + return tablename; + + Debug.Assert(false, "Could not find known color '" + ((KnownColor)knownColor) + "' in the KnownColorTable"); + + return ((KnownColor)knownColor).ToString(); + } + + // if we reached here, just encode the value + // + return Convert.ToString(value, 16); + } + } + + /// + /// + /// Actual color to be rendered. + /// + private long Value + { + get + { + if ((state & StateValueMask) != 0) + { + return value; + } + if (IsKnownColor) + { + return unchecked((int)KnownColorTable.KnownColorToArgb((KnownColor)knownColor)); + } + + return NotDefinedValue; + } + } + + private static void CheckByte(int value, string name) + { + if (value < 0 || value > 255) + throw new ArgumentException("InvalidEx2BoundArgument", nameof(value)); + } + + /// + /// + /// Encodes the four values into ARGB (32 bit) format. + /// + private static long MakeArgb(byte alpha, byte red, byte green, byte blue) + { + return (long)(unchecked((uint)(red << ARGBRedShift | + green << ARGBGreenShift | + blue << ARGBBlueShift | + alpha << ARGBAlphaShift))) & 0xffffffff; + } + + /// + /// + /// + /// Creates a Color from its 32-bit component + /// (alpha, red, green, and blue) values. + /// + /// + public static Color FromArgb(int argb) + { + return new Color((long)argb & 0xffffffff, StateARGBValueValid, null, (KnownColor)0); + } + + /// + /// + /// + /// Creates a Color from its 32-bit component (alpha, red, + /// green, and blue) values. + /// + /// + public static Color FromArgb(int alpha, int red, int green, int blue) + { + CheckByte(alpha, "alpha"); + CheckByte(red, "red"); + CheckByte(green, "green"); + CheckByte(blue, "blue"); + return new Color(MakeArgb((byte)alpha, (byte)red, (byte)green, (byte)blue), StateARGBValueValid, null, (KnownColor)0); + } + + /// + /// + /// + /// Creates a new from the specified , but with + /// the new specified alpha value. + /// + /// + public static Color FromArgb(int alpha, Color baseColor) + { + CheckByte(alpha, "alpha"); + // unchecked - because we already checked that alpha is a byte in CheckByte above + return new Color(MakeArgb(unchecked((byte)alpha), baseColor.R, baseColor.G, baseColor.B), StateARGBValueValid, null, (KnownColor)0); + } + + /// + /// + /// + /// Creates a from the specified red, green, and + /// blue values. + /// + /// + public static Color FromArgb(int red, int green, int blue) + { + return FromArgb(255, red, green, blue); + } + + /// + /// + /// + /// Creates a from the specified . + /// + /// + public static Color FromKnownColor(KnownColor color) + { + if (!IsEnumValid(color, unchecked((int)color), (int)KnownColor.ActiveBorder, (int)KnownColor.MenuHighlight)) + { + return Color.FromName(color.ToString()); + } + return new Color(color); + } + + private static bool IsEnumValid(Enum enumValue, int value, int minValue, int maxValue) + { + bool valid = (value >= minValue) && (value <= maxValue); + return valid; + } + + /// + /// + /// + /// Creates a with the specified name. + /// + /// + public static Color FromName(string name) + { + // try to get a known color first + object color = ColorConverter.GetNamedColor(name); + if (color != null) + { + return (Color)color; + } + // otherwise treat it as a named color + return new Color(NotDefinedValue, StateNameValid, name, (KnownColor)0); + } + + /// + /// + /// + /// Returns the Hue-Saturation-Brightness (HSB) brightness + /// for this . + /// + /// + public float GetBrightness() + { + float r = (float)R / 255.0f; + float g = (float)G / 255.0f; + float b = (float)B / 255.0f; + + float max, min; + + max = r; min = r; + + if (g > max) max = g; + if (b > max) max = b; + + if (g < min) min = g; + if (b < min) min = b; + + return (max + min) / 2; + } + + + /// + /// + /// + /// Returns the Hue-Saturation-Brightness (HSB) hue + /// value, in degrees, for this . + /// If R == G == B, the hue is meaningless, and the return value is 0. + /// + /// + public Single GetHue() + { + if (R == G && G == B) + return 0; // 0 makes as good an UNDEFINED value as any + + float r = (float)R / 255.0f; + float g = (float)G / 255.0f; + float b = (float)B / 255.0f; + + float max, min; + float delta; + float hue = 0.0f; + + max = r; min = r; + + if (g > max) max = g; + if (b > max) max = b; + + if (g < min) min = g; + if (b < min) min = b; + + delta = max - min; + + if (r == max) + { + hue = (g - b) / delta; + } + else if (g == max) + { + hue = 2 + (b - r) / delta; + } + else if (b == max) + { + hue = 4 + (r - g) / delta; + } + hue *= 60; + + if (hue < 0.0f) + { + hue += 360.0f; + } + return hue; + } + + /// + /// + /// + /// The Hue-Saturation-Brightness (HSB) saturation for this + /// + /// . + /// + /// + public float GetSaturation() + { + float r = (float)R / 255.0f; + float g = (float)G / 255.0f; + float b = (float)B / 255.0f; + + float max, min; + float l, s = 0; + + max = r; min = r; + + if (g > max) max = g; + if (b > max) max = b; + + if (g < min) min = g; + if (b < min) min = b; + + // if max == min, then there is no color and + // the saturation is zero. + // + if (max != min) + { + l = (max + min) / 2; + + if (l <= .5) + { + s = (max - min) / (max + min); + } + else + { + s = (max - min) / (2 - max - min); + } + } + return s; + } + + /// + /// + /// + /// Returns the ARGB value of this . + /// + /// + public int ToArgb() + { + return unchecked((int)Value); + } + + /// + /// + /// + /// Returns the value for this color, if it is + /// based on a . + /// + /// + public KnownColor ToKnownColor() + { + return (KnownColor)knownColor; + } + + /// + /// + /// Converts this to a human-readable + /// string. + /// + public override string ToString() + { + StringBuilder sb = new StringBuilder(32); + sb.Append(GetType().Name); + sb.Append(" ["); + + if ((state & StateNameValid) != 0) + { + sb.Append(Name); + } + else if ((state & StateKnownColorValid) != 0) + { + sb.Append(Name); + } + else if ((state & StateValueMask) != 0) + { + sb.Append("A="); + sb.Append(A); + sb.Append(", R="); + sb.Append(R); + sb.Append(", G="); + sb.Append(G); + sb.Append(", B="); + sb.Append(B); + } + else + { + sb.Append("Empty"); + } + + + sb.Append("]"); + + return sb.ToString(); + } + + /// + /// + /// + /// Tests whether two specified objects + /// are equivalent. + /// + /// + public static bool operator ==(Color left, Color right) + { + if (left.value == right.value + && left.state == right.state + && left.knownColor == right.knownColor) + { + + if (left.name == right.name) + { + return true; + } + + if (left.name == (object)null || right.name == (object)null) + { + return false; + } + + return left.name.Equals(right.name); + } + + return false; + } + + /// + /// + /// + /// Tests whether two specified objects + /// are equivalent. + /// + /// + public static bool operator !=(Color left, Color right) + { + return !(left == right); + } + + /// + /// + /// Tests whether the specified object is a + /// + /// and is equivalent to this . + /// + public override bool Equals(object obj) + { + if (obj is Color) + { + Color right = (Color)obj; + if (value == right.value + && state == right.state + && knownColor == right.knownColor) + { + + if (name == right.name) + { + return true; + } + + if (name == (object)null || right.name == (object)null) + { + return false; + } + + return name.Equals(name); + } + } + return false; + } + + /// + /// + /// [To be supplied.] + /// + public override int GetHashCode() + { + return unchecked(value.GetHashCode() ^ + state.GetHashCode() ^ + knownColor.GetHashCode()); + } + } +} \ No newline at end of file diff --git a/Core/Owl/Drawing/ColorConverter.cs b/Core/Owl/Drawing/ColorConverter.cs new file mode 100644 index 0000000..a1ce2e5 --- /dev/null +++ b/Core/Owl/Drawing/ColorConverter.cs @@ -0,0 +1,100 @@ +using System.Reflection; +using System.Collections.Generic; +using System; +using System.Linq; + +namespace Owl.Drawing +{ + /// + /// + /// ColorConverter is a class that can be used to convert + /// colors from one data type to another. Access this + /// class through the TypeDescriptor. + /// + public class ColorConverter + { + private static string ColorConstantsLock = "colorConstants"; + private static Dictionary colorConstants; + private static string SystemColorConstantsLock = "systemColorConstants"; + private static Dictionary systemColorConstants; + + internal static object GetNamedColor(string name) + { + object color = null; + // First, check to see if this is a standard name. + // + color = Colors[name]; + if (color != null) + { + return color; + } + // Ok, how about a system color? + // + color = SystemColors[name]; + return color; + } + + private static Dictionary SystemColors + { + get + { + if (systemColorConstants == null) + { + lock (SystemColorConstantsLock) + { + if (systemColorConstants == null) + { + Dictionary tempHash = new Dictionary(StringComparer.OrdinalIgnoreCase); + FillConstants(tempHash, typeof(SystemColors)); + systemColorConstants = tempHash; + } + } + } + + return systemColorConstants; + } + } + + + private static IDictionary Colors + { + get + { + if (colorConstants == null) + { + lock (ColorConstantsLock) + { + if (colorConstants == null) + { + Dictionary tempHash = new Dictionary(StringComparer.OrdinalIgnoreCase); + FillConstants(tempHash, typeof(Color)); + colorConstants = tempHash; + } + } + } + + return colorConstants; + } + } + + private static void FillConstants(Dictionary hash, Type enumType) + { + MethodAttributes attrs = MethodAttributes.Public | MethodAttributes.Static; + PropertyInfo[] props = enumType.GetTypeInfo().DeclaredProperties.ToArray(); + + for (int i = 0; i < props.Length; i++) + { + PropertyInfo prop = props[i]; + if (prop.PropertyType == typeof(Color)) + { + MethodInfo method = prop.GetMethod; + if (method != null && (method.Attributes & attrs) == attrs) + { + object[] tempIndex = null; + hash[prop.Name] = (Color)prop.GetValue(null, tempIndex); + } + } + } + } + } +} diff --git a/Core/Owl/Drawing/ColorTranslator.cs b/Core/Owl/Drawing/ColorTranslator.cs new file mode 100644 index 0000000..3b349c1 --- /dev/null +++ b/Core/Owl/Drawing/ColorTranslator.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Owl.Drawing +{ + class ColorTranslator + { + public static string ToHtml(Color c) + { + string colorString = String.Empty; + + if (c.IsEmpty) + return colorString; + + if (c.IsSystemColor) + { + switch (c.ToKnownColor()) + { + case KnownColor.ActiveBorder: colorString = "activeborder"; break; + case KnownColor.GradientActiveCaption: + case KnownColor.ActiveCaption: colorString = "activecaption"; break; + case KnownColor.AppWorkspace: colorString = "appworkspace"; break; + case KnownColor.Desktop: colorString = "background"; break; + case KnownColor.Control: colorString = "buttonface"; break; + case KnownColor.ControlLight: colorString = "buttonface"; break; + case KnownColor.ControlDark: colorString = "buttonshadow"; break; + case KnownColor.ControlText: colorString = "buttontext"; break; + case KnownColor.ActiveCaptionText: colorString = "captiontext"; break; + case KnownColor.GrayText: colorString = "graytext"; break; + case KnownColor.HotTrack: + case KnownColor.Highlight: colorString = "highlight"; break; + case KnownColor.MenuHighlight: + case KnownColor.HighlightText: colorString = "highlighttext"; break; + case KnownColor.InactiveBorder: colorString = "inactiveborder"; break; + case KnownColor.GradientInactiveCaption: + case KnownColor.InactiveCaption: colorString = "inactivecaption"; break; + case KnownColor.InactiveCaptionText: colorString = "inactivecaptiontext"; break; + case KnownColor.Info: colorString = "infobackground"; break; + case KnownColor.InfoText: colorString = "infotext"; break; + case KnownColor.MenuBar: + case KnownColor.Menu: colorString = "menu"; break; + case KnownColor.MenuText: colorString = "menutext"; break; + case KnownColor.ScrollBar: colorString = "scrollbar"; break; + case KnownColor.ControlDarkDark: colorString = "threeddarkshadow"; break; + case KnownColor.ControlLightLight: colorString = "buttonhighlight"; break; + case KnownColor.Window: colorString = "window"; break; + case KnownColor.WindowFrame: colorString = "windowframe"; break; + case KnownColor.WindowText: colorString = "windowtext"; break; + } + } + else if (c.IsNamedColor && !c.IsKnownColor) + { + if (c == Color.LightGray) + { + // special case due to mismatch between Html and enum spelling + colorString = "LightGrey"; + } + else + { + colorString = c.Name; + } + } + else + { + colorString = "#" + c.R.ToString("X2", null) + + c.G.ToString("X2", null) + + c.B.ToString("X2", null); + } + + return colorString; + } + + } +} diff --git a/Core/Owl/Drawing/KnownColor.cs b/Core/Owl/Drawing/KnownColor.cs new file mode 100644 index 0000000..82d1e88 --- /dev/null +++ b/Core/Owl/Drawing/KnownColor.cs @@ -0,0 +1,894 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Owl.Drawing +{ + public enum KnownColor + { + // This enum is order dependant!!! + // + // The value of these known colors are indexes into a color array. + // Do not modify this enum without updating KnownColorTable. + // + + + // 0 - reserved for "not a known color" + + // "System" colors + /// + /// + /// [To be supplied.] + /// + ActiveBorder = 1, + /// + /// + /// [To be supplied.] + /// + ActiveCaption, + /// + /// + /// [To be supplied.] + /// + ActiveCaptionText, + /// + /// + /// [To be supplied.] + /// + AppWorkspace, + /// + /// + /// [To be supplied.] + /// + Control, + /// + /// + /// [To be supplied.] + /// + ControlDark, + /// + /// + /// [To be supplied.] + /// + ControlDarkDark, + /// + /// + /// [To be supplied.] + /// + ControlLight, + /// + /// + /// [To be supplied.] + /// + ControlLightLight, + /// + /// + /// [To be supplied.] + /// + ControlText, + /// + /// + /// [To be supplied.] + /// + Desktop, + /// + /// + /// [To be supplied.] + /// + GrayText, + /// + /// + /// [To be supplied.] + /// + Highlight, + /// + /// + /// [To be supplied.] + /// + HighlightText, + /// + /// + /// [To be supplied.] + /// + HotTrack, + /// + /// + /// [To be supplied.] + /// + InactiveBorder, + /// + /// + /// [To be supplied.] + /// + InactiveCaption, + /// + /// + /// [To be supplied.] + /// + InactiveCaptionText, + /// + /// + /// [To be supplied.] + /// + Info, + /// + /// + /// [To be supplied.] + /// + InfoText, + /// + /// + /// [To be supplied.] + /// + Menu, + /// + /// + /// [To be supplied.] + /// + MenuText, + /// + /// + /// [To be supplied.] + /// + ScrollBar, + /// + /// + /// [To be supplied.] + /// + Window, + /// + /// + /// [To be supplied.] + /// + WindowFrame, + /// + /// + /// [To be supplied.] + /// + WindowText, + + // "Web" Colors + /// + /// + /// [To be supplied.] + /// + Transparent, + /// + /// + /// [To be supplied.] + /// + AliceBlue, + /// + /// + /// [To be supplied.] + /// + AntiqueWhite, + /// + /// + /// [To be supplied.] + /// + Aqua, + /// + /// + /// [To be supplied.] + /// + Aquamarine, + /// + /// + /// [To be supplied.] + /// + Azure, + /// + /// + /// [To be supplied.] + /// + Beige, + /// + /// + /// [To be supplied.] + /// + Bisque, + /// + /// + /// [To be supplied.] + /// + Black, + /// + /// + /// [To be supplied.] + /// + BlanchedAlmond, + /// + /// + /// [To be supplied.] + /// + Blue, + /// + /// + /// [To be supplied.] + /// + BlueViolet, + /// + /// + /// [To be supplied.] + /// + Brown, + /// + /// + /// [To be supplied.] + /// + BurlyWood, + /// + /// + /// [To be supplied.] + /// + CadetBlue, + /// + /// + /// [To be supplied.] + /// + Chartreuse, + /// + /// + /// [To be supplied.] + /// + Chocolate, + /// + /// + /// [To be supplied.] + /// + Coral, + /// + /// + /// [To be supplied.] + /// + CornflowerBlue, + /// + /// + /// [To be supplied.] + /// + Cornsilk, + /// + /// + /// [To be supplied.] + /// + Crimson, + /// + /// + /// [To be supplied.] + /// + Cyan, + /// + /// + /// [To be supplied.] + /// + DarkBlue, + /// + /// + /// [To be supplied.] + /// + DarkCyan, + /// + /// + /// [To be supplied.] + /// + DarkGoldenrod, + /// + /// + /// [To be supplied.] + /// + DarkGray, + /// + /// + /// [To be supplied.] + /// + DarkGreen, + /// + /// + /// [To be supplied.] + /// + DarkKhaki, + /// + /// + /// [To be supplied.] + /// + DarkMagenta, + /// + /// + /// [To be supplied.] + /// + DarkOliveGreen, + /// + /// + /// [To be supplied.] + /// + DarkOrange, + /// + /// + /// [To be supplied.] + /// + DarkOrchid, + /// + /// + /// [To be supplied.] + /// + DarkRed, + /// + /// + /// [To be supplied.] + /// + DarkSalmon, + /// + /// + /// [To be supplied.] + /// + DarkSeaGreen, + /// + /// + /// [To be supplied.] + /// + DarkSlateBlue, + /// + /// + /// [To be supplied.] + /// + DarkSlateGray, + /// + /// + /// [To be supplied.] + /// + DarkTurquoise, + /// + /// + /// [To be supplied.] + /// + DarkViolet, + /// + /// + /// [To be supplied.] + /// + DeepPink, + /// + /// + /// [To be supplied.] + /// + DeepSkyBlue, + /// + /// + /// [To be supplied.] + /// + DimGray, + /// + /// + /// [To be supplied.] + /// + DodgerBlue, + /// + /// + /// [To be supplied.] + /// + Firebrick, + /// + /// + /// [To be supplied.] + /// + FloralWhite, + /// + /// + /// [To be supplied.] + /// + ForestGreen, + /// + /// + /// [To be supplied.] + /// + Fuchsia, + /// + /// + /// [To be supplied.] + /// + Gainsboro, + /// + /// + /// [To be supplied.] + /// + GhostWhite, + /// + /// + /// [To be supplied.] + /// + Gold, + /// + /// + /// [To be supplied.] + /// + Goldenrod, + /// + /// + /// [To be supplied.] + /// + Gray, + /// + /// + /// [To be supplied.] + /// + Green, + /// + /// + /// [To be supplied.] + /// + GreenYellow, + /// + /// + /// [To be supplied.] + /// + Honeydew, + /// + /// + /// [To be supplied.] + /// + HotPink, + /// + /// + /// [To be supplied.] + /// + IndianRed, + /// + /// + /// [To be supplied.] + /// + Indigo, + /// + /// + /// [To be supplied.] + /// + Ivory, + /// + /// + /// [To be supplied.] + /// + Khaki, + /// + /// + /// [To be supplied.] + /// + Lavender, + /// + /// + /// [To be supplied.] + /// + LavenderBlush, + /// + /// + /// [To be supplied.] + /// + LawnGreen, + /// + /// + /// [To be supplied.] + /// + LemonChiffon, + /// + /// + /// [To be supplied.] + /// + LightBlue, + /// + /// + /// [To be supplied.] + /// + LightCoral, + /// + /// + /// [To be supplied.] + /// + LightCyan, + /// + /// + /// [To be supplied.] + /// + LightGoldenrodYellow, + /// + /// + /// [To be supplied.] + /// + LightGray, + /// + /// + /// [To be supplied.] + /// + LightGreen, + /// + /// + /// [To be supplied.] + /// + LightPink, + /// + /// + /// [To be supplied.] + /// + LightSalmon, + /// + /// + /// [To be supplied.] + /// + LightSeaGreen, + /// + /// + /// [To be supplied.] + /// + LightSkyBlue, + /// + /// + /// [To be supplied.] + /// + LightSlateGray, + /// + /// + /// [To be supplied.] + /// + LightSteelBlue, + /// + /// + /// [To be supplied.] + /// + LightYellow, + /// + /// + /// [To be supplied.] + /// + Lime, + /// + /// + /// [To be supplied.] + /// + LimeGreen, + /// + /// + /// [To be supplied.] + /// + Linen, + /// + /// + /// [To be supplied.] + /// + Magenta, + /// + /// + /// [To be supplied.] + /// + Maroon, + /// + /// + /// [To be supplied.] + /// + MediumAquamarine, + /// + /// + /// [To be supplied.] + /// + MediumBlue, + /// + /// + /// [To be supplied.] + /// + MediumOrchid, + /// + /// + /// [To be supplied.] + /// + MediumPurple, + /// + /// + /// [To be supplied.] + /// + MediumSeaGreen, + /// + /// + /// [To be supplied.] + /// + MediumSlateBlue, + /// + /// + /// [To be supplied.] + /// + MediumSpringGreen, + /// + /// + /// [To be supplied.] + /// + MediumTurquoise, + /// + /// + /// [To be supplied.] + /// + MediumVioletRed, + /// + /// + /// [To be supplied.] + /// + MidnightBlue, + /// + /// + /// [To be supplied.] + /// + MintCream, + /// + /// + /// [To be supplied.] + /// + MistyRose, + /// + /// + /// [To be supplied.] + /// + Moccasin, + /// + /// + /// [To be supplied.] + /// + NavajoWhite, + /// + /// + /// [To be supplied.] + /// + Navy, + /// + /// + /// [To be supplied.] + /// + OldLace, + /// + /// + /// [To be supplied.] + /// + Olive, + /// + /// + /// [To be supplied.] + /// + OliveDrab, + /// + /// + /// [To be supplied.] + /// + Orange, + /// + /// + /// [To be supplied.] + /// + OrangeRed, + /// + /// + /// [To be supplied.] + /// + Orchid, + /// + /// + /// [To be supplied.] + /// + PaleGoldenrod, + /// + /// + /// [To be supplied.] + /// + PaleGreen, + /// + /// + /// [To be supplied.] + /// + PaleTurquoise, + /// + /// + /// [To be supplied.] + /// + PaleVioletRed, + /// + /// + /// [To be supplied.] + /// + PapayaWhip, + /// + /// + /// [To be supplied.] + /// + PeachPuff, + /// + /// + /// [To be supplied.] + /// + Peru, + /// + /// + /// [To be supplied.] + /// + Pink, + /// + /// + /// [To be supplied.] + /// + Plum, + /// + /// + /// [To be supplied.] + /// + PowderBlue, + /// + /// + /// [To be supplied.] + /// + Purple, + /// + /// + /// [To be supplied.] + /// + Red, + /// + /// + /// [To be supplied.] + /// + RosyBrown, + /// + /// + /// [To be supplied.] + /// + RoyalBlue, + /// + /// + /// [To be supplied.] + /// + SaddleBrown, + /// + /// + /// [To be supplied.] + /// + Salmon, + /// + /// + /// [To be supplied.] + /// + SandyBrown, + /// + /// + /// [To be supplied.] + /// + SeaGreen, + /// + /// + /// [To be supplied.] + /// + SeaShell, + /// + /// + /// [To be supplied.] + /// + Sienna, + /// + /// + /// [To be supplied.] + /// + Silver, + /// + /// + /// [To be supplied.] + /// + SkyBlue, + /// + /// + /// [To be supplied.] + /// + SlateBlue, + /// + /// + /// [To be supplied.] + /// + SlateGray, + /// + /// + /// [To be supplied.] + /// + Snow, + /// + /// + /// [To be supplied.] + /// + SpringGreen, + /// + /// + /// [To be supplied.] + /// + SteelBlue, + /// + /// + /// [To be supplied.] + /// + Tan, + /// + /// + /// [To be supplied.] + /// + Teal, + /// + /// + /// [To be supplied.] + /// + Thistle, + /// + /// + /// [To be supplied.] + /// + Tomato, + /// + /// + /// [To be supplied.] + /// + Turquoise, + /// + /// + /// [To be supplied.] + /// + Violet, + /// + /// + /// [To be supplied.] + /// + Wheat, + /// + /// + /// [To be supplied.] + /// + White, + /// + /// + /// [To be supplied.] + /// + WhiteSmoke, + /// + /// + /// [To be supplied.] + /// + Yellow, + /// + /// + /// [To be supplied.] + /// + YellowGreen, + + // NEW ADDITIONS IN WHIDBEY - DO NOT MOVE THESE UP OR IT WILL BE A BREAKING CHANGE + + /// + /// + /// [To be supplied.] + /// + ButtonFace, + /// + /// + /// [To be supplied.] + /// + ButtonHighlight, + /// + /// + /// [To be supplied.] + /// + ButtonShadow, + /// + /// + /// [To be supplied.] + /// + GradientActiveCaption, + /// + /// + /// [To be supplied.] + /// + GradientInactiveCaption, + /// + /// + /// [To be supplied.] + /// + MenuBar, + /// + /// + /// [To be supplied.] + /// + MenuHighlight, + } +} diff --git a/Core/Owl/Drawing/KnownColorTable.cs b/Core/Owl/Drawing/KnownColorTable.cs new file mode 100644 index 0000000..7f3c004 --- /dev/null +++ b/Core/Owl/Drawing/KnownColorTable.cs @@ -0,0 +1,464 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + + +namespace Owl.Drawing +{ + + static internal class KnownColorTable + { + private static int[] colorTable; + private static string[] colorNameTable; + + /** + * Shift count and bit mask for A, R, G, B components + */ + private const int AlphaShift = 24; + private const int RedShift = 16; + private const int GreenShift = 8; + private const int BlueShift = 0; + + private const int Win32RedShift = 0; + private const int Win32GreenShift = 8; + private const int Win32BlueShift = 16; + + public static Color ArgbToKnownColor(int targetARGB) + { + EnsureColorTable(); + for (int index = 0; index < colorTable.Length; ++index) + { + int argb = colorTable[index]; + if (argb == targetARGB) + { + Color color = Color.FromKnownColor((KnownColor)index); + if (!color.IsSystemColor) + return color; + } + } + + return Color.FromArgb(targetARGB); + } + + private static void EnsureColorTable() + { + // no need to lock... worse case is a double create of the table... + // + if (colorTable == null) + { + InitColorTable(); + } + } + + private static void InitColorTable() + { + int[] values = new int[(unchecked((int)KnownColor.MenuHighlight)) + 1]; + + // system + // + UpdateSystemColors(values); + + // just consts... + // + values[(int)KnownColor.Transparent] = 0x00FFFFFF; + values[(int)KnownColor.AliceBlue] = unchecked((int)0xFFF0F8FF); + values[(int)KnownColor.AntiqueWhite] = unchecked((int)0xFFFAEBD7); + values[(int)KnownColor.Aqua] = unchecked((int)0xFF00FFFF); + values[(int)KnownColor.Aquamarine] = unchecked((int)0xFF7FFFD4); + values[(int)KnownColor.Azure] = unchecked((int)0xFFF0FFFF); + values[(int)KnownColor.Beige] = unchecked((int)0xFFF5F5DC); + values[(int)KnownColor.Bisque] = unchecked(unchecked((int)0xFFFFE4C4)); + values[(int)KnownColor.Black] = unchecked((int)0xFF000000); + values[(int)KnownColor.BlanchedAlmond] = unchecked((int)0xFFFFEBCD); + values[(int)KnownColor.Blue] = unchecked((int)0xFF0000FF); + values[(int)KnownColor.BlueViolet] = unchecked((int)0xFF8A2BE2); + values[(int)KnownColor.Brown] = unchecked((int)0xFFA52A2A); + values[(int)KnownColor.BurlyWood] = unchecked((int)0xFFDEB887); + values[(int)KnownColor.CadetBlue] = unchecked((int)0xFF5F9EA0); + values[(int)KnownColor.Chartreuse] = unchecked((int)0xFF7FFF00); + values[(int)KnownColor.Chocolate] = unchecked((int)0xFFD2691E); + values[(int)KnownColor.Coral] = unchecked((int)0xFFFF7F50); + values[(int)KnownColor.CornflowerBlue] = unchecked((int)0xFF6495ED); + values[(int)KnownColor.Cornsilk] = unchecked((int)0xFFFFF8DC); + values[(int)KnownColor.Crimson] = unchecked((int)0xFFDC143C); + values[(int)KnownColor.Cyan] = unchecked((int)0xFF00FFFF); + values[(int)KnownColor.DarkBlue] = unchecked((int)0xFF00008B); + values[(int)KnownColor.DarkCyan] = unchecked((int)0xFF008B8B); + values[(int)KnownColor.DarkGoldenrod] = unchecked((int)0xFFB8860B); + values[(int)KnownColor.DarkGray] = unchecked((int)0xFFA9A9A9); + values[(int)KnownColor.DarkGreen] = unchecked((int)0xFF006400); + values[(int)KnownColor.DarkKhaki] = unchecked((int)0xFFBDB76B); + values[(int)KnownColor.DarkMagenta] = unchecked((int)0xFF8B008B); + values[(int)KnownColor.DarkOliveGreen] = unchecked((int)0xFF556B2F); + values[(int)KnownColor.DarkOrange] = unchecked((int)0xFFFF8C00); + values[(int)KnownColor.DarkOrchid] = unchecked((int)0xFF9932CC); + values[(int)KnownColor.DarkRed] = unchecked((int)0xFF8B0000); + values[(int)KnownColor.DarkSalmon] = unchecked((int)0xFFE9967A); + values[(int)KnownColor.DarkSeaGreen] = unchecked((int)0xFF8FBC8B); + values[(int)KnownColor.DarkSlateBlue] = unchecked((int)0xFF483D8B); + values[(int)KnownColor.DarkSlateGray] = unchecked((int)0xFF2F4F4F); + values[(int)KnownColor.DarkTurquoise] = unchecked((int)0xFF00CED1); + values[(int)KnownColor.DarkViolet] = unchecked((int)0xFF9400D3); + values[(int)KnownColor.DeepPink] = unchecked((int)0xFFFF1493); + values[(int)KnownColor.DeepSkyBlue] = unchecked((int)0xFF00BFFF); + values[(int)KnownColor.DimGray] = unchecked((int)0xFF696969); + values[(int)KnownColor.DodgerBlue] = unchecked((int)0xFF1E90FF); + values[(int)KnownColor.Firebrick] = unchecked((int)0xFFB22222); + values[(int)KnownColor.FloralWhite] = unchecked((int)0xFFFFFAF0); + values[(int)KnownColor.ForestGreen] = unchecked((int)0xFF228B22); + values[(int)KnownColor.Fuchsia] = unchecked((int)0xFFFF00FF); + values[(int)KnownColor.Gainsboro] = unchecked((int)0xFFDCDCDC); + values[(int)KnownColor.GhostWhite] = unchecked((int)0xFFF8F8FF); + values[(int)KnownColor.Gold] = unchecked((int)0xFFFFD700); + values[(int)KnownColor.Goldenrod] = unchecked((int)0xFFDAA520); + values[(int)KnownColor.Gray] = unchecked((int)0xFF808080); + values[(int)KnownColor.Green] = unchecked((int)0xFF008000); + values[(int)KnownColor.GreenYellow] = unchecked((int)0xFFADFF2F); + values[(int)KnownColor.Honeydew] = unchecked((int)0xFFF0FFF0); + values[(int)KnownColor.HotPink] = unchecked((int)0xFFFF69B4); + values[(int)KnownColor.IndianRed] = unchecked((int)0xFFCD5C5C); + values[(int)KnownColor.Indigo] = unchecked((int)0xFF4B0082); + values[(int)KnownColor.Ivory] = unchecked((int)0xFFFFFFF0); + values[(int)KnownColor.Khaki] = unchecked((int)0xFFF0E68C); + values[(int)KnownColor.Lavender] = unchecked((int)0xFFE6E6FA); + values[(int)KnownColor.LavenderBlush] = unchecked((int)0xFFFFF0F5); + values[(int)KnownColor.LawnGreen] = unchecked((int)0xFF7CFC00); + values[(int)KnownColor.LemonChiffon] = unchecked((int)0xFFFFFACD); + values[(int)KnownColor.LightBlue] = unchecked((int)0xFFADD8E6); + values[(int)KnownColor.LightCoral] = unchecked((int)0xFFF08080); + values[(int)KnownColor.LightCyan] = unchecked((int)0xFFE0FFFF); + values[(int)KnownColor.LightGoldenrodYellow] = unchecked((int)0xFFFAFAD2); + values[(int)KnownColor.LightGray] = unchecked((int)0xFFD3D3D3); + values[(int)KnownColor.LightGreen] = unchecked((int)0xFF90EE90); + values[(int)KnownColor.LightPink] = unchecked((int)0xFFFFB6C1); + values[(int)KnownColor.LightSalmon] = unchecked((int)0xFFFFA07A); + values[(int)KnownColor.LightSeaGreen] = unchecked((int)0xFF20B2AA); + values[(int)KnownColor.LightSkyBlue] = unchecked((int)0xFF87CEFA); + values[(int)KnownColor.LightSlateGray] = unchecked((int)0xFF778899); + values[(int)KnownColor.LightSteelBlue] = unchecked((int)0xFFB0C4DE); + values[(int)KnownColor.LightYellow] = unchecked((int)0xFFFFFFE0); + values[(int)KnownColor.Lime] = unchecked((int)0xFF00FF00); + values[(int)KnownColor.LimeGreen] = unchecked((int)0xFF32CD32); + values[(int)KnownColor.Linen] = unchecked((int)0xFFFAF0E6); + values[(int)KnownColor.Magenta] = unchecked((int)0xFFFF00FF); + values[(int)KnownColor.Maroon] = unchecked((int)0xFF800000); + values[(int)KnownColor.MediumAquamarine] = unchecked((int)0xFF66CDAA); + values[(int)KnownColor.MediumBlue] = unchecked((int)0xFF0000CD); + values[(int)KnownColor.MediumOrchid] = unchecked((int)0xFFBA55D3); + values[(int)KnownColor.MediumPurple] = unchecked((int)0xFF9370DB); + values[(int)KnownColor.MediumSeaGreen] = unchecked((int)0xFF3CB371); + values[(int)KnownColor.MediumSlateBlue] = unchecked((int)0xFF7B68EE); + values[(int)KnownColor.MediumSpringGreen] = unchecked((int)0xFF00FA9A); + values[(int)KnownColor.MediumTurquoise] = unchecked((int)0xFF48D1CC); + values[(int)KnownColor.MediumVioletRed] = unchecked((int)0xFFC71585); + values[(int)KnownColor.MidnightBlue] = unchecked((int)0xFF191970); + values[(int)KnownColor.MintCream] = unchecked((int)0xFFF5FFFA); + values[(int)KnownColor.MistyRose] = unchecked((int)0xFFFFE4E1); + values[(int)KnownColor.Moccasin] = unchecked((int)0xFFFFE4B5); + values[(int)KnownColor.NavajoWhite] = unchecked((int)0xFFFFDEAD); + values[(int)KnownColor.Navy] = unchecked((int)0xFF000080); + values[(int)KnownColor.OldLace] = unchecked((int)0xFFFDF5E6); + values[(int)KnownColor.Olive] = unchecked((int)0xFF808000); + values[(int)KnownColor.OliveDrab] = unchecked((int)0xFF6B8E23); + values[(int)KnownColor.Orange] = unchecked((int)0xFFFFA500); + values[(int)KnownColor.OrangeRed] = unchecked((int)0xFFFF4500); + values[(int)KnownColor.Orchid] = unchecked((int)0xFFDA70D6); + values[(int)KnownColor.PaleGoldenrod] = unchecked((int)0xFFEEE8AA); + values[(int)KnownColor.PaleGreen] = unchecked((int)0xFF98FB98); + values[(int)KnownColor.PaleTurquoise] = unchecked((int)0xFFAFEEEE); + values[(int)KnownColor.PaleVioletRed] = unchecked((int)0xFFDB7093); + values[(int)KnownColor.PapayaWhip] = unchecked((int)0xFFFFEFD5); + values[(int)KnownColor.PeachPuff] = unchecked((int)0xFFFFDAB9); + values[(int)KnownColor.Peru] = unchecked((int)0xFFCD853F); + values[(int)KnownColor.Pink] = unchecked((int)0xFFFFC0CB); + values[(int)KnownColor.Plum] = unchecked((int)0xFFDDA0DD); + values[(int)KnownColor.PowderBlue] = unchecked((int)0xFFB0E0E6); + values[(int)KnownColor.Purple] = unchecked((int)0xFF800080); + values[(int)KnownColor.Red] = unchecked((int)0xFFFF0000); + values[(int)KnownColor.RosyBrown] = unchecked((int)0xFFBC8F8F); + values[(int)KnownColor.RoyalBlue] = unchecked((int)0xFF4169E1); + values[(int)KnownColor.SaddleBrown] = unchecked((int)0xFF8B4513); + values[(int)KnownColor.Salmon] = unchecked((int)0xFFFA8072); + values[(int)KnownColor.SandyBrown] = unchecked((int)0xFFF4A460); + values[(int)KnownColor.SeaGreen] = unchecked((int)0xFF2E8B57); + values[(int)KnownColor.SeaShell] = unchecked((int)0xFFFFF5EE); + values[(int)KnownColor.Sienna] = unchecked((int)0xFFA0522D); + values[(int)KnownColor.Silver] = unchecked((int)0xFFC0C0C0); + values[(int)KnownColor.SkyBlue] = unchecked((int)0xFF87CEEB); + values[(int)KnownColor.SlateBlue] = unchecked((int)0xFF6A5ACD); + values[(int)KnownColor.SlateGray] = unchecked((int)0xFF708090); + values[(int)KnownColor.Snow] = unchecked((int)0xFFFFFAFA); + values[(int)KnownColor.SpringGreen] = unchecked((int)0xFF00FF7F); + values[(int)KnownColor.SteelBlue] = unchecked((int)0xFF4682B4); + values[(int)KnownColor.Tan] = unchecked((int)0xFFD2B48C); + values[(int)KnownColor.Teal] = unchecked((int)0xFF008080); + values[(int)KnownColor.Thistle] = unchecked((int)0xFFD8BFD8); + values[(int)KnownColor.Tomato] = unchecked((int)0xFFFF6347); + values[(int)KnownColor.Turquoise] = unchecked((int)0xFF40E0D0); + values[(int)KnownColor.Violet] = unchecked((int)0xFFEE82EE); + values[(int)KnownColor.Wheat] = unchecked((int)0xFFF5DEB3); + values[(int)KnownColor.White] = unchecked((int)0xFFFFFFFF); + values[(int)KnownColor.WhiteSmoke] = unchecked((int)0xFFF5F5F5); + values[(int)KnownColor.Yellow] = unchecked((int)0xFFFFFF00); + values[(int)KnownColor.YellowGreen] = unchecked((int)0xFF9ACD32); + colorTable = values; + } + + private static void EnsureColorNameTable() + { + // no need to lock... worse case is a double create of the table... + // + if (colorNameTable == null) + { + InitColorNameTable(); + } + } + + private static void InitColorNameTable() + { + string[] values = new string[((int)KnownColor.MenuHighlight) + 1]; + + // just consts... + // + values[(int)KnownColor.ActiveBorder] = "ActiveBorder"; + values[(int)KnownColor.ActiveCaption] = "ActiveCaption"; + values[(int)KnownColor.ActiveCaptionText] = "ActiveCaptionText"; + values[(int)KnownColor.AppWorkspace] = "AppWorkspace"; + values[(int)KnownColor.ButtonFace] = "ButtonFace"; + values[(int)KnownColor.ButtonHighlight] = "ButtonHighlight"; + values[(int)KnownColor.ButtonShadow] = "ButtonShadow"; + values[(int)KnownColor.Control] = "Control"; + values[(int)KnownColor.ControlDark] = "ControlDark"; + values[(int)KnownColor.ControlDarkDark] = "ControlDarkDark"; + values[(int)KnownColor.ControlLight] = "ControlLight"; + values[(int)KnownColor.ControlLightLight] = "ControlLightLight"; + values[(int)KnownColor.ControlText] = "ControlText"; + values[(int)KnownColor.Desktop] = "Desktop"; + values[(int)KnownColor.GradientActiveCaption] = "GradientActiveCaption"; + values[(int)KnownColor.GradientInactiveCaption] = "GradientInactiveCaption"; + values[(int)KnownColor.GrayText] = "GrayText"; + values[(int)KnownColor.Highlight] = "Highlight"; + values[(int)KnownColor.HighlightText] = "HighlightText"; + values[(int)KnownColor.HotTrack] = "HotTrack"; + values[(int)KnownColor.InactiveBorder] = "InactiveBorder"; + values[(int)KnownColor.InactiveCaption] = "InactiveCaption"; + values[(int)KnownColor.InactiveCaptionText] = "InactiveCaptionText"; + values[(int)KnownColor.Info] = "Info"; + values[(int)KnownColor.InfoText] = "InfoText"; + values[(int)KnownColor.Menu] = "Menu"; + values[(int)KnownColor.MenuBar] = "MenuBar"; + values[(int)KnownColor.MenuHighlight] = "MenuHighlight"; + values[(int)KnownColor.MenuText] = "MenuText"; + values[(int)KnownColor.ScrollBar] = "ScrollBar"; + values[(int)KnownColor.Window] = "Window"; + values[(int)KnownColor.WindowFrame] = "WindowFrame"; + values[(int)KnownColor.WindowText] = "WindowText"; + + values[(int)KnownColor.Transparent] = "Transparent"; + values[(int)KnownColor.AliceBlue] = "AliceBlue"; + values[(int)KnownColor.AntiqueWhite] = "AntiqueWhite"; + values[(int)KnownColor.Aqua] = "Aqua"; + values[(int)KnownColor.Aquamarine] = "Aquamarine"; + values[(int)KnownColor.Azure] = "Azure"; + values[(int)KnownColor.Beige] = "Beige"; + values[(int)KnownColor.Bisque] = "Bisque"; + values[(int)KnownColor.Black] = "Black"; + values[(int)KnownColor.BlanchedAlmond] = "BlanchedAlmond"; + values[(int)KnownColor.Blue] = "Blue"; + values[(int)KnownColor.BlueViolet] = "BlueViolet"; + values[(int)KnownColor.Brown] = "Brown"; + values[(int)KnownColor.BurlyWood] = "BurlyWood"; + values[(int)KnownColor.CadetBlue] = "CadetBlue"; + values[(int)KnownColor.Chartreuse] = "Chartreuse"; + values[(int)KnownColor.Chocolate] = "Chocolate"; + values[(int)KnownColor.Coral] = "Coral"; + values[(int)KnownColor.CornflowerBlue] = "CornflowerBlue"; + values[(int)KnownColor.Cornsilk] = "Cornsilk"; + values[(int)KnownColor.Crimson] = "Crimson"; + values[(int)KnownColor.Cyan] = "Cyan"; + values[(int)KnownColor.DarkBlue] = "DarkBlue"; + values[(int)KnownColor.DarkCyan] = "DarkCyan"; + values[(int)KnownColor.DarkGoldenrod] = "DarkGoldenrod"; + values[(int)KnownColor.DarkGray] = "DarkGray"; + values[(int)KnownColor.DarkGreen] = "DarkGreen"; + values[(int)KnownColor.DarkKhaki] = "DarkKhaki"; + values[(int)KnownColor.DarkMagenta] = "DarkMagenta"; + values[(int)KnownColor.DarkOliveGreen] = "DarkOliveGreen"; + values[(int)KnownColor.DarkOrange] = "DarkOrange"; + values[(int)KnownColor.DarkOrchid] = "DarkOrchid"; + values[(int)KnownColor.DarkRed] = "DarkRed"; + values[(int)KnownColor.DarkSalmon] = "DarkSalmon"; + values[(int)KnownColor.DarkSeaGreen] = "DarkSeaGreen"; + values[(int)KnownColor.DarkSlateBlue] = "DarkSlateBlue"; + values[(int)KnownColor.DarkSlateGray] = "DarkSlateGray"; + values[(int)KnownColor.DarkTurquoise] = "DarkTurquoise"; + values[(int)KnownColor.DarkViolet] = "DarkViolet"; + values[(int)KnownColor.DeepPink] = "DeepPink"; + values[(int)KnownColor.DeepSkyBlue] = "DeepSkyBlue"; + values[(int)KnownColor.DimGray] = "DimGray"; + values[(int)KnownColor.DodgerBlue] = "DodgerBlue"; + values[(int)KnownColor.Firebrick] = "Firebrick"; + values[(int)KnownColor.FloralWhite] = "FloralWhite"; + values[(int)KnownColor.ForestGreen] = "ForestGreen"; + values[(int)KnownColor.Fuchsia] = "Fuchsia"; + values[(int)KnownColor.Gainsboro] = "Gainsboro"; + values[(int)KnownColor.GhostWhite] = "GhostWhite"; + values[(int)KnownColor.Gold] = "Gold"; + values[(int)KnownColor.Goldenrod] = "Goldenrod"; + values[(int)KnownColor.Gray] = "Gray"; + values[(int)KnownColor.Green] = "Green"; + values[(int)KnownColor.GreenYellow] = "GreenYellow"; + values[(int)KnownColor.Honeydew] = "Honeydew"; + values[(int)KnownColor.HotPink] = "HotPink"; + values[(int)KnownColor.IndianRed] = "IndianRed"; + values[(int)KnownColor.Indigo] = "Indigo"; + values[(int)KnownColor.Ivory] = "Ivory"; + values[(int)KnownColor.Khaki] = "Khaki"; + values[(int)KnownColor.Lavender] = "Lavender"; + values[(int)KnownColor.LavenderBlush] = "LavenderBlush"; + values[(int)KnownColor.LawnGreen] = "LawnGreen"; + values[(int)KnownColor.LemonChiffon] = "LemonChiffon"; + values[(int)KnownColor.LightBlue] = "LightBlue"; + values[(int)KnownColor.LightCoral] = "LightCoral"; + values[(int)KnownColor.LightCyan] = "LightCyan"; + values[(int)KnownColor.LightGoldenrodYellow] = "LightGoldenrodYellow"; + values[(int)KnownColor.LightGray] = "LightGray"; + values[(int)KnownColor.LightGreen] = "LightGreen"; + values[(int)KnownColor.LightPink] = "LightPink"; + values[(int)KnownColor.LightSalmon] = "LightSalmon"; + values[(int)KnownColor.LightSeaGreen] = "LightSeaGreen"; + values[(int)KnownColor.LightSkyBlue] = "LightSkyBlue"; + values[(int)KnownColor.LightSlateGray] = "LightSlateGray"; + values[(int)KnownColor.LightSteelBlue] = "LightSteelBlue"; + values[(int)KnownColor.LightYellow] = "LightYellow"; + values[(int)KnownColor.Lime] = "Lime"; + values[(int)KnownColor.LimeGreen] = "LimeGreen"; + values[(int)KnownColor.Linen] = "Linen"; + values[(int)KnownColor.Magenta] = "Magenta"; + values[(int)KnownColor.Maroon] = "Maroon"; + values[(int)KnownColor.MediumAquamarine] = "MediumAquamarine"; + values[(int)KnownColor.MediumBlue] = "MediumBlue"; + values[(int)KnownColor.MediumOrchid] = "MediumOrchid"; + values[(int)KnownColor.MediumPurple] = "MediumPurple"; + values[(int)KnownColor.MediumSeaGreen] = "MediumSeaGreen"; + values[(int)KnownColor.MediumSlateBlue] = "MediumSlateBlue"; + values[(int)KnownColor.MediumSpringGreen] = "MediumSpringGreen"; + values[(int)KnownColor.MediumTurquoise] = "MediumTurquoise"; + values[(int)KnownColor.MediumVioletRed] = "MediumVioletRed"; + values[(int)KnownColor.MidnightBlue] = "MidnightBlue"; + values[(int)KnownColor.MintCream] = "MintCream"; + values[(int)KnownColor.MistyRose] = "MistyRose"; + values[(int)KnownColor.Moccasin] = "Moccasin"; + values[(int)KnownColor.NavajoWhite] = "NavajoWhite"; + values[(int)KnownColor.Navy] = "Navy"; + values[(int)KnownColor.OldLace] = "OldLace"; + values[(int)KnownColor.Olive] = "Olive"; + values[(int)KnownColor.OliveDrab] = "OliveDrab"; + values[(int)KnownColor.Orange] = "Orange"; + values[(int)KnownColor.OrangeRed] = "OrangeRed"; + values[(int)KnownColor.Orchid] = "Orchid"; + values[(int)KnownColor.PaleGoldenrod] = "PaleGoldenrod"; + values[(int)KnownColor.PaleGreen] = "PaleGreen"; + values[(int)KnownColor.PaleTurquoise] = "PaleTurquoise"; + values[(int)KnownColor.PaleVioletRed] = "PaleVioletRed"; + values[(int)KnownColor.PapayaWhip] = "PapayaWhip"; + values[(int)KnownColor.PeachPuff] = "PeachPuff"; + values[(int)KnownColor.Peru] = "Peru"; + values[(int)KnownColor.Pink] = "Pink"; + values[(int)KnownColor.Plum] = "Plum"; + values[(int)KnownColor.PowderBlue] = "PowderBlue"; + values[(int)KnownColor.Purple] = "Purple"; + values[(int)KnownColor.Red] = "Red"; + values[(int)KnownColor.RosyBrown] = "RosyBrown"; + values[(int)KnownColor.RoyalBlue] = "RoyalBlue"; + values[(int)KnownColor.SaddleBrown] = "SaddleBrown"; + values[(int)KnownColor.Salmon] = "Salmon"; + values[(int)KnownColor.SandyBrown] = "SandyBrown"; + values[(int)KnownColor.SeaGreen] = "SeaGreen"; + values[(int)KnownColor.SeaShell] = "SeaShell"; + values[(int)KnownColor.Sienna] = "Sienna"; + values[(int)KnownColor.Silver] = "Silver"; + values[(int)KnownColor.SkyBlue] = "SkyBlue"; + values[(int)KnownColor.SlateBlue] = "SlateBlue"; + values[(int)KnownColor.SlateGray] = "SlateGray"; + values[(int)KnownColor.Snow] = "Snow"; + values[(int)KnownColor.SpringGreen] = "SpringGreen"; + values[(int)KnownColor.SteelBlue] = "SteelBlue"; + values[(int)KnownColor.Tan] = "Tan"; + values[(int)KnownColor.Teal] = "Teal"; + values[(int)KnownColor.Thistle] = "Thistle"; + values[(int)KnownColor.Tomato] = "Tomato"; + values[(int)KnownColor.Turquoise] = "Turquoise"; + values[(int)KnownColor.Violet] = "Violet"; + values[(int)KnownColor.Wheat] = "Wheat"; + values[(int)KnownColor.White] = "White"; + values[(int)KnownColor.WhiteSmoke] = "WhiteSmoke"; + values[(int)KnownColor.Yellow] = "Yellow"; + values[(int)KnownColor.YellowGreen] = "YellowGreen"; + colorNameTable = values; + } + + public static int KnownColorToArgb(KnownColor color) + { + EnsureColorTable(); + if (color <= KnownColor.MenuHighlight) + { + return colorTable[unchecked((int)color)]; + } + else + { + return 0; + } + } + + public static string KnownColorToName(KnownColor color) + { + EnsureColorNameTable(); + if (color <= KnownColor.MenuHighlight) + { + return colorNameTable[unchecked((int)color)]; + } + else + { + return null; + } + } + + private static void UpdateSystemColors(int[] colorTable) + { + // Colors from a default XP desktop for use by UI designers in ASP.NET: Microsoft + colorTable[(int)KnownColor.ActiveBorder] = unchecked((int)0xffd4d0c8); + colorTable[(int)KnownColor.ActiveCaption] = unchecked((int)0xff0054e3); + colorTable[(int)KnownColor.ActiveCaptionText] = unchecked((int)0xffffffff); + colorTable[(int)KnownColor.AppWorkspace] = unchecked((int)0xff808080); + colorTable[(int)KnownColor.ButtonFace] = unchecked((int)0x0); + colorTable[(int)KnownColor.ButtonHighlight] = unchecked((int)0x0); + colorTable[(int)KnownColor.ButtonShadow] = unchecked((int)0x0); + colorTable[(int)KnownColor.Control] = unchecked((int)0xffece9d8); + colorTable[(int)KnownColor.ControlDark] = unchecked((int)0xffaca899); + colorTable[(int)KnownColor.ControlDarkDark] = unchecked((int)0xff716f64); + colorTable[(int)KnownColor.ControlLight] = unchecked((int)0xfff1efe2); + colorTable[(int)KnownColor.ControlLightLight] = unchecked((int)0xffffffff); + colorTable[(int)KnownColor.ControlText] = unchecked((int)0xff000000); + colorTable[(int)KnownColor.Desktop] = unchecked((int)0xff004e98); + colorTable[(int)KnownColor.GradientActiveCaption] = unchecked((int)0x0); + colorTable[(int)KnownColor.GradientInactiveCaption] = unchecked((int)0x0); + colorTable[(int)KnownColor.GrayText] = unchecked((int)0xffaca899); + colorTable[(int)KnownColor.Highlight] = unchecked((int)0xff316ac5); + colorTable[(int)KnownColor.HighlightText] = unchecked((int)0xffffffff); + colorTable[(int)KnownColor.HotTrack] = unchecked((int)0xff000080); + colorTable[(int)KnownColor.InactiveBorder] = unchecked((int)0xffd4d0c8); + colorTable[(int)KnownColor.InactiveCaption] = unchecked((int)0xff7a96df); + colorTable[(int)KnownColor.InactiveCaptionText] = unchecked((int)0xffd8e4f8); + colorTable[(int)KnownColor.Info] = unchecked((int)0xffffffe1); + colorTable[(int)KnownColor.InfoText] = unchecked((int)0xff000000); + colorTable[(int)KnownColor.Menu] = unchecked((int)0xffffffff); + colorTable[(int)KnownColor.MenuBar] = unchecked((int)0x0); + colorTable[(int)KnownColor.MenuHighlight] = unchecked((int)0x0); + colorTable[(int)KnownColor.MenuText] = unchecked((int)0xff000000); + colorTable[(int)KnownColor.ScrollBar] = unchecked((int)0xffd4d0c8); + colorTable[(int)KnownColor.Window] = unchecked((int)0xffffffff); + colorTable[(int)KnownColor.WindowFrame] = unchecked((int)0xff000000); + colorTable[(int)KnownColor.WindowText] = unchecked((int)0xff000000); + } + } +} diff --git a/Core/Owl/Drawing/SystemColors.cs b/Core/Owl/Drawing/SystemColors.cs new file mode 100644 index 0000000..73afa00 --- /dev/null +++ b/Core/Owl/Drawing/SystemColors.cs @@ -0,0 +1,418 @@ +namespace Owl.Drawing +{ + public sealed class SystemColors + { + + // not creatable... + // + private SystemColors() + { + } + + /// + /// + /// The color of the filled area of an active window border. + /// + public static Color ActiveBorder + { + get + { + return new Color(KnownColor.ActiveBorder); + } + } + + /// + /// + /// The color of the background of an active title bar caption. + /// + public static Color ActiveCaption + { + get + { + return new Color(KnownColor.ActiveCaption); + } + } + + /// + /// + /// The color of the text of an active title bar caption. + /// + public static Color ActiveCaptionText + { + get + { + return new Color(KnownColor.ActiveCaptionText); + } + } + + /// + /// + /// The color of the application workspace. The application workspace + /// is the area in a multiple document view that is not being occupied + /// by documents. + /// + public static Color AppWorkspace + { + get + { + return new Color(KnownColor.AppWorkspace); + } + } + + /// + /// + /// Face color for three-dimensional display elements and for dialog box backgrounds. + /// + public static Color ButtonFace + { + get + { + return new Color(KnownColor.ButtonFace); + } + } + + /// + /// + /// Highlight color for three-dimensional display elements (for edges facing the light source.) + /// + public static Color ButtonHighlight + { + get + { + return new Color(KnownColor.ButtonHighlight); + } + } + + /// + /// + /// Shadow color for three-dimensional display elements (for edges facing away from the light source.) + /// + public static Color ButtonShadow + { + get + { + return new Color(KnownColor.ButtonShadow); + } + } + + /// + /// + /// The color of the background of push buttons and other 3D objects. + /// + public static Color Control + { + get + { + return new Color(KnownColor.Control); + } + } + + /// + /// + /// The color of shadows on 3D objects. + /// + public static Color ControlDark + { + get + { + return new Color(KnownColor.ControlDark); + } + } + + /// + /// + /// The color of very dark shadows on 3D objects. + /// + public static Color ControlDarkDark + { + get + { + return new Color(KnownColor.ControlDarkDark); + } + } + + /// + /// + /// The color of highlights on 3D objects. + /// + public static Color ControlLight + { + get + { + return new Color(KnownColor.ControlLight); + } + } + + /// + /// + /// The color of very light highlights on 3D objects. + /// + public static Color ControlLightLight + { + get + { + return new Color(KnownColor.ControlLightLight); + } + } + + /// + /// + /// The color of the text of push buttons and other 3D objects + /// + public static Color ControlText + { + get + { + return new Color(KnownColor.ControlText); + } + } + + /// + /// + /// This color is the user-defined color of the Windows desktop. + /// + public static Color Desktop + { + get + { + return new Color(KnownColor.Desktop); + } + } + + /// + /// + /// Right side color in the color gradient of an active window's title bar. + /// The ActiveCaption Color specifies the left side color. + /// + public static Color GradientActiveCaption + { + get + { + return new Color(KnownColor.GradientActiveCaption); + } + } + + /// + /// + /// Right side color in the color gradient of an inactive window's title bar. + /// The InactiveCaption Color specifies the left side color. + /// + public static Color GradientInactiveCaption + { + get + { + return new Color(KnownColor.GradientInactiveCaption); + } + } + + /// + /// + /// The color of text that is being shown in a disabled, or grayed-out + /// state. + /// + public static Color GrayText + { + get + { + return new Color(KnownColor.GrayText); + } + } + + /// + /// + /// The color of the background of highlighted text. This includes + /// selected menu items as well as selected text. + /// + public static Color Highlight + { + get + { + return new Color(KnownColor.Highlight); + } + } + + /// + /// + /// The color of the text of highlighted text. This includes + /// selected menu items as well as selected text. + /// + public static Color HighlightText + { + get + { + return new Color(KnownColor.HighlightText); + } + } + + /// + /// + /// The hot track color. + /// + public static Color HotTrack + { + get + { + return new Color(KnownColor.HotTrack); + } + } + + /// + /// + /// The color of the filled area of an inactive window border. + /// + public static Color InactiveBorder + { + get + { + return new Color(KnownColor.InactiveBorder); + } + } + + /// + /// + /// The color of the background of an inactive title bar caption. + /// + public static Color InactiveCaption + { + get + { + return new Color(KnownColor.InactiveCaption); + } + } + + /// + /// + /// The color of the text of an inactive title bar caption. + /// + public static Color InactiveCaptionText + { + get + { + return new Color(KnownColor.InactiveCaptionText); + } + } + + /// + /// + /// The color of the info/tool tip background. + /// + public static Color Info + { + get + { + return new Color(KnownColor.Info); + } + } + + /// + /// + /// The color of the info/tool tip text. + /// + public static Color InfoText + { + get + { + return new Color(KnownColor.InfoText); + } + } + + /// + /// + /// The color of the background of a menu. + /// + public static Color Menu + { + get + { + return new Color(KnownColor.Menu); + } + } + + /// + /// + /// The color of the background of a menu bar. + /// + public static Color MenuBar + { + get + { + return new Color(KnownColor.MenuBar); + } + } + + /// + /// + /// The color used to highlight menu items when the menu appears as a flat menu. + /// The highlighted menu item is outlined with the Highlight Color. + /// + public static Color MenuHighlight + { + get + { + return new Color(KnownColor.MenuHighlight); + } + } + + /// + /// + /// The color of the text on a menu. + /// + public static Color MenuText + { + get + { + return new Color(KnownColor.MenuText); + } + } + + /// + /// + /// The color of the scroll bar area that is not being used by the + /// thumb button. + /// + public static Color ScrollBar + { + get + { + return new Color(KnownColor.ScrollBar); + } + } + + /// + /// + /// The color of the client area of a window. + /// + public static Color Window + { + get + { + return new Color(KnownColor.Window); + } + } + + /// + /// + /// The color of the thin frame drawn around a window. + /// + public static Color WindowFrame + { + get + { + return new Color(KnownColor.WindowFrame); + } + } + + /// + /// + /// The color of the text in the client area of a window. + /// + public static Color WindowText + { + get + { + return new Color(KnownColor.WindowText); + } + } + } + +} From c00af896017cfb63738177df5fc8062cfa35a78e Mon Sep 17 00:00:00 2001 From: Christiano Donke Date: Wed, 21 Mar 2018 14:40:54 -0300 Subject: [PATCH 3/7] Setup for NetStandard --- .../ConExcelPlayground.NetStandard.csproj | 7 +- Playground/ConExcelPlayground/Program.cs | 21 ++-- .../ConWordPlayground.NetStandard.csproj | 9 +- Playground/ConWordPlayground/Program.cs | 100 ++++++++++-------- 4 files changed, 80 insertions(+), 57 deletions(-) diff --git a/Playground/ConExcelPlayground/ConExcelPlayground.NetStandard.csproj b/Playground/ConExcelPlayground/ConExcelPlayground.NetStandard.csproj index 2cd8667..13a57e5 100644 --- a/Playground/ConExcelPlayground/ConExcelPlayground.NetStandard.csproj +++ b/Playground/ConExcelPlayground/ConExcelPlayground.NetStandard.csproj @@ -1,10 +1,13 @@ - netstandard2.0 + netcoreapp1.5 ConExcelPlayground ConExcelPlayground true + + Exe + ConExcelPlayground.Program @@ -12,7 +15,7 @@ - + diff --git a/Playground/ConExcelPlayground/Program.cs b/Playground/ConExcelPlayground/Program.cs index 650ff45..f814170 100644 --- a/Playground/ConExcelPlayground/Program.cs +++ b/Playground/ConExcelPlayground/Program.cs @@ -1,14 +1,14 @@ -using Owl.Excel; +using Owl.Data; +using Owl.Excel; using System; -using System.Data; using System.Diagnostics; using System.IO; namespace ConExcelPlayground { class Program { static void Main(string[] args) { - - string document = "test.xlsx"; + + string document = Path.Combine(Path.GetTempPath(), "test.xlsx"); if (File.Exists(document)) File.Delete(document); @@ -63,11 +63,14 @@ static DataTable GetTable(string name) { int limiar = j * 10; - data.Rows.Add(baseDate.AddDays(j), - rnd.Next(limiar, limiar + 30), - rnd.Next(limiar, limiar + 30), - rnd.Next(limiar, limiar + 30), - rnd.Next(limiar, limiar + 30)); + var row = data.NewRow(); + row[0] = baseDate.AddDays(j); + row[1] = rnd.Next(limiar, limiar + 30); + row[2] = rnd.Next(limiar, limiar + 30); + row[3] = rnd.Next(limiar, limiar + 30); + row[4] = rnd.Next(limiar, limiar + 30); + + data.AddRow(row); } return data; diff --git a/Playground/ConWordPlayground/ConWordPlayground.NetStandard.csproj b/Playground/ConWordPlayground/ConWordPlayground.NetStandard.csproj index 1288684..01ed45b 100644 --- a/Playground/ConWordPlayground/ConWordPlayground.NetStandard.csproj +++ b/Playground/ConWordPlayground/ConWordPlayground.NetStandard.csproj @@ -1,10 +1,13 @@ - netstandard2.0 + netcoreapp1.5 ConWordPlayground ConWordPlayground true + + Exe + @@ -15,6 +18,10 @@ + + + + diff --git a/Playground/ConWordPlayground/Program.cs b/Playground/ConWordPlayground/Program.cs index c019eb0..310288c 100644 --- a/Playground/ConWordPlayground/Program.cs +++ b/Playground/ConWordPlayground/Program.cs @@ -1,27 +1,33 @@ using Owl.Word; -using System.Data; +using Owl.Drawing; using System.Diagnostics; using System.IO; +using Owl.Data; -namespace ConWordPlayground { - class Program { - static void Main(string[] args) { +namespace ConWordPlayground +{ + class Program + { + static void Main(string[] args) + { - string document = "test.docx"; + string document = Path.Combine(Path.GetTempPath(), "test.docx"); if (File.Exists(document)) File.Delete(document); - using (WordBuilder builder = new WordBuilder()) { + using (WordBuilder builder = new WordBuilder()) + { builder.CreateDocument(document); - - builder.AddCustomStyle(new FormatStyle() { - Color = System.Drawing.Color.Maroon, + + builder.AddCustomStyle(new FormatStyle() + { + Color = Color.Maroon, FontName = "Courier New", FontSize = 14, IsBold = true, - IsItalic = true, + IsItalic = true, Name = "Warning", StyleId = "Warning", HighlightColor = FormatStyle.HighlightColors.Yellow @@ -35,9 +41,9 @@ static void Main(string[] args) { builder.CreateTextParagraph(TextParagraphType.Heading1, "Heading 1"); builder.CreateTextParagraph(TextParagraphType.Heading2, "Heading 2"); builder.CreateTextParagraph(TextParagraphType.Heading3, "Heading 3"); - builder.CreateTextParagraph(TextParagraphType.Normal, "Normal text."); - builder.CreateTextParagraph(TextParagraphType.Normal, "Normal text."); - builder.CreateTextParagraph(TextParagraphType.Normal, "Normal text."); + builder.CreateTextParagraph(TextParagraphType.Normal, "Normal text."); + builder.CreateTextParagraph(TextParagraphType.Normal, "Normal text."); + builder.CreateTextParagraph(TextParagraphType.Normal, "Normal text."); builder.CreateTextParagraph(TextParagraphType.Normal, "Normal text."); builder.CreateTextParagraph(TextParagraphType.None, "None style text."); builder.CreateTextParagraph("Warning", "Warning to this point. Pay attention!"); @@ -49,7 +55,7 @@ static void Main(string[] args) { builder.CreateTextParagraph(TextParagraphType.Normal, HorizontalAlignmentType.Center, "Normal text."); builder.CreateTextParagraph(TextParagraphType.None, HorizontalAlignmentType.Center, "None style text."); builder.CreateTextParagraph("Warning", HorizontalAlignmentType.Center, "Warning to this point. Pay attention!"); - + builder.CreateTextParagraph(TextParagraphType.Title, HorizontalAlignmentType.Right, "Title"); builder.CreateTextParagraph(TextParagraphType.Heading1, HorizontalAlignmentType.Right, "Heading 1"); builder.CreateTextParagraph(TextParagraphType.Heading2, HorizontalAlignmentType.Right, "Heading 2"); @@ -57,20 +63,21 @@ static void Main(string[] args) { builder.CreateTextParagraph(TextParagraphType.Normal, HorizontalAlignmentType.Right, "Normal text."); builder.CreateTextParagraph(TextParagraphType.None, HorizontalAlignmentType.Right, "None style text."); builder.CreateTextParagraph("Warning", HorizontalAlignmentType.Right, "Warning to this point. Pay attention!"); - - builder.AddImage("Super-IT.png"); - builder.AddImage("Super-IT.png", HorizontalAlignmentType.Center); - builder.AddImage("Super-IT.png", HorizontalAlignmentType.Right); - builder.AddImage("Super-IT.png", 0.75M); - builder.AddImage("Super-IT.png", 0.50M); - builder.AddImage("Super-IT.png", 0.4M, HorizontalAlignmentType.Center); - builder.AddImage("Super-IT.png", 0.25M, HorizontalAlignmentType.Right); + + //builder.AddImage("Super-IT.png"); + //builder.AddImage("Super-IT.png", HorizontalAlignmentType.Center); + //builder.AddImage("Super-IT.png", HorizontalAlignmentType.Right); + //builder.AddImage("Super-IT.png", 0.75M); + //builder.AddImage("Super-IT.png", 0.50M); + //builder.AddImage("Super-IT.png", 0.4M, HorizontalAlignmentType.Center); + //builder.AddImage("Super-IT.png", 0.25M, HorizontalAlignmentType.Right); } - - using (WordBuilder builder = new WordBuilder()) { + + using (WordBuilder builder = new WordBuilder()) + { builder.OpenDocument(document); - + builder.CreateTextParagraph(TextParagraphType.Title, "Title"); builder.CreateTextParagraph(TextParagraphType.Heading1, "Heading 1"); builder.CreateTextParagraph(TextParagraphType.Heading2, "Heading 2"); @@ -82,9 +89,9 @@ static void Main(string[] args) { builder.CreateTextParagraph(TextParagraphType.None, "None style text."); builder.CreateTextParagraph("Warning", "Warning to this point. Pay attention!"); - builder.AddImage("Super-IT.png"); - builder.AddImage("Super-IT.png", HorizontalAlignmentType.Center); - builder.AddImage("Super-IT.png", HorizontalAlignmentType.Right); + //builder.AddImage("Super-IT.png"); + //builder.AddImage("Super-IT.png", HorizontalAlignmentType.Center); + //builder.AddImage("Super-IT.png", HorizontalAlignmentType.Right); AddTable(builder); } @@ -93,29 +100,32 @@ static void Main(string[] args) { Process.Start(startInfo); } - private static void AddTable(WordBuilder builder) { + private static void AddTable(WordBuilder builder) + { - using (var table = new DataTable()) { + var table = new DataTable(); - table.Columns.Add("Item", typeof(string)); - table.Columns.Add("Min", typeof(string)); - table.Columns.Add("Avg", typeof(string)); - table.Columns.Add("Max", typeof(string)); - - for (int i = 0; i < 10; i++) { + table.Columns.Add("Item", typeof(string)); + table.Columns.Add("Min", typeof(string)); + table.Columns.Add("Avg", typeof(string)); + table.Columns.Add("Max", typeof(string)); - var r = table.NewRow(); - r[0] = i.ToString(); r[1] = 10M.ToString(); r[2] = 11M.ToString(); r[3] = 12M.ToString(); + for (int i = 0; i < 10; i++) + { - table.Rows.Add(r); - } + var r = table.NewRow(); + r[0] = i.ToString(); r[1] = 10M.ToString(); r[2] = 11M.ToString(); r[3] = 12M.ToString(); - builder.CreateTable(table, new TableStyle() { - Alignment = HorizontalAlignmentType.Center, - ShowTitle = true, - Title = "My Table" - }); + table.Rows.Add(r); } + + builder.CreateTable(table, new TableStyle() + { + Alignment = HorizontalAlignmentType.Center, + ShowTitle = true, + Title = "My Table" + }); + } } } From 56d278eb69c34d517f3257b695fee2f9fc711083 Mon Sep 17 00:00:00 2001 From: Christiano Donke Date: Wed, 21 Mar 2018 14:42:03 -0300 Subject: [PATCH 4/7] System.Data replacement --- Core/Owl/Data/DataColumn.cs | 32 +++++ Core/Owl/Data/DataColumnCollection.cs | 198 ++++++++++++++++++++++++++ Core/Owl/Data/DataRow.cs | 121 ++++++++++++++++ Core/Owl/Data/DataRowCollection.cs | 69 +++++++++ Core/Owl/Data/DataSet.cs | 20 +++ Core/Owl/Data/DataTable.cs | 184 ++++++++++++++++++++++++ Core/Owl/Data/DataTableCollection.cs | 197 +++++++++++++++++++++++++ 7 files changed, 821 insertions(+) create mode 100644 Core/Owl/Data/DataColumn.cs create mode 100644 Core/Owl/Data/DataColumnCollection.cs create mode 100644 Core/Owl/Data/DataRow.cs create mode 100644 Core/Owl/Data/DataRowCollection.cs create mode 100644 Core/Owl/Data/DataSet.cs create mode 100644 Core/Owl/Data/DataTable.cs create mode 100644 Core/Owl/Data/DataTableCollection.cs diff --git a/Core/Owl/Data/DataColumn.cs b/Core/Owl/Data/DataColumn.cs new file mode 100644 index 0000000..9cbe370 --- /dev/null +++ b/Core/Owl/Data/DataColumn.cs @@ -0,0 +1,32 @@ +using System; +using System.Reflection; + +namespace Owl.Data +{ + public class DataColumn + { + private DataTable _table; + private Type type; + internal int _hashCode; + + public DataColumn(string columnName) + { + this.ColumnName = columnName; + } + public DataColumn(string columnName, Type type) + { + this.ColumnName = columnName; + this.type = type; + } + + public string ColumnName { get; private set; } + public DataTable Table + { + get => _table; + internal set => _table = value; + } + public bool IsValueType => type.GetTypeInfo().IsValueType; + + public Type DataType => type; + } +} diff --git a/Core/Owl/Data/DataColumnCollection.cs b/Core/Owl/Data/DataColumnCollection.cs new file mode 100644 index 0000000..8c6131a --- /dev/null +++ b/Core/Owl/Data/DataColumnCollection.cs @@ -0,0 +1,198 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Owl.Data +{ + public class DataColumnCollection : ICollection + { + private readonly List _list = new List(); + private readonly Dictionary _columnFromName; + private readonly StringComparer _hashProvider = StringComparer.OrdinalIgnoreCase; + private readonly DataTable _table; + + public DataColumnCollection(DataTable table) + { + _table = table; + _columnFromName = new Dictionary(); + } + + + #region Index + internal int IndexOfCaseInsensitive(string name) + { + int hashcode = name.GetHashCode(); + int cachedI = -1; + DataColumn column = null; + for (int i = 0; i < Count; i++) + { + column = (DataColumn)_list[i]; + if ((hashcode == 0 || column._hashCode == 0 || column._hashCode == hashcode)) + { + if (cachedI == -1) + cachedI = i; + else + return -2; + } + } + return cachedI; + } + + public DataColumn this[int index] => (DataColumn)_list[index]; + public DataColumn this[string name] + { + get + { + if (null == name) + { + throw new ArgumentNullException(nameof(name)); + } + DataColumn column; + if ((!_columnFromName.TryGetValue(name, out column)) || (column == null)) + { + // Case-Insensitive compares + int index = IndexOfCaseInsensitive(name); + if (0 <= index) + { + column = (DataColumn)_list[index]; + } + } + return column; + } + set + { + var column = this[name]; + column = value; + } + } + + public DataColumn this[DataColumn column] + { + get + { + return this[column.ColumnName]; + } + set + { + this[column.ColumnName] = value; + } + } + #endregion + + #region Add + public void AddRange(DataColumn[] dataColumn) + { + foreach (var column in dataColumn) + Add(column); + } + + public DataColumn Add(string columnName, Type type) + { + DataColumn column = new DataColumn(columnName, type); + Add(column); + return column; + } + public DataColumn Add(string columnName) + { + DataColumn column = new DataColumn(columnName); + Add(column); + return column; + } + public void Add(DataColumn column) + { + AddAt(-1, column); + } + internal void AddAt(int index, DataColumn column) + { + if (column != null) + { + BaseAdd(column); + if (index != -1) + ArrayAdd(index, column); + else + ArrayAdd(column); + } + } + private void ArrayAdd(DataColumn column) + { + _list.Add(column); + } + + private void ArrayAdd(int index, DataColumn column) + { + _list.Insert(index, column); + } + + private void BaseAdd(DataColumn column) + { + if (column == null) + throw new ArgumentNullException(nameof(column)); + + column.Table = _table; + RegisterColumnName(column.ColumnName, column); + + } + internal void RegisterColumnName(string name, DataColumn column) + { + try + { + _columnFromName.Add(name, column); + + if (null != column) + { + column._hashCode = _hashProvider.GetHashCode(name); + } + } + catch (ArgumentException) + { // Argument exception means that there is already an existing key + if (_columnFromName[name] != null) + { + if (column != null) + { + throw new Exception("Cannot Add Duplicate"); + } + } + } + } + + #endregion + + #region Interface Methods + public int Count => _list.Count; + + public bool IsSynchronized => throw new NotImplementedException(); + + public object SyncRoot => throw new NotImplementedException(); + + public void CopyTo(Array array, int index) + { + var arr = _list.ToArray(); + arr.CopyTo(array, index); + } + + public IEnumerator GetEnumerator() + { + return _list.GetEnumerator(); + } + #endregion + + + public int IndexOf(DataColumn column) + { + int columnCount = _list.Count; + for (int i = 0; i < columnCount; ++i) + { + if (column == (DataColumn)_list[i]) + { + return i; + } + } + return -1; + } + + public DataColumnCollection Clone() + { + return (DataColumnCollection)this.MemberwiseClone(); + } + } +} \ No newline at end of file diff --git a/Core/Owl/Data/DataRow.cs b/Core/Owl/Data/DataRow.cs new file mode 100644 index 0000000..2ad4194 --- /dev/null +++ b/Core/Owl/Data/DataRow.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; + +namespace Owl.Data +{ + public class DataRow + { + private readonly DataTable _table; + private readonly DataColumnCollection _columns; + private readonly Dictionary _storage; + internal int _tempRecord = -1; + internal int _newRecord = -1; + internal long _rowID = -1; + + internal DataRow(DataRowBuilder builder) + { + _tempRecord = builder._record; + _table = builder._table; + _storage = new Dictionary(); + _columns = builder._table.Columns; + foreach (DataColumn col in _columns) + _storage.Add(col, null); + } + public object this[string columnName] + { + get + { + var column = GetDataColumn(columnName); + return this[column]; + } + set + { + DataColumn column = GetDataColumn(columnName); + this[column] = value; + } + } + public object this[DataColumn column] + { + get + { + return _storage[column]; + } + set + { + if (column.Table != _table) + { + // user removed column from table during OnColumnChanging event + throw new Exception("ColumnNotInTheTable");// (column.ColumnName, _table.TableName); + } + + object proposed = value; + if (null == proposed) + { + if (column.IsValueType) + { // WebData 105963 + throw new Exception("CannotSetToNull"); + } + } + + int record = _tempRecord; + _storage[column] = proposed; + } + } + public object this[int record] + { + get + { + var column = _columns[record]; + return this[column]; + } + set + { + var column = _columns[record]; + this[column] = value; + } + } + + + internal DataColumn GetDataColumn(string columnName) + { + DataColumn column = _columns[columnName]; + if (null != column) + { + return column; + } + throw new Exception("ColumnNotInTheTable"); // (columnName, _table.TableName); + } + + internal int GetDefaultRecord() + { + if (_tempRecord != -1) + return _tempRecord; + if (_newRecord != -1) + { + return _newRecord; + } + + throw new Exception("Row Removed"); + } + + public long rowID + { + get => _rowID; + set => _rowID = value; + } + public DataTable Table => _table; + + public sealed class DataRowBuilder + { + internal readonly DataTable _table; + internal int _record; + + internal DataRowBuilder(DataTable table, int record) + { + _table = table; + _record = record; + } + } + + } +} diff --git a/Core/Owl/Data/DataRowCollection.cs b/Core/Owl/Data/DataRowCollection.cs new file mode 100644 index 0000000..bdc1b72 --- /dev/null +++ b/Core/Owl/Data/DataRowCollection.cs @@ -0,0 +1,69 @@ +using System.Collections; +using System.Collections.Generic; + +namespace Owl.Data +{ + public class DataRowCollection : ICollection + { + private readonly List _list; + private readonly DataTable _table; + + public DataRowCollection(DataTable table) + { + this._table = table; + _list = new List(); + } + + public DataRow this[int index] + { + get + { + return _list[index]; + } + } + + public void Add(DataRow row) + { + _table.AddRow(row, -1); + _list.Add(row); + } + + #region Interface Methods + + public int Count => _list.Count; + + public bool IsReadOnly => false; + + public void Clear() + { + _list.Clear(); + } + + public bool Contains(DataRow item) + { + return _list.Contains(item); + } + + public void CopyTo(DataRow[] array, int arrayIndex) + { + _list.CopyTo(array, arrayIndex); + } + + public IEnumerator GetEnumerator() + { + return _list.GetEnumerator(); + } + + public bool Remove(DataRow item) + { + return _list.Remove(item); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return _list.GetEnumerator(); + } + + #endregion + } +} diff --git a/Core/Owl/Data/DataSet.cs b/Core/Owl/Data/DataSet.cs new file mode 100644 index 0000000..fe43521 --- /dev/null +++ b/Core/Owl/Data/DataSet.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; + +namespace Owl.Data +{ + public class DataSet + { + public DataSet() + { + Tables = new DataTableCollection(this); + } + public string DataSetName { get; set; } + + public DataTableCollection Tables { get; } + + public CultureInfo Locale = CultureInfo.CurrentCulture; + } +} diff --git a/Core/Owl/Data/DataTable.cs b/Core/Owl/Data/DataTable.cs new file mode 100644 index 0000000..df4edff --- /dev/null +++ b/Core/Owl/Data/DataTable.cs @@ -0,0 +1,184 @@ +using System; +using System.Globalization; +using static Owl.Data.DataRow; + +namespace Owl.Data +{ + public class DataTable + { + internal readonly DataRowCollection rowCollection; + internal readonly DataColumnCollection columnCollection; + private readonly DataRowBuilder rowBuilder; + + private DataSet dataSet; + private string tableName = ""; + internal string tableNamespace = null; + private string tablePrefix = ""; + internal long _nextRowID; + + public DataTable() + { + rowCollection = new DataRowCollection(this); + columnCollection = new DataColumnCollection(this); + + rowBuilder = new DataRowBuilder(this, -1); + + _nextRowID = 1; + } + public DataTable(string name) : this() + { + tableName = name; + } + public DataRowCollection Rows + { + get + { + return rowCollection; + } + } + + public DataColumnCollection Columns + { + get + { + return columnCollection; + } + } + + #region Add + public void AddRow(DataRow row) + { + rowCollection.Add(row); + //AddRow(row, -1); + } + internal void AddRow(DataRow row, int proposedID) + { + InsertRow(row, proposedID, -1); + } + internal void InsertRow(DataRow row, long proposedID, int pos) + { + Exception deferredException = null; + + if (row == null) + { + throw new ArgumentNullException("row"); + } + if (row.Table != this) + { + throw new Exception("RowAlreadyInOtherCollection"); + } + if (row.rowID != -1) + { + throw new Exception("RowAlreadyInOtherCollection"); + } + + int record = row._tempRecord; + row._tempRecord = -1; + + if (proposedID == -1) + { + proposedID = _nextRowID; + } + + _nextRowID = checked(proposedID + 1); + + + try + { + row.rowID = proposedID; + } + catch + { + row.rowID = -1; + row._tempRecord = record; + throw; + } + + // since expression evaluation occurred in SetNewRecordWorker, there may have been a problem that + // was deferred to this point. If so, throw now since row has already been added. + if (deferredException != null) + throw deferredException; + + } + #endregion + + public DataRow NewRow() + { + DataRow dr = NewRow(-1); + return dr; + } + internal DataRow NewRow(int record) + { + rowBuilder._record = record; + DataRow row = NewRowFromBuilder(rowBuilder); + return row; + } + protected virtual DataRow NewRowFromBuilder(DataRowBuilder builder) + { + return new DataRow(builder); + } + + //internal int NewRecordFromArray(object[] value) + //{ + // int colCount = columnCollection.Count; // Perf: use the readonly columnCollection field directly + // if (colCount < value.Length) + // { + // throw new Exception("ValueArrayLength"); + // } + // int record = recordManager.NewRecordBase(); + // try + // { + // for (int i = 0; i < value.Length; i++) + // { + // if (null != value[i]) + // { + // columnCollection[i][record] = value[i]; + // } + // else + // { + // columnCollection[i].Init(record); // Increase AutoIncrementCurrent + // } + // } + // for (int i = value.Length; i < colCount; i++) + // { + // columnCollection[i].Init(record); + // } + // return record; + // } + // catch (Exception e) + // { + // // + // if (Common.ADP.IsCatchableOrSecurityExceptionType(e)) + // { + // FreeRecord(ref record); // WebData 104246 + // } + // throw; + // } + //} + + public string TableName + { + get => tableName; + set + { + if (value == null) + { + value = ""; + } + + if (String.Compare(tableName, value, true) != 0) + { + if (dataSet != null) + { + if (value.Length == 0) + throw new Exception("NoTableName"); + if ((0 == String.Compare(value, dataSet.DataSetName, true))) + throw new Exception($"DatasetConflictingName({dataSet.DataSetName}"); + } + tableName = value; + } + } + } + public string Namespace { get; internal set; } + } +} diff --git a/Core/Owl/Data/DataTableCollection.cs b/Core/Owl/Data/DataTableCollection.cs new file mode 100644 index 0000000..5c629b9 --- /dev/null +++ b/Core/Owl/Data/DataTableCollection.cs @@ -0,0 +1,197 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Text; + +namespace Owl.Data +{ + public class DataTableCollection : ICollection + { + private readonly DataSet _dataSet = null; + private readonly List _list; + + public DataTableCollection(DataSet dataSet) + { + _dataSet = dataSet; + _list = new List(); + } + + public DataTable this[int index] + { + get + { + try + { // Perf: use the readonly _list field directly and let ArrayList check the range + return (DataTable)_list[index]; + } + catch (ArgumentOutOfRangeException) + { + throw new Exception($"TableOutOfRange({index})"); + } + } + } + + /// + /// Gets the table in the collection with the given name (not case-sensitive). + /// + public DataTable this[string name] + { + get + { + int index = InternalIndexOf(name); + if (index == -2) + { + throw new Exception($"CaseInsensitiveNameConflict({name})"); + } + if (index == -3) + { + throw new Exception($"NamespaceNameConflict({name})"); + } + return (index < 0) ? null : (DataTable)_list[index]; + } + } + + public DataTable this[string name, string tableNamespace] + { + get + { + if (tableNamespace == null) + throw new ArgumentNullException(nameof(tableNamespace)); + int index = InternalIndexOf(name, tableNamespace); + if (index == -2) + { + throw new Exception($"CaseInsensitiveNameConflict({name})"); + } + return (index < 0) ? null : (DataTable)_list[index]; + } + } + + internal int InternalIndexOf(string tableName) + { + int cachedI = -1; + if ((null != tableName) && (0 < tableName.Length)) + { + int count = _list.Count; + int result = 0; + for (int i = 0; i < count; i++) + { + DataTable table = (DataTable)_list[i]; + result = NamesEqual(table.TableName, tableName, false, _dataSet.Locale); + if (result == 1) + { + // ok, we have found a table with the same name. + // let's see if there are any others with the same name + // if any let's return (-3) otherwise... + for (int j = i + 1; j < count; j++) + { + DataTable dupTable = (DataTable)_list[j]; + if (NamesEqual(dupTable.TableName, tableName, false, _dataSet.Locale) == 1) + return -3; + } + //... let's just return i + return i; + } + + if (result == -1) + cachedI = (cachedI == -1) ? i : -2; + } + } + return cachedI; + } + // Return value: + // >= 0: find the match + // -1: No match + // -2: At least two matches with different cases + internal int InternalIndexOf(string tableName, string tableNamespace) + { + int cachedI = -1; + if ((null != tableName) && (0 < tableName.Length)) + { + int count = _list.Count; + int result = 0; + for (int i = 0; i < count; i++) + { + DataTable table = (DataTable)_list[i]; + result = NamesEqual(table.TableName, tableName, false, _dataSet.Locale); + if ((result == 1) && (table.Namespace == tableNamespace)) + return i; + + if ((result == -1) && (table.Namespace == tableNamespace)) + cachedI = (cachedI == -1) ? i : -2; + } + } + return cachedI; + + } + + // Return value: + // > 0 (1) : CaseSensitve equal + // < 0 (-1) : Case-Insensitive Equal + // = 0 : Not Equal + internal int NamesEqual(string s1, string s2, bool fCaseSensitive, CultureInfo locale) + { + if (fCaseSensitive) + { + if (String.Compare(s1, s2, false) == 0) + return 1; + else + return 0; + } + + // Case, kana and width -Insensitive compare + if (locale.CompareInfo.Compare(s1, s2, + CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth) == 0) + { + if (String.Compare(s1, s2, false) == 0) + return 1; + else + return -1; + } + return 0; + } + + + #region Interface Members + public int Count => _list.Count; + + public bool IsReadOnly => throw new NotImplementedException(); + + public void Add(DataTable item) + { + if (!_list.Contains(item)) + _list.Add(item); + } + + public void Clear() + { + _list.Clear(); + } + + public bool Contains(DataTable item) + { + return _list.Contains(item); + } + + public void CopyTo(DataTable[] array, int arrayIndex) + { + _list.CopyTo(array, arrayIndex); + } + + public IEnumerator GetEnumerator() + { + return _list.GetEnumerator(); + } + + public bool Remove(DataTable item) + { + return _list.Remove(item); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return this.GetEnumerator(); + } + #endregion + } +} From 16e3b3b52fdb1e23544ac5474e3abe80a4bc75b1 Mon Sep 17 00:00:00 2001 From: Christiano Donke Date: Wed, 21 Mar 2018 14:42:21 -0300 Subject: [PATCH 5/7] Mapping to use Owl.Data instead of System.Data --- Core/Owl/Excel/DataTableImporter.cs | 4 ++-- Core/Owl/Excel/_ExcelBuilder.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/Owl/Excel/DataTableImporter.cs b/Core/Owl/Excel/DataTableImporter.cs index 9eafae0..7f256a7 100644 --- a/Core/Owl/Excel/DataTableImporter.cs +++ b/Core/Owl/Excel/DataTableImporter.cs @@ -1,7 +1,7 @@ using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; +using Owl.Data; using System; -using System.Data; using System.Globalization; using System.Linq; @@ -19,7 +19,7 @@ public void ImportDataSet(SpreadsheetDocument package, DataSet dataset) { for (int i = 0; i < dataset.Tables.Count; i++) { - System.Data.DataTable targetTable = dataset.Tables[i]; + DataTable targetTable = dataset.Tables[i]; string sheetName = string.IsNullOrEmpty(targetTable.TableName) ? "sheet" + i : targetTable.TableName; diff --git a/Core/Owl/Excel/_ExcelBuilder.cs b/Core/Owl/Excel/_ExcelBuilder.cs index 92c14b6..d8e1fad 100644 --- a/Core/Owl/Excel/_ExcelBuilder.cs +++ b/Core/Owl/Excel/_ExcelBuilder.cs @@ -1,6 +1,6 @@ using DocumentFormat.OpenXml.Packaging; +using Owl.Data; using System; -using System.Data; namespace Owl.Excel { From 0b50144d91118489c1a9903702c17096fda68504 Mon Sep 17 00:00:00 2001 From: Christiano Donke Date: Wed, 21 Mar 2018 14:43:42 -0300 Subject: [PATCH 6/7] Mapping to use Owl.Data and Owl.Drawing --- Core/Owl/Word/FormatStyle.cs | 4 ++-- Core/Owl/Word/ImageCreator.cs | 2 +- Core/Owl/Word/_WordBuilder.cs | 34 +++++++++++++++++----------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Core/Owl/Word/FormatStyle.cs b/Core/Owl/Word/FormatStyle.cs index 344451e..edb6158 100644 --- a/Core/Owl/Word/FormatStyle.cs +++ b/Core/Owl/Word/FormatStyle.cs @@ -22,14 +22,14 @@ public class FormatStyle { public string FontName { get; set; } - public System.Drawing.Color Color { get; set; } + public Drawing.Color Color { get; set; } public HighlightColors HighlightColor { get; set; } public FormatStyle() { this.HighlightColor = FormatStyle.HighlightColors.None; - this.Color = System.Drawing.Color.FromArgb(00, 00, 00); + this.Color = Drawing.Color.FromArgb(00, 00, 00); this.FontName = "Arial"; this.FontSize = 16; this.BasedOn = "Normal"; diff --git a/Core/Owl/Word/ImageCreator.cs b/Core/Owl/Word/ImageCreator.cs index cef62fe..1905ef4 100644 --- a/Core/Owl/Word/ImageCreator.cs +++ b/Core/Owl/Word/ImageCreator.cs @@ -3,7 +3,7 @@ using DocumentFormat.OpenXml.Wordprocessing; using Owl.Common; using System; -using System.Drawing; +using Owl.Drawing; using System.IO; using A = DocumentFormat.OpenXml.Drawing; using DW = DocumentFormat.OpenXml.Drawing.Wordprocessing; diff --git a/Core/Owl/Word/_WordBuilder.cs b/Core/Owl/Word/_WordBuilder.cs index a09822c..f18cc4b 100644 --- a/Core/Owl/Word/_WordBuilder.cs +++ b/Core/Owl/Word/_WordBuilder.cs @@ -1,6 +1,6 @@ using DocumentFormat.OpenXml.Packaging; +using Owl.Data; using System; -using System.Data; namespace Owl.Word { public class WordBuilder : IDisposable { @@ -40,29 +40,29 @@ public void AddCustomStyle(FormatStyle customStyle) { styleCreator.AddCustomStyle(customStyle); } - public void AddImage(string picturePath) { + //public void AddImage(string picturePath) { - var imageCreator = new ImageCreator(this._package); - imageCreator.InsertPicture(picturePath, 1.0M, HorizontalAlignmentType.Left); - } + // var imageCreator = new ImageCreator(this._package); + // imageCreator.InsertPicture(picturePath, 1.0M, HorizontalAlignmentType.Left); + //} - public void AddImage(string picturePath, HorizontalAlignmentType alignment) { + //public void AddImage(string picturePath, HorizontalAlignmentType alignment) { - var imageCreator = new ImageCreator(this._package); - imageCreator.InsertPicture(picturePath, 1.0M, alignment); - } + // var imageCreator = new ImageCreator(this._package); + // imageCreator.InsertPicture(picturePath, 1.0M, alignment); + //} - public void AddImage(string picturePath, decimal resizablePercent) { + //public void AddImage(string picturePath, decimal resizablePercent) { - var imageCreator = new ImageCreator(this._package); - imageCreator.InsertPicture(picturePath, resizablePercent, HorizontalAlignmentType.Left); - } + // var imageCreator = new ImageCreator(this._package); + // imageCreator.InsertPicture(picturePath, resizablePercent, HorizontalAlignmentType.Left); + //} - public void AddImage(string picturePath, decimal resizablePercent, HorizontalAlignmentType alignment) { + //public void AddImage(string picturePath, decimal resizablePercent, HorizontalAlignmentType alignment) { - var imageCreator = new ImageCreator(this._package); - imageCreator.InsertPicture(picturePath, resizablePercent, alignment); - } + // var imageCreator = new ImageCreator(this._package); + // imageCreator.InsertPicture(picturePath, resizablePercent, alignment); + //} public void CreateTextParagraph(TextParagraphType paragraphType, string text) { From ce4e0748b6fcccadc14450736c9e9af156401706 Mon Sep 17 00:00:00 2001 From: Christiano Donke Date: Wed, 21 Mar 2018 14:43:55 -0300 Subject: [PATCH 7/7] Custom properties to Cells on Word --- Core/Owl/Owl.NetStandard.csproj | 5 +- Core/Owl/Word/ICellProperties.cs | 24 +++ Core/Owl/Word/TableCreator.cs | 259 ++++++++++++++++++++++++++----- Core/Owl/Word/TableHeader.cs | 22 +++ Core/Owl/Word/TableStyle.cs | 12 +- 5 files changed, 274 insertions(+), 48 deletions(-) create mode 100644 Core/Owl/Word/ICellProperties.cs create mode 100644 Core/Owl/Word/TableHeader.cs diff --git a/Core/Owl/Owl.NetStandard.csproj b/Core/Owl/Owl.NetStandard.csproj index 85713bc..486a719 100644 --- a/Core/Owl/Owl.NetStandard.csproj +++ b/Core/Owl/Owl.NetStandard.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard1.5 Owl Owl true @@ -20,6 +20,7 @@ + @@ -28,8 +29,6 @@ - - diff --git a/Core/Owl/Word/ICellProperties.cs b/Core/Owl/Word/ICellProperties.cs new file mode 100644 index 0000000..7126bf0 --- /dev/null +++ b/Core/Owl/Word/ICellProperties.cs @@ -0,0 +1,24 @@ +using DocumentFormat.OpenXml.Wordprocessing; +using System; + +namespace Owl.Word +{ + public interface ICellProperties + { + JustificationValues Justification { get; set; } + + bool DrawShade { get; set; } + Drawing.Color ShadeColor { get; set; } + + + bool DrawBorder { get; set; } + Drawing.Color BorderColor { get; set; } + /// + /// Specifies the width of the border. Table borders are line borders, and so the width is specified in eighths of a point, with a minimum value of two (1/4 of a point) and a maximum value of 96 (twelve points) + /// + uint BorderSize { get; set; } + + + Action OnCellRender { get; set; } + } +} diff --git a/Core/Owl/Word/TableCreator.cs b/Core/Owl/Word/TableCreator.cs index b74df84..5b179c3 100644 --- a/Core/Owl/Word/TableCreator.cs +++ b/Core/Owl/Word/TableCreator.cs @@ -1,21 +1,23 @@ using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; +using Owl.Data; using System; -using System.Data; +using System.Collections.Generic; namespace Owl.Word { - internal class TableCreator { - - private enum RowIdentification { - - Title, - Header, + internal class TableCreator + { + private enum RowIdentification + { + Title, + Header, Row } - public void AddTable(WordprocessingDocument package, DataTable table, TableStyle tableStyle) { + public void AddTable(WordprocessingDocument package, DataTable table, TableStyle tableStyle) + { Body body = package.MainDocumentPart.Document.Body; @@ -34,13 +36,22 @@ public void AddTable(WordprocessingDocument package, DataTable table, TableStyle // Append the TableProperties object to the empty table. tbl.AppendChild(tblProp); - if (tableStyle.ShowTitle) { + if (tableStyle.ShowTitle) + { AddTitleRow(table, tableStyle, tbl); } - if (tableStyle.ShowHeader) { + if (tableStyle.ShowHeader) + { AddHeaderRow(table, tbl, tableStyle); } + else + { + if (tableStyle.CustomHeader != null) + { + AddCustomHeaderRow(table, tbl, tableStyle); + } + } AddRows(table, tableStyle, tbl, tblProp); @@ -48,7 +59,8 @@ public void AddTable(WordprocessingDocument package, DataTable table, TableStyle body.Append(tbl); } - private static TableProperties CreateTableProperties() { + private static TableProperties CreateTableProperties() + { return new TableProperties( new TableBorders( new TopBorder() { Val = new EnumValue(BorderValues.Single), Size = 1 }, @@ -61,14 +73,17 @@ private static TableProperties CreateTableProperties() { ); } - private static void SetTableWidth(TableStyle tableStyle, Table tbl) { + private static void SetTableWidth(TableStyle tableStyle, Table tbl) + { - if (tableStyle.WidthUnit == TableStyle.TableWidthUnit.Percent) { + if (tableStyle.WidthUnit == TableStyle.TableWidthUnit.Percent) + { double percent = tableStyle.Width / 100D; int wordPercent = (int)(5000 * (percent)); - TableWidth width = new TableWidth() { + TableWidth width = new TableWidth() + { Type = TableWidthUnitValues.Pct, Width = wordPercent.ToString() }; @@ -76,27 +91,27 @@ private static void SetTableWidth(TableStyle tableStyle, Table tbl) { } } - private static void AddRows(DataTable table, TableStyle tableStyle, Table wordTable, TableProperties tableProperties) { + private static void AddRows(DataTable table, TableStyle tableStyle, Table wordTable, TableProperties tableProperties) + { - for (int r = 0; r < table.Rows.Count; r++) { + for (int r = 0; r < table.Rows.Count; r++) + { // Create a row. TableRow tRow = new TableRow(); - for (int c = 0; c < table.Columns.Count; c++) { + for (int c = 0; c < table.Columns.Count; c++) + { // Create a cell. TableCell tCell = new TableCell(); + var tCellProperties = new TableCellProperties(); - if ((r % 2 == 0) && (tableStyle.EnableAlternativeBackgroundColor)) { - - var tCellProperties = new TableCellProperties(); - + if ((r % 2 == 0) && (tableStyle.EnableAlternativeBackgroundColor)) + { // Set Cell Color - Shading tCellColor = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = System.Drawing.ColorTranslator.ToHtml(tableStyle.AlternativeBackgroundColor) }; + Shading tCellColor = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = Drawing.ColorTranslator.ToHtml(tableStyle.AlternativeBackgroundColor) }; tCellProperties.Append(tCellColor); - - tCell.Append(tCellProperties); } string rowContent = table.Rows[r][c] == null ? string.Empty : table.Rows[r][c].ToString(); @@ -105,21 +120,50 @@ private static void AddRows(DataTable table, TableStyle tableStyle, Table wordTa SpacingBetweenLines spacingBetweenLines1 = new SpacingBetweenLines() { After = "0" }; paragProperties.Append(spacingBetweenLines1); + if (table.Columns[c] is ICellProperties cellProp) + { + Justification cellJustification = new Justification() { Val = cellProp.Justification }; + paragProperties.Append(cellJustification); + + cellProp.OnCellRender?.Invoke(tCell, table.Columns[c], rowContent); + + if (cellProp.DrawShade) + { + tCellProperties.RemoveAllChildren(); + + Shading tCellColor = new Shading() + { + Val = ShadingPatternValues.Clear, + Color = "auto", + Fill = Drawing.ColorTranslator.ToHtml(cellProp.ShadeColor) + }; + tCellProperties.Append(tCellColor); + } + + if (cellProp.DrawBorder) + CreateTableBorders(tCell, cellProp); + } + + Run run = new Run(); - if (rowContent.Contains(Environment.NewLine)) { + if (rowContent.Contains(Environment.NewLine)) + { string[] lines = rowContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); - for (int i = 0; i < lines.Length; i++) { + for (int i = 0; i < lines.Length; i++) + { var line = lines[i]; - if (i > 0) { + if (i > 0) + { run.AppendChild(new Break()); } Text newText = new Text(line); run.AppendChild(newText); } } - else { + else + { Text newText = new Text(rowContent); run.AppendChild(newText); } @@ -133,6 +177,9 @@ private static void AddRows(DataTable table, TableStyle tableStyle, Table wordTa // Specify the table cell content. tCell.Append(parag); + // Append the cell properties to the cell. + tCell.Append(tCellProperties); + // Append the table cell to the table row. tRow.Append(tCell); } @@ -142,18 +189,75 @@ private static void AddRows(DataTable table, TableStyle tableStyle, Table wordTa } } - private static void ApplyFontProperties(TableStyle tableStyle, RowIdentification rowIdentification, Run run) { + private static void CreateTableBorders(TableCell tCell, ICellProperties cellProp) + { + TableBorders borders = new TableBorders(); + + var topBorder = new TopBorder() + { + Val = new EnumValue(BorderValues.Thick), + Size = new UInt32Value() { Value = cellProp.BorderSize }, + Color = Drawing.ColorTranslator.ToHtml(cellProp.BorderColor) + }; + var bottomBorder = new BottomBorder() + { + Val = new EnumValue(BorderValues.Thick), + Size = new UInt32Value() { Value = cellProp.BorderSize }, + Color = Drawing.ColorTranslator.ToHtml(cellProp.BorderColor) + }; + var leftBorder = new LeftBorder() + { + Val = new EnumValue(BorderValues.Thick), + Size = new UInt32Value() { Value = cellProp.BorderSize }, + Color = Drawing.ColorTranslator.ToHtml(cellProp.BorderColor) + }; + var rightBorder = new RightBorder() + { + Val = new EnumValue(BorderValues.Thick), + Size = new UInt32Value() { Value = cellProp.BorderSize }, + Color = Drawing.ColorTranslator.ToHtml(cellProp.BorderColor) + }; + var insideHBorder = new InsideHorizontalBorder() + { + Val = new EnumValue(BorderValues.Thick), + Size = new UInt32Value() { Value = cellProp.BorderSize }, + Color = Drawing.ColorTranslator.ToHtml(cellProp.BorderColor) + }; + var insideVBorder = new InsideVerticalBorder() + { + Val = new EnumValue(BorderValues.Thick), + Size = new UInt32Value() { Value = cellProp.BorderSize }, + Color = Drawing.ColorTranslator.ToHtml(cellProp.BorderColor) + }; + + + borders.AppendChild(topBorder); + borders.AppendChild(bottomBorder); + borders.AppendChild(leftBorder); + borders.AppendChild(rightBorder); + borders.AppendChild(insideHBorder); + borders.AppendChild(insideVBorder); + + if (tCell.TableCellProperties == null) + tCell.TableCellProperties = new TableCellProperties(); + + tCell.TableCellProperties.Append(borders); + } + + private static void ApplyFontProperties(TableStyle tableStyle, RowIdentification rowIdentification, Run run) + { int fontSize = 0; - switch (rowIdentification) { + switch (rowIdentification) + { case RowIdentification.Title: fontSize = tableStyle.TitleFontSize; break; case RowIdentification.Header: fontSize = tableStyle.HeaderFontSize; break; - case RowIdentification.Row: + case RowIdentification.Row: default: fontSize = tableStyle.RowFontSize; break; @@ -167,12 +271,14 @@ private static void ApplyFontProperties(TableStyle tableStyle, RowIdentification run.PrependChild(runProp); } - private static void AddHeaderRow(DataTable table, Table wordTable, TableStyle tableStyle) { + private static void AddHeaderRow(DataTable table, Table wordTable, TableStyle tableStyle) + { // Create a row. TableRow tRow = new TableRow(); - foreach (DataColumn iColumn in table.Columns) { + foreach (DataColumn iColumn in table.Columns) + { // Create a cell. TableCell tCell = new TableCell(); @@ -180,7 +286,7 @@ private static void AddHeaderRow(DataTable table, Table wordTable, TableStyle ta TableCellProperties tCellProperties = new TableCellProperties(); // Set Cell Color - Shading tCellColor = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = System.Drawing.ColorTranslator.ToHtml(tableStyle.HeaderBackgroundColor) }; + Shading tCellColor = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = Drawing.ColorTranslator.ToHtml(tableStyle.HeaderBackgroundColor) }; tCellProperties.Append(tCellColor); // Append properties to the cell @@ -210,7 +316,76 @@ private static void AddHeaderRow(DataTable table, Table wordTable, TableStyle ta wordTable.Append(tRow); } - private static void AddTitleRow(DataTable table, TableStyle tableStyle, Table wordTable) { + private static void AddCustomHeaderRow(DataTable table, Table wordTable, TableStyle tableStyle) + { + foreach (List iRow in tableStyle.CustomHeader.Rows) + { + // Create a row. + TableRow tRow = new TableRow(); + + foreach (TableHeader.HeaderColumn iColumn in iRow) + { + // Create a cell. + TableCell tCell = new TableCell(); + + TableCellProperties tCellProperties = new TableCellProperties(); + + // Set Cell Color + Shading tCellColor = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = Drawing.ColorTranslator.ToHtml(tableStyle.HeaderBackgroundColor) }; + tCellProperties.Append(tCellColor); + + // Set Cell Column Span + if (iColumn.ColSpan > 1) + { + GridSpan tColSpan = new GridSpan() { Val = iColumn.ColSpan }; + tCellProperties.Append(tColSpan); + } + + VerticalMerge tRowSpan = null; + switch (iColumn.RowSpan) + { + case TableHeader.HeaderColumn.RowSpanStatus.Restart: + tRowSpan = new VerticalMerge() { Val = MergedCellValues.Restart }; + break; + case TableHeader.HeaderColumn.RowSpanStatus.Continue: + tRowSpan = new VerticalMerge(); + break; + } + if (tRowSpan != null) + tCellProperties.Append(tRowSpan); + + + // Append properties to the cell + tCell.Append(tCellProperties); + + ParagraphProperties paragProperties = new ParagraphProperties(); + Justification justification1 = new Justification() { Val = JustificationValues.Center }; + SpacingBetweenLines spacingBetweenLines1 = new SpacingBetweenLines() { After = "0" }; + paragProperties.Append(spacingBetweenLines1); + paragProperties.Append(justification1); + + var parag = new Paragraph(); + parag.Append(paragProperties); + + var run = new Run(new Text(iColumn.Title)); + ApplyFontProperties(tableStyle, RowIdentification.Header, run); + parag.Append(run); + + // Specify the table cell content. + tCell.Append(parag); + + // Append the table cell to the table row. + tRow.Append(tCell); + } + + // Append the table row to the table. + wordTable.Append(tRow); + } + + } + + private static void AddTitleRow(DataTable table, TableStyle tableStyle, Table wordTable) + { // Create a row. TableRow tRow = new TableRow(); @@ -221,7 +396,7 @@ private static void AddTitleRow(DataTable table, TableStyle tableStyle, Table wo TableCellProperties tCellProperties = new TableCellProperties(); // Set Cell Color - Shading tCellColor = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = System.Drawing.ColorTranslator.ToHtml(tableStyle.TitleBackgroundColor) }; + Shading tCellColor = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = Drawing.ColorTranslator.ToHtml(tableStyle.TitleBackgroundColor) }; tCellProperties.Append(tCellColor); // Set Cell Span @@ -255,19 +430,23 @@ private static void AddTitleRow(DataTable table, TableStyle tableStyle, Table wo wordTable.Append(tRow); } - private static void SetTableAlignment(HorizontalAlignmentType alignment, TableProperties tblProp) { + private static void SetTableAlignment(HorizontalAlignmentType alignment, TableProperties tblProp) + { TableJustification tblJustification = null; - if (alignment == HorizontalAlignmentType.Center) { + if (alignment == HorizontalAlignmentType.Center) + { tblJustification = new TableJustification() { Val = TableRowAlignmentValues.Center }; } - else if (alignment == HorizontalAlignmentType.Right) { + else if (alignment == HorizontalAlignmentType.Right) + { tblJustification = new TableJustification() { Val = TableRowAlignmentValues.Right }; } - else { + else + { tblJustification = new TableJustification() { Val = TableRowAlignmentValues.Left }; } diff --git a/Core/Owl/Word/TableHeader.cs b/Core/Owl/Word/TableHeader.cs new file mode 100644 index 0000000..70ed382 --- /dev/null +++ b/Core/Owl/Word/TableHeader.cs @@ -0,0 +1,22 @@ +using Owl.Data; +using System.Collections.Generic; + +namespace Owl.Word +{ + public class TableHeader + { + public List> Rows { get; } = new List>(); + + public class HeaderColumn + { + public enum RowSpanStatus + { + None, Restart, Continue + }; + public int ColSpan { get; set; } = 1; + public RowSpanStatus RowSpan { get; set; } = RowSpanStatus.None; + public DataColumn Column { get; set; } + public string Title { get; set; } = string.Empty; + } + } +} diff --git a/Core/Owl/Word/TableStyle.cs b/Core/Owl/Word/TableStyle.cs index 7d4b1e7..e17cc81 100644 --- a/Core/Owl/Word/TableStyle.cs +++ b/Core/Owl/Word/TableStyle.cs @@ -1,11 +1,10 @@ - -using System.Drawing; +using Owl.Drawing; namespace Owl.Word { public class TableStyle { - - public enum TableWidthUnit { + public enum TableWidthUnit + { Auto, Percent, } @@ -28,6 +27,8 @@ public enum TableWidthUnit { public bool ShowHeader { get; set; } + public TableHeader CustomHeader { get; set; } + public bool EnableAlternativeBackgroundColor { set; get; } public Color TitleBackgroundColor { get; set; } @@ -36,7 +37,8 @@ public enum TableWidthUnit { public Color AlternativeBackgroundColor { get; set; } - public TableStyle() { + public TableStyle() + { ShowHeader = true; ShowTitle = false;