/// <summary>
        /// Setups the shading pattern from the specified brush.
        /// </summary>
        internal void SetupFromBrush(XLinearGradientBrush brush, XMatrix matrix, XGraphicsPDFRenderer renderer)
        {
            if (brush == null)
            {
                throw new ArgumentNullException("brush");
            }

            PDFShading shading = new PDFShading(_document);

            shading.SetupFromBrush(brush, renderer);
            Elements[Keys.Shading] = shading;
            //Elements[Keys.Matrix] = new PDFLiteral("[" + PDFEncoders.ToString(matrix) + "]");
            Elements.SetMatrix(Keys.Matrix, matrix);
        }
Example #2
0
        /// <summary>
        /// Setups the shading from the specified brush.
        /// </summary>
        internal void SetupFromBrush(XLinearGradientBrush brush, XGraphicsPDFRenderer renderer)
        {
            if (brush == null)
            {
                throw new ArgumentNullException("brush");
            }

            PDFColorMode colorMode = _document.Options.ColorMode;
            XColor       color1    = ColorSpaceHelper.EnsureColorMode(colorMode, brush._color1);
            XColor       color2    = ColorSpaceHelper.EnsureColorMode(colorMode, brush._color2);

            PDFDictionary function = new PDFDictionary();

            Elements[Keys.ShadingType] = new PDFInteger(2);
            Elements[Keys.ColorSpace]  = colorMode != PDFColorMode.Cmyk ? new PDFName("/DeviceRGB") : new PDFName("/DeviceCMYK");

            double x1 = 0, y1 = 0, x2 = 0, y2 = 0;

            if (brush._useRect)
            {
                XPoint pt1 = renderer.WorldToView(brush._rect.TopLeft);
                XPoint pt2 = renderer.WorldToView(brush._rect.BottomRight);

                switch (brush._linearGradientMode)
                {
                case XLinearGradientMode.Horizontal:
                    x1 = pt1.X;
                    y1 = pt1.Y;
                    x2 = pt2.X;
                    y2 = pt1.Y;
                    break;

                case XLinearGradientMode.Vertical:
                    x1 = pt1.X;
                    y1 = pt1.Y;
                    x2 = pt1.X;
                    y2 = pt2.Y;
                    break;

                case XLinearGradientMode.ForwardDiagonal:
                    x1 = pt1.X;
                    y1 = pt1.Y;
                    x2 = pt2.X;
                    y2 = pt2.Y;
                    break;

                case XLinearGradientMode.BackwardDiagonal:
                    x1 = pt2.X;
                    y1 = pt1.Y;
                    x2 = pt1.X;
                    y2 = pt2.Y;
                    break;
                }
            }
            else
            {
                XPoint pt1 = renderer.WorldToView(brush._point1);
                XPoint pt2 = renderer.WorldToView(brush._point2);

                x1 = pt1.X;
                y1 = pt1.Y;
                x2 = pt2.X;
                y2 = pt2.Y;
            }

            const string format = Config.SignificantFigures3;

            Elements[Keys.Coords] = new PDFLiteral("[{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "}]", x1, y1, x2, y2);

            //Elements[Keys.Background] = new PDFRawItem("[0 1 1]");
            //Elements[Keys.Domain] =
            Elements[Keys.Function] = function;
            //Elements[Keys.Extend] = new PDFRawItem("[true true]");

            string clr1 = "[" + PDFEncoders.ToString(color1, colorMode) + "]";
            string clr2 = "[" + PDFEncoders.ToString(color2, colorMode) + "]";

            function.Elements["/FunctionType"] = new PDFInteger(2);
            function.Elements["/C0"]           = new PDFLiteral(clr1);
            function.Elements["/C1"]           = new PDFLiteral(clr2);
            function.Elements["/Domain"]       = new PDFLiteral("[0 1]");
            function.Elements["/N"]            = new PDFInteger(1);
        }
 public PDFGraphicsState(XGraphicsPDFRenderer renderer) => _renderer = renderer;