예제 #1
0
        /// <summary>
        /// Render a polygon.
        /// </summary>
        /// <param name="stroke">The stroke style to draw border</param>
        /// <param name="fill">The fill style to render inner region</param>
        /// <param name="coordinates">Coordinate data. Must be in format [x1, y1, x2, y2, ...]</param>
        /// <remarks>The stroke and the fill can both be a null reference (Nothing in Visual Basic). If the stroke is null, no stroke is performed. If the fill is null, no fill is performed.</remarks>
        public void DrawPolygon(Fill fill, double[] coordinates)
        {
            double[] data = null;

            if (preparationRequired)
            {
                Prepare();
            }

            //transform input coordinates
            if (transformRequired)
            {
                data = TransformCoordinates(coordinates);
            }
            else
            {
                data = coordinates;
            }

            //render the inner region
            if (fill != null)
            {
                rasterizer = GetRasterizer(fill.Paint);
                if ((rasterizer is TranformableRasterizer) && (transformRequired))
                {
                    // set transform matrix to current transformable matrix
                    ((TranformableRasterizer)rasterizer).SetTransformMatrix(currentTransform);
                }
                rasterizer.FillPolygon(fill, data, coordinates.Length / 2, 0);
            }
        }
예제 #2
0
        /// <summary>
        /// Preparations before drawing
        /// </summary>
        void Prepare()
        {
            if (mBuffer == null) 
            NullArgumentException.Publish(typeof(PixelsBuffer), "Buffer");

            #region Initialize rasterizers

            if (mPathGenerator == null) mPathGenerator = new DrawingPathGenerator();

            if (mColorRasterizer == null) mColorRasterizer = new ColorRasterizer();
            mColorRasterizer.Buffer = mBuffer;

            if (mLinearGradientRasterizer == null) mLinearGradientRasterizer = new LinearGradientRasterizer();
            mLinearGradientRasterizer.Buffer = mBuffer;

            if (mRadialGradientRasterizer == null) mRadialGradientRasterizer = new RadialGradientRasterizer();
            mRadialGradientRasterizer.Buffer = mBuffer;

            preparationRequired = false;
            #endregion

            #region Prepare gamma correction
            if (gammaPreparationRequired)
            {
                if (mGammaCorrected)
                {
                    IGammaCorrector corrector = new PowerGammaCorrector(gammaRed, gammaGreen, gammaBlue);
                    mColorRasterizer.Gamma = corrector;
                    mLinearGradientRasterizer.Gamma = corrector;
                    mRadialGradientRasterizer.Gamma = corrector;
                }
                else
                {
                    mColorRasterizer.Gamma = null;
                    mLinearGradientRasterizer.Gamma = null;
                    mRadialGradientRasterizer.Gamma = null;
                }

                gammaPreparationRequired = false;
            }
            #endregion

            #region Prepare opacity masking
            if (opacityPreparationRequired)
            {
                mColorRasterizer.OpacityMask = mOpacityMask;
                mLinearGradientRasterizer.OpacityMask = mOpacityMask;
                mRadialGradientRasterizer.OpacityMask = mOpacityMask;

                opacityPreparationRequired = false;
            }
            #endregion

        }
예제 #3
0
        /// <summary>
        /// Render a path
        /// </summary>
        /// <param name="stroke">The stroke style to draw border</param>
        /// <param name="fill">The fill style to render inner region</param>
        /// <param name="path">The path geometry</param>
        /// <remarks>The stroke and the fill can both be a null reference (Nothing in Visual Basic). If the stroke is null, no stroke is performed. If the fill is null, no fill is performed.</remarks>
        public void DrawPath(Fill fill, DrawingPath path)
        {
            if (preparationRequired)
            {
                Prepare();
            }

            #region detemin current scale factor
            double sizeScale = 1.0;
            if (currentTransform != null)
            {
                sizeScale = (currentTransform.ScaleXFactor > currentTransform.ScaleYFactor) ?
                            currentTransform.ScaleXFactor : currentTransform.ScaleYFactor;
            }
            #endregion

            // this need scale factor before generate
            double[][] coordinates = mPathGenerator.Generate(path, 1.0);
            //transform input coordinates

            //render the inner region
            if (fill != null)
            {
                rasterizer       = GetRasterizer(fill.Paint);
                rasterizer.Paint = fill;
                rasterizer.Begin();
                if ((transformRequired))
                {
                    if ((rasterizer is TranformableRasterizer))
                    {
                        // set transform matrix to current transformable matrix
                        ((TranformableRasterizer)rasterizer).SetTransformMatrix(currentTransform);
                    }
                    for (int coordinateIndex = 0; coordinateIndex < coordinates.Length; coordinateIndex++)
                    {
                        rasterizer.AddPolygon(
                            TransformCoordinates(coordinates[coordinateIndex]),
                            coordinates[coordinateIndex].Length / 2, 0);
                    }
                }
                else
                {
                    // set paint before using approach 2

                    for (int coordinateIndex = 0; coordinateIndex < coordinates.Length; coordinateIndex++)
                    {
                        rasterizer.AddPolygon(coordinates[coordinateIndex], coordinates[coordinateIndex].Length / 2, 0);
                    }
                }
                rasterizer.Finish();
            }
        }
