From 44b64cc26fa8aee3e1055fdabc0559c8ccd2e1f6 Mon Sep 17 00:00:00 2001 From: dmester Date: Sat, 17 Jul 2021 14:58:06 +0200 Subject: [PATCH] Updated expected result. --- tests/PdfToSvg.Tests/ConversionTests.cs | 17 ++++++ .../TestFiles/Own/expected/masked-images.svg | 53 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tests/TestFiles/Own/expected/masked-images.svg diff --git a/tests/PdfToSvg.Tests/ConversionTests.cs b/tests/PdfToSvg.Tests/ConversionTests.cs index e3fd872..7f65a55 100644 --- a/tests/PdfToSvg.Tests/ConversionTests.cs +++ b/tests/PdfToSvg.Tests/ConversionTests.cs @@ -145,6 +145,10 @@ private static string RecompressPngs(string svgMarkup) .Descendants(ns + "use") .ToLookup(el => el.Attribute("href").Value); + var maskReferences = svg + .Descendants(ns + "g") + .ToLookup(el => el.Attribute("mask")?.Value); + foreach (var image in svg.Descendants(ns + "image")) { var hrefAttribute = image.Attribute("href"); @@ -165,6 +169,19 @@ private static string RecompressPngs(string svgMarkup) foreach (var reference in useElements["#" + oldId]) { reference.SetAttributeValue("href", "#" + newId); + + if (reference.Parent.Name.LocalName == "mask") + { + var newMaskId = StableID.Generate("m", newId); + var oldMaskId = reference.Parent.Attribute("id").Value; + + reference.Parent.SetAttributeValue("id", newMaskId); + + foreach (var maskReference in maskReferences["url(#" + oldMaskId + ")"]) + { + maskReference.SetAttributeValue("mask", "url(#" + newMaskId + ")"); + } + } } } } diff --git a/tests/TestFiles/Own/expected/masked-images.svg b/tests/TestFiles/Own/expected/masked-images.svg new file mode 100644 index 0000000..5bb1b00 --- /dev/null +++ b/tests/TestFiles/Own/expected/masked-images.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + +Color key mask + + + +Stencil mask + + + +Masked JPEG + + + +Inverted stencil mask + + + +Masked JPEG + + + +Soft mask + + + +Masked JPEG + + + + + \ No newline at end of file