示例#1
0
        internal static PdfColors.RadialGradient ConvertRadialGradientBrush(RadialGradientBrush brush, double opacity, IPosition position, double width, double height)
        {
            if (width * height == 0)
            {
                return(null);
            }

            var center1 = new Point(brush.GradientOrigin.X * height, brush.GradientOrigin.Y * height);
            var center2 = new Point(brush.Center.X * height, brush.Center.Y * height);

            PdfColors.RadialGradient pdfGradient = new PdfColors.RadialGradient(center1, center2, 0, height / 2);

            var matrix    = new Matrix(width / height, 0, 0, 1, 0, 0);
            var newMatrix = matrix = MathHelper.Multiply(position.Matrix, matrix);

            pdfGradient.Position = new Telerik.Windows.Documents.Fixed.Model.Data.MatrixPosition(newMatrix);

            foreach (var gradientStop in brush.GradientStops)
            {
                var rgbColor = new PdfColors.RgbColor((byte)(gradientStop.Color.A * opacity), gradientStop.Color.R, gradientStop.Color.G, gradientStop.Color.B);
                pdfGradient.GradientStops.Add(new PdfColors.GradientStop(rgbColor, gradientStop.Offset));
            }

            return(pdfGradient);
        }
示例#2
0
        internal static PdfColors.RadialGradient ConvertRadialGradientBrush(RadialGradientBrush brush, double opacity, IPosition position, double width, double height)
        {
            if (width * height == 0)
            {
                return null;
            }

            var center1 = new Point(brush.GradientOrigin.X * height, brush.GradientOrigin.Y * height);
            var center2 = new Point(brush.Center.X * height, brush.Center.Y * height);
            PdfColors.RadialGradient pdfGradient = new PdfColors.RadialGradient(center1, center2, 0, height / 2);

            var matrix = new Matrix(width / height, 0, 0, 1, 0, 0);
            var newMatrix = matrix = MathHelper.Multiply(position.Matrix, matrix);
            pdfGradient.Position = new Telerik.Windows.Documents.Fixed.Model.Data.MatrixPosition(newMatrix);

            foreach (var gradientStop in brush.GradientStops)
            {
                var rgbColor = new PdfColors.RgbColor((byte)(gradientStop.Color.A * opacity), gradientStop.Color.R, gradientStop.Color.G, gradientStop.Color.B);
                pdfGradient.GradientStops.Add(new PdfColors.GradientStop(rgbColor, gradientStop.Offset));
            }

            return pdfGradient;
        }