@@ -32,6 +32,7 @@ You should have received a copy of the GNU Affero General Public License
3232using iText . Kernel . Pdf ;
3333using iText . Kernel . Pdf . Xobject ;
3434using iText . Kernel . Utils ;
35+ using iText . Layout ;
3536using iText . Svg ;
3637using iText . Svg . Converter ;
3738using iText . Svg . Exceptions ;
@@ -198,8 +199,6 @@ public virtual void ResourceResolverHtmlWithSvgDifferentLevels() {
198199 }
199200
200201 [ NUnit . Framework . Test ]
201- [ LogMessage ( iText . StyledXmlParser . Logs . StyledXmlParserLogMessageConstant . UNABLE_TO_RETRIEVE_IMAGE_WITH_GIVEN_BASE_URI
202- ) ]
203202 public virtual void AttemptToProcessBySvgProcessingUtilSvgWithImageTest ( ) {
204203 // TODO review this test in the scope of DEVSIX-4107
205204 String fileName = "svgWithImage.svg" ;
@@ -209,21 +208,19 @@ public virtual void AttemptToProcessBySvgProcessingUtilSvgWithImageTest() {
209208 ISvgProcessorResult res = SvgConverter . ParseAndProcess ( resourceResolver . RetrieveResourceAsInputStream ( fileName
210209 ) , svgConverterProperties ) ;
211210 ISvgNodeRenderer imageRenderer = ( ( SvgTagSvgNodeRenderer ) res . GetRootRenderer ( ) ) . GetChildren ( ) [ 0 ] ;
212- // Remove the previous result of the resource resolving in order to demonstrate that the resource will not be
213- // resolved due to not setting of baseUri in the SvgProcessingUtil#createXObjectFromProcessingResult method.
214- imageRenderer . SetAttribute ( SvgConstants . Attributes . XLINK_HREF , "doggo.jpg" ) ;
211+ // Remove the previous result of the resource resolving in order to demonstrate that the resource will be
212+ // resolved due to setting of baseUri in the SvgProcessingUtil#createXObjectFromProcessingResult method.
213+ imageRenderer . SetAttribute ( SvgConstants . Attributes . XLINK_HREF , "res/itextpdf.com/ doggo.jpg" ) ;
215214 SvgProcessingUtil processingUtil = new SvgProcessingUtil ( resourceResolver ) ;
216- PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new ByteArrayOutputStream ( ) ) ) ;
217- PdfFormXObject pdfFormXObject = processingUtil . CreateXObjectFromProcessingResult ( res , pdfDocument ) ;
215+ PdfDocument document = new PdfDocument ( new PdfWriter ( new ByteArrayOutputStream ( ) ) ) ;
216+ PdfFormXObject pdfFormXObject = processingUtil . CreateXObjectFromProcessingResult ( res , document ) ;
218217 PdfDictionary resources = ( PdfDictionary ) pdfFormXObject . GetResources ( ) . GetPdfObject ( ) . Get ( PdfName . XObject ) ;
219218 PdfDictionary fm1Dict = ( PdfDictionary ) resources . Get ( new PdfName ( "Fm1" ) ) ;
220- NUnit . Framework . Assert . IsFalse ( ( ( PdfDictionary ) fm1Dict . Get ( PdfName . Resources ) ) . ContainsKey ( PdfName . XObject
221- ) ) ;
219+ NUnit . Framework . Assert . IsTrue ( ( ( PdfDictionary ) fm1Dict . Get ( PdfName . Resources ) ) . ContainsKey ( PdfName . XObject )
220+ ) ;
222221 }
223222
224223 [ NUnit . Framework . Test ]
225- [ LogMessage ( iText . StyledXmlParser . Logs . StyledXmlParserLogMessageConstant . UNABLE_TO_RETRIEVE_IMAGE_WITH_GIVEN_BASE_URI
226- ) ]
227224 public virtual void AttemptToProcessBySvgProcessingUtilSvgWithSvgTest ( ) {
228225 // TODO review this test in the scope of DEVSIX-4107
229226 String fileName = "svgWithSvg.svg" ;
@@ -233,23 +230,45 @@ public virtual void AttemptToProcessBySvgProcessingUtilSvgWithSvgTest() {
233230 ISvgProcessorResult res = SvgConverter . ParseAndProcess ( resourceResolver . RetrieveResourceAsInputStream ( fileName
234231 ) , svgConverterProperties ) ;
235232 ISvgNodeRenderer imageRenderer = ( ( SvgTagSvgNodeRenderer ) res . GetRootRenderer ( ) ) . GetChildren ( ) [ 1 ] ;
236- // Remove the previous result of the resource resolving in order to demonstrate that the resource will not be
237- // resolved due to not setting of baseUri in the SvgProcessingUtil#createXObjectFromProcessingResult method.
238- // But even if set baseUri in the SvgProcessingUtil#createXObjectFromProcessingResult method, the SVG will not
239- // be processed, because in the createXObjectFromProcessingResult method we create ResourceResolver, not HtmlResourceResolver.
240- imageRenderer . SetAttribute ( SvgConstants . Attributes . XLINK_HREF , "res\\ itextpdf.com\\ lines.svg" ) ;
233+ // Remove the previous result of the resource resolving in order to demonstrate that the resource will be
234+ // resolved due to setting of baseUri in the SvgProcessingUtil#createXObjectFromProcessingResult method.
235+ imageRenderer . SetAttribute ( SvgConstants . Attributes . XLINK_HREF , "res/itextpdf.com/lines.svg" ) ;
241236 SvgProcessingUtil processingUtil = new SvgProcessingUtil ( resourceResolver ) ;
242- PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new ByteArrayOutputStream ( ) ) ) ;
243- PdfFormXObject pdfFormXObject = processingUtil . CreateXObjectFromProcessingResult ( res , pdfDocument ) ;
237+ PdfDocument document = new PdfDocument ( new PdfWriter ( new ByteArrayOutputStream ( ) ) ) ;
238+ PdfFormXObject pdfFormXObject = processingUtil . CreateXObjectFromProcessingResult ( res , document ) ;
244239 PdfDictionary resources = ( PdfDictionary ) pdfFormXObject . GetResources ( ) . GetPdfObject ( ) . Get ( PdfName . XObject ) ;
245240 PdfDictionary fm1Dict = ( PdfDictionary ) resources . Get ( new PdfName ( "Fm1" ) ) ;
246- NUnit . Framework . Assert . IsFalse ( ( ( PdfDictionary ) fm1Dict . Get ( PdfName . Resources ) ) . ContainsKey ( PdfName . XObject
247- ) ) ;
241+ NUnit . Framework . Assert . IsTrue ( ( ( PdfDictionary ) fm1Dict . Get ( PdfName . Resources ) ) . ContainsKey ( PdfName . XObject )
242+ ) ;
243+ }
244+
245+ [ NUnit . Framework . Test ]
246+ public virtual void SvgInsideSvgTest ( ) {
247+ String svgFileName = "svgInsideSvg.svg" ;
248+ String cmpFileName = SOURCE_FOLDER + "cmp_svgInsideSvg.pdf" ;
249+ String outFileName = DESTINATION_FOLDER + "svgInsideSvg.pdf" ;
250+ using ( Document document = new Document ( new PdfDocument ( new PdfWriter ( outFileName ) ) ) ) {
251+ ProcessorContext context = new ProcessorContext ( new ConverterProperties ( ) ) ;
252+ HtmlResourceResolver resourceResolver = new HtmlResourceResolver ( SOURCE_FOLDER , context ) ;
253+ ISvgConverterProperties svgConverterProperties = ContextMappingHelper . MapToSvgConverterProperties ( context ) ;
254+ ISvgProcessorResult result = SvgConverter . ParseAndProcess ( resourceResolver . RetrieveResourceAsInputStream ( svgFileName
255+ ) , svgConverterProperties ) ;
256+ ISvgNodeRenderer imageRenderer = ( ( SvgTagSvgNodeRenderer ) result . GetRootRenderer ( ) ) . GetChildren ( ) [ 0 ] ;
257+ ISvgNodeRenderer svgRenderer = ( ( SvgTagSvgNodeRenderer ) result . GetRootRenderer ( ) ) . GetChildren ( ) [ 2 ] ;
258+ // Remove the previous result of the resource resolving in order to demonstrate that the resource will be
259+ // resolved due to setting of baseUri in the SvgProcessingUtil#createXObjectFromProcessingResult method.
260+ // TODO DEVSIX-4107 However the SVG will not be displayed since it is expected to be drawn during
261+ // HtmlResourceResolver#processAsSvg call, but document is null, so SvgProcessingUtil#
262+ // createSvgImageFromProcessingResult method is called instead of createXObjectFromProcessingResult.
263+ imageRenderer . SetAttribute ( SvgConstants . Attributes . XLINK_HREF , "res/itextpdf.com/doggo.jpg" ) ;
264+ svgRenderer . SetAttribute ( SvgConstants . Attributes . XLINK_HREF , "res/itextpdf.com/lines.svg" ) ;
265+ document . Add ( new SvgProcessingUtil ( resourceResolver ) . CreateSvgImageFromProcessingResult ( result ) ) ;
266+ }
267+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFileName , cmpFileName , DESTINATION_FOLDER
268+ , "diff" ) ) ;
248269 }
249270
250271 [ NUnit . Framework . Test ]
251- [ LogMessage ( iText . StyledXmlParser . Logs . StyledXmlParserLogMessageConstant . UNABLE_TO_RETRIEVE_IMAGE_WITH_GIVEN_BASE_URI
252- ) ]
253272 public virtual void ResourceResolverSvgEmbeddedSvg ( ) {
254273 // TODO review this test in the scope of DEVSIX-4107
255274 String outPdf = DESTINATION_FOLDER + "resourceResolverSvgEmbeddedSvg.pdf" ;
@@ -259,8 +278,6 @@ public virtual void ResourceResolverSvgEmbeddedSvg() {
259278 }
260279
261280 [ NUnit . Framework . Test ]
262- [ LogMessage ( iText . StyledXmlParser . Logs . StyledXmlParserLogMessageConstant . UNABLE_TO_RETRIEVE_IMAGE_WITH_GIVEN_BASE_URI
263- ) ]
264281 public virtual void ResourceResolverObjectWithSvgEmbeddedSvg ( ) {
265282 // TODO review this test in the scope of DEVSIX-4107
266283 String outPdf = DESTINATION_FOLDER + "resourceResolverObjectWithSvgEmbeddedSvg.pdf" ;
0 commit comments