From 8575a6b1c4f4a380fee32e83b6fea0a3608a6e41 Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Thu, 6 Jul 2023 22:49:34 +0200 Subject: [PATCH] fix: properly set font fields in the JSON report All fonts were added to the `refFonts` field, even when embedded. This commit fixes that. See #1515 Fix #1519 --- .../com/adobe/epubcheck/css/CSSHandler.java | 1 + .../fonts-embedded/EPUB/content_001.xhtml | 11 +++++++++++ .../files/fonts-embedded/EPUB/font.woff | 0 .../files/fonts-embedded/EPUB/nav.xhtml | 14 ++++++++++++++ .../files/fonts-embedded/EPUB/package.opf | 18 ++++++++++++++++++ .../files/fonts-embedded/EPUB/style.css | 4 ++++ .../fonts-embedded/META-INF/container.xml | 6 ++++++ .../reporting/files/fonts-embedded/mimetype | 1 + .../files/fonts-remote/EPUB/content_001.xhtml | 11 +++++++++++ .../files/fonts-remote/EPUB/nav.xhtml | 14 ++++++++++++++ .../files/fonts-remote/EPUB/package.opf | 18 ++++++++++++++++++ .../files/fonts-remote/EPUB/style.css | 4 ++++ .../files/fonts-remote/META-INF/container.xml | 6 ++++++ .../reporting/files/fonts-remote/mimetype | 1 + .../resources/reporting/json-report.feature | 16 ++++++++++++++++ 15 files changed, 125 insertions(+) create mode 100644 src/test/resources/reporting/files/fonts-embedded/EPUB/content_001.xhtml create mode 100644 src/test/resources/reporting/files/fonts-embedded/EPUB/font.woff create mode 100644 src/test/resources/reporting/files/fonts-embedded/EPUB/nav.xhtml create mode 100644 src/test/resources/reporting/files/fonts-embedded/EPUB/package.opf create mode 100644 src/test/resources/reporting/files/fonts-embedded/EPUB/style.css create mode 100644 src/test/resources/reporting/files/fonts-embedded/META-INF/container.xml create mode 100644 src/test/resources/reporting/files/fonts-embedded/mimetype create mode 100644 src/test/resources/reporting/files/fonts-remote/EPUB/content_001.xhtml create mode 100644 src/test/resources/reporting/files/fonts-remote/EPUB/nav.xhtml create mode 100644 src/test/resources/reporting/files/fonts-remote/EPUB/package.opf create mode 100644 src/test/resources/reporting/files/fonts-remote/EPUB/style.css create mode 100644 src/test/resources/reporting/files/fonts-remote/META-INF/container.xml create mode 100644 src/test/resources/reporting/files/fonts-remote/mimetype diff --git a/src/main/java/com/adobe/epubcheck/css/CSSHandler.java b/src/main/java/com/adobe/epubcheck/css/CSSHandler.java index fec6c3f16..db90a62b8 100644 --- a/src/main/java/com/adobe/epubcheck/css/CSSHandler.java +++ b/src/main/java/com/adobe/epubcheck/css/CSSHandler.java @@ -324,6 +324,7 @@ else if (propertyName.equals("src")) URL fontURL = parsedURLs.get(((CssURI) construct).toUriString()); if (fontURL != null && context.resourceRegistry.isPresent()) { + fontURI = context.relativize(fontURL); // check font mimetypes String fontMimeType = context.getMimeType(fontURL); if (fontMimeType != null) diff --git a/src/test/resources/reporting/files/fonts-embedded/EPUB/content_001.xhtml b/src/test/resources/reporting/files/fonts-embedded/EPUB/content_001.xhtml new file mode 100644 index 000000000..96ea27c7e --- /dev/null +++ b/src/test/resources/reporting/files/fonts-embedded/EPUB/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/reporting/files/fonts-embedded/EPUB/font.woff b/src/test/resources/reporting/files/fonts-embedded/EPUB/font.woff new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/resources/reporting/files/fonts-embedded/EPUB/nav.xhtml b/src/test/resources/reporting/files/fonts-embedded/EPUB/nav.xhtml new file mode 100644 index 000000000..240745e63 --- /dev/null +++ b/src/test/resources/reporting/files/fonts-embedded/EPUB/nav.xhtml @@ -0,0 +1,14 @@ + + + + + Minimal Nav + + + + + diff --git a/src/test/resources/reporting/files/fonts-embedded/EPUB/package.opf b/src/test/resources/reporting/files/fonts-embedded/EPUB/package.opf new file mode 100644 index 000000000..9f4e8dd4e --- /dev/null +++ b/src/test/resources/reporting/files/fonts-embedded/EPUB/package.opf @@ -0,0 +1,18 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/reporting/files/fonts-embedded/EPUB/style.css b/src/test/resources/reporting/files/fonts-embedded/EPUB/style.css new file mode 100644 index 000000000..a5d6bbec4 --- /dev/null +++ b/src/test/resources/reporting/files/fonts-embedded/EPUB/style.css @@ -0,0 +1,4 @@ +@font-face { + font-family: "Open Sans"; + src: url("font.woff") format("woff"); +} \ No newline at end of file diff --git a/src/test/resources/reporting/files/fonts-embedded/META-INF/container.xml b/src/test/resources/reporting/files/fonts-embedded/META-INF/container.xml new file mode 100644 index 000000000..318782179 --- /dev/null +++ b/src/test/resources/reporting/files/fonts-embedded/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/test/resources/reporting/files/fonts-embedded/mimetype b/src/test/resources/reporting/files/fonts-embedded/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/reporting/files/fonts-embedded/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/reporting/files/fonts-remote/EPUB/content_001.xhtml b/src/test/resources/reporting/files/fonts-remote/EPUB/content_001.xhtml new file mode 100644 index 000000000..96ea27c7e --- /dev/null +++ b/src/test/resources/reporting/files/fonts-remote/EPUB/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/reporting/files/fonts-remote/EPUB/nav.xhtml b/src/test/resources/reporting/files/fonts-remote/EPUB/nav.xhtml new file mode 100644 index 000000000..240745e63 --- /dev/null +++ b/src/test/resources/reporting/files/fonts-remote/EPUB/nav.xhtml @@ -0,0 +1,14 @@ + + + + + Minimal Nav + + + + + diff --git a/src/test/resources/reporting/files/fonts-remote/EPUB/package.opf b/src/test/resources/reporting/files/fonts-remote/EPUB/package.opf new file mode 100644 index 000000000..99602fdf5 --- /dev/null +++ b/src/test/resources/reporting/files/fonts-remote/EPUB/package.opf @@ -0,0 +1,18 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/reporting/files/fonts-remote/EPUB/style.css b/src/test/resources/reporting/files/fonts-remote/EPUB/style.css new file mode 100644 index 000000000..b22d0174f --- /dev/null +++ b/src/test/resources/reporting/files/fonts-remote/EPUB/style.css @@ -0,0 +1,4 @@ +@font-face { + font-family: "Open Sans"; + src: url("https://example.org/font") format("woff"); +} \ No newline at end of file diff --git a/src/test/resources/reporting/files/fonts-remote/META-INF/container.xml b/src/test/resources/reporting/files/fonts-remote/META-INF/container.xml new file mode 100644 index 000000000..318782179 --- /dev/null +++ b/src/test/resources/reporting/files/fonts-remote/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/test/resources/reporting/files/fonts-remote/mimetype b/src/test/resources/reporting/files/fonts-remote/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/reporting/files/fonts-remote/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/reporting/json-report.feature b/src/test/resources/reporting/json-report.feature index 9f02693b6..14f01e354 100644 --- a/src/test/resources/reporting/json-report.feature +++ b/src/test/resources/reporting/json-report.feature @@ -14,6 +14,22 @@ And JSON at '$.items' contains 5 items And JSON at '$..checkSum' has no null values + ## Fonts + + Scenario: Font remote + When checking EPUB 'fonts-remote' + Then the JSON report is valid + And JSON at '$.publication.refFonts' is: + | Open Sans | + And JSON at '$.publication.embeddedFonts' is empty + + Scenario: Font embedded + When checking EPUB 'fonts-embedded' + Then the JSON report is valid + And JSON at '$.publication.embeddedFonts' is: + | Open Sans | + And JSON at '$.publication.refFonts' is empty + ## References Scenario: cross-HTML references