Beispiel #1
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);

            Graphics g = e.Graphics;


            // 如果设置了渐变色
            if (this.FirstColor != Color.Empty && this.SecondColor != Color.Empty)
            {
                if (RoundBorderRadius > 0)
                {
                    // 填充圆角矩形
                    using (LinearGradientBrush brush = new LinearGradientBrush(
                               new Point(this.Width / 2, 0),
                               new Point(this.Width / 2, this.Height),
                               this.FirstColor,
                               this.SecondColor
                               ))
                    {
                        g.FillRoundedRectangle(brush, 0, 0, this.Width, this.Height, RoundBorderRadius);
                    }
                }
                else
                {
                    // 填充直角矩形
                    GradientFill.Fill(g, this.ClientRectangle, this.FirstColor, this.SecondColor, this.GradientDirection);
                }
            }

            if (this.BorderColor != Color.Empty)
            {
                if (RoundBorderRadius > 0)
                {
                    // 画圆角边框
                    using (Pen borderPen = new Pen(this.BorderColor, BorderWidth))
                    {
                        g.DrawRoundedRectangle(borderPen, 0, 0, this.Width - 1, this.Height - 1, this.RoundBorderRadius);
                    }
                }
                else
                {
                    // 画直角边框
                    using (Pen borderPen = new Pen(this.BorderColor, BorderWidth))
                    {
                        g.DrawRectangle(borderPen, 0, 0, this.Width - 1, this.Height - 1);
                    }
                }
            }
            else
            {
                if (BottomBorderColor != Color.Empty)
                {
                    using (Pen borderPen = new Pen(this.BottomBorderColor, BorderWidth))
                    {
                        g.DrawLine(borderPen, 0, this.Height - 1, this.Width, this.Height - 1);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 创建渐变填充的圆角矩形位图
        /// </summary>
        /// <param name="rc"></param>
        /// <param name="startColorValue"></param>
        /// <param name="endColorValue"></param>
        /// <param name="borderColor"></param>
        /// <param name="size"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        private Bitmap GetGradiendRoundedRectangle(Rectangle rc, Color startColorValue, Color endColorValue, Color borderColor, Size size, FillDirection direction)
        {
            Bitmap outputImage = new Bitmap(rc.Width, rc.Height);
            // Create temporary graphics
            Graphics gx = Graphics.FromImage(outputImage);

            GradientFill.Fill(
                gx,
                rc,
                startColorValue,
                endColorValue,
                direction);

            Rectangle roundedRect = rc;

            roundedRect.Width--;
            roundedRect.Height--;

            Bitmap borderImage = ImposeRoundedRectangle(roundedRect, borderColor, size);

            ImageAttributes attrib = new ImageAttributes();

            attrib.SetColorKey(Color.Green, Color.Green);

            gx.DrawImage(borderImage, rc, 0, 0, borderImage.Width, borderImage.Height, GraphicsUnit.Pixel, attrib);

            // Clean up
            attrib.Dispose();
            gx.Dispose();

            return(outputImage);
        }
Beispiel #3
0
        public static float[] GetGradientLine(GradientFill gf)
        {
            float[] result = new float[4];

            System.Drawing.PointF[] pts = GradientFill.GradientVexRect.SysPointFs();
            using (Draw2D.Matrix m = gf.Transform.SysMatrix())
            {
                m.TransformPoints(pts);
            }

            if (gf.GradientType == GradientType.Linear)
            {
                result[0] = pts[0].X;
                result[1] = pts[0].Y;
                result[2] = pts[1].X;
                result[3] = pts[1].Y;
            }
            else // radial is center to rightCenter edge
            {
                result[0] = pts[0].X + (pts[1].X - pts[0].X) / 2;
                result[1] = pts[0].Y + (pts[2].Y - pts[0].Y) / 2;
                result[2] = pts[1].X;
                result[3] = pts[1].Y + (pts[2].Y - pts[0].Y) / 2;
            }

            return(result);
        }
        static Color32[] RasterizeGradient(GradientFill gradient, int width, int height)
        {
            Color32[] pixels = new Color32[width * height];

            if (gradient.Type == GradientFillType.Linear)
            {
                int pixIndex = 0;
                for (int x = 0; x < width; x++)
                {
                    pixels[pixIndex++] = SampleGradient(gradient.Stops, x / (float)(width - 1));
                }
                for (int y = 1; y < height; y++)
                {
                    Array.Copy(pixels, 0, pixels, pixIndex, width);
                    pixIndex += width;
                }
            }
            else if (gradient.Type == GradientFillType.Radial)
            {
                int pixIndex = 0;
                for (int y = 0; y < height; y++)
                {
                    float v = y / ((float)height - 1);
                    for (int x = 0; x < width; x++)
                    {
                        float u = x / ((float)width - 1);
                        pixels[pixIndex++] = SampleGradient(gradient.Stops, RadialAddress(new Vector2(u, 1.0f - v), gradient.RadialFocus));
                    }
                }
            }

            return(pixels);
        }
        internal GradientFillContent(LottieDrawable lottieDrawable, BaseLayer layer, GradientFill fill)
        {
            _layer          = layer;
            Name            = fill.Name;
            _lottieDrawable = lottieDrawable;
            _type           = fill.GradientType;
            _path.FillType  = fill.FillType;
            _cacheSteps     = (int)(lottieDrawable.Composition.Duration / CacheStepsMs);

            _colorAnimation = fill.GradientColor.CreateAnimation();
            _colorAnimation.ValueChanged += OnValueChanged;
            layer.AddAnimation(_colorAnimation);

            _opacityAnimation = fill.Opacity.CreateAnimation();
            _opacityAnimation.ValueChanged += OnValueChanged;
            layer.AddAnimation(_opacityAnimation);

            _startPointAnimation = fill.StartPoint.CreateAnimation();
            _startPointAnimation.ValueChanged += OnValueChanged;
            layer.AddAnimation(_startPointAnimation);

            _endPointAnimation = fill.EndPoint.CreateAnimation();
            _endPointAnimation.ValueChanged += OnValueChanged;
            layer.AddAnimation(_endPointAnimation);
        }
Beispiel #6
0
        private static void AddGradient(SpreadsheetDocument spreadSheet, string dummyColorCode, string firstColorCode, string secondColorCode)
        {
            var wbPart      = spreadSheet.GetPartsOfType <WorkbookPart>().FirstOrDefault();
            var wbStylePart = wbPart?.GetPartsOfType <WorkbookStylesPart>().FirstOrDefault();
            var stylesheet  = wbStylePart?.Stylesheet;

            var oldFill =
                stylesheet?.Fills.FirstOrDefault(f => f.OuterXml.Contains(dummyColorCode));             // find the fill that uses your unique color

            if (oldFill == null)
            {
                return;
            }
            var gradientFill = new GradientFill {
                Degree = 0
            };

            gradientFill.Append(new GradientStop {
                Position = 0D, Color = new Color {
                    Rgb = firstColorCode
                }
            });
            gradientFill.Append(new GradientStop {
                Position = 1D, Color = new Color {
                    Rgb = secondColorCode
                }
            });
            oldFill.ReplaceChild(gradientFill, oldFill.FirstChild);        // inside the fill replace the patternFill with your gradientFill
        }
Beispiel #7
0
        private ColorBlend GetColorBlend(GradientFill fill)
        {
            List <float>    positions = new List <float>();
            List <Ms.Color> colors    = new List <Ms.Color>();

            int numGradients = fill.Fills.Count;

            for (int i = 0; i < numGradients; i++)
            {
                positions.Add(fill.Stops[i]);
                colors.Add(GetColor(fill.Fills[i]));
            }

            // GDI color blends must start at 0.0 and end at 1.0 or they will crash
            if ((float)positions[0] != 0.0F)
            {
                positions.Insert(0, 0.0F);
                colors.Insert(0, colors[0]);
            }
            if ((float)positions[positions.Count - 1] != 1.0F)
            {
                positions.Add(1.0F);
                colors.Add(colors[colors.Count - 1]);
            }

            ColorBlend cb = new ColorBlend(positions.Count);

            cb.Colors    = colors.ToArray();
            cb.Positions = positions.ToArray();

            return(cb);
        }
        public static void Run()
        {
            // ExStart:ModifyShapeGradientFillData
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ShapeGradientFillData();
            // Load the Visio diagram
            Diagram diagram = new Diagram(dataDir + "ShapewithGradientFill.vsdx");

            // get page by name
            Aspose.Diagram.Page page = diagram.Pages.GetPage("Page-1");
            // get shape by ID
            Aspose.Diagram.Shape shape = page.Shapes.GetShape(1);
            // get the gradient fill properties
            GradientFill gradientfill = shape.Fill.GradientFill;
            // get the gradient stops
            GradientStopCollection stops = gradientfill.GradientStops;
            // get the gradient stop by index
            GradientStop stop = stops[0];

            // set gradient stop properties
            stop.Color.Ufe.F                 = "";
            stop.Position.Value              = 0.5;
            gradientfill.GradientDir.Value   = (int)GradientFillDir.RectangleFromBottomRight;
            gradientfill.GradientAngle.Value = 0.7853981633974501;
            // save the Visio drawing
            diagram.Save(dataDir + "ShapewithGradientFill_out.vsdx", SaveFileFormat.VSDX);
            // ExEnd:ModifyShapeGradientFillData
        }
Beispiel #9
0
        public void SetRunProperties(RunProperties runProperties,
                                     DocumentFormat.OpenXml.Presentation.Shape shape,
                                     ref LinkedList <string> effectShapes)
        {
            if (runProperties != null)
            {
                EffectList   effects  = runProperties.GetFirstChild <EffectList>();
                GradientFill gradient = runProperties.GetFirstChild <GradientFill>();

                if ((shape.TextBody.BodyProperties != null && shape.TextBody.BodyProperties.FromWordArt != null && shape.TextBody.BodyProperties.FromWordArt) ||
                    (effects != null && effects.HasChildren) ||
                    (gradient != null && gradient.HasChildren))
                {
                    UInt32Value id = shape.NonVisualShapeProperties.NonVisualDrawingProperties.Id;
                    effectShapes.AddLast(slide.slideIndex + "_" + id.Value);
                }


                //get the text color.
                var solidFill = runProperties.GetFirstChild <SolidFill>();
                if (solidFill != null)
                {
                    this.ReadSolidFillColors(solidFill);
                }
                if (runProperties.FontSize != null)
                {
                    FontSize = runProperties.FontSize / Globals.FontPoint;
                }
                if (runProperties.Bold != null)
                {
                    Bold = runProperties.Bold;
                }

                if (runProperties.Italic != null)
                {
                    Italic = runProperties.Italic;
                }
                if (runProperties.Underline != null)
                {
                    Underline = runProperties.Underline.Value.ToString();
                }
                if (runProperties.Spacing != null)
                {
                    Spacing = runProperties.Spacing.Value;
                }

                var latinFonts        = runProperties.GetFirstChild <LatinFont>();
                var coplexScriptFonts = runProperties.Descendants <ComplexScriptFont>();

                if (latinFonts != null)
                {
                    this.ReadFontFamilyFromTheme(latinFonts);
                }
                else if (coplexScriptFonts.GetEnumerator().Current != null)
                {
                    FontFamily = coplexScriptFonts.GetEnumerator().Current.Typeface;
                }
            }
        }
Beispiel #10
0
 public GradientColor(Color color1, Color color2, GradientFill gradient)
 {
     this.color1 = color1;
     this.color2 = color2;
     this.fill   = gradient;
     this.rect   = new Rectangle(0, 0, 100, 100);
     this.align  = TabAlignment.Top;
 }
Beispiel #11
0
        private void DrawSeparator(PaintEventArgs e, Point point, int widthHeight, Orientation orientation)
        {
            for (int i = 0; i < 2; i++)
            {
                Color colorL = (i == 0 ? Strings.ToColor(Separator1L) : Strings.ToColor(Separator2L));
                Color colorD = (i == 0 ? Strings.ToColor(Separator1D) : Strings.ToColor(Separator2D));
                switch (orientation)
                {
                case Orientation.Horizontal:
                {
                    Rectangle rect = new Rectangle(point.X, point.Y + i, widthHeight / 3, 1);
                    if (e.ClipRectangle.IntersectsWith(rect))
                    {
                        GradientFill.Fill(e.Graphics, rect, colorL, colorD, GradientFill.FillDirection.LeftToRight);
                    }

                    rect.Offset(rect.Width, 0);
                    if (e.ClipRectangle.IntersectsWith(rect))
                    {
                        e.Graphics.FillRectangle(new SolidBrush(colorD), rect);
                    }

                    rect.Offset(rect.Width, 0);
                    if (e.ClipRectangle.IntersectsWith(rect))
                    {
                        GradientFill.Fill(e.Graphics, rect, colorD, colorL, GradientFill.FillDirection.LeftToRight);
                    }
                }
                break;

                case Orientation.Vertical:
                {
                    Rectangle rect = new Rectangle(point.X + i, point.Y, 1, widthHeight / 3);
                    if (e.ClipRectangle.IntersectsWith(rect))
                    {
                        GradientFill.Fill(e.Graphics, rect, colorL, colorD, GradientFill.FillDirection.TopToBottom);
                    }

                    rect.Offset(0, rect.Height);
                    if (e.ClipRectangle.IntersectsWith(rect))
                    {
                        e.Graphics.FillRectangle(new SolidBrush(colorD), rect);
                    }

                    rect.Offset(0, rect.Height);
                    if (e.ClipRectangle.IntersectsWith(rect))
                    {
                        GradientFill.Fill(e.Graphics, rect, colorD, colorL, GradientFill.FillDirection.TopToBottom);
                    }
                }
                break;

                default:
                    break;
                }
            }
        }
 static Color32[] RasterizeGradientStripe(GradientFill gradient, int width)
 {
     Color32[] pixels = new Color32[width];
     for (int x = 0; x < width; ++x)
     {
         float u = x / ((float)width - 1);
         pixels[x] = SampleGradient(gradient.Stops, u);
     }
     return(pixels);
 }
Beispiel #13
0
        public void SetGradientFill()
        {
            #region radspreadsheet-features-formatting-cells_5
            Workbook  workbook  = new Workbook();
            Worksheet worksheet = workbook.Worksheets.Add();
            worksheet.Rows[0].SetHeight(new RowHeight(50, true));

            GradientFill greenGradientFill = new GradientFill(GradientType.Horizontal, Color.FromRgb(46, 204, 113), Color.FromRgb(0, 134, 56));
            worksheet.Cells[0, 0, 0, 5].SetFill(greenGradientFill);
            #endregion
        }
        public void SetGradientFill()
        {
            #region radspreadprocessing-working-with-cells-get-set-clear-properties_5
            Workbook  workbook  = new Workbook();
            Worksheet worksheet = workbook.Worksheets.Add();
            worksheet.Rows[0].SetHeight(new RowHeight(50, true));

            GradientFill greenGradientFill = new GradientFill(GradientType.Horizontal, Color.FromRgb(46, 204, 113), Color.FromRgb(0, 134, 56));
            worksheet.Cells[0, 0, 0, 5].SetFill(greenGradientFill);
            #endregion
        }
    void Start()
    {
        var tessOptions = new VectorUtils.TessellationOptions()
        {
            StepDistance         = 100.0f,
            MaxCordDeviation     = 0.5f,
            MaxTanAngleDeviation = 0.1f,
            SamplingStepSize     = 0.01f
        };

        // Prepare the fill
        var fill = new GradientFill()
        {
            Type  = GradientFillType.Linear,
            Stops = new GradientStop[] {
                new GradientStop()
                {
                    Color = Color.blue, StopPercentage = 0.0f
                },
                new GradientStop()
                {
                    Color = Color.red, StopPercentage = 1.0f
                },
            }
        };

        // Build the scene
        var cornerRad = new Vector2(10, 10);
        var rect      = VectorUtils.BuildRectangleContour(new Rect(0, 0, 100, 100), cornerRad, cornerRad, cornerRad, cornerRad);
        var scene     = new Scene()
        {
            Root = new SceneNode()
            {
                Shapes = new List <Shape> {
                    new Shape()
                    {
                        Contours = new BezierContour[] { rect },
                        Fill     = fill
                    }
                }
            }
        };

        // Dynamically import the SVG data, and tessellate the resulting vector scene.
        var geoms = VectorUtils.TessellateScene(scene, tessOptions);

        // Build a sprite with the tessellated geometry.
        var sprite = VectorUtils.BuildSprite(geoms, 10.0f, VectorUtils.Alignment.Center, Vector2.zero, 16, true);

        GetComponent <SpriteRenderer>().sprite = sprite;
    }
        static void ChangeCellGradientFill(IWorkbook workbook)
        {
            workbook.BeginUpdate();
            try
            {
                Worksheet worksheet = workbook.Worksheets[0];

                worksheet.Range["C3:F8"].Merge();
                worksheet.Range["C3:F8"].Value = "Test";
                worksheet.Range["C3:F8"].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
                worksheet.Range["C3:F8"].Alignment.Vertical   = SpreadsheetVerticalAlignment.Center;

                worksheet.Range["C13:F18"].Merge();
                worksheet.Range["C13:F18"].Value = "Test";
                worksheet.Range["C13:F18"].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
                worksheet.Range["C13:F18"].Alignment.Vertical   = SpreadsheetVerticalAlignment.Center;

                #region #GradientLinear
                // Specify a linear gradient fill for a cell.
                Fill fillA1 = worksheet.Cells["A1"].Fill;
                fillA1.FillType      = FillType.Gradient;
                fillA1.Gradient.Type = GradientFillType.Linear;
                // Set the tilt for the gradient line in degrees.
                // 90 degree angle defines a color transition from the top to the bottom.
                fillA1.Gradient.Degree = 90;
                // Specify two gradient colors.
                // The position of a color stop should be either 0 (start) or 1 (end).
                fillA1.Gradient.Stops.Add(0, Color.Yellow);
                fillA1.Gradient.Stops.Add(1, Color.SkyBlue);

                // Specify a linear gradient fill for a range.
                worksheet.Range["C3:F8"].Fill.FillType = FillType.Gradient;
                GradientFill rangeGradient1 = worksheet.Range["C3:F8"].Fill.Gradient;
                rangeGradient1.Type = GradientFillType.Linear;
                // Set the tilt for the gradient line in degrees.
                // 45 degree angle defines a color transition from top left to bottom right.
                rangeGradient1.Degree = 45;
                // Specify two gradient colors.
                // The position of a color stop should be either 0 (start) or 1 (end).
                GradientStopCollection rangeStops1 = rangeGradient1.Stops;
                rangeStops1.Add(0, Color.BlanchedAlmond);
                rangeStops1.Add(1, Color.Blue);
                #endregion #GradientLinear
            }
            finally
            {
                workbook.EndUpdate();
            }
        }
Beispiel #17
0
        private string GetGradientLineString(GradientFill gf)
        {
            string result = "";

            float[] pts   = GetGradientLine(gf);
            string  comma = "";

            for (int i = 0; i < pts.Length; i++)
            {
                result += comma + pts[i].ToString("0.##");
                comma   = ",";
            }

            return(result);
        }
Beispiel #18
0
        /// <summary>
        /// 绘制渐变填充的半透明圆角矩形
        /// </summary>
        /// <param name="gx">Destination graphics</param>
        /// <param name="rc">Destination rectangle</param>
        /// <param name="startColorValue">Starting color for gradient</param>
        /// <param name="endColorValue">End color for gradient</param>
        /// <param name="borderColor">The color of the border</param>
        /// <param name="size">The size of the rounded corners</param>
        /// <param name="transparency">Transparency constant</param>
        public void DrawGradientRoundedRectangleAlpha(Graphics gx, Rectangle rc, Color startColorValue, Color endColorValue, Color borderColor, Size size, byte transparency, FillDirection direction)
        {
            // Prepare image for gradient
            Bitmap gradientImage = new Bitmap(rc.Width, rc.Height);
            // Create temporary graphics
            Graphics gxGradient = Graphics.FromImage(gradientImage);
            // This is our rectangle
            Rectangle roundedRect = new Rectangle(0, 0, rc.Width, rc.Height);

            // Fill in gradient
            GradientFill.Fill(
                gxGradient,
                roundedRect,
                startColorValue,
                endColorValue,
                direction);

            // Prepare the copy of the screen graphics
            Bitmap   tempBitmap = new Bitmap(rc.Width, rc.Height);
            Graphics tempGx     = Graphics.FromImage(tempBitmap);

            // Copy from the screen's graphics to the temp graphics
            CopyGraphics(gx, tempGx, rc.Width, rc.Height, rc.X, rc.Y);
            // Draw the gradient image with transparency on the temp graphics
            tempGx.DrawAlpha(gradientImage, transparency, rc.X, rc.Y);
            // Cut out the transparent image
            gxGradient.DrawImage(tempBitmap, new Rectangle(0, 0, rc.Width, rc.Height), rc, GraphicsUnit.Pixel);
            // Prepare for imposing
            roundedRect.Width--;
            roundedRect.Height--;
            // Impose the rounded rectangle with transparent color
            Bitmap borderImage = ImposeRoundedRectangle(roundedRect, borderColor, size);
            // Draw the transparent rounded rectangle
            ImageAttributes attrib = new ImageAttributes();

            attrib.SetColorKey(Color.Green, Color.Green);
            gxGradient.DrawImage(borderImage, new Rectangle(0, 0, rc.Width, rc.Height), 0, 0, borderImage.Width, borderImage.Height, GraphicsUnit.Pixel, attrib);
            // OK... now are ready to draw the final image on the original graphics
            gx.DrawImageTransparent(gradientImage, rc);

            // Clean up
            attrib.Dispose();
            tempGx.Dispose();
            tempBitmap.Dispose();
            gradientImage.Dispose();
            gxGradient.Dispose();
        }
Beispiel #19
0
        internal override void DrawHeaderBackGround(HeaderStrip control, PaintEventArgs eventArgs)
        {
            Size controlSize = control.Size;

            if (control.Tabs.Count > 0)
            {
                controlSize.Height -= HeaderSelectedTabStrip * ScaleFactor.Height;
            }

            Rectangle rect  = new Rectangle(eventArgs.ClipRectangle.X, 0, eventArgs.ClipRectangle.Width, controlSize.Height);
            Color     start = Strings.ToColor(HeaderStartColor);
            Color     end   = Strings.ToColor(HeaderEndColor);

            GradientFill.Fill(eventArgs.Graphics, rect, start, end, GradientFill.FillDirection.TopToBottom);

            eventArgs.Graphics.DrawLine(new Pen(Strings.ToColor(BorderLineColor)), rect.X, rect.Height - 1, rect.Width, rect.Height - 1);
        }
Beispiel #20
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);

            Graphics g = e.Graphics;

            if (this.FirstColor != Color.Empty && this.SecondColor != Color.Empty)
            {
                GradientFill.Fill(g, this.ClientRectangle, this.FirstColor, this.SecondColor, this.GradientDirection);
            }

            if (this.BorderColor != Color.Empty)
            {
                using (Pen borderPen = new Pen(this.BorderColor))
                {
                    g.DrawRectangle(borderPen, 0, 0, this.Width - 1, this.Height - 1);
                }
            }
        }
Beispiel #21
0
 protected override void OnPaintBackground(PaintEventArgs e)
 {
     if (this.Focused && !this.ReadOnly)
     {
         e.Graphics.Clear(this.m_textBox.BackColor);
     }
     else if (this.VisualStyle == Resco.Controls.NumericUpDown.VisualStyle.VistaStyle)
     {
         GradientFill.DrawVistaGradient(e.Graphics, this.BackColor, new Rectangle(0, 0, base.Width, base.Height), FillDirection.Vertical);
     }
     else if (this.VisualStyle == Resco.Controls.NumericUpDown.VisualStyle.Gradients)
     {
         GradientFill.Fill(e.Graphics, base.ClientRectangle, base.ClientRectangle, this.m_gradientColors);
     }
     else
     {
         base.OnPaintBackground(e);
     }
 }
Beispiel #22
0
        void kListControl1_DrawItem(object sender, Tenor.Mobile.UI.DrawItemEventArgs e)
        {
            Graphics     g      = e.Graphics;
            StringFormat format = new StringFormat();

            format.Alignment     = StringAlignment.Near;
            format.LineAlignment = StringAlignment.Near;
            SolidBrush textBrush;

            if (e.Item.Selected)
            {
                SolidBrush backBrush;
                backBrush = new SolidBrush(SystemColors.Highlight);
                textBrush = new SolidBrush(SystemColors.HighlightText);
                g.FillRectangle(backBrush, e.Bounds);
            }
            else
            {
                //backBrush = new SolidBrush(SystemColors.Window);
                textBrush = new SolidBrush(SystemColors.ControlText);
            }

            FF        ff       = (FF)e.Item.Value;
            Rectangle iconRect = new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, ff.icon.Width, ff.icon.Height);

            RoundedRectangle.Fill(g, new Pen(SystemColors.ControlDark), new SolidBrush(SystemColors.ControlDark), iconRect, new Size(8, 8));
            g.DrawIcon(ff.icon, iconRect.X, iconRect.Y);
            Rectangle r = e.Bounds;

            r.X += 32;

            g.DrawString("  " + ff.file.Name, kListControl1.Font, textBrush, r, format);
            r.Y += 14;
            g.DrawString("  " + ff.file.CreationTime.ToString(), kListControl1.Font, textBrush, r, format);


            Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Bottom - 2, Convert.ToInt32(e.Bounds.Width / 2), 2);

            GradientFill.Fill(g, rect, SystemColors.Window, SystemColors.Control, GradientFill.FillDirection.LeftToRight);
            rect.Offset(rect.Width, 0);
            GradientFill.Fill(g, rect, SystemColors.Control, SystemColors.Window, GradientFill.FillDirection.LeftToRight);
        }
