Skip to content

Commit d0a2650

Browse files
committed
8324774: Add DejaVu web fonts
8327385: Add JavaDoc option to exclude web fonts from generated documentation Reviewed-by: ihse, jjg
1 parent 37a5a08 commit d0a2650

38 files changed

+546
-13
lines changed

make/CompileInterimLangtools.gmk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -105,7 +105,7 @@ define SetupInterimModule
105105
Standard.java, \
106106
EXTRA_FILES := $(BUILDTOOLS_OUTPUTDIR)/gensrc/$1.interim/module-info.java \
107107
$($1.interim_EXTRA_FILES), \
108-
COPY := .gif .png .xml .css .svg .js .js.template .txt javax.tools.JavaCompilerTool, \
108+
COPY := .gif .png .xml .css .svg .js .js.template .txt .woff .woff2 javax.tools.JavaCompilerTool, \
109109
BIN := $(BUILDTOOLS_OUTPUTDIR)/interim_langtools_modules/$1.interim, \
110110
DISABLED_WARNINGS := module options, \
111111
JAVAC_FLAGS := \

make/modules/jdk.javadoc/Java.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
# -Werror and all lint warnings enabled. In particular,
2828
# DISABLED_WARNINGS_java should not be augmented.
2929

30-
COPY += .xml .css .svg .js .js.template .png .txt
30+
COPY += .xml .css .svg .js .js.template .png .txt .woff .woff2

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525

2626
package jdk.javadoc.internal.doclets.formats.html;
2727

28+
import java.io.BufferedReader;
2829
import java.io.FileNotFoundException;
2930
import java.io.IOException;
31+
import java.io.InputStream;
32+
import java.io.InputStreamReader;
3033
import java.net.URISyntaxException;
3134
import java.net.URL;
3235
import java.nio.file.DirectoryStream;
@@ -42,6 +45,8 @@
4245
import java.util.Set;
4346
import java.util.SortedSet;
4447
import java.util.function.Function;
48+
import java.util.regex.Matcher;
49+
import java.util.regex.Pattern;
4550

4651
import javax.lang.model.SourceVersion;
4752
import javax.lang.model.element.ModuleElement;
@@ -303,9 +308,13 @@ protected void generateOtherFiles(ClassTree classTree)
303308
w.buildPage();
304309
}
305310

311+
if (!options.noFonts()) {
312+
copyFontResources();
313+
}
314+
306315
// If a stylesheet file is not specified, copy the default stylesheet
307316
// and replace newline with platform-specific newline.
308-
if (options.stylesheetFile().length() == 0) {
317+
if (options.stylesheetFile().isEmpty()) {
309318
copyResource(DocPaths.STYLESHEET, DocPaths.RESOURCE_FILES.resolve(DocPaths.STYLESHEET), true);
310319
}
311320
copyResource(DocPaths.SCRIPT_JS_TEMPLATE, DocPaths.SCRIPT_FILES.resolve(DocPaths.SCRIPT_JS), true);
@@ -453,6 +462,31 @@ private void copyResource(DocPath sourcePath, DocPath targetPath, boolean replac
453462
}
454463
}
455464

465+
private void copyFontResources() throws DocletException {
466+
DocPath cssPath = DocPaths.FONTS.resolve(DocPaths.DEJAVU_CSS);
467+
copyResource(cssPath, DocPaths.RESOURCE_FILES.resolve(cssPath), true);
468+
469+
try {
470+
// Extract font file names from CSS file
471+
URL cssURL = HtmlConfiguration.class.getResource(DocPaths.RESOURCES.resolve(cssPath).getPath());
472+
Pattern pattern = Pattern.compile("DejaVu[-\\w]+\\.\\w+");
473+
474+
try (InputStream in = cssURL.openStream();
475+
BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
476+
String line;
477+
while ((line = reader.readLine()) != null) {
478+
Matcher m = pattern.matcher(line);
479+
if (m.find()) {
480+
DocPath fontPath = DocPaths.FONTS.resolve(m.group());
481+
copyResource(fontPath, DocPaths.RESOURCE_FILES.resolve(fontPath), false);
482+
}
483+
}
484+
}
485+
} catch (IOException e) {
486+
throw new ResourceIOException(cssPath, e);
487+
}
488+
}
489+
456490
private void copyFile(String filename, DocPath targetPath) throws DocFileIOException {
457491
if (filename.isEmpty()) {
458492
return;

0 commit comments

Comments
 (0)