Пример #1
0
 internal ImageHash(byte[] md4, RPLFormat.Sizings sizing, int width, int height)
 {
     m_md4    = md4;
     m_sizing = sizing;
     m_width  = width;
     m_height = height;
 }
Пример #2
0
        public override void DrawImage(RectangleF position, RPLImage image, RPLImageProps instanceProperties, RPLImagePropsDef definitionProperties)
        {
            RPLImageData image2 = instanceProperties.Image;

            System.Drawing.Image image3 = default(System.Drawing.Image);
            bool flag = this.GetImage(image2.ImageName, image2.ImageData, image2.ImageDataOffset, false, out image3);

            RPLFormat.Sizings sizing = definitionProperties.Sizing;
            if (image3 == null)
            {
                this.GetDefaultImage(out image3);
                flag   = true;
                sizing = RPLFormat.Sizings.Clip;
            }
            GDIImageProps gDIImageProps = new GDIImageProps(image3);
            RectangleF    destination   = default(RectangleF);
            RectangleF    source        = default(RectangleF);

            SharedRenderer.CalculateImageRectangle(position, gDIImageProps.Width, gDIImageProps.Height, (float)this.m_measureImageDpiX, (float)this.m_measureImageDpiY, sizing, out destination, out source);
            this.m_graphics.DrawImage(image3, destination, source);
            if (!flag)
            {
                image3.Dispose();
                image3 = null;
            }
        }
Пример #3
0
        public void AddImage(byte[] imgBuf, float height, float width, RPLFormat.Sizings sizing)
        {
            if (imgBuf == null || imgBuf.Length == 0)
            {
                sizing = RPLFormat.Sizings.Clip;
                imgBuf = PictureDescriptor.INVALIDIMAGEDATA;
            }
            OfficeImageHasher officeImageHasher = new OfficeImageHasher(imgBuf);

            byte[]    hash = officeImageHasher.Hash;
            int       num  = Word97Writer.ToTwips(height);
            int       num2 = Word97Writer.ToTwips(width);
            int       num3 = (int)this.m_dataStream.Position;
            ImageHash key  = new ImageHash(hash, sizing, num2, num);

            if (this.m_images.ContainsKey(key))
            {
                num3 = this.m_images[key];
            }
            else
            {
                PictureDescriptor pictureDescriptor = new PictureDescriptor(imgBuf, hash, num2, num, sizing, this.m_imgIndex);
                pictureDescriptor.Serialize(this.m_dataStream);
                this.m_imgIndex++;
                this.m_images.Add(key, num3);
            }
            this.m_charFormat.SetIsInlineImage(num3);
            this.WriteSpecialText("\u0001");
        }
 internal PictureDescriptor(byte[] imgData, byte[] hash, int aWidth, int aHeight, RPLFormat.Sizings sizing, int imgIndex)
 {
     m_mX             = 1000;
     m_mY             = 1000;
     m_dxaGoal        = (short)aWidth;
     m_dyaGoal        = (short)aHeight;
     m_originalWidth  = m_dxaGoal;
     m_originalHeight = m_dyaGoal;
     m_mappingMode    = 100;
     m_brcTop         = 1073741824;
     m_brcLeft        = 1073741824;
     m_brcBottom      = 1073741824;
     m_brcRight       = 1073741824;
     m_unknownData    = new byte[0];
     m_sizing         = sizing;
     m_imgData        = imgData;
     if (m_imgData == null)
     {
         m_imgData = INVALIDIMAGEDATA;
     }
     ParseImageData();
     CreateDefaultEscherRecords(hash, imgIndex);
     if (sizing == RPLFormat.Sizings.Clip)
     {
         m_dxaCropLeft   = 0;
         m_dyaCropTop    = 0;
         m_dxaCropRight  = m_dxaGoal - aWidth;
         m_dyaCropBottom = m_dyaGoal - aHeight;
     }
 }
