Пример #1
0
        public IClientAnchor GetPreferredSize(double scale)
        {
            XSSFClientAnchor anchor         = (XSSFClientAnchor)this.GetAnchor();
            XSSFPictureData  pictureData    = (XSSFPictureData)this.PictureData;
            Size             imageDimension = XSSFPicture.GetImageDimension(pictureData.GetPackagePart(), pictureData.GetPictureType());
            double           num1           = (double)imageDimension.Width * scale;
            double           num2           = (double)imageDimension.Height * scale;
            float            num3           = 0.0f;
            int col1 = anchor.Col1;
            int num4 = 0;

            while (true)
            {
                num3 += this.GetColumnWidthInPixels(col1);
                if ((double)num3 <= num1)
                {
                    ++col1;
                }
                else
                {
                    break;
                }
            }
            if ((double)num3 > num1)
            {
                double columnWidthInPixels = (double)this.GetColumnWidthInPixels(col1);
                double num5 = (double)num3 - num1;
                num4 = (int)((double)XSSFShape.EMU_PER_PIXEL * (columnWidthInPixels - num5));
            }
            anchor.Col2 = col1;
            anchor.Dx2  = num4;
            double num6 = 0.0;
            int    row1 = anchor.Row1;
            int    num7 = 0;

            while (true)
            {
                num6 += (double)this.GetRowHeightInPixels(row1);
                if (num6 <= num2)
                {
                    ++row1;
                }
                else
                {
                    break;
                }
            }
            if (num6 > num2)
            {
                double rowHeightInPixels = (double)this.GetRowHeightInPixels(row1);
                double num5 = num6 - num2;
                num7 = (int)((double)XSSFShape.EMU_PER_PIXEL * (rowHeightInPixels - num5));
            }
            anchor.Row2 = row1;
            anchor.Dy2  = num7;
            CT_PositiveSize2D ext = this.ctPicture.spPr.xfrm.ext;

            ext.cx = (long)(num1 * (double)XSSFShape.EMU_PER_PIXEL);
            ext.cy = (long)(num2 * (double)XSSFShape.EMU_PER_PIXEL);
            return((IClientAnchor)anchor);
        }
Пример #2
0
        /**
         * Calculate the preferred size for this picture.
         *
         * @param scale the amount by which image dimensions are multiplied relative to the original size.
         * @return XSSFClientAnchor with the preferred size for this image
         */
        public IClientAnchor GetPreferredSize(double scale)
        {
            XSSFClientAnchor anchor = (XSSFClientAnchor)GetAnchor();

            XSSFPictureData data         = (XSSFPictureData)this.PictureData;
            Size            size         = GetImageDimension(data.GetPackagePart(), data.GetPictureType());
            double          scaledWidth  = size.Width * scale;
            double          scaledHeight = size.Height * scale;

            float w    = 0;
            int   col2 = anchor.Col1;
            int   dx2  = 0;

            for (; ;)
            {
                w += GetColumnWidthInPixels(col2);
                if (w > scaledWidth)
                {
                    break;
                }
                col2++;
            }

            if (w > scaledWidth)
            {
                double cw    = GetColumnWidthInPixels(col2);
                double delta = w - scaledWidth;
                dx2 = (int)(EMU_PER_PIXEL * (cw - delta));
            }
            anchor.Col2 = (col2);
            anchor.Dx2  = (dx2);

            double h    = 0;
            int    row2 = anchor.Row1;
            int    dy2  = 0;

            for (; ;)
            {
                h += GetRowHeightInPixels(row2);
                if (h > scaledHeight)
                {
                    break;
                }
                row2++;
            }

            if (h > scaledHeight)
            {
                double ch    = GetRowHeightInPixels(row2);
                double delta = h - scaledHeight;
                dy2 = (int)(EMU_PER_PIXEL * (ch - delta));
            }
            anchor.Row2 = (row2);
            anchor.Dy2  = (dy2);

            CT_PositiveSize2D size2d = ctPicture.spPr.xfrm.ext;

            size2d.cx = ((long)(scaledWidth * EMU_PER_PIXEL));
            size2d.cy = ((long)(scaledHeight * EMU_PER_PIXEL));

            return(anchor);
        }