private void ProcessImage(HtmlEnumerator en) { if (this.ImageProcessing == ImageProcessing.Ignore) return; Drawing drawing = null; wBorder border = new wBorder() { Val = BorderValues.None }; string src = en.Attributes["src"]; Uri uri; if (src != null && Uri.TryCreate(src, UriKind.RelativeOrAbsolute, out uri)) { string alt = en.Attributes["alt"]; bool process = true; if (!uri.IsAbsoluteUri && this.BaseImageUrl != null) uri = new Uri(this.BaseImageUrl, uri); Size preferredSize = Size.Empty; if (en.Attributes["width"] != null || en.Attributes["height"] != null) { Unit wu = en.Attributes.GetAsUnit("width"); Unit hu = en.Attributes.GetAsUnit("height"); // % is not supported if (wu.IsValid && wu.Value > 0 && wu.Type != UnitMetric.Percent) { preferredSize.Width = wu.ValueInPx; } if (hu.IsValid && hu.Value > 0 && wu.Type != UnitMetric.Percent) { // Image perspective skewed. Bug fixed by ddeforge on http://notesforhtml2openxml.codeplex.com/discussions/350500 preferredSize.Height = hu.ValueInPx; } } SideBorder attrBorder = en.StyleAttributes.GetAsSideBorder("border"); if (attrBorder.IsValid) { border.Val = attrBorder.Style; border.Color = attrBorder.Color.ToHexString(); border.Size = (uint) attrBorder.Width.ValueInPx * 4; } if (process) drawing = AddImagePart(uri, src, alt, preferredSize); } if (drawing != null) { Run run = new Run(drawing); if (border.Val != BorderValues.None) run.InsertInProperties(border); elements.Add(run); } }
private void ProcessImage(HtmlEnumerator en) { if (this.ImageProcessing == ImageProcessing.Ignore) return; Drawing drawing = null; wBorder border = new wBorder() { Val = BorderValues.None }; string src = en.Attributes["src"]; Uri uri = null; // Bug reported by Erik2014. Inline 64 bit images can be too big and Uri.TryCreate will fail silently with a SizeLimit error. // To circumvent this buffer size, we will work either on the Uri, either on the original src. if (src != null && (DataUri.IsWellFormed(src) || Uri.TryCreate(src, UriKind.RelativeOrAbsolute, out uri))) { string alt = (en.Attributes["title"] ?? en.Attributes["alt"]) ?? String.Empty; bool process = true; if (uri != null && !uri.IsAbsoluteUri && this.BaseImageUrl != null) uri = new Uri(this.BaseImageUrl, uri); Size preferredSize = Size.Empty; Unit wu = en.Attributes.GetAsUnit("width"); if (!wu.IsValid) wu = en.StyleAttributes.GetAsUnit("width"); Unit hu = en.Attributes.GetAsUnit("height"); if (!hu.IsValid) hu = en.StyleAttributes.GetAsUnit("height"); // % is not supported if (wu.IsFixed && wu.Value > 0) { preferredSize.Width = wu.ValueInPx; } if (hu.IsFixed && hu.Value > 0) { // Image perspective skewed. Bug fixed by ddeforge on http://html2openxml.codeplex.com/discussions/350500 preferredSize.Height = hu.ValueInPx; } SideBorder attrBorder = en.StyleAttributes.GetAsSideBorder("border"); if (attrBorder.IsValid) { border.Val = attrBorder.Style; border.Color = attrBorder.Color.ToHexString(); border.Size = (uint)attrBorder.Width.ValueInPx * 4; } if (process) drawing = AddImagePart(uri, src, alt, preferredSize); } if (drawing != null) { Run run = new Run(drawing); if (border.Val != BorderValues.None) run.InsertInProperties(prop => prop.Border = border); elements.Add(run); } }