Beispiel #23
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            Color aColor = base.Capture ? ((this.PressedBackColor == Color.Transparent) ? this.ForeColor : this.PressedBackColor) : this.BackColor;

            if (this.m_visualStyle == Resco.Controls.NumericUpDown.VisualStyle.VistaStyle)
            {
                GradientFill.DrawVistaGradient(e.Graphics, aColor, base.ClientRectangle, FillDirection.Vertical);
            }
            else if (this.m_visualStyle == Resco.Controls.NumericUpDown.VisualStyle.Gradients)
            {
                GradientFill.Fill(e.Graphics, base.ClientRectangle, base.ClientRectangle, base.Capture ? this.m_gradientColorsPressed : this.m_gradientColors);
            }
            else if (this.m_visualStyle == Resco.Controls.NumericUpDown.VisualStyle.Images)
            {
                Image image = null;
                if (base.Capture)
                {
                    image = ((e.Graphics.DpiX == 192f) && (this.m_imageVgaPressed != null)) ? this.m_imageVgaPressed : (image = this.m_imagePressed);
                }
                if (image == null)
                {
                    image = ((e.Graphics.DpiX == 192f) && (this.m_imageVgaDefault != null)) ? this.m_imageVgaDefault : this.m_imageDefault;
                }
                if (image != null)
                {
                    e.Graphics.DrawImage(image, base.ClientRectangle, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
                }
                else
                {
                    e.Graphics.Clear(aColor);
                }
            }
            else
            {
                e.Graphics.Clear(aColor);
            }
        }
