@@ -575,17 +575,17 @@ private function prepareImageAttrs($replaceImage, $varInlineArgs)
575575 if ($ mime !== 'image/svg+xml ' ) {
576576 $ imageData = @getimagesize ($ imgPath );
577577 if (!is_array ($ imageData )) {
578- throw new Exception (sprintf ('Invalid image: %s ' , $ imgPath ));
578+ throw new Exception (sprintf ('Invalid image: %s ' , $ imgPath )); // @codeCoverageIgnore
579579 }
580580 [$ actualWidth , $ actualHeight , $ imageType ] = $ imageData ;
581581 } else {
582582 $ content = file_get_contents ($ imgPath );
583583 if (!$ content ) {
584- throw new Exception (sprintf ('Invalid image: %s ' , $ imgPath ));
584+ throw new Exception (sprintf ('Invalid image: %s ' , $ imgPath )); // @codeCoverageIgnore
585585 }
586586 $ svgXml = simplexml_load_string ($ content );
587587 if (!$ svgXml ) {
588- throw new Exception (sprintf ('Invalid image: %s ' , $ imgPath ));
588+ throw new Exception (sprintf ('Invalid image: %s ' , $ imgPath )); // @codeCoverageIgnore
589589 }
590590 $ svgAttributes = $ svgXml ->attributes ();
591591 $ actualWidth = $ svgAttributes ->width ;
@@ -637,7 +637,7 @@ private function addImageToRelations($partFileName, $rid, $imgPath, $imageMimeTy
637637 if (isset ($ extTransform [$ imageMimeType ])) {
638638 $ imgExt = $ extTransform [$ imageMimeType ];
639639 } else {
640- throw new Exception ("Unsupported image type $ imageMimeType " );
640+ throw new Exception ("Unsupported image type $ imageMimeType " ); // @codeCoverageIgnore
641641 }
642642
643643 // add image to document
@@ -771,47 +771,19 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
771771 $ width = Converter::cssToEmu ($ preparedImageAttrs ['width ' ]);
772772 $ height = Converter::cssToEmu ($ preparedImageAttrs ['height ' ]);
773773 if ($ width === null ) {
774+ $ width = Converter::cssToEmu ($ preparedImageAttrs ['originalWidth ' ]);
774775 if (preg_match ('/^[+-]?([0-9]+\.?[0-9]*)?(em|ex|%)$/i ' , $ preparedImageAttrs ['width ' ], $ matches )) {
775- $ size = (float ) ($ matches [1 ]);
776776 $ unit = $ matches [2 ];
777- switch ($ unit ) {
778- case 'ex ' :
779- $ size = $ size * 2 ;
780-
781- // no break
782- case 'em ' :
783- $ width = $ size * 152400 ;
784-
785- break ;
786- case '% ' :
787- $ width = Converter::cssToEmu ($ preparedImageAttrs ['originalWidth ' ]) * $ size ;
788-
789- break ;
790- }
791- } else {
792- $ width = Converter::cssToEmu ($ preparedImageAttrs ['originalWidth ' ]);
777+ $ size = (float ) ($ matches [1 ]) * (($ unit === 'ex ' ) ? 2 : 1 );
778+ $ width = ($ unit === '% ' ) ? (Converter::cssToEmu ($ preparedImageAttrs ['originalWidth ' ]) * $ size ) : ($ size * 152400 );
793779 }
794780 }
795781 if ($ height === null ) {
782+ $ height = Converter::cssToEmu ($ preparedImageAttrs ['originalHeight ' ]);
796783 if (preg_match ('/^[+-]?([0-9]+\.?[0-9]*)?(em|ex|%)$/i ' , $ preparedImageAttrs ['height ' ], $ matches )) {
797- $ size = (float ) ($ matches [1 ]);
798784 $ unit = $ matches [2 ];
799- switch ($ unit ) {
800- case 'ex ' :
801- $ size *= 2 ;
802-
803- // no break
804- case 'em ' :
805- $ height = $ size * 152400 ;
806-
807- break ;
808- case '% ' :
809- $ height = Converter::cssToEmu ($ preparedImageAttrs ['originalHeight ' ]) * $ size ;
810-
811- break ;
812- }
813- } else {
814- $ height = Converter::cssToEmu ($ preparedImageAttrs ['originalHeight ' ]);
785+ $ size = (float ) ($ matches [1 ]) * (($ unit === 'ex ' ) ? 2 : 1 );
786+ $ height = ($ unit === '% ' ) ? (Converter::cssToEmu ($ preparedImageAttrs ['originalHeight ' ]) * $ size ) : ($ size * 152400 );
815787 }
816788 }
817789 $ xmlImage = str_replace (['{RID} ' , '{WIDTH} ' , '{HEIGHT} ' , '{ID} ' , '{NAME} ' ], [$ rid , (string ) $ width , (string ) $ height , $ imgIndex , 'graphic ' ], $ svgTpl );
0 commit comments