public static int ConvertToPixels(float mm, float?dpi, WriterBase writer)
 {
     if (dpi.HasValue)
     {
         return(SharedRenderer.ConvertToPixels(mm, dpi.Value));
     }
     return(writer.ConvertToPixels(mm));
 }
Exemplo n.º 2
0
        public override void ClipTextboxRectangle(Win32DCSafeHandle hdc, RectangleF position)
        {
            if (this.m_bodyRect.X != 0 || this.m_bodyRect.Y != 0)
            {
                if (!AspNetCore.ReportingServices.Rendering.RichText.Win32.GetViewportOrgEx(hdc, out this.m_prevViewportOrg))
                {
                    int    lastWin32Error = Marshal.GetLastWin32Error();
                    string message        = string.Format(CultureInfo.InvariantCulture, ImageRendererRes.Win32ErrorInfo, "GetViewportOrgEx", lastWin32Error);
                    throw new Exception(message);
                }
                if (!AspNetCore.ReportingServices.Rendering.RichText.Win32.SetViewportOrgEx(hdc, this.m_bodyRect.X, this.m_bodyRect.Y, Win32ObjectSafeHandle.Zero))
                {
                    int    lastWin32Error2 = Marshal.GetLastWin32Error();
                    string message2        = string.Format(CultureInfo.InvariantCulture, ImageRendererRes.Win32ErrorInfo, "SetViewportOrgEx", lastWin32Error2);
                    throw new Exception(message2);
                }
            }
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(SharedRenderer.ConvertToPixels(position.X, (float)base.m_commonGraphics.DpiX), SharedRenderer.ConvertToPixels(position.Y, (float)base.m_commonGraphics.DpiY), SharedRenderer.ConvertToPixels(position.Width, (float)base.m_commonGraphics.DpiX), SharedRenderer.ConvertToPixels(position.Height, (float)base.m_commonGraphics.DpiY));
            if (position.X < 0.0)
            {
                rectangle.Width += rectangle.X;
                rectangle.X      = 0;
            }
            if (position.Y < 0.0)
            {
                rectangle.Height += rectangle.Y;
                rectangle.Y       = 0;
            }
            rectangle.X += this.m_bodyRect.X;
            rectangle.Y += this.m_bodyRect.Y;
            if (rectangle.Right > this.m_bodyRect.Right)
            {
                rectangle.Width = this.m_bodyRect.Right - rectangle.Left;
            }
            if (rectangle.Bottom > this.m_bodyRect.Bottom)
            {
                rectangle.Height = this.m_bodyRect.Bottom - rectangle.Top;
            }
            Win32ObjectSafeHandle win32ObjectSafeHandle = AspNetCore.ReportingServices.Rendering.RichText.Win32.CreateRectRgn(rectangle.X, rectangle.Y, rectangle.Right, rectangle.Bottom);

            if (!win32ObjectSafeHandle.IsInvalid)
            {
                try
                {
                    if (AspNetCore.ReportingServices.Rendering.RichText.Win32.SelectClipRgn(hdc, win32ObjectSafeHandle) == 0)
                    {
                        int    lastWin32Error3 = Marshal.GetLastWin32Error();
                        string message3        = string.Format(CultureInfo.InvariantCulture, ImageRendererRes.Win32ErrorInfo, "SelectClipRgn", lastWin32Error3);
                        throw new Exception(message3);
                    }
                }
                finally
                {
                    win32ObjectSafeHandle.Close();
                }
            }
        }