Beispiel #24
0
        internal override void DrawListItemBackground(Graphics g, Rectangle bounds, int index, bool selected)
        {
            if (selected)
            {
                Color     gradT         = Strings.ToColor(SelectedBackColorGradient);
                Color     selectedColor = SelectedBackColor;
                Rectangle gradBounds    = new Rectangle(bounds.X, bounds.Y, bounds.Width, 5 * ScaleFactor.Height);

                GradientFill.Fill(g, gradBounds, gradT, selectedColor, GradientFill.FillDirection.TopToBottom);
                gradBounds = new Rectangle(bounds.X, bounds.Y + gradBounds.Height, bounds.Width, bounds.Height - gradBounds.Height);

                SolidBrush brush = new SolidBrush(selectedColor);
                g.FillRectangle(brush, gradBounds);
                brush.Dispose();
            }
            else
            {
                Color color;
                if (index % 2 == 0)
                {
                    color = AlternateBackColor;
                }
                else
                {
                    color = ControlBackColor;
                }

                SolidBrush brush = new SolidBrush(color);
                g.FillRectangle(brush, bounds);
                brush.Dispose();

                Pen pen = new Pen(Strings.ToColor(ListSeparatorColor));
                g.DrawLine(pen, bounds.X, bounds.Bottom, bounds.Right, bounds.Bottom);
                pen.Dispose();
            }
        }
