Пример #1
0
        /// <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);
        }
Пример #2
0
 public PdfGraphicsState(XGraphicsPdfRenderer renderer)
 {
   this.renderer = renderer;
 }
Пример #3
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);
            if (colorMode != PdfColorMode.Cmyk)
                Elements[Keys.ColorSpace] = new PdfName("/DeviceRGB");
            else
                Elements[Keys.ColorSpace] = 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);
        }