Example #1
0
        /// <summary>
        /// Gets the matrix described by this transformation style
        /// </summary>
        /// <returns></returns>
        public PDFTransformationMatrix GetMatrix()
        {
            PDFTransformationMatrix current = new PDFTransformationMatrix();

            //current.SetTranslation(this.OffsetH, this.OffsetV);
            current.SetRotation(this.Rotate);
            current.SetScale(this.ScaleX, this.ScaleY);
            current.SetSkew(this.SkewX, this.SkewY);
            return(current);
        }
Example #2
0
        //
        // scaling calculations
        //

        public static void ApplyMaxNonUniformScaling(PDFTransformationMatrix onmatrix, PDFSize dest, PDFRect viewport)
        {
            PDFSize source = viewport.Size;
            double  scalex = dest.Width.PointsValue / source.Width.PointsValue;
            double  scaley = dest.Height.PointsValue / source.Height.PointsValue;
            double  offx   = 0; // viewport.X.PointsValue;
            double  offy   = 0; // viewport.Y.PointsValue;

            onmatrix.SetTranslation(offx, offy);
            onmatrix.SetScale((float)scalex, (float)scaley);
        }
Example #3
0
        public static void ApplyUniformStretching(PDFTransformationMatrix onmatrix, PDFSize dest, PDFRect viewport, AspectRatioAlign align)
        {
            PDFSize source = viewport.Size;
            double  scalex = dest.Width.PointsValue / source.Width.PointsValue;
            double  scaley = dest.Height.PointsValue / source.Height.PointsValue;
            double  offx   = 0; // viewport.X.PointsValue;
            double  offy   = 0; // viewport.Y.PointsValue;
            float   max    = (float)Math.Max(scalex, scaley);
            double  w      = source.Width.PointsValue * max;
            double  h      = source.Height.PointsValue * max;

            switch (align)
            {
            //YMin
            case (AspectRatioAlign.xMinYMin):
                //Scale to fit within the size without overflow and show at the top (so no x or y offset)
                offx = 0;
                offy = (dest.Height.PointsValue - h);     //plus as from the bottom
                onmatrix.SetTranslation(offx, offy);
                onmatrix.SetScale(max, max);
                break;

            case (AspectRatioAlign.xMidYMin):
                offx = (dest.Width.PointsValue - w) / 2;
                offy = (dest.Height.PointsValue - h);     //plus as from the bottom
                onmatrix.SetTranslation(offx, offy);
                onmatrix.SetScale(max, max);
                break;

            case (AspectRatioAlign.xMaxYMin):
                //Scale to fit within the size without overflow and show at the top (so no x or y offset)
                offx = dest.Width.PointsValue - w;
                offy = (dest.Height.PointsValue - h);     //plus as from the bottom
                onmatrix.SetTranslation(offx, offy);
                onmatrix.SetScale(max, max);
                break;

            //YMid
            case (AspectRatioAlign.xMinYMid):
                //Scale to fit within the size without overflow and show at the top (so no x or y offset)
                offx = 0;
                offy = (dest.Height.PointsValue - h) / 2;     //plus as from the bottom
                onmatrix.SetTranslation(offx, offy);
                onmatrix.SetScale(max, max);
                break;

            case (AspectRatioAlign.xMidYMid):
                //Scale to fit within the size without overflow and then position in the middle
                offx = (dest.Width.PointsValue - w) / 2;
                offy = (dest.Height.PointsValue - h) / 2;     //plus as from the bottom
                onmatrix.SetTranslation(offx, offy);
                onmatrix.SetScale(max, max);
                break;

            case (AspectRatioAlign.xMaxYMid):
                //Scale to fit within the size without overflow and show at the top (so no x or y offset)
                offx = dest.Width.PointsValue - w;
                offy = (dest.Height.PointsValue - h) / 2;     //plus as from the bottom
                onmatrix.SetTranslation(offx, offy);
                onmatrix.SetScale(max, max);
                break;


            //YMax
            case (AspectRatioAlign.xMinYMax):
                //Scale to fit within the size without overflow and show at the top (so no x or y offset)
                offx = 0;
                offy = 0;     //plus as from the bottom
                onmatrix.SetTranslation(offx, offy);
                onmatrix.SetScale(max, max);
                break;

            case (AspectRatioAlign.xMidYMax):
                //Scale to fit within the size without overflow and then position in the middle
                offx = (dest.Width.PointsValue - w) / 2;
                offy = 0;     //plus as from the bottom
                onmatrix.SetTranslation(offx, offy);
                onmatrix.SetScale(max, max);
                break;

            case (AspectRatioAlign.xMaxYMax):
                //Scale to fit within the size without overflow and show at the top (so no x or y offset)
                offx = dest.Width.PointsValue - w;
                offy = 0;     //plus as from the bottom
                onmatrix.SetTranslation(offx, offy);
                onmatrix.SetScale(max, max);
                break;

            default:
                break;
            }
        }