Beispiel #25
0
        /// <summary>
        /// Form a DocumentFormat.OpenXml.Spreadsheet.GradientFill class from SLGradientFill.
        /// </summary>
        /// <returns>A DocumentFormat.OpenXml.Spreadsheet.GradientFill with the properties of this SLGradientFill.</returns>
        public GradientFill ToGradientFill()
        {
            GradientFill gf = new GradientFill();
            for (int i = 0; i < this.listGradientStops.Count; ++i)
            {
                gf.Append(listGradientStops[i]);
            }

            if (HasType) gf.Type = this.Type;
            if (this.Degree != null) gf.Degree = this.Degree.Value;
            if (this.Left != null) gf.Left = this.Left.Value;
            if (this.Right != null) gf.Right = this.Right.Value;
            if (this.Top != null) gf.Top = this.Top.Value;
            if (this.Bottom != null) gf.Bottom = this.Bottom.Value;

            return gf;
        }
Beispiel #26
0
 public override void WriteGradientColor(GradientFill gf)
 {
     //this.WriteString("#" + gf.Color.ARGB.ToString("X8"));
 }
Beispiel #27
0
        /// <summary>
        /// Form SLGradientFill from DocumentFormat.OpenXml.Spreadsheet.GradientFill class.
        /// </summary>
        /// <param name="gradientFill">The source DocumentFormat.OpenXml.Spreadsheet.GradientFill class.</param>
        public void FromGradientFill(GradientFill gradientFill)
        {
            this.SetAllNull();

            using (OpenXmlReader oxr = OpenXmlReader.Create(gradientFill))
            {
                while (oxr.Read())
                {
                    if (oxr.ElementType == typeof(GradientStop))
                    {
                        listGradientStops.Add((GradientStop)oxr.LoadCurrentElement().CloneNode(true));
                    }
                }
            }

            if (gradientFill.Type != null)
            {
                this.Type = gradientFill.Type.Value;
            }

            if (gradientFill.Degree != null)
            {
                this.Degree = gradientFill.Degree.Value;
            }

            if (gradientFill.Left != null)
            {
                this.Left = gradientFill.Left.Value;
            }

            if (gradientFill.Right != null)
            {
                this.Right = gradientFill.Right.Value;
            }

            if (gradientFill.Top != null)
            {
                this.Top = gradientFill.Top.Value;
            }

            if (gradientFill.Bottom != null)
            {
                this.Bottom = gradientFill.Bottom.Value;
            }
        }