Exemplo n.º 3
0
        public override void BeginPageSection(RectangleF bounds)
        {
            base.BeginPageSection(bounds);
            int dpiX = base.m_commonGraphics.DpiX;
            int dpiY = base.m_commonGraphics.DpiY;

            this.m_bodyRect = new System.Drawing.Rectangle(SharedRenderer.ConvertToPixels(bounds.X, (float)dpiX), SharedRenderer.ConvertToPixels(bounds.Y, (float)dpiY), SharedRenderer.ConvertToPixels(bounds.Width + this.HalfPixelWidthX, (float)dpiX), SharedRenderer.ConvertToPixels(bounds.Height + this.HalfPixelWidthY, (float)dpiY));
            this.m_graphics.ResetClipAndTransform(new RectangleF(bounds.Left, bounds.Top, bounds.Width + this.HalfPixelWidthX, bounds.Height + this.HalfPixelWidthY));
        }
        public static void CalculateImageRectangle(RectangleF position, int width, int height, float horizontalResolution, float verticalResolution, RPLFormat.Sizings sizing, out RectangleF imagePositionAndSize, out RectangleF imagePortion)
        {
            imagePositionAndSize = position;
            if (sizing == RPLFormat.Sizings.Clip)
            {
                imagePortion = new RectangleF(0f, 0f, (float)width, (float)height);
                float num = (float)SharedRenderer.ConvertToPixels(imagePositionAndSize.Width, horizontalResolution);
                if ((float)width > num)
                {
                    imagePortion.Width = num;
                }
                else
                {
                    imagePositionAndSize.Width = SharedRenderer.ConvertToMillimeters(width, horizontalResolution);
                }
                float num2 = (float)SharedRenderer.ConvertToPixels(imagePositionAndSize.Height, verticalResolution);
                if ((float)height > num2)
                {
                    imagePortion.Height = num2;
                }
                else
                {
                    imagePositionAndSize.Height = SharedRenderer.ConvertToMillimeters(height, verticalResolution);
                }
            }
            else
            {
                imagePortion = new RectangleF(0f, 0f, (float)width, (float)height);
                switch (sizing)
                {
                case RPLFormat.Sizings.AutoSize:
                    imagePositionAndSize.Width  = SharedRenderer.ConvertToMillimeters(width, horizontalResolution);
                    imagePositionAndSize.Height = SharedRenderer.ConvertToMillimeters(height, verticalResolution);
                    break;

                case RPLFormat.Sizings.FitProportional:
                {
                    float num3 = SharedRenderer.ConvertToMillimeters(width, horizontalResolution);
                    float num4 = SharedRenderer.ConvertToMillimeters(height, verticalResolution);
                    float num5 = position.Width / num3;
                    float num6 = position.Height / num4;
                    if (num5 > num6)
                    {
                        imagePositionAndSize.Width = num3 * num6;
                    }
                    else
                    {
                        imagePositionAndSize.Height = num4 * num5;
                    }
                    break;
                }
                }
            }
        }
 public static bool CalculateImageClippedUnscaledBounds(WriterBase writer, RectangleF bounds, int width, int height, float xOffsetMM, float yOffsetMM, int?measureImageDpiX, int?measureImageDpiY, out RectangleF destination, out RectangleF source)
 {
     destination = Rectangle.Empty;
     source      = Rectangle.Empty;
     if (!(bounds.Left + xOffsetMM > bounds.Right) && !(bounds.Top + yOffsetMM > bounds.Bottom))
     {
         RectangleF rectangleF = default(RectangleF);
         float      num        = SharedRenderer.ConvertToMillimeters(width, (float?)measureImageDpiX, writer);
         if (xOffsetMM >= 0.0)
         {
             rectangleF.X     = bounds.Left + xOffsetMM;
             rectangleF.Width = Math.Min(num, bounds.Width - xOffsetMM);
         }
         else
         {
             rectangleF.X     = bounds.Left;
             rectangleF.Width = Math.Min(num, num + xOffsetMM);
         }
         float num2 = SharedRenderer.ConvertToMillimeters(height, (float?)measureImageDpiY, writer);
         if (yOffsetMM >= 0.0)
         {
             rectangleF.Y      = bounds.Top + yOffsetMM;
             rectangleF.Height = Math.Min(num2, bounds.Height - yOffsetMM);
         }
         else
         {
             rectangleF.Y      = bounds.Top;
             rectangleF.Height = Math.Min(num2, num2 + yOffsetMM);
         }
         if (!(rectangleF.Right < 0.0) && !(rectangleF.Bottom < 0.0))
         {
             destination = rectangleF;
             float x = 0f;
             if (xOffsetMM < 0.0)
             {
                 x = (float)(-SharedRenderer.ConvertToPixels(xOffsetMM, (float?)measureImageDpiX, writer));
             }
             float y = 0f;
             if (yOffsetMM < 0.0)
             {
                 y = (float)(-SharedRenderer.ConvertToPixels(yOffsetMM, (float?)measureImageDpiY, writer));
             }
             float width2  = (float)Math.Min(width, SharedRenderer.ConvertToPixels(rectangleF.Width, (float?)measureImageDpiX, writer));
             float height2 = (float)Math.Min(height, SharedRenderer.ConvertToPixels(rectangleF.Height, (float?)measureImageDpiY, writer));
             source = new RectangleF(x, y, width2, height2);
             return(true);
         }
         return(false);
     }
     return(false);
 }
 public static void DrawImage(System.Drawing.Graphics graphics, Image image, PointF[] pointsDestMM, RectangleF rectSourcePX, ImageAttributes imageAttributes)
 {
     PointF[] destPoints = new PointF[3]
     {
         new PointF((float)SharedRenderer.ConvertToPixels(pointsDestMM[0].X, graphics.DpiX), (float)SharedRenderer.ConvertToPixels(pointsDestMM[0].Y, graphics.DpiY)),
         new PointF((float)SharedRenderer.ConvertToPixels(pointsDestMM[1].X, graphics.DpiX), (float)SharedRenderer.ConvertToPixels(pointsDestMM[1].Y, graphics.DpiY)),
         new PointF((float)SharedRenderer.ConvertToPixels(pointsDestMM[2].X, graphics.DpiX), (float)SharedRenderer.ConvertToPixels(pointsDestMM[2].Y, graphics.DpiY))
     };
     using (Matrix matrix = graphics.Transform)
     {
         using (Matrix transform = new Matrix(matrix.Elements[0], matrix.Elements[1], matrix.Elements[2], matrix.Elements[3], (float)SharedRenderer.ConvertToPixels(matrix.Elements[4], graphics.DpiX), (float)SharedRenderer.ConvertToPixels(matrix.Elements[5], graphics.DpiY)))
         {
             graphics.Transform = transform;
             graphics.PageUnit  = GraphicsUnit.Pixel;
             graphics.DrawImage(image, destPoints, rectSourcePX, GraphicsUnit.Pixel, imageAttributes);
             graphics.PageUnit  = GraphicsUnit.Millimeter;
             graphics.Transform = matrix;
         }
     }
 }
Exemplo n.º 7
0
 private void CalculateMetafileRectangle(float pageWidth, float pageHeight)
 {
     if (this.IsEmf)
     {
         Win32DCSafeHandle hdc = this.m_graphics.GetHdc();
         try
         {
             int    deviceCaps  = AspNetCore.ReportingServices.Rendering.RichText.Win32.GetDeviceCaps(hdc, 4);
             int    deviceCaps2 = AspNetCore.ReportingServices.Rendering.RichText.Win32.GetDeviceCaps(hdc, 6);
             int    deviceCaps3 = AspNetCore.ReportingServices.Rendering.RichText.Win32.GetDeviceCaps(hdc, 8);
             int    deviceCaps4 = AspNetCore.ReportingServices.Rendering.RichText.Win32.GetDeviceCaps(hdc, 10);
             double num         = (double)SharedRenderer.ConvertToPixels(pageWidth, (float)this.m_graphics.DpiX);
             double num2        = (double)SharedRenderer.ConvertToPixels(pageHeight, (float)this.m_graphics.DpiY);
             float  width       = (float)(num * (double)deviceCaps * 100.0) / (float)deviceCaps3;
             float  height      = (float)(num2 * (double)deviceCaps2 * 100.0) / (float)deviceCaps4;
             this.MetafileRectangle = new RectangleF(0f, 0f, width, height);
         }
         finally
         {
             this.m_graphics.ReleaseHdc();
         }
     }
 }
 public int ConvertToPixels(float mm)
 {
     return(SharedRenderer.ConvertToPixels(mm, (float)this.m_dpiX));
 }