Skip to content

Commit

Permalink
8324774: Add DejaVu web fonts
Browse files Browse the repository at this point in the history
8327385: Add JavaDoc option to exclude web fonts from generated documentation

Reviewed-by: ihse, jjg
  • Loading branch information
hns committed Mar 27, 2024
1 parent 37a5a08 commit d0a2650
Show file tree
Hide file tree
Showing 38 changed files with 546 additions and 13 deletions.
4 changes: 2 additions & 2 deletions make/CompileInterimLangtools.gmk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -105,7 +105,7 @@ define SetupInterimModule
Standard.java, \
EXTRA_FILES := $(BUILDTOOLS_OUTPUTDIR)/gensrc/$1.interim/module-info.java \
$($1.interim_EXTRA_FILES), \
COPY := .gif .png .xml .css .svg .js .js.template .txt javax.tools.JavaCompilerTool, \
COPY := .gif .png .xml .css .svg .js .js.template .txt .woff .woff2 javax.tools.JavaCompilerTool, \
BIN := $(BUILDTOOLS_OUTPUTDIR)/interim_langtools_modules/$1.interim, \
DISABLED_WARNINGS := module options, \
JAVAC_FLAGS := \
Expand Down
2 changes: 1 addition & 1 deletion make/modules/jdk.javadoc/Java.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
# -Werror and all lint warnings enabled. In particular,
# DISABLED_WARNINGS_java should not be augmented.

COPY += .xml .css .svg .js .js.template .png .txt
COPY += .xml .css .svg .js .js.template .png .txt .woff .woff2
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@

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

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.DirectoryStream;
Expand All @@ -42,6 +45,8 @@
import java.util.Set;
import java.util.SortedSet;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.lang.model.SourceVersion;
import javax.lang.model.element.ModuleElement;
Expand Down Expand Up @@ -303,9 +308,13 @@ protected void generateOtherFiles(ClassTree classTree)
w.buildPage();
}

if (!options.noFonts()) {
copyFontResources();
}

// If a stylesheet file is not specified, copy the default stylesheet
// and replace newline with platform-specific newline.
if (options.stylesheetFile().length() == 0) {
if (options.stylesheetFile().isEmpty()) {
copyResource(DocPaths.STYLESHEET, DocPaths.RESOURCE_FILES.resolve(DocPaths.STYLESHEET), true);
}
copyResource(DocPaths.SCRIPT_JS_TEMPLATE, DocPaths.SCRIPT_FILES.resolve(DocPaths.SCRIPT_JS), true);
Expand Down Expand Up @@ -453,6 +462,31 @@ private void copyResource(DocPath sourcePath, DocPath targetPath, boolean replac
}
}

private void copyFontResources() throws DocletException {
DocPath cssPath = DocPaths.FONTS.resolve(DocPaths.DEJAVU_CSS);
copyResource(cssPath, DocPaths.RESOURCE_FILES.resolve(cssPath), true);

try {
// Extract font file names from CSS file
URL cssURL = HtmlConfiguration.class.getResource(DocPaths.RESOURCES.resolve(cssPath).getPath());
Pattern pattern = Pattern.compile("DejaVu[-\\w]+\\.\\w+");

try (InputStream in = cssURL.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
String line;
while ((line = reader.readLine()) != null) {
Matcher m = pattern.matcher(line);
if (m.find()) {
DocPath fontPath = DocPaths.FONTS.resolve(m.group());
copyResource(fontPath, DocPaths.RESOURCE_FILES.resolve(fontPath), false);
}
}
}
} catch (IOException e) {
throw new ResourceIOException(cssPath, e);
}
}