Beispiel #28
0
        private void FillPaths(FillStyle fill, List <GraphicsPath> paths)
        {
            Brush b = null;

            foreach (GraphicsPath path in paths)
            {
                path.Transform(translateMatrix);
                switch (fill.FillType)
                {
                case FillType.Solid:
                    SolidFill sf = (SolidFill)fill;
                    b = new SolidBrush(GetColor(sf.Color));
                    break;

                case FillType.Linear:
                    GradientFill        lf   = (GradientFill)fill;
                    RectangleF          rect = Vex.GradientFill.GradientVexRect.SysRectangleF();
                    LinearGradientBrush lgb  = new LinearGradientBrush(
                        rect,
                        Ms.Color.White,
                        Ms.Color.White,
                        1.0F
                        );
                    lgb.InterpolationColors = GetColorBlend(lf);
                    lgb.Transform           = GetMatrix(lf.Transform);
                    lgb.WrapMode            = WrapMode.TileFlipX;
                    ExtendGradientBrush(lgb, path);
                    b = lgb;
                    break;

                case FillType.Radial:
                    GradientFill rf = (GradientFill)fill;

                    ColorBlend cb = GetColorBlend(rf);

                    SolidBrush bkgCol = new SolidBrush(cb.Colors[0]);
                    g.FillPath(bkgCol, path);
                    bkgCol.Dispose();

                    // radial fill part
                    GraphicsPath gp = new GraphicsPath();
                    gp.AddEllipse(Vex.GradientFill.GradientVexRect.SysRectangleF());

                    PathGradientBrush pgb = new PathGradientBrush(gp);
                    pgb.InterpolationColors = GetColorBlend(rf);
                    pgb.Transform           = GetMatrix(rf.Transform);
                    b = pgb;
                    break;

                case FillType.Image:
                    ImageFill imgFill = (ImageFill)fill;
                    Bitmap    bmp     = new Bitmap(imgFill.ImagePath);
                    b = new TextureBrush(bmp);
                    break;

                default:
                    b = new SolidBrush(Ms.Color.Red);
                    break;
                }
                g.FillPath(b, path);
            }
            if (b != null)
            {
                b.Dispose();
            }
        }
 public static int GetFillIndex(SpreadsheetDocument document, GradientFill gradientFill)
 {
     return GetFillIndex(document, gradientFill.GetXElement());
 }
Beispiel #30
0
 public abstract void WriteGradientColor(GradientFill gf);