예제 #4
0
        /// <summary>
        /// Render a path
        /// </summary>
        /// <param name="stroke">The stroke style to draw border</param>
        /// <param name="fill">The fill style to render inner region</param>
        /// <param name="path">The path geometry</param>
        /// <remarks>The stroke and the fill can both be a null reference (Nothing in Visual Basic). If the stroke is null, no stroke is performed. If the fill is null, no fill is performed.</remarks>
        public void DrawPath(Fill fill, DrawingPath path)
        {
            if (preparationRequired) Prepare();

            #region detemin current scale factor
            double sizeScale = 1.0;
            if (currentTransform != null)
            {
                sizeScale = (currentTransform.ScaleXFactor > currentTransform.ScaleYFactor) ?
                    currentTransform.ScaleXFactor : currentTransform.ScaleYFactor;
            }
            #endregion

            // this need scale factor before generate
            double[][] coordinates = mPathGenerator.Generate(path, 1.0);
            //transform input coordinates

            //render the inner region
            if (fill != null)
            {
                rasterizer = GetRasterizer(fill.Paint);
                rasterizer.Paint = fill;
                rasterizer.Begin();
                if ((transformRequired))
                {
                    if ((rasterizer is TranformableRasterizer))
                    {
                        // set transform matrix to current transformable matrix
                        ((TranformableRasterizer)rasterizer).SetTransformMatrix(currentTransform);
                    }
                    for (int coordinateIndex = 0; coordinateIndex < coordinates.Length; coordinateIndex++)
                    {
                        rasterizer.AddPolygon(
                            TransformCoordinates(coordinates[coordinateIndex]),
                            coordinates[coordinateIndex].Length / 2, 0);
                    }
                }
                else
                {
                    // set paint before using approach 2

                    for (int coordinateIndex = 0; coordinateIndex < coordinates.Length; coordinateIndex++)
                    {
                        rasterizer.AddPolygon(coordinates[coordinateIndex], coordinates[coordinateIndex].Length / 2, 0);
                    }
                }
                rasterizer.Finish();
            }
        }
예제 #5
0
        /// <summary>
        /// Render a polygon.
        /// </summary>
        /// <param name="stroke">The stroke style to draw border</param>
        /// <param name="fill">The fill style to render inner region</param>
        /// <param name="coordinates">Coordinate data. Must be in format [x1, y1, x2, y2, ...]</param>
        /// <remarks>The stroke and the fill can both be a null reference (Nothing in Visual Basic). If the stroke is null, no stroke is performed. If the fill is null, no fill is performed.</remarks>
        public void DrawPolygon(Fill fill, double[] coordinates)
        {
            double[] data = null;

            if (preparationRequired) Prepare();

            //transform input coordinates
            if (transformRequired) data = TransformCoordinates(coordinates);
            else data = coordinates;

            //render the inner region
            if (fill != null)
            {
                rasterizer = GetRasterizer(fill.Paint);
                if ((rasterizer is TranformableRasterizer) && (transformRequired))
                {
                    // set transform matrix to current transformable matrix
                    ((TranformableRasterizer)rasterizer).SetTransformMatrix(currentTransform);
                }
                rasterizer.FillPolygon(fill, data, coordinates.Length / 2, 0);
            }
        }
예제 #6
0
        /// <summary>
        /// Preparations before drawing
        /// </summary>
        void Prepare()
        {
            if (mBuffer == null)
            {
                NullArgumentException.Publish(typeof(PixelsBuffer), "Buffer");
            }

            #region Initialize rasterizers

            if (mPathGenerator == null)
            {
                mPathGenerator = new DrawingPathGenerator();
            }

            if (mColorRasterizer == null)
            {
                mColorRasterizer = new ColorRasterizer();
            }
            mColorRasterizer.Buffer = mBuffer;

            if (mLinearGradientRasterizer == null)
            {
                mLinearGradientRasterizer = new LinearGradientRasterizer();
            }
            mLinearGradientRasterizer.Buffer = mBuffer;

            if (mRadialGradientRasterizer == null)
            {
                mRadialGradientRasterizer = new RadialGradientRasterizer();
            }
            mRadialGradientRasterizer.Buffer = mBuffer;

            preparationRequired = false;
            #endregion

            #region Prepare gamma correction
            if (gammaPreparationRequired)
            {
                if (mGammaCorrected)
                {
                    IGammaCorrector corrector = new PowerGammaCorrector(gammaRed, gammaGreen, gammaBlue);
                    mColorRasterizer.Gamma          = corrector;
                    mLinearGradientRasterizer.Gamma = corrector;
                    mRadialGradientRasterizer.Gamma = corrector;
                }
                else
                {
                    mColorRasterizer.Gamma          = null;
                    mLinearGradientRasterizer.Gamma = null;
                    mRadialGradientRasterizer.Gamma = null;
                }

                gammaPreparationRequired = false;
            }
            #endregion

            #region Prepare opacity masking
            if (opacityPreparationRequired)
            {
                mColorRasterizer.OpacityMask          = mOpacityMask;
                mLinearGradientRasterizer.OpacityMask = mOpacityMask;
                mRadialGradientRasterizer.OpacityMask = mOpacityMask;

                opacityPreparationRequired = false;
            }
            #endregion
        }