Ver código fonte

fixed potential scaling issue when replacing IMG with SVG tags

Gildas 7 anos atrás
pai
commit
5e0a2a11f0
1 arquivos alterados com 23 adições e 4 exclusões
  1. 23 4
      lib/single-file/doc-helper.js

+ 23 - 4
lib/single-file/doc-helper.js

@@ -172,17 +172,36 @@ this.docHelper = this.docHelper || (() => {
 						naturalHeight = imgElement.height;
 						imgElement.remove();
 					}
+					const marginValue = imageElement.style.getPropertyValue("margin");
+					const marginPriority = imageElement.style.getPropertyPriority("margin");
+					const paddingValue = imageElement.style.getPropertyValue("padding");
+					const paddingPriority = imageElement.style.getPropertyPriority("padding");
+					imageElement.style.setProperty("margin", "0", "important");
+					imageElement.style.setProperty("padding", "0", "important");
+					const clientWidth = imageElement.clientWidth;
+					const clientHeight = imageElement.clientHeight;
+					if (marginValue || marginPriority) {
+						imageElement.style.setProperty("margin", marginValue, marginPriority);
+					} else {
+						imageElement.style.removeProperty("margin");
+					}
+					if (paddingValue || paddingPriority) {
+						imageElement.style.setProperty("padding", paddingValue, paddingPriority);
+					} else {
+						imageElement.style.removeProperty("padding");
+					}
+					imageElement.style.removeProperty("padding");
 					imageData = {
 						width: imageElement.width,
 						height: imageElement.height,
-						clientWidth: imageElement.clientWidth,
-						clientHeight: imageElement.clientHeight,
+						clientWidth,
+						clientHeight,
 						naturalWidth,
-						naturalHeight						
+						naturalHeight
 					};
 				}
 				data.push(imageData);
-			});			
+			});
 			return data;
 		}
 	}