private void copyFile(String filename, DocPath targetPath) throws DocFileIOException {
if (filename.isEmpty()) {
return;
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
*/

/* DejaVu fonts v2.37 */

@font-face {
font-family: 'DejaVu Sans Mono';
src: url('DejaVuLGCSansMono.woff2') format('woff2'),
url('DejaVuLGCSansMono.woff') format('woff');
font-weight: normal;
font-style: normal;
}

@font-face {
font-family: 'DejaVu Sans Mono';
src: url('DejaVuLGCSansMono-Oblique.woff2') format('woff2'),
url('DejaVuLGCSansMono-Oblique.woff') format('woff');
font-weight: normal;
font-style: italic;
}

@font-face {
font-family: 'DejaVu Sans Mono';
src: url('DejaVuLGCSansMono-Bold.woff2') format('woff2'),
url('DejaVuLGCSansMono-Bold.woff') format('woff');
font-weight: bold;
font-style: normal;
}

@font-face {
font-family: 'DejaVu Sans Mono';
src: url('DejaVuLGCSansMono-BoldOblique.woff2') format('woff2'),
url('DejaVuLGCSansMono-BoldOblique.woff') format('woff');
font-weight: bold;
font-style: italic;
}

@font-face {
font-family: 'DejaVu Sans';
src: url('DejaVuLGCSans.woff2') format('woff2'),
url('DejaVuLGCSans.woff') format('woff');
font-weight: normal;
font-style: normal;
}

@font-face {
font-family: 'DejaVu Sans';
src: url('DejaVuLGCSans-Oblique.woff2') format('woff2'),
url('DejaVuLGCSans-Oblique.woff') format('woff');
font-weight: normal;
font-style: italic;
}

@font-face {
font-family: 'DejaVu Sans';
src: url('DejaVuLGCSans-Bold.woff2') format('woff2'),
url('DejaVuLGCSans-Bold.woff') format('woff');
font-weight: bold;
font-style: normal;
}

@font-face {
font-family: 'DejaVu Sans';
src: url('DejaVuLGCSans-BoldOblique.woff2') format('woff2'),
url('DejaVuLGCSans-BoldOblique.woff') format('woff');
font-weight: bold;
font-style: italic;
}

@font-face {
font-family: 'DejaVu Serif';
src: url('DejaVuLGCSerif.woff2') format('woff2'),
url('DejaVuLGCSerif.woff') format('woff');
font-weight: normal;
font-style: normal;
}

@font-face {
font-family: 'DejaVu Serif';
src: url('DejaVuLGCSerif-Italic.woff2') format('woff2'),
url('DejaVuLGCSerif-Italic.woff') format('woff');
font-weight: normal;
font-style: italic;
}

@font-face {
font-family: 'DejaVu Serif';
src: url('DejaVuLGCSerif-Bold.woff2') format('woff2'),
url('DejaVuLGCSerif-Bold.woff') format('woff');
font-weight: bold;
font-style: normal;
}

@font-face {
font-family: 'DejaVu Serif';
src: url('DejaVuLGCSerif-BoldItalic.woff2') format('woff2'),
url('DejaVuLGCSerif-BoldItalic.woff') format('woff');
font-weight: bold;
font-style: italic;
}
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ doclet.usage.nocomment.description=\
doclet.usage.nodeprecated.description=\
Do not include @deprecated information

doclet.usage.no-fonts.description=\
Do not include standard web fonts in generated documentation

doclet.usage.noqualifier.parameters=\
<name1>,<name2>,...
doclet.usage.noqualifier.description=\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ public enum ModularityMismatchPolicy {
*/
private boolean noDeprecated = false;

/**
* Argument for command-line option {@code --no-fonts}.
* True if command-line option {@code --no-fonts} is used and font files
* should not be included in generated documentation. Default value is false.
*/
private boolean noFonts = false;

/**
* Argument for command-line option {@code --no-platform-links}.
* True if command-line option "--no-platform-links" is used. Default value is
Expand Down Expand Up @@ -481,6 +488,14 @@ public boolean process(String opt, List<String> args) {
}
},

new Option(resources, "--no-fonts") {
@Override
public boolean process(String opt, List<String> args) {
noFonts = true;
return true;
}
},

new Option(resources, "-nosince") {
@Override
public boolean process(String opt, List<String> args) {
Expand Down Expand Up @@ -889,6 +904,15 @@ public boolean noDeprecated() {
return noDeprecated;
}

/**
* Argument for command-line option {@code --no-fonts}.
* True if command-line option {@code --no-fonts"} is used.
* Default value is false.
*/
public boolean noFonts() {
return noFonts;
}

/**
* Argument for command-line option {@code --no-platform-links}.
* True if command-line option {@code --no-platform-links"} is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public DocPaths(Utils utils) {
/** The name of the file for all references to external specifications. */
public static final DocPath EXTERNAL_SPECS = DocPath.create("external-specs.html");

/** The name of the sub-directory containing font resources. */
public static final DocPath FONTS = DocPath.create("fonts");

/** The name of the DejaVu web fonts CSS file. */
public static final DocPath DEJAVU_CSS = DocPath.create("dejavu.css");

/** The name of the image file showing a magnifying glass on the search box. */
public static final DocPath GLASS_IMG = DocPath.create("glass.png");

Expand Down
Loading

1 comment on commit d0a2650

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.