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)); }
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); }
/// <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)); }