Beispiel #31
0
        protected override void RenderPath(FillStyle fs, StrokeStyle ss, List <IShapeData> sh, bool silverlight)
        {
            // <Path Fill="#FFFF0000"
            // StrokeThickness="0.00491913" StrokeLineJoin="Round" Stroke="#FF014393"
            // Data="M 196.667,4L 388.667,100L 388.667,292L 196.667,388L 4.66669,292L 4.66669,100L 196.667,4 Z "/>
            if (sh.Count == 0)
            {
                return;
            }

            xw.WriteStartElement("Path");

            bool isGradient    = false;
            bool isTiledBitmap = false;

            if (fs != null)
            {
                if (fs.FillType == FillType.Solid)
                {
                    Color c = ((SolidFill)fs).Color;
                    xw.WriteStartAttribute("Fill");
                    xw.WriteColor(c);
                    xw.WriteEndAttribute();

                    // try to clean up faint edges
                    if (ss == null && c != new Color(0xFF, 0xFF, 0xFF) && c.A != 0)
                    {
                        ss = new SolidStroke(0.3F, c);
                    }
                }
                else if (
                    fs.FillType == FillType.Linear ||
                    fs.FillType == FillType.Radial ||
                    fs.FillType == FillType.Focal)
                {
                    isGradient = true;
                }
                else if (fs.FillType == FillType.Image)
                {
                    // Fill="{StaticResource vb_1}"
                    ImageFill img = (ImageFill)fs;
                    if (img.IsTiled || silverlight)
                    {
                        isTiledBitmap = true;// this causes bitmap to be written inline
                    }
                    else
                    {
                        string brushName = imageBrushes[img.ImagePath];
                        xw.WriteStartAttribute("Fill");
                        xw.WriteValue("{StaticResource " + brushName + "}");
                        xw.WriteEndAttribute();
                    }
                }
            }
            if (ss != null)
            {
                if (ss is SolidStroke)
                {
                    // StrokeThickness="3" StrokeLineJoin="Round" Stroke="#FF014393"
                    // StrokeStartLineCap="Round"
                    // StrokeEndLineCap="Round"
                    SolidStroke st = (SolidStroke)ss;

                    xw.WriteStartAttribute("StrokeThickness");
                    xw.WriteFloat(st.LineWidth);
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("StrokeLineJoin");
                    xw.WriteString("Round");
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("StrokeStartLineCap");
                    xw.WriteString("Round");
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("StrokeEndLineCap");
                    xw.WriteString("Round");
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("Stroke");
                    xw.WriteColor(st.Color);
                    xw.WriteEndAttribute();
                }
            }
            float minX = float.PositiveInfinity;
            float minY = float.PositiveInfinity;
            float maxX = float.NegativeInfinity;
            float maxY = float.NegativeInfinity;

            xw.WriteStartAttribute("Data");

            xw.WriteMoveTo(sh[0].StartPoint);

            Point lastPoint = sh[0].StartPoint;

            for (int i = 0; i < sh.Count; i++)
            {
                IShapeData sd = sh[i];
                if (lastPoint != sd.StartPoint)
                {
                    xw.WriteMoveTo(sd.StartPoint);
                }
                switch (sd.SegmentType)
                {
                case SegmentType.Line:
                    xw.WriteLineTo(sd.EndPoint);
                    lastPoint = sd.EndPoint;
                    break;

                case SegmentType.CubicBezier:
                    CubicBezier cb = (CubicBezier)sd;
                    xw.WriteCubicCurveTo(cb.Control0, cb.Control1, cb.Anchor1);
                    lastPoint = cb.EndPoint;
                    minX      = Math.Min(minX, cb.Control0.X);
                    maxX      = Math.Max(maxX, cb.Control0.X);
                    minY      = Math.Min(minY, cb.Control0.Y);
                    maxY      = Math.Max(maxY, cb.Control0.Y);
                    minX      = Math.Min(minX, cb.Control1.X);
                    maxX      = Math.Max(maxX, cb.Control1.X);
                    minY      = Math.Min(minY, cb.Control1.Y);
                    maxY      = Math.Max(maxY, cb.Control1.Y);
                    break;

                case SegmentType.QuadraticBezier:
                    QuadBezier qb = (QuadBezier)sd;
                    xw.WriteQuadraticCurveTo(qb.Control, qb.Anchor1);
                    lastPoint = qb.EndPoint;
                    minX      = Math.Min(minX, qb.Control.X);
                    maxX      = Math.Max(maxX, qb.Control.X);
                    minY      = Math.Min(minY, qb.Control.Y);
                    maxY      = Math.Max(maxY, qb.Control.Y);
                    break;
                }

                // need bounds for gradient :(
                if (isGradient)
                {
                    minX = Math.Min(minX, sd.StartPoint.X);
                    maxX = Math.Max(maxX, sd.StartPoint.X);
                    minY = Math.Min(minY, sd.StartPoint.Y);
                    maxY = Math.Max(maxY, sd.StartPoint.Y);

                    minX = Math.Min(minX, sd.EndPoint.X);
                    maxX = Math.Max(maxX, sd.EndPoint.X);
                    minY = Math.Min(minY, sd.EndPoint.Y);
                    maxY = Math.Max(maxY, sd.EndPoint.Y);
                }
            }
            xw.WriteEndAttribute();

            if (isGradient)
            {
                GradientFill gf = (GradientFill)fs;
                // need a gradient def here
                if (fs.FillType == FillType.Linear)
                {
                    //<Path.Fill>
                    //    <LinearGradientBrush StartPoint="0.14706,0.532137" EndPoint="1.14962,0.55353">
                    //        <LinearGradientBrush.GradientStops>
                    //            <GradientStop Color="#FF4A4A4A" Offset="0"/>
                    //            <GradientStop Color="#FFB0B0B0" Offset="0.412067"/>
                    //            <GradientStop Color="#FFBBBBBB" Offset="0.638141"/>
                    //            <GradientStop Color="#FF545454" Offset="1"/>
                    //        </LinearGradientBrush.GradientStops>
                    //    </LinearGradientBrush>
                    //</Path.Fill>
                    xw.WriteStartElement("Path.Fill");

                    xw.WriteStartElement("LinearGradientBrush");

                    Matrix           m    = gf.Transform;
                    Rectangle        r    = GradientFill.GradientVexRect;
                    sysDraw2D.Matrix m2   = new sysDraw2D.Matrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, m.TranslateX, m.TranslateY);
                    float            midY = r.Point.Y + (r.Size.Height / 2);
                    sysDraw.PointF   pt0  = new sysDraw.PointF(r.Point.X, midY);
                    sysDraw.PointF   pt1  = new sysDraw.PointF(r.Point.X + r.Size.Width, midY);
                    sysDraw.PointF[] pts  = new sysDraw.PointF[] { pt0, pt1 };
                    m2.TransformPoints(pts);

                    float ratX = 1 / (maxX - minX);
                    float ratY = 1 / (maxY - minY);
                    float d0x  = (pts[0].X - minX) * ratX;
                    float d0y  = (pts[0].Y - minY) * ratY;
                    float d1x  = (pts[1].X - minX) * ratX;
                    float d1y  = (pts[1].Y - minY) * ratY;

                    xw.WriteStartAttribute("StartPoint");
                    xw.WritePoint(new Point(d0x, d0y));
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("EndPoint");
                    xw.WritePoint(new Point(d1x, d1y));
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("SpreadMethod");
                    xw.WriteValue("Pad");
                    xw.WriteEndAttribute();

                    xw.WriteStartElement("LinearGradientBrush.GradientStops");
                    for (int i = 0; i < gf.Stops.Count; i++)
                    {
                        xw.WriteStartElement("GradientStop");

                        xw.WriteStartAttribute("Color");
                        xw.WriteColor(gf.Fills[i]);
                        xw.WriteEndAttribute();

                        xw.WriteStartAttribute("Offset");
                        xw.WriteFloat(gf.Stops[i]);
                        xw.WriteEndAttribute();

                        xw.WriteEndElement(); // GradientStop
                    }
                    xw.WriteEndElement();     // LinearGradientBrush.GradientStops
                    xw.WriteEndElement();     // LinearGradientBrush
                    xw.WriteEndElement();     // Path.Fill
                }
                else if (fs.FillType == FillType.Radial)
                {
                    //<Ellipse.Fill>
                    //    <RadialGradientBrush RadiusX="0.622359" RadiusY="0.604589" Center="0.5,0.5" GradientOrigin="0.5,0.5">
                    //        <RadialGradientBrush.RelativeTransform>
                    //            <TransformGroup/>
                    //        </RadialGradientBrush.RelativeTransform>
                    //        <GradientStop Color="#95000000" Offset="0.347222"/>
                    //        <GradientStop Color="#007877A7" Offset="0.773148"/>
                    //    </RadialGradientBrush>
                    //</Ellipse.Fill>

                    xw.WriteStartElement("Path.Fill");

                    xw.WriteStartElement("RadialGradientBrush");

                    Matrix           m    = gf.Transform;
                    Rectangle        r    = GradientFill.GradientVexRect;
                    sysDraw2D.Matrix m2   = new sysDraw2D.Matrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, m.TranslateX, m.TranslateY);
                    float            midX = r.Point.X + (r.Size.Width / 2);
                    float            midY = r.Point.Y + (r.Size.Height / 2);
                    sysDraw.PointF   pt0  = new sysDraw.PointF(midX, midY);                     // center
                    sysDraw.PointF   pt1  = new sysDraw.PointF(r.Point.X + r.Size.Width, midY); // radius vector
                    sysDraw.PointF[] pts  = new sysDraw.PointF[] { pt0, pt1 };
                    m2.TransformPoints(pts);

                    float ratX = 1 / (maxX - minX);
                    float ratY = 1 / (maxY - minY);
                    float d0x  = (pts[0].X - minX) * ratX;
                    float d0y  = (pts[0].Y - minY) * ratY;
                    float d1x  = (pts[1].X - pts[0].X);
                    //float d1y = (pts[1].Y - pts[0].Y) * ratY;

                    float rad = (float)Math.Sqrt(d1x * d1x);
                    xw.WriteStartAttribute("RadiusX");
                    xw.WriteFloat(rad * ratX);
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("RadiusY");
                    xw.WriteFloat(rad * ratY);
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("Center");
                    xw.WritePoint(new Point(d0x, d0y));
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("GradientOrigin");
                    xw.WritePoint(new Point(d0x, d0y));
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("SpreadMethod");
                    xw.WriteValue("Pad");
                    xw.WriteEndAttribute();

                    //xw.WriteStartElement("RadialGradientBrush.GradientStops");
                    for (int i = 0; i < gf.Stops.Count; i++)
                    {
                        xw.WriteStartElement("GradientStop");

                        xw.WriteStartAttribute("Color");
                        xw.WriteColor(gf.Fills[i]);
                        xw.WriteEndAttribute();

                        xw.WriteStartAttribute("Offset");
                        xw.WriteFloat(1 - gf.Stops[i]); // xaml fill is reversed from gdi
                        xw.WriteEndAttribute();

                        xw.WriteEndElement(); // GradientStop
                    }
                    //xw.WriteEndElement(); // LinearGradientBrush.GradientStops
                    xw.WriteEndElement(); // LinearGradientBrush
                    xw.WriteEndElement(); // Path.Fill
                }
            }
            else if (isTiledBitmap)
            {
                //<Path.Fill>
                //   <ImageBrush ImageSource="Resources\bmp_1.jpg" TileMode="Tile" RelativeTransform=".2,0,0,.2,0,0"/>
                //</Path.Fill>

                ImageFill img = (ImageFill)fs;

                xw.WriteStartElement("Path.Fill");
                xw.WriteStartElement("ImageBrush");

                xw.WriteStartAttribute("ImageSource");
                xw.WriteValue(img.ImagePath);
                xw.WriteEndAttribute();

                if (!silverlight)
                {
                    xw.WriteStartAttribute("TileMode");
                    xw.WriteValue("Tile");
                    xw.WriteEndAttribute();
                }

                //xw.WriteStartAttribute("ViewportUnits");
                //xw.WriteValue("Absolute");
                //xw.WriteEndAttribute();

                Matrix pMatrix = ApplyMatrixToShape(sh, img.Matrix, images[img.ImagePath].StrokeBounds);
                //Matrix pMatrix = ApplyMatrixToImage(img.Matrix, images[img.ImagePath].Bounds);
                xw.WriteStartAttribute("RelativeTransform");
                xw.WriteMatrix(pMatrix);
                //xw.WriteMatrix(img.Matrix);
                xw.WriteEndAttribute();

                xw.WriteEndElement(); // Path.Fill
                xw.WriteEndElement(); // ImageBrush
            }
            xw.WriteEndElement();     // Path
        }