Пример #5
0
 public ImageHash(byte[] md4, RPLFormat.Sizings sizing, int width, int height)
 {
     this.m_md4    = md4;
     this.m_sizing = sizing;
     this.m_width  = width;
     this.m_height = height;
 }
        public void AddImage(byte[] imgBuf, float height, float width, RPLFormat.Sizings sizing)
        {
            bool   flag      = imgBuf == null || imgBuf.Length == 0;
            Size   image     = default(Size);
            string extension = null;

            if (!flag)
            {
                try
                {
                    using (Image image2 = Image.FromStream(new MemoryStream(imgBuf)))
                    {
                        image.Height = WordOpenXmlUtils.PixelsToEmus(image2.Height, image2.VerticalResolution, 0, 20116800);
                        image.Width  = WordOpenXmlUtils.PixelsToEmus(image2.Width, image2.HorizontalResolution, 0, 20116800);
                        extension    = ((image2.RawFormat.Guid == ImageFormat.Png.Guid) ? "png" : ((image2.RawFormat.Guid == ImageFormat.Jpeg.Guid) ? "jpg" : ((!(image2.RawFormat.Guid == ImageFormat.Gif.Guid)) ? "bmp" : "gif")));
                    }
                }
                catch (ArgumentException)
                {
                    flag = true;
                }
            }
            if (flag)
            {
                AddImage(PictureDescriptor.INVALIDIMAGEDATA, height, width, RPLFormat.Sizings.Clip);
                return;
            }
            Size size = default(Size);

            size.Height = WordOpenXmlUtils.ToEmus(height, 0, 20116800);
            size.Width  = WordOpenXmlUtils.ToEmus(width, 0, 20116800);
            Size         size2        = size;
            ImageHash    hash         = new SizingIndependentImageHash(new OfficeImageHasher(imgBuf).Hash);
            Relationship relationship = _document.WriteImageData(imgBuf, hash, extension);

            Size.Strategy strategy = Size.Strategy.AutoSize;
            switch (sizing)
            {
            case RPLFormat.Sizings.AutoSize:
                strategy = Size.Strategy.AutoSize;
                break;

            case RPLFormat.Sizings.Fit:
                strategy = Size.Strategy.Fit;
                break;

            case RPLFormat.Sizings.FitProportional:
                strategy = Size.Strategy.FitProportional;
                break;

            case RPLFormat.Sizings.Clip:
                strategy = Size.Strategy.Clip;
                break;
            }
            Size size3       = WordOpenXmlUtils.SizeImage(image, size2, strategy);
            Size desiredSize = (strategy == Size.Strategy.FitProportional || strategy == Size.Strategy.AutoSize) ? size3 : size2;

            GetCurrentParagraph().AddImage(new OpenXmlPictureModel(size3, desiredSize, sizing == RPLFormat.Sizings.Clip, NextPictureId(), NextPictureId(), relationship.RelationshipId, Path.GetFileName(relationship.RelatedPart)));
        }
Пример #7
0
 internal override void ProcessRenderingElementContent(RPLElement rplElement, GdiContext context, RectangleF bounds)
 {
     Image = RenderingItem.GetImage(context, ((RPLImageProps)InstanceProperties).Image);
     if (Image == null)
     {
         Image  = GdiContext.ImageResources["InvalidImage"];
         Sizing = RPLFormat.Sizings.Clip;
     }
     else
     {
         Sizing = ((RPLImagePropsDef)DefinitionProperties).Sizing;
     }
     ImagePosition = new RectangleF(base.Position.Location, base.Position.Size);
     GdiContext.CalculateUsableReportItemRectangle(InstanceProperties, ref ImagePosition);
     if (!(ImagePosition.Width <= 0f))
     {
         _ = ImagePosition.Height;
         _ = 0f;
     }
 }
Пример #8
0
        internal override void DrawImage(RectangleF position, RPLImage image, RPLImageProps instanceProperties, RPLImagePropsDef definitionProperties)
        {
            RPLImageData image2 = instanceProperties.Image;

            System.Drawing.Image image3;
            bool flag = GetImage(image2.ImageName, image2.ImageData, image2.ImageDataOffset, dynamicImage: false, out image3);

            RPLFormat.Sizings sizing = definitionProperties.Sizing;
            if (image3 == null)
            {
                GetDefaultImage(out image3);
                flag   = true;
                sizing = RPLFormat.Sizings.Clip;
            }
            GDIImageProps gDIImageProps = new GDIImageProps(image3);

            SharedRenderer.CalculateImageRectangle(position, gDIImageProps.Width, gDIImageProps.Height, m_measureImageDpiX, m_measureImageDpiY, sizing, out RectangleF imagePositionAndSize, out RectangleF imagePortion);
            m_graphics.DrawImage(image3, imagePositionAndSize, imagePortion);
            if (!flag)
            {
                image3.Dispose();
                image3 = null;
            }
        }
