@@ -437,7 +437,9 @@ public function save($filename, int $flags = 0): void
437437 }
438438
439439 // Add drawing and image relationship parts
440- if (($ drawingCount > 0 ) || ($ chartCount > 0 )) {
440+ /** @var bool $hasPassThroughDrawing */
441+ $ hasPassThroughDrawing = $ unparsedSheet ['drawingPassThroughEnabled ' ] ?? false ;
442+ if (($ drawingCount > 0 ) || ($ chartCount > 0 ) || $ hasPassThroughDrawing ) {
441443 // Drawing relationships
442444 $ zipContent ['xl/drawings/_rels/drawing ' . ($ i + 1 ) . '.xml.rels ' ] = $ this ->getWriterPartRels ()->writeDrawingRelationships ($ this ->spreadSheet ->getSheet ($ i ), $ chartRef1 , $ this ->includeCharts );
443445
@@ -558,6 +560,9 @@ public function save($filename, int $flags = 0): void
558560 }
559561 }
560562
563+ // Add pass-through media files (original media that may not be in the drawing collection)
564+ $ this ->addPassThroughMediaFiles ($ zipContent ); // @phpstan-ignore argument.type
565+
561566 Functions::setReturnDateType ($ saveDateReturnType );
562567 Calculation::getInstance ($ this ->spreadSheet )->getDebugLog ()->setWriteDebugLog ($ saveDebugLog );
563568
@@ -843,4 +848,43 @@ public function getRestrictMaxColumnWidth(): bool
843848 {
844849 return $ this ->restrictMaxColumnWidth ;
845850 }
851+
852+ /**
853+ * Add pass-through media files from original spreadsheet.
854+ * This copies media files that are referenced in pass-through drawing XML
855+ * but may not be in the drawing collection (e.g., unsupported formats like SVG).
856+ *
857+ * @param string[] $zipContent
858+ */
859+ private function addPassThroughMediaFiles (array &$ zipContent ): void
860+ {
861+ /** @var array<string, array<string, mixed>> $sheets */
862+ $ sheets = $ this ->spreadSheet ->getUnparsedLoadedData ()['sheets ' ] ?? [];
863+ foreach ($ sheets as $ sheetData ) {
864+ /** @var string[] $mediaFiles */
865+ $ mediaFiles = $ sheetData ['drawingMediaFiles ' ] ?? [];
866+ /** @var ?string $sourceFile */
867+ $ sourceFile = $ sheetData ['drawingSourceFile ' ] ?? null ;
868+ if (($ sheetData ['drawingPassThroughEnabled ' ] ?? false ) !== true || $ mediaFiles === [] || !is_string ($ sourceFile ) || !file_exists ($ sourceFile )) {
869+ continue ;
870+ }
871+
872+ $ sourceZip = new ZipArchive ();
873+ if ($ sourceZip ->open ($ sourceFile ) !== true ) {
874+ continue ; // @codeCoverageIgnore
875+ }
876+
877+ foreach ($ mediaFiles as $ mediaPath ) {
878+ $ zipPath = 'xl/media/ ' . basename ($ mediaPath );
879+ if (!isset ($ zipContent [$ zipPath ])) {
880+ $ mediaContent = $ sourceZip ->getFromName ($ mediaPath );
881+ if ($ mediaContent !== false ) {
882+ $ zipContent [$ zipPath ] = $ mediaContent ;
883+ }
884+ }
885+ }
886+
887+ $ sourceZip ->close ();
888+ }
889+ }
846890}
0 commit comments