Beispiel #32
0
        internal void FromHash(string Hash)
        {
            GradientFill gf = new GradientFill();

            string[] saElementAttribute = Hash.Split(new string[] { SLConstants.XmlGradientFillElementAttributeSeparator }, StringSplitOptions.None);
            if (saElementAttribute.Length >= 2)
            {
                gf.InnerXml = saElementAttribute[0];
                string[] sa = saElementAttribute[1].Split(new string[] { SLConstants.XmlGradientFillAttributeSeparator }, StringSplitOptions.None);
                if (sa.Length >= 6)
                {
                    if (!sa[0].Equals("null")) gf.Type = (GradientValues)Enum.Parse(typeof(GradientValues), sa[0]);

                    if (!sa[1].Equals("null")) gf.Degree = double.Parse(sa[1]);

                    if (!sa[2].Equals("null")) gf.Left = double.Parse(sa[2]);

                    if (!sa[3].Equals("null")) gf.Right = double.Parse(sa[3]);

                    if (!sa[4].Equals("null")) gf.Top = double.Parse(sa[4]);

                    if (!sa[5].Equals("null")) gf.Bottom = double.Parse(sa[5]);
                }
            }

            this.FromGradientFill(gf);
        }
Beispiel #33
0
        private static void ConsolidatePaths(Symbol symbol, DVexWriter writer)
        {
            List <FillStyle>   fills   = new List <FillStyle>();
            List <StrokeStyle> strokes = new List <StrokeStyle>();

            fills.Add(new SolidFill(Color.Transparent));
            strokes.Add(new SolidStroke(0.0F, Color.Transparent));
            ArrayList allPaths = new ArrayList();
            ArrayList allSrs   = new ArrayList();

            // Find all used colors/strokes, and the F0,F1,S info for each seg
            foreach (Shape sh in symbol.Shapes)
            {
                foreach (IShapeData s in sh.ShapeData)
                {
                    int fill   = 0;
                    int stroke = 0;
                    if (!fills.Contains(shape.Fills[s.FillIndex]))
                    {
                        fill = fills.Add(shape.Fills[s.FillIndex]);
                    }
                    else
                    {
                        fill = fills.IndexOf(shape.Fills[s.FillIndex]);
                    }
                    if (!strokes.Contains(shape.Strokes[s.StrokeIndex]))
                    {
                        stroke = strokes.Add(shape.Strokes[s.StrokeIndex]);
                    }
                    else
                    {
                        stroke = strokes.IndexOf(shape.Strokes[s.StrokeIndex]);
                    }
                    // break path into shape records
                    foreach (IPathPrimitive ipp in s.Path)
                    {
                        if (ipp is IShapeData)
                        {
                            IShapeData ip = (IShapeData)ipp;
                            if (allPaths.Contains(ip))
                            {
                                // this must be a fill1 if it is a dup
                                int   index    = allPaths.IndexOf(ip);
                                Shrec sr       = (Shrec)allSrs[index];
                                Shrec newShrec = new Shrec(0, 0);
                                newShrec.F0   = (sr.F0 == 0) ? fill : sr.F0;
                                newShrec.F1   = (sr.F1 == 0) ? fill : sr.F1;
                                newShrec.S    = (sr.S == 0) ? stroke : sr.S;
                                allSrs[index] = newShrec;
                            }
                            else
                            {
                                allSrs.Add(new Shrec(fill, stroke));
                                allPaths.Add(ip);
                            }
                        }
                    }
                }         // end groups
            }             // end shapes


            // ok, now write out colors
            // sort fills by rgb, argb, and gradients
            ArrayList orderedFills = new ArrayList();
            ArrayList rgbas        = new ArrayList();
            ArrayList gfs          = new ArrayList();

            foreach (Fill sf in fills)
            {
                if (sf is SolidFill)
                {
                    if (((SolidFill)sf).Color.A == 255 ||
                        (SolidFill)sf == fills[0])                         // 'no fill'
                    {
                        orderedFills.Add(sf);
                    }
                    else
                    {
                        rgbas.Add(sf);
                    }
                }
                else if (sf is GradientFill)
                {
                    gfs.Add(sf);
                }
                else
                {
                    // bitmap fills
                    orderedFills.Add(new SolidFill(Color.Gray));
                };
            }

            SolidFill[] wrgbs = new SolidFill[orderedFills.Count];
            wrgbs[0] = new SolidFill(Color.FromArgb(255, 0, 0, 0));
            int fRgb = 1;

            foreach (Fill f in orderedFills)
            {
                if (f != fills[0])
                {
                    wrgbs[fRgb++] = (SolidFill)f;
                }
            }
            int fRgba = 0;

            SolidFill[] wrgbas = new SolidFill[rgbas.Count];
            foreach (Fill f in rgbas)
            {
                orderedFills.Add(f);
                wrgbas[fRgba++] = (SolidFill)f;
            }

            int fGr = 0;

            GradientFill[] wgfs = new GradientFill[gfs.Count];
            foreach (Fill f in gfs)
            {
                orderedFills.Add(f);
                wgfs[fGr++] = (GradientFill)(f);
            }

            writer.WriteNbitColorDefs(wrgbs);
            writer.WriteNbitColorDefs(wrgbas);
            writer.WriteNbitGradientDefs(wgfs);
            //writer.WriteRgbColorDefs(wrgbs);
            //writer.WriteRgbaColorDefs(wrgbas);
            //writer.WriteGradientColorDefs(wgfs);



            // ok, colors written, now strokes
            // write out all the stroke defs second
            // get counts
            int wrgbCount  = 0;
            int wrgbaCount = 0;

            foreach (Stroke st in strokes)
            {
                if (st.Color.A == 255 || st == strokes[0])
                {
                    wrgbCount++;
                }
                else
                {
                    wrgbaCount++;
                }
            }
            // create stroke arrays
            Stroke[] wsrgbs  = new Stroke[wrgbCount];
            Stroke[] wsrgbas = new Stroke[wrgbaCount];
            int      sRgb    = 0;
            int      sRgba   = 0;

            foreach (Stroke st in strokes)
            {
                if (st.Color.A == 255 || st == strokes[0])
                {
                    wsrgbs[sRgb++] = st;
                }
                else
                {
                    wsrgbas[sRgba++] = st;
                }
            }
            // now write the stroke data
            writer.WriteNbitStrokeDefs(wsrgbs);
            writer.WriteNbitStrokeDefs(wsrgbas);
            //writer.WriteRgbStrokeDefs(wsrgbs);
            //writer.WriteRgbaStrokeDefs(wsrgbas);


            // and now paths
            // valid pathsegs must have the same F0, F1, and S
            ArrayList      tempPaths = new ArrayList();
            ArrayList      tempSrsAl = new ArrayList();
            PathCollection pc        = new PathCollection();
            Shrec          curShrec  = Shrec.Empty;

            for (int i = 0; i < allSrs.Count; i++)            //Shrec sr in srsAl)
            {
                Shrec sr = (Shrec)allSrs[i];
                if (sr.Equals(curShrec) || curShrec.Equals(Shrec.Empty))
                {
                    //add to path
                    pc.Add((IShapeData)allPaths[i]);
                }
                else
                {
                    // write to hash
                    tempPaths.Add(pc);
                    tempSrsAl.Add(curShrec);

                    pc = new PathCollection();
                    pc.Add((IShapeData)allPaths[i]);
                }
                curShrec = sr;
            }
            if (!tempSrsAl.Contains(curShrec))
            {
                tempPaths.Add(pc);
                tempSrsAl.Add(curShrec);
            }
            // split non contig paths
            ArrayList paths = new ArrayList();
            ArrayList srsAl = new ArrayList();

            foreach (PathCollection pcoll in tempPaths)
            {
                //pcoll.ReorderPath();
                PathCollection[] pcolls = pcoll.SplitPath();
                foreach (PathCollection splitP in pcolls)
                {
                    paths.Add(splitP);
                    srsAl.Add(tempSrsAl[tempPaths.IndexOf(pcoll)]);
                    //writer.WritePath(splitP.PointSegments);
                }
            }
            IShapeData[][] ips = new IShapeData[paths.Count][];
            for (int i = 0; i < paths.Count; i++)
            {
                ips[i] = ((PathCollection)paths[i]).PointSegments;
            }
            writer.WritePaths(ips);


            // convert to array
            Shrec[] srs = new Shrec[srsAl.Count];
            for (int i = 0; i < srsAl.Count; i++)
            {
                srs[i] = (Shrec)srsAl[i];
            }

            // and finally, uses - must be sorted by fill color
            // use order Fill1 (no strokes), fill0[stroke], stroke only's
            // for each fill index{..}, then dangling strokes

            ArrayList shapeRecords = new ArrayList();

            // start at 1 to avoid empty fills
            foreach (Fill f in orderedFills)
            {
                int curFill = fills.IndexOf(f);
                if (curFill != 0)
                {
                    // all F1's of this color first
                    ArrayList Fs = new ArrayList();
                    for (int i = 0; i < srs.Length; i++)
                    {
                        if (srs[i].F0 == curFill)
                        {
                            // add use for F0
                            ShapeRecord curSr = new ShapeRecord();

                            curSr.Fill   = orderedFills.IndexOf(f);
                            curSr.Stroke = srs[i].S;
                            curSr.Path   = i;
                            Fs.Add(curSr);
                        }
                        if (srs[i].F1 == curFill)
                        {
                            // add use for F1
                            ShapeRecord curSr = new ShapeRecord();
                            curSr.Fill   = orderedFills.IndexOf(f);
                            curSr.Stroke = 0;
                            curSr.Path   = i;
                            Fs.Add(curSr);
                        }
                    }
                    //now sort the F1s from tip to tail
                    if (Fs.Count > 0)
                    {
                        ArrayList finalFs = new ArrayList();
                        finalFs.Add(Fs[0]);
                        PointF end =
                            ((PathCollection)paths[((ShapeRecord)Fs[0]).Path]).LastPoint;
                        Fs.RemoveAt(0);
                        while (Fs.Count > 0)
                        {
                            bool found = false;
                            foreach (ShapeRecord sr in Fs)
                            {
                                PathCollection srp = (PathCollection)paths[sr.Path];
                                if (srp.FirstPoint == end)
                                {
                                    end = srp.LastPoint;
                                    finalFs.Add(sr);
                                    Fs.Remove(sr);
                                    found = true;
                                    break;
                                }
                            }
                            if (found == false)
                            {
                                finalFs.Add(Fs[0]);
                                end = ((PathCollection)paths[
                                           ((ShapeRecord)Fs[0]).Path]).LastPoint;
                                Fs.RemoveAt(0);
                            }
                        }
                        // and write them
                        foreach (ShapeRecord sr in finalFs)
                        {
                            shapeRecords.Add(sr);
                        }
                    }
                }
            }
            for (int i = 0; i < srs.Length; i++)
            {
                if (srs[i].F0 == 0 && srs[i].F1 == 0)
                {
                    // must be stroke
                    ShapeRecord curSr = new ShapeRecord();
                    curSr.Fill   = 0;
                    curSr.Stroke = srs[i].S;
                    curSr.Path   = i;
                    shapeRecords.Add(curSr);
                }
            }
            // convert to array
            ShapeRecord[] srecs = new ShapeRecord[shapeRecords.Count];
            for (int i = 0; i < shapeRecords.Count; i++)
            {
                srecs[i] = (ShapeRecord)shapeRecords[i];
            }

            writer.WriteUses(srecs);
        }
