@@ -242,6 +242,155 @@ public async Task PB010_EmbeddedFontWithEot10Header()
242242 await Assert . That ( fonts [ "New Font" ] ) . IsEquivalentTo ( eot22 ) ;
243243 }
244244
245+ [ Test ]
246+ public async Task PB011_SlideWith3DModelSourceUrl ( )
247+ {
248+ var sourceUrl = new Uri ( "https://example.com/models/cube" ) ;
249+
250+ var sourceDir = new DirectoryInfo ( "../../../../TestFiles/" ) ;
251+ using var sourceStream = new MemoryStream ( ) ;
252+ sourceStream . Write ( File . ReadAllBytes ( Path . Combine ( sourceDir . FullName , "PB008-3DModel.pptx" ) ) ) ;
253+ using ( var source = PresentationDocument . Open ( sourceStream , true ) )
254+ {
255+ var sourceSlide = source . PresentationPart ! . SlideParts . Single ( s =>
256+ s . Model3DReferenceRelationshipParts . Any ( )
257+ ) ;
258+ var hyperlink = sourceSlide . AddHyperlinkRelationship ( sourceUrl , true ) ;
259+ var raster = sourceSlide . GetXDocument ( ) . Descendants ( AM3D . blip ) . Single ( ) . Parent ! ;
260+ raster . AddBeforeSelf ( new XElement ( AM3D . attrSrcUrl , new XAttribute ( R . id , hyperlink . Id ) ) ) ;
261+ sourceSlide . PutXDocument ( ) ;
262+ }
263+
264+ var sources = new List < SlideSource >
265+ {
266+ new ( new PmlDocument ( "PB011-Input.pptx" , sourceStream . ToArray ( ) ) , 1 , 1 , true ) ,
267+ } ;
268+ var outputPptx = new FileInfo ( Path . Combine ( TempDir , "PB011-Output.pptx" ) ) ;
269+ PresentationBuilder . BuildPresentation ( sources ) . SaveAs ( outputPptx . FullName ) ;
270+
271+ using var pptx = PresentationDocument . Open ( outputPptx . FullName , false ) ;
272+ await Validate ( pptx ) ;
273+
274+ var slidePart = pptx . PresentationPart ! . SlideParts . Single ( ) ;
275+ var relId = ( string ) slidePart . GetXDocument ( ) . Descendants ( AM3D . attrSrcUrl ) . Single ( ) . Attribute ( R . id ) ;
276+ var copied = slidePart . HyperlinkRelationships . Single ( h => h . Id == relId ) ;
277+ await Assert . That ( copied . Uri ) . IsEqualTo ( sourceUrl ) ;
278+ await Assert . That ( copied . IsExternal ) . IsTrue ( ) ;
279+ }
280+
281+ [ Test ]
282+ public async Task PB012_SlideWithWebExtension ( )
283+ {
284+ var snapshotUrl = new Uri ( "https://example.com/snapshot.png" ) ;
285+ var snapshot = Convert . FromBase64String (
286+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
287+ ) ;
288+ var webExtension = new XElement (
289+ WE . webextension ,
290+ new XAttribute ( XNamespace . Xmlns + "we" , WE . we ) ,
291+ new XAttribute ( XNamespace . Xmlns + "r" , R . r ) ,
292+ new XAttribute ( "id" , "{6F1B2A5C-0B5E-4C0E-9A57-2D0C3E6B7A11}" ) ,
293+ new XElement (
294+ WE . reference ,
295+ new XAttribute ( "id" , "wa000000000" ) ,
296+ new XAttribute ( "version" , "1.0.0.0" ) ,
297+ new XAttribute ( "store" , "en-US" ) ,
298+ new XAttribute ( "storeType" , "OMEX" )
299+ ) ,
300+ new XElement ( WE . alternateReferences ) ,
301+ new XElement ( WE . properties ) ,
302+ new XElement ( WE . bindings ) ,
303+ new XElement ( WE . snapshot )
304+ ) ;
305+
306+ var sourceDir = new DirectoryInfo ( "../../../../TestFiles/" ) ;
307+ using var sourceStream = new MemoryStream ( ) ;
308+ sourceStream . Write ( File . ReadAllBytes ( Path . Combine ( sourceDir . FullName , "PB001-Input1.pptx" ) ) ) ;
309+ using ( var source = PresentationDocument . Open ( sourceStream , true ) )
310+ {
311+ var presentationPart = source . PresentationPart ! ;
312+ var firstSlideId = ( string )
313+ presentationPart . GetXDocument ( ) . Root ! . Element ( P . sldIdLst ) ! . Elements ( P . sldId ) . First ( ) . Attribute ( R . id ) ;
314+ var sourceSlide = ( SlidePart ) presentationPart . GetPartById ( firstSlideId ) ;
315+
316+ var webExtensionPart = sourceSlide . AddNewPart < WebExtensionPart > ( ) ;
317+ var snapshotPart = webExtensionPart . AddImagePart ( ImagePartType . Png ) ;
318+ using ( var snapshotStream = new MemoryStream ( snapshot ) )
319+ snapshotPart . FeedData ( snapshotStream ) ;
320+ var snapshotLink = webExtensionPart . AddExternalRelationship (
321+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" ,
322+ snapshotUrl
323+ ) ;
324+ webExtension
325+ . Element ( WE . snapshot ) !
326+ . Add (
327+ new XAttribute ( R . embed , webExtensionPart . GetIdOfPart ( snapshotPart ) ) ,
328+ new XAttribute ( R . link , snapshotLink . Id )
329+ ) ;
330+ webExtensionPart . PutXDocument ( new XDocument ( webExtension ) ) ;
331+
332+ var spTree = sourceSlide . GetXDocument ( ) . Descendants ( P . spTree ) . Single ( ) ;
333+ spTree . Add (
334+ new XElement (
335+ P . graphicFrame ,
336+ new XElement (
337+ P . nvGraphicFramePr ,
338+ new XElement ( P . cNvPr , new XAttribute ( "id" , "1000" ) , new XAttribute ( "name" , "Add-in" ) ) ,
339+ new XElement ( P . cNvGraphicFramePr ) ,
340+ new XElement ( P . nvPr )
341+ ) ,
342+ new XElement (
343+ P . xfrm ,
344+ new XElement ( A . off , new XAttribute ( "x" , "0" ) , new XAttribute ( "y" , "0" ) ) ,
345+ new XElement ( A . ext , new XAttribute ( "cx" , "914400" ) , new XAttribute ( "cy" , "914400" ) )
346+ ) ,
347+ new XElement (
348+ A . graphic ,
349+ new XElement (
350+ A . graphicData ,
351+ new XAttribute ( "uri" , WE . we . NamespaceName ) ,
352+ new XElement (
353+ WE . webextensionref ,
354+ new XAttribute ( XNamespace . Xmlns + "we" , WE . we ) ,
355+ new XAttribute ( R . id , sourceSlide . GetIdOfPart ( webExtensionPart ) )
356+ )
357+ )
358+ )
359+ )
360+ ) ;
361+ sourceSlide . PutXDocument ( ) ;
362+ }
363+
364+ var sources = new List < SlideSource >
365+ {
366+ new ( new PmlDocument ( "PB012-Input.pptx" , sourceStream . ToArray ( ) ) , 0 , 1 , true ) ,
367+ } ;
368+ var outputPptx = new FileInfo ( Path . Combine ( TempDir , "PB012-Output.pptx" ) ) ;
369+ PresentationBuilder . BuildPresentation ( sources ) . SaveAs ( outputPptx . FullName ) ;
370+
371+ using var pptx = PresentationDocument . Open ( outputPptx . FullName , false ) ;
372+ await Validate ( pptx , DocumentFormat . OpenXml . FileFormatVersions . Office2013 ) ;
373+
374+ var slidePart = pptx . PresentationPart ! . SlideParts . Single ( ) ;
375+ var relId = ( string ) slidePart . GetXDocument ( ) . Descendants ( WE . webextensionref ) . Single ( ) . Attribute ( R . id ) ;
376+ var copiedPart = slidePart . WebExtensionParts . Single ( ) ;
377+ await Assert . That ( slidePart . GetIdOfPart ( copiedPart ) ) . IsEqualTo ( relId ) ;
378+
379+ var copiedXml = copiedPart . GetXDocument ( ) . Root ! ;
380+ await Assert . That ( ( string ) copiedXml . Attribute ( "id" ) ) . IsEqualTo ( ( string ) webExtension . Attribute ( "id" ) ) ;
381+ await Assert
382+ . That ( ( string ) copiedXml . Element ( WE . reference ) ! . Attribute ( "id" ) )
383+ . IsEqualTo ( ( string ) webExtension . Element ( WE . reference ) ! . Attribute ( "id" ) ) ;
384+
385+ var copiedSnapshot = copiedXml . Element ( WE . snapshot ) ! ;
386+ var snapshotId = ( string ) copiedSnapshot . Attribute ( R . embed ) ;
387+ await Assert . That ( ReadAllBytes ( copiedPart . GetPartById ( snapshotId ) ) ) . IsEquivalentTo ( snapshot ) ;
388+
389+ var linkedSnapshotId = ( string ) copiedSnapshot . Attribute ( R . link ) ;
390+ var copiedSnapshotLink = copiedPart . ExternalRelationships . Single ( r => r . Id == linkedSnapshotId ) ;
391+ await Assert . That ( copiedSnapshotLink . Uri ) . IsEqualTo ( snapshotUrl ) ;
392+ }
393+
245394 private static byte [ ] ReadAllBytes ( OpenXmlPart part )
246395 {
247396 using var stream = part . GetStream ( FileMode . Open , FileAccess . Read ) ;
0 commit comments