Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
31 changes: 10 additions & 21 deletions src/MiniPdf/DocxReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
var xpath = dataBinding.Attribute(W + "xpath")?.Value;
var prefixMappings = dataBinding.Attribute(W + "prefixMappings")?.Value ?? "";
if (string.IsNullOrEmpty(storeItemID) || string.IsNullOrEmpty(xpath)) return null;
if (!ctx.XmlStores.TryGetValue(storeItemID, out var doc) || doc.Root == null) return null;

Check warning on line 133 in src/MiniPdf/DocxReader.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'key' in 'bool Dictionary<string, XDocument>.TryGetValue(string key, out XDocument value)'.

var nsMgr = new System.Xml.XmlNamespaceManager(new System.Xml.NameTable());
foreach (System.Text.RegularExpressions.Match m in System.Text.RegularExpressions.Regex.Matches(
Expand Down Expand Up @@ -871,7 +871,7 @@
if (string.IsNullOrWhiteSpace(style))
return values;

foreach (var declaration in style.Split(';', StringSplitOptions.RemoveEmptyEntries))

Check warning on line 874 in src/MiniPdf/DocxReader.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 's' in 'string[] NetFxPolyfills.Split(string s, char separator, StringSplitOptions options)'.
{
var separator = declaration.IndexOf(':');
if (separator <= 0)
Expand Down Expand Up @@ -2573,29 +2573,18 @@
var scale = Math.Min(1d, Math.Min(4096d / requestedWidth, 4096d / requestedHeight));
var targetWidth = Math.Max(32, (int)Math.Round(requestedWidth * scale));
var targetHeight = Math.Max(32, (int)Math.Round(requestedHeight * scale));
var normalizedBytes = EmfCompatibilityNormalizer.NormalizeForMiniPdfDrawing(sourceBytes, targetWidth, targetHeight);
using var sourceStream = new MemoryStream(normalizedBytes, writable: false);
using var metafile = new global::MiniSoftware.Drawing.Imaging.Metafile(sourceStream);
using var bitmap = metafile.ToBitmap();
using var outputStream = new MemoryStream();
if (hasCrop)
{
var cropX = Compat.Clamp((int)Math.Round(bitmap.Width * cropL), 0, bitmap.Width - 1);
var cropY = Compat.Clamp((int)Math.Round(bitmap.Height * cropT), 0, bitmap.Height - 1);
var cropWidth = Compat.Clamp((int)Math.Round(bitmap.Width * (1 - cropL - cropR)), 1, bitmap.Width - cropX);
var cropHeight = Compat.Clamp((int)Math.Round(bitmap.Height * (1 - cropT - cropB)), 1, bitmap.Height - cropY);
using var cropped = bitmap.Clone(
new global::MiniSoftware.Drawing.Geometry.Rectangle(cropX, cropY, cropWidth, cropHeight), bitmap.PixelFormat);
cropped.Save(outputStream, global::MiniSoftware.Drawing.Imaging.ImageFormat.Png);
}
else
{
bitmap.Save(outputStream, global::MiniSoftware.Drawing.Imaging.ImageFormat.Png);
}
return outputStream.ToArray();
var renderBytes = WmfVectorAdapter.IsWmf(sourceBytes) ? WmfVectorAdapter.Convert(sourceBytes, targetWidth, targetHeight) : sourceBytes;
return EmfVectorRenderer.RenderCropped(renderBytes, targetWidth, targetHeight, PdfWriter.ResolveMetafileFont,
hasCrop ? cropL : 0, hasCrop ? cropT : 0, hasCrop ? cropR : 0, hasCrop ? cropB : 0);
}
catch
catch (NotSupportedException error)
{
System.Diagnostics.Trace.TraceWarning("Independent metafile conversion is unsupported: {0}", error.Message);
return null;
}
catch (InvalidDataException error)
{
System.Diagnostics.Trace.TraceWarning("Independent metafile conversion rejected invalid data: {0}", error.Message);
return null;
}
}
Expand Down
53 changes: 0 additions & 53 deletions src/MiniPdf/Drawing/Brushes/Brush.cs

This file was deleted.

Loading
Loading