Beispiel #34
0
        private void WriteGradientDefs(List <GradientFill> gradients)
        {
            WriteTag(VexDrawTag.GradientFillList);
            WriteBits(0, 5);             // note: no nBits here, just padding
            WriteBits(gradients.Count, 11);
            for (int index = 0; index < gradients.Count; index++)
            {
                GradientFill gf = gradients[index];
                // first type - all non radial will be solid
                // use 8 bits for future expansion and to keep semi aligned
                int type = (gf.FillType == FillType.Radial) ? 1 : 0;
                WriteBits(type, 3);

                float[] tltr   = DrawObject.GetGradientLine(gf);
                int[]   values = new int[4];
                for (int i = 0; i < tltr.Length; i++)
                {
                    values[i] = (int)(tltr[i] * DrawObject.twips);
                }
                WriteFourNBitValues(values);

                // new argb colors
                List <Color> colors    = new List <Color>(gf.Fills);
                List <float> positions = new List <float>(gf.Stops);
                if (gf.FillType == FillType.Radial)
                {
                    gf.ReverseStops(colors, positions);
                }

                // stops and ratios [[col,rat],[col,rat]...]
                int stopCount = colors.Count;
                if (stopCount > 8)
                {
                    stopCount = 8;
                    Console.WriteLine("*Flash only supports 8 colors max in gradients");
                }

                uint[] wCols = new uint[stopCount];
                for (int i = 0; i < stopCount; i++)
                {
                    wCols[i] = colors[i].AFlipRGB;
                }
                uint colBits = MinBits(wCols);
                WriteNBitsCount(colBits);

                int[] ratios = new int[positions.Count];
                for (int i = 0; i < stopCount; i++)
                {
                    ratios[i] = (int)(positions[i] * 255);
                }
                uint ratioBits = MinBits(ratios);
                WriteNBitsCount(ratioBits);

                WriteBits(stopCount, 11);

                for (int i = 0; i < stopCount; i++)
                {
                    WriteBits(wCols[i], colBits);
                    WriteBits(ratios[i], ratioBits);
                }
            }
            FlushTag();
        }