示例#1
0
文件: ExcelColor.cs 项目: Daoting/dt
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Dt.Xls.ExcelColor" /> class.
 /// </summary>
 /// <param name="colorType">Type of the color.</param>
 /// <param name="color">The value of the color</param>
 /// <param name="tint">The tint applied to the color</param>
 public ExcelColor(ExcelColorType colorType, uint color, double tint = 0.0)
 {
     if ((((colorType == ExcelColorType.Theme) && (color > 11)) && ((color != 0xf1) && (color != 0xf2))) && (((color != 0xf3) && (color != 0xf4)) && (color != 0xff)))
     {
         throw new ArgumentOutOfRangeException(ResourceHelper.GetResourceString("themeColorIndexError"));
     }
     if ((tint > 1.0) || (tint < -1.0))
     {
         throw new ArgumentOutOfRangeException(ResourceHelper.GetResourceString("colorTintError"));
     }
     if ((colorType == ExcelColorType.Indexed) && (color == 0x7fff))
     {
         this.IsAutoColor = true;
     }
     this._colorType = colorType;
     this._color     = color;
     this._tint      = tint;
 }
示例#2
0
        internal static void WriteColor(XmlWriter writer, IExcelColor color, ExcelDrawingColorSettings drawingColorSettings)
        {
            if (color != null)
            {
                if (drawingColorSettings == null)
                {
                    drawingColorSettings = new ExcelDrawingColorSettings();
                }
                if (color.ColorType == ExcelColorType.RGB)
                {
                    using (writer.WriteElement("srgbClr", null, "a"))
                    {
                        writer.WriteAttributeString("val", ((uint)color.Value).ToString("X8").Substring(2));
                        uint num = 0xff;
                        uint.TryParse(((uint)color.Value).ToString("X8").Substring(0, 2), (NumberStyles)NumberStyles.HexNumber, (IFormatProvider)CultureInfo.InvariantCulture, out num);
                        double num2 = ((double)num) / 255.0;
                        if (!(num2 - 1.0).IsZero() && !num2.IsZero())
                        {
                            using (writer.WriteElement("alpha", null, "a"))
                            {
                                int num5 = (int)(num2 * 100000.0);
                                writer.WriteAttributeString("val", ((int)num5).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                                goto Label_0138;
                            }
                        }
                        if ((drawingColorSettings != null) && drawingColorSettings.Alpha.HasValue)
                        {
                            writer.WriteLeafElementWithAttribute("alpha", null, "a", "val", ((double)drawingColorSettings.Alpha.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                        }
Label_0138:
                        if (drawingColorSettings != null)
                        {
                            if (drawingColorSettings.Tint.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("tint", null, "a", "val", ((double)drawingColorSettings.Tint.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            if (drawingColorSettings.Shade.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("shade", null, "a", "val", ((double)drawingColorSettings.Shade.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                        }
                        return;
                    }
                }
                if (color.ColorType == ExcelColorType.Theme)
                {
                    using (writer.WriteElement("schemeClr", null, "a"))
                    {
                        writer.WriteAttributeString("val", ((ColorSchemeIndex)color.Value).ToSchemeClrValue());
                        if (!color.Tint.IsZero())
                        {
                            if ((drawingColorSettings != null) && drawingColorSettings.LumMod.HasValue)
                            {
                                double num9 = color.Tint * 100000.0;
                                writer.WriteLeafElementWithAttribute("tint", null, "a", "val", ((double)num9).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            else if (color.Tint < 0.0)
                            {
                                double num10 = (1.0 + color.Tint) * 100000.0;
                                writer.WriteLeafElementWithAttribute("lumMod", null, "a", "val", ((double)num10).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            else
                            {
                                double num11 = color.Tint * 100000.0;
                                writer.WriteLeafElementWithAttribute("tint", null, "a", "val", ((double)num11).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                        }
                        else if ((drawingColorSettings != null) && drawingColorSettings.Tint.HasValue)
                        {
                            writer.WriteLeafElementWithAttribute("tint", null, "a", "val", ((double)drawingColorSettings.Tint.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                        }
                        if (drawingColorSettings != null)
                        {
                            if (drawingColorSettings.Alpha.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("alpha", null, "a", "val", ((double)drawingColorSettings.Alpha.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            if (drawingColorSettings.Shade.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("shade", null, "a", "val", ((double)drawingColorSettings.Shade.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            if (drawingColorSettings.Sat.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("sat", null, "a", "val", ((double)drawingColorSettings.Sat.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            if (drawingColorSettings.SatMod.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("satMod", null, "a", "val", ((double)drawingColorSettings.SatMod.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            if (drawingColorSettings.SatOff.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("satOff", null, "a", "val", ((double)drawingColorSettings.SatOff.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            if (drawingColorSettings.Hue.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("hue", null, "a", "val", ((double)drawingColorSettings.Hue.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            if (drawingColorSettings.HueMod.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("hueMod", null, "a", "val", ((double)drawingColorSettings.HueMod.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            if (drawingColorSettings.HueOff.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("hueOff", null, "a", "val", ((double)drawingColorSettings.HueOff.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            if (drawingColorSettings.Lum.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("lum", null, "a", "val", ((double)drawingColorSettings.Lum.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            if (drawingColorSettings.LumMod.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("lumMod", null, "a", "val", ((double)drawingColorSettings.LumMod.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                            if (drawingColorSettings.LumOff.HasValue)
                            {
                                writer.WriteLeafElementWithAttribute("lumOff", null, "a", "val", ((double)drawingColorSettings.LumOff.Value).ToString((IFormatProvider)CultureInfo.InvariantCulture));
                            }
                        }
                        return;
                    }
                }
                ExcelColorType colorType = color.ColorType;
            }
        }