示例#1
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;
            }
        }
示例#2
0
 public SVGAspectRatio(AspectRatioAlign align, AspectRatioMeet meet)
 {
     this.Align = align;
     this.Meet  = meet;
 }
示例#3
0
 public SVGAspectRatio(AspectRatioAlign align) : this(align, AspectRatioMeet.Meet)
 {
 }