コード例 #1
0
ファイル: ImageConverter.cs プロジェクト: stuzzicadenti/aodl
        /// <summary>
        /// Scales the pdf image if nessarry by percent.
        /// </summary>
        /// <param name="img">The img.</param>
        /// <param name="frame">The frame.</param>
        /// <returns>The scaled image.</returns>
        private iTextSharp.text.Image ScaleIfNessarry(iTextSharp.text.Image img, Frame frame)
        {
            try
            {
                double scalingPrescision = 0.25;
                double scaledWidthPercent = 0;
                double scaledHeightPercent = 0;
                double odfScaledWidth = AODL.Document.Helper.SizeConverter.GetDoubleFromAnOfficeSizeValue(frame.SvgWidth);
                double odfScaledHeight = AODL.Document.Helper.SizeConverter.GetDoubleFromAnOfficeSizeValue(frame.SvgHeight);

                if((frame.Height - odfScaledHeight) > scalingPrescision
                    || (frame.Height - odfScaledHeight) < scalingPrescision)
                {
                    scaledHeightPercent = ((100.0/frame.Height) * odfScaledHeight);
                    Console.WriteLine("ScaledHeightPerc {0} , frame {1}, odfScaledHeight {2}", scaledHeightPercent, frame.Height, odfScaledHeight);
                }

                if((frame.Width - odfScaledWidth) > scalingPrescision
                    || (frame.Width - odfScaledWidth) < scalingPrescision)
                {
                    scaledWidthPercent = ((100.0/frame.Width) * odfScaledWidth);
                }

                if(scaledHeightPercent != 0 || scaledWidthPercent != 0)
                {
                    img.ScalePercent((float) scaledWidthPercent, (float) scaledHeightPercent);
                }

                return img;
            }
            catch(Exception)
            {
                throw;
            }
        }