Пример #9
0
        public void RenderReportItem(RPLElement reportItem, RPLItemMeasurement measurement, StyleContext styleContext, ref int borderContext, bool renderId, bool treatAsTopLevel)
        {
            RPLImageProps    rPLImageProps    = (RPLImageProps)reportItem.ElementProps;
            RPLImagePropsDef rPLImagePropsDef = (RPLImagePropsDef)rPLImageProps.Definition;

            RPLFormat.Sizings sizing = rPLImagePropsDef.Sizing;
            RPLImageData      image  = rPLImageProps.Image;

            this.html5Renderer.GetInnerContainerHeightSubtractBorders(measurement, rPLImageProps.Style);
            float  innerContainerWidthSubtractBorders = this.html5Renderer.GetInnerContainerWidthSubtractBorders(measurement, rPLImageProps.Style);
            string text      = this.html5Renderer.GetImageUrl(true, image);
            string ariaLabel = null;
            string role      = null;
            string tooltip   = this.html5Renderer.GetTooltip(rPLImageProps);

            if (treatAsTopLevel)
            {
                ariaLabel = (string.IsNullOrEmpty(tooltip) ? RenderRes.AccessibleImageLabel : RenderRes.AccessibleImageNavigationGroupLabel(tooltip));
                role      = HTMLElements.m_navigationRole;
            }
            string altText = string.IsNullOrEmpty(tooltip) ? RenderRes.AccessibleImageLabel : tooltip;
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            if (this.html5Renderer.m_elementExtender.ShouldApplyToElement(treatAsTopLevel))
            {
                dictionary.Add(HTMLElements.m_reportItemDataName, this.html5Renderer.m_elementExtender.ApplyToElement());
                dictionary.Add(HTMLElements.m_reportItemCustomAttrStr, this.html5Renderer.GetReportItemPath(rPLImagePropsDef.Name));
            }
            bool flag = rPLImageProps.ActionImageMapAreas != null && rPLImageProps.ActionImageMapAreas.Length > 0;

            if (flag)
            {
                string s = HTMLElements.m_hashTag + this.html5Renderer.m_deviceInfo.HtmlPrefixId + HTMLElements.m_mapPrefixString + rPLImageProps.UniqueName;
                dictionary.Add(HTMLElements.m_useMapName, HttpUtility.HtmlAttributeEncode(s));
            }
            if (this.html5Renderer.HasAction(rPLImageProps.ActionInfo))
            {
                this.RenderElementHyperlink(rPLImageProps.Style, rPLImageProps.ActionInfo.Actions[0]);
            }
            if (!styleContext.InTablix)
            {
                if (sizing == RPLFormat.Sizings.AutoSize)
                {
                    styleContext.RenderMeasurements = false;
                }
                this.html5Renderer.WriteStream(HTMLElements.m_openDiv);
                this.html5Renderer.RenderReportItemStyle(reportItem, (RPLElementProps)rPLImageProps, (RPLElementPropsDef)rPLImagePropsDef, measurement, styleContext, ref borderContext, rPLImagePropsDef.ID);
                this.html5Renderer.WriteStream(HTMLElements.m_closeBracket);
            }
            if (string.IsNullOrEmpty(text))
            {
                text = "data:image/gif;base64," + Convert.ToBase64String(HTMLRendererResources.GetBytes("Blank.gif"));
            }
            HtmlElement htmlElement;

            switch (sizing)
            {
            case RPLFormat.Sizings.FitProportional:
                htmlElement = new FitProportionalImageElement(text, innerContainerWidthSubtractBorders, role, altText, ariaLabel, dictionary);
                break;

            case RPLFormat.Sizings.Fit:
                htmlElement = new FitImageElement(text, role, altText, ariaLabel, dictionary);
                break;

            case RPLFormat.Sizings.Clip:
                htmlElement = new ClipImageElement(text, role, altText, ariaLabel, dictionary);
                break;

            default:
                htmlElement = new OriginalSizeImageElement(text, role, altText, ariaLabel, dictionary);
                break;
            }
            htmlElement.Render(new Html5OutputStream(this.html5Renderer));
            if (!styleContext.InTablix)
            {
                this.html5Renderer.WriteStream(HTMLElements.m_closeDiv);
            }
            if (this.html5Renderer.HasAction(rPLImageProps.ActionInfo))
            {
                this.html5Renderer.WriteStream(HTMLElements.m_closeA);
            }
            if (flag)
            {
                this.html5Renderer.RenderImageMapAreas(rPLImageProps.ActionImageMapAreas, (double)measurement.Width, (double)measurement.Height, rPLImageProps.UniqueName, 0, 0);
            }
        }
        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 void CalculateImageRectangle(RectangleF position, GDIImageProps gdiProperties, RPLFormat.Sizings sizing, out RectangleF imagePositionAndSize, out RectangleF imagePortion)
 {
     SharedRenderer.CalculateImageRectangle(position, gdiProperties.Width, gdiProperties.Height, gdiProperties.HorizontalResolution, gdiProperties.VerticalResolution, sizing, out imagePositionAndSize, out imagePortion);
 }
        public void RenderReportItem(RPLElement dynamicImage, RPLItemMeasurement measurement, StyleContext styleContext, ref int borderContext, bool renderId, bool treatAsTopLevel)
        {
            RPLElementProps      elementProps         = dynamicImage.ElementProps;
            RPLElementPropsDef   definition           = elementProps.Definition;
            RPLDynamicImageProps rPLDynamicImageProps = (RPLDynamicImageProps)elementProps;
            string tooltip = html5Renderer.GetTooltip(rPLDynamicImageProps);

            if (dynamicImage == null)
            {
                return;
            }
            bool      flag      = rPLDynamicImageProps.ActionImageMapAreas != null && rPLDynamicImageProps.ActionImageMapAreas.Length != 0;
            Rectangle rectangle = RenderDynamicImage(measurement, rPLDynamicImageProps);
            int       xOffset   = 0;
            int       yOffset   = 0;
            bool      flag2     = !rectangle.IsEmpty;
            bool      flag3     = !html5Renderer.m_deviceInfo.IsBrowserSafari || html5Renderer.m_deviceInfo.AllowScript || !styleContext.InTablix;

            if (flag3)
            {
                html5Renderer.WriteStream(HTMLElements.m_openDiv);
                if (flag2 && html5Renderer.m_elementExtender.ShouldApplyToElement(treatAsTopLevel))
                {
                    WriteReportItemDataName();
                }
                html5Renderer.WriteAccesibilityTags(RenderRes.AccessibleChartLabel, rPLDynamicImageProps, treatAsTopLevel);
                if (treatAsTopLevel)
                {
                    string accessibleAriaName = string.IsNullOrEmpty(tooltip) ? RenderRes.AccessibleChartLabel : RenderResWrapper.AccessibleChartNavigationGroupLabel(tooltip);
                    html5Renderer.WriteAriaAccessibleTags(accessibleAriaName);
                }
            }
            bool flag4 = html5Renderer.m_deviceInfo.DataVisualizationFitSizing == DataVisualizationFitSizing.Exact && styleContext.InTablix;

            if (flag2)
            {
                RPLFormat.Sizings sizing = flag4 ? RPLFormat.Sizings.Fit : RPLFormat.Sizings.AutoSize;
                html5Renderer.WriteOuterConsolidation(rectangle, sizing, rPLDynamicImageProps.UniqueName);
                html5Renderer.RenderReportItemStyle(dynamicImage, null, ref borderContext);
                xOffset = rectangle.Left;
                yOffset = rectangle.Top;
            }
            else if (flag4 && html5Renderer.m_deviceInfo.AllowScript)
            {
                if (html5Renderer.m_imgFitDivIdsStream == null)
                {
                    html5Renderer.CreateImgFitDivImageIdsStream();
                }
                html5Renderer.WriteIdToSecondaryStream(html5Renderer.m_imgFitDivIdsStream, rPLDynamicImageProps.UniqueName + "_ifd");
                html5Renderer.RenderReportItemId(rPLDynamicImageProps.UniqueName + "_ifd");
            }
            if (flag3)
            {
                html5Renderer.WriteStream(HTMLElements.m_closeBracket);
            }
            html5Renderer.WriteStream(HTMLElements.m_img);
            if (html5Renderer.m_elementExtender.ShouldApplyToElement(treatAsTopLevel))
            {
                if (!flag2)
                {
                    WriteReportItemDataName();
                }
                RPLItemPropsDef rPLItemPropsDef = (RPLItemPropsDef)definition;
                html5Renderer.WriteAttrEncoded(HTMLElements.m_reportItemCustomAttr, html5Renderer.GetReportItemPath(rPLItemPropsDef.Name));
            }
            if (html5Renderer.m_browserIE)
            {
                html5Renderer.WriteStream(HTMLElements.m_imgOnError);
            }
            if (renderId)
            {
                html5Renderer.RenderReportItemId(rPLDynamicImageProps.UniqueName);
            }
            html5Renderer.WriteStream(HTMLElements.m_zeroBorder);
            bool flag5 = dynamicImage is RPLChart;

            if (flag)
            {
                html5Renderer.WriteAttrEncoded(HTMLElements.m_useMap, "#" + html5Renderer.m_deviceInfo.HtmlPrefixId + HTMLElements.m_mapPrefixString + rPLDynamicImageProps.UniqueName);
                if (flag4)
                {
                    html5Renderer.OpenStyle();
                    if (html5Renderer.m_useInlineStyle && !flag2)
                    {
                        html5Renderer.WriteStream(HTMLElements.m_styleHeight);
                        html5Renderer.WriteStream(HTMLElements.m_percent);
                        html5Renderer.WriteStream(HTMLElements.m_semiColon);
                        html5Renderer.WriteStream(HTMLElements.m_styleWidth);
                        html5Renderer.WriteStream(HTMLElements.m_percent);
                        html5Renderer.WriteStream(HTMLElements.m_semiColon);
                        flag5 = false;
                    }
                    html5Renderer.WriteStream("border-style:none;");
                }
            }
            else if (flag4 && html5Renderer.m_useInlineStyle && !flag2)
            {
                html5Renderer.PercentSizes();
                flag5 = false;
            }
            StyleContext styleContext2 = new StyleContext();

            if (!flag4 && (html5Renderer.m_deviceInfo.IsBrowserIE7 || html5Renderer.m_deviceInfo.IsBrowserIE6))
            {
                styleContext2.RenderMeasurements    = false;
                styleContext2.RenderMinMeasurements = false;
            }
            if (!flag2)
            {
                if (flag4)
                {
                    html5Renderer.RenderReportItemStyle(dynamicImage, null, ref borderContext, styleContext2);
                }
                else if (flag5)
                {
                    RPLElementProps elementProps2 = dynamicImage.ElementProps;
                    StyleContext    styleContext3 = new StyleContext();
                    styleContext3.RenderMeasurements = false;
                    html5Renderer.OpenStyle();
                    html5Renderer.RenderMeasurementStyle(measurement.Height, measurement.Width);
                    html5Renderer.RenderReportItemStyle(dynamicImage, elementProps2, definition, measurement, styleContext3, ref borderContext, definition.ID);
                }
                else
                {
                    html5Renderer.RenderReportItemStyle(dynamicImage, measurement, ref borderContext, styleContext2);
                }
            }
            else
            {
                html5Renderer.WriteClippedDiv(rectangle);
            }
            tooltip = (string.IsNullOrEmpty(tooltip) ? RenderRes.AccessibleChartLabel : tooltip);
            html5Renderer.WriteToolTipAttribute(tooltip);
            html5Renderer.WriteStream(HTMLElements.m_src);
            html5Renderer.RenderDynamicImageSrc(rPLDynamicImageProps);
            html5Renderer.WriteStreamCR(HTMLElements.m_closeTag);
            if (flag)
            {
                html5Renderer.RenderImageMapAreas(rPLDynamicImageProps.ActionImageMapAreas, measurement.Width, measurement.Height, rPLDynamicImageProps.UniqueName, xOffset, yOffset);
            }
            if (flag3)
            {
                html5Renderer.WriteStream(HTMLElements.m_closeDiv);
            }
        }