Exemplo n.º 1
0
        internal int           Index; //stores at 1 the first entry, that is biff8 entry 8.

        internal bool ColorIsValid(TExcelColor aColor, IFlexCelPalette xls)
        {
            int RealIndex = Index < 1 ? Index + 8 : Index;

            if (RealIndex <= 0 || RealIndex > 56)
            {
                return(false);
            }
            if (LastColorStored != aColor)
            {
                return(false);
            }
            Color c = xls.GetColorPalette(RealIndex);

            //If the color is Theme, it could have changed if the theme palette changed.
            if (aColor.ColorType == TColorType.Theme)
            {
                if (xls.GetColorTheme(aColor.Theme) != LastColorInTheme)
                {
                    return(false);
                }
            }

            return(c.ToArgb() == LastColorInPalette);
        }
Exemplo n.º 2
0
        internal int GetBiff8ColorIndex(IFlexCelPalette xls, TAutomaticColor autoType)
        {
            if (xls == null)
            {
                xls = TDummyFlexCelPalette.Instance;
            }
            switch (ColorType)
            {
            case TColorType.RGB:
                unchecked
                {
                    Color cRGB = ColorUtil.FromArgb((int)((uint)(0xFF000000 | FRGB)));
                    return(xls.NearestColorIndex(ApplyTint(cRGB)) - 1 + 8);      // nearestcolorindex returns 1-based
                }

            case TColorType.Automatic:
                return(GetAutomaticColorIndex(autoType));

            case TColorType.Theme:
                return(xls.NearestColorIndex(ApplyTint(xls.GetColorTheme(FTheme).ToColor(xls))) - 1 + 8);

            case TColorType.Indexed:
                return(FIndex - 1 + 8);     //findex is 1-based too.
            }

            return(1);
        }
Exemplo n.º 3
0
 internal static TExcelColor Copy(TExcelColor aColor, IFlexCelPalette Source, IFlexCelPalette Dest)
 {
     if (aColor.ColorType != TColorType.Indexed)
     {
         return(aColor);                                        //Themed colors are not converted when copying. Color Acc1 in source will be Color Acc2 in Dest, no matter if Acc and Dest are different.
     }
     if (Source.GetColorPalette(aColor.Index).ToArgb() == Dest.GetColorPalette(aColor.Index).ToArgb())
     {
         return(aColor);                                                                                              //Most common case, palettes are the same.
     }
     return(Source.GetColorPalette(aColor.Index));
 }
Exemplo n.º 4
0
        private static ColorBlend GetInterpolationColors(Color Color1, Color Color2, IFlexCelPalette Palette, TExcelGradient gr, bool InvertColors)
        {
            ColorBlend Result = null;

            if (gr.Stops != null && gr.Stops.Length > 0) //It should be gr.Stops.Length > 2, but we will add them even if not needed, so there aren't exceptions when retrieving them.
            {
                Result = new ColorBlend(gr.Stops.Length);
                for (int i = 0; i < gr.Stops.Length; i++)
                {
                    Result.Colors[i]    = gr.Stops[i].Color.ToColor(Palette);
                    Result.Positions[i] = (float)gr.Stops[i].Position;
                }

                FlxGradient.EnsureMinimumAndMaximum(Color1, Color2, ref Result);
                if (InvertColors)
                {
                    FlxGradient.InvertColorBlend(Result);
                }
            }

            return(Result);
        }
Exemplo n.º 5
0
        internal int GetBiff8ColorIndex(IFlexCelPalette xls, TAutomaticColor autoType, ref TColorIndexCache IndexCache)
        {
            if (xls == null)
            {
                xls = TDummyFlexCelPalette.Instance;
            }
            if (IndexCache.ColorIsValid(this, xls))
            {
                return(IndexCache.Index - 1 + 8);
            }

            int ColorIndex = GetBiff8ColorIndex(xls, autoType);

            IndexCache.LastColorStored    = this;
            IndexCache.LastColorInPalette = ToColor(xls).ToArgb();
            IndexCache.Index = ColorIndex + 1 - 8; //IndexCache is the same base as index.
            if (ColorType == TColorType.Theme)
            {
                IndexCache.LastColorInTheme = xls.GetColorTheme(Theme);
            }

            return(ColorIndex);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the value of this class as a system color.
        /// </summary>
        /// <param name="xls">Excel file containing the themes and palettes for the color indexes.</param>
        /// <param name="automaticColor">Color to be returned if this structure has an automatic color.</param>
        /// <returns></returns>
        public Color ToColor(IFlexCelPalette xls, Color automaticColor)
        {
            if (automaticColor != ColorUtil.Empty && IsAutomatic)
            {
                return(ApplyTint(automaticColor));
            }

            if (xls == null)
            {
                xls = TDummyFlexCelPalette.Instance;
            }
            Color Result = automaticColor;

            switch (ColorType)
            {
            case TColorType.RGB:
                unchecked
                {
                    Result = ColorUtil.FromArgb((int)((uint)(0xFF000000 | FRGB)));
                }
                break;

            case TColorType.Automatic:
                Result = GetAutomaticRGB();
                break;

            case TColorType.Theme:
                Result = xls.GetColorTheme(FTheme).ToColor(xls);
                break;

            case TColorType.Indexed:
                Result = xls.GetColorPalette(Index);
                break;
            }

            return(ApplyTint(Result));
        }
Exemplo n.º 7
0
 internal TExcelColor GetTabColor(IFlexCelPalette xls)
 {
     return(SheetColor);
 }
Exemplo n.º 8
0
        private static Brush GetGradient(ref Color ColorFg, ref Color ColorBg, TExcelGradient GradientFill, RectangleF CellRect, IFlexCelPalette Palette)
        {
            if (GradientFill == null)
            {
                return(new SolidBrush(ColorFg));
            }

            Color Color1 = ColorFg;
            Color Color2 = ColorBg;

            if (GradientFill.Stops != null && GradientFill.Stops.Length > 0)
            {
                Color1 = GradientFill.Stops[0].Color.ToColor(Palette);
                Color2 = GradientFill.Stops[GradientFill.Stops.Length - 1].Color.ToColor(Palette);
            }

            switch (GradientFill.GradientType)
            {
            case TGradientType.Linear:
            {
                TExcelLinearGradient lgr    = GradientFill as TExcelLinearGradient;
                LinearGradientBrush  Result = new LinearGradientBrush(CellRect, Color1, Color2, (real)(lgr.RotationAngle), true);
                Result.WrapMode = WrapMode.TileFlipXY;
                ColorBlend cb = GetInterpolationColors(Color1, Color2, Palette, lgr, false);
                if (cb != null)
                {
                    Result.InterpolationColors = cb;
                }
                return(Result);
            }

            case TGradientType.Rectangular:
            {
                TExcelRectangularGradient rgr    = GradientFill as TExcelRectangularGradient;
                PathGradientBrush         Result = new PathGradientBrush(new PointF[] {
                        CellRect.Location,
                        new PointF(CellRect.Right, CellRect.Top),
                        new PointF(CellRect.Right, CellRect.Bottom),
                        new PointF(CellRect.Left, CellRect.Bottom)
                    });
                Result.WrapMode       = WrapMode.TileFlipXY;
                Result.CenterPoint    = new PointF(CellRect.Left + (float)rgr.Left * CellRect.Width, CellRect.Top + (float)rgr.Top * CellRect.Height);
                Result.CenterColor    = Color1;
                Result.SurroundColors = new Color[] { Color2 };
                ColorBlend cb = GetInterpolationColors(Color1, Color2, Palette, rgr, true);         //must be (Color1, Color2), not (Color2, Color1) even if the blending will be reversed. This is because it will be reversed *after* Color1 and 2 have been added.
                if (cb != null)
                {
                    Result.InterpolationColors = cb;
                }

                return(Result);
            }
            }
            return(new SolidBrush(ColorFg));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Deprecated by the moment. Could be of use in the future.
        /// </summary>

        /*
         * internal static Brush CreateBmpPattern( TFlxPatternStyle Pattern, Color ColorFg, Color ColorBg )
         * {
         *  Bitmap Ac=null;
         *  switch (Pattern)
         *  {
         *      case TFlxPatternStyle.None: //No pattern
         *          return new SolidBrush(ColorBg);
         *
         *      case TFlxPatternStyle.Solid: //fill pattern
         *          return new SolidBrush(ColorFg);
         *
         *      case TFlxPatternStyle.Gray50: //50%
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          for (int y=0; y<4; y++)
         *              for (int x=0; x<4; x++)
         *                  if ((x + (y%2))%2==0)
         *                      Ac.SetPixel(x, y ,ColorFg);
         *                  else
         *                      Ac.SetPixel(x, y ,ColorBg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.Gray75: //75%
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,4, ColorFg );
         *          Ac.SetPixel(0,0,ColorBg);
         *          Ac.SetPixel(2,1,ColorBg);
         *          Ac.SetPixel(0,2,ColorBg);
         *          Ac.SetPixel(2,3,ColorBg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.Gray25: //25%
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,4,ColorBg);
         *          Ac.SetPixel(0,0,ColorFg);
         *          Ac.SetPixel(2,1,ColorFg);
         *          Ac.SetPixel(0,2,ColorFg);
         *          Ac.SetPixel(2,3,ColorFg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.Horizontal: //Horz lines
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,2,ColorFg);
         *          FillRect(Ac,0,2,4,4,ColorBg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.Vertical: //Vert lines
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,2,4,ColorFg);
         *          FillRect(Ac,2,0,4,4,ColorBg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.Down: //   \ lines
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,4,ColorBg);
         *          Ac.SetPixel(0,0,ColorFg); Ac.SetPixel(1,0,ColorFg);
         *          Ac.SetPixel(1,1,ColorFg); Ac.SetPixel(2,1,ColorFg);
         *          Ac.SetPixel(2,2,ColorFg); Ac.SetPixel(3,2,ColorFg);
         *          Ac.SetPixel(3,3,ColorFg); Ac.SetPixel(0,3,ColorFg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.Up: //   / lines
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac, 0,0,4,4,ColorBg);
         *          Ac.SetPixel(2,0,ColorFg); Ac.SetPixel(3,0,ColorFg);
         *          Ac.SetPixel(1,1,ColorFg); Ac.SetPixel(2,1,ColorFg);
         *          Ac.SetPixel(0,2,ColorFg); Ac.SetPixel(1,2,ColorFg);
         *          Ac.SetPixel(3,3,ColorFg); Ac.SetPixel(0,3,ColorFg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.Checker: //  diagonal hatch
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,4,ColorBg);
         *          Ac.SetPixel(0,0,ColorFg); Ac.SetPixel(1,0,ColorFg);
         *          Ac.SetPixel(0,1,ColorFg); Ac.SetPixel(1,1,ColorFg);
         *          Ac.SetPixel(2,2,ColorFg); Ac.SetPixel(3,2,ColorFg);
         *          Ac.SetPixel(2,3,ColorFg); Ac.SetPixel(3,3,ColorFg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.SemiGray75: //  bold diagonal
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,4,ColorFg);
         *          Ac.SetPixel(2,0,ColorBg); Ac.SetPixel(3,0,ColorBg);
         *          Ac.SetPixel(0,2,ColorBg); Ac.SetPixel(1,2,ColorBg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.LightHorizontal: //  thin horz lines
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,1,ColorFg);
         *          FillRect(Ac,0,1,4,4,ColorBg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.LightVertical: //  thin vert lines
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,1,4,ColorFg);
         *          FillRect(Ac,1,0,4,4,ColorBg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.LightDown: //  thin \ lines
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,4,ColorBg);
         *          Ac.SetPixel(0,0,ColorFg);
         *          Ac.SetPixel(1,1,ColorFg);
         *          Ac.SetPixel(2,2,ColorFg);
         *          Ac.SetPixel(3,3,ColorFg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.LightUp: //  thin / lines
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,4,ColorBg);
         *          Ac.SetPixel(3,0,ColorFg);
         *          Ac.SetPixel(2,1,ColorFg);
         *          Ac.SetPixel(1,2,ColorFg);
         *          Ac.SetPixel(0,3,ColorFg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.Grid: //  thin horz hatch
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,4,ColorFg);
         *          FillRect(Ac,1,1,4,4,ColorBg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.CrissCross: //  thin diag
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,4,ColorBg);
         *          Ac.SetPixel(0,0,ColorFg); Ac.SetPixel(2,0,ColorFg);
         *          Ac.SetPixel(1,1,ColorFg);
         *          Ac.SetPixel(0,2,ColorFg); Ac.SetPixel(2,2,ColorFg);
         *          Ac.SetPixel(3,3,ColorFg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.Gray16: //  12.5 %
         *          Ac= new Bitmap(4,4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,4,4,ColorBg);
         *          Ac.SetPixel(0,0,ColorFg);
         *          Ac.SetPixel(2,2,ColorFg);
         *          return new TextureBrush(Ac);
         *
         *      case TFlxPatternStyle.Gray8: //  6.25 % gray
         *          Ac= new Bitmap(8,8, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         *          FillRect(Ac,0,0,8,8,ColorBg);
         *          Ac.SetPixel(0,0,ColorFg);
         *          Ac.SetPixel(4,2,ColorFg);
         *          Ac.SetPixel(0,4,ColorFg);
         *          Ac.SetPixel(4,6,ColorFg);
         *          return new TextureBrush(Ac);
         *  }//case
         *
         *  return new SolidBrush(ColorBg);
         * }
         */

        internal static Brush CreatePattern(TFlxPatternStyle Pattern, Color ColorFg, Color ColorBg, TExcelGradient GradientFill, RectangleF CellRect, IFlexCelPalette Palette)
        {
            switch (Pattern)
            {
            case TFlxPatternStyle.None:     //No pattern
                return(null);

            case TFlxPatternStyle.Solid:     //fill pattern
                return(new SolidBrush(ColorFg));

            case TFlxPatternStyle.Gray50:     //50%
                return(new HatchBrush(HatchStyle.Percent50, ColorFg, ColorBg));

            case TFlxPatternStyle.Gray75:     //75%
                return(new HatchBrush(HatchStyle.Percent75, ColorFg, ColorBg));

            case TFlxPatternStyle.Gray25:     //25%
                return(new HatchBrush(HatchStyle.Percent25, ColorFg, ColorBg));

            case TFlxPatternStyle.Horizontal:     //Horz lines
                return(new HatchBrush(HatchStyle.DarkHorizontal, ColorFg, ColorBg));

            case TFlxPatternStyle.Vertical:     //Vert lines
                return(new HatchBrush(HatchStyle.DarkVertical, ColorFg, ColorBg));

            case TFlxPatternStyle.Down:     //   \ lines
                return(new HatchBrush(HatchStyle.DarkDownwardDiagonal, ColorFg, ColorBg));

            case TFlxPatternStyle.Up:     //   / lines
                return(new HatchBrush(HatchStyle.DarkUpwardDiagonal, ColorFg, ColorBg));

            case TFlxPatternStyle.Checker:     //  diagonal hatch
                return(new HatchBrush(HatchStyle.SmallCheckerBoard, ColorFg, ColorBg));

            case TFlxPatternStyle.SemiGray75:     //  bold diagonal
                return(new HatchBrush(HatchStyle.Percent70, ColorFg, ColorBg));

            case TFlxPatternStyle.LightHorizontal:     //  thin horz lines
                return(new HatchBrush(HatchStyle.LightHorizontal, ColorFg, ColorBg));

            case TFlxPatternStyle.LightVertical:     //  thin vert lines
                return(new HatchBrush(HatchStyle.LightVertical, ColorFg, ColorBg));

            case TFlxPatternStyle.LightDown:     //  thin \ lines
                return(new HatchBrush(HatchStyle.LightDownwardDiagonal, ColorFg, ColorBg));

            case TFlxPatternStyle.LightUp:     //  thin / lines
                return(new HatchBrush(HatchStyle.LightUpwardDiagonal, ColorFg, ColorBg));

            case TFlxPatternStyle.Grid:     //  thin horz hatch
                return(new HatchBrush(HatchStyle.SmallGrid, ColorFg, ColorBg));

            case TFlxPatternStyle.CrissCross:     //  thin diag
                return(new HatchBrush(HatchStyle.Percent60, ColorFg, ColorBg));

            case TFlxPatternStyle.Gray16:     //  12.5 %
                return(new HatchBrush(HatchStyle.Percent10, ColorFg, ColorBg));

            case TFlxPatternStyle.Gray8:     //  6.25 % gray
                return(new HatchBrush(HatchStyle.Percent05, ColorFg, ColorBg));

            case TFlxPatternStyle.Gradient:
                return(GetGradient(ref ColorFg, ref ColorBg, GradientFill, CellRect, Palette));
            }//case

            return(new SolidBrush(ColorBg));
        }
Exemplo n.º 10
0
 /// <summary>
 /// Returns the value of this class as a system color.
 /// </summary>
 /// <param name="Xls">Excel file containing the themes and palettes for the color indexes.</param>
 public Color ToColor(IFlexCelPalette Xls)
 {
     return(ToColor(Xls, ColorUtil.Empty));
 }