Przeglądaj źródła

test font validity

Gildas 7 lat temu
rodzic
commit
4e80dc5805
1 zmienionych plików z 11 dodań i 5 usunięć
  1. 11 5
      lib/single-file/single-file-core.js

+ 11 - 5
lib/single-file/single-file-core.js

@@ -1074,17 +1074,23 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 
 		static async processStylesheet(doc, stylesheetContent, cssRules, baseURI, options, batchRequest) {
 			const urlFunctions = getURLFunctions(cssRules);
-			const styleResources = Promise.all(urlFunctions.style.map(urlFunction => processURLFunction(urlFunction, true)));
-			const otherResources = Promise.all(urlFunctions.other.map(urlFunction => processURLFunction(urlFunction, false)));
+			const styleResources = Promise.all(urlFunctions.style.map(urlFunction => processURLFunction(urlFunction)));
+			const otherResources = Promise.all(urlFunctions.other.map(urlFunction => processURLFunction(urlFunction, true)));
 			await Promise.all([styleResources, otherResources]);
 			return stylesheetContent;
 
-			async function processURLFunction(urlFunction, groupDuplicates) {
+			async function processURLFunction(urlFunction, processFont) {
 				const originalResourceURL = DomUtil.matchURL(urlFunction);
 				const resourceURL = DomUtil.normalizeURL(originalResourceURL);
 				if (!DomUtil.testIgnoredPath(resourceURL)) {
 					if (DomUtil.testValidURL(resourceURL, baseURI, options.url)) {
-						const { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL);
+						let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL);
+						if (processFont) {
+							const validFont = await DOM.validFont(content);
+							if (!validFont) {
+								content = EMPTY_DATA_URI;
+							}
+						}
 						let regExpUrlFunction = DomUtil.getRegExp(urlFunction);
 						if (!stylesheetContent.match(regExpUrlFunction)) {
 							urlFunction = "url(" + originalResourceURL + ")";
@@ -1095,7 +1101,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 							regExpUrlFunction = DomUtil.getRegExp(urlFunction);
 						}
 						if (stylesheetContent.match(regExpUrlFunction)) {
-							if (duplicate && options.groupDuplicateImages && groupDuplicates) {
+							if (duplicate && options.groupDuplicateImages && !processFont) {
 								stylesheetContent = stylesheetContent.replace(regExpUrlFunction, "var(" + SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource + ")");
 								DomUtil.insertVariable(doc, indexResource, content, options);
 							} else {