|
25 | 25 |
|
26 | 26 | package jdk.javadoc.internal.doclets.formats.html; |
27 | 27 |
|
| 28 | +import java.io.BufferedReader; |
28 | 29 | import java.io.FileNotFoundException; |
29 | 30 | import java.io.IOException; |
| 31 | +import java.io.InputStream; |
| 32 | +import java.io.InputStreamReader; |
30 | 33 | import java.net.URISyntaxException; |
31 | 34 | import java.net.URL; |
32 | 35 | import java.nio.file.DirectoryStream; |
|
42 | 45 | import java.util.Set; |
43 | 46 | import java.util.SortedSet; |
44 | 47 | import java.util.function.Function; |
| 48 | +import java.util.regex.Matcher; |
| 49 | +import java.util.regex.Pattern; |
45 | 50 |
|
46 | 51 | import javax.lang.model.SourceVersion; |
47 | 52 | import javax.lang.model.element.ModuleElement; |
@@ -303,9 +308,13 @@ protected void generateOtherFiles(ClassTree classTree) |
303 | 308 | w.buildPage(); |
304 | 309 | } |
305 | 310 |
|
| 311 | + if (!options.noFonts()) { |
| 312 | + copyFontResources(); |
| 313 | + } |
| 314 | + |
306 | 315 | // If a stylesheet file is not specified, copy the default stylesheet |
307 | 316 | // and replace newline with platform-specific newline. |
308 | | - if (options.stylesheetFile().length() == 0) { |
| 317 | + if (options.stylesheetFile().isEmpty()) { |
309 | 318 | copyResource(DocPaths.STYLESHEET, DocPaths.RESOURCE_FILES.resolve(DocPaths.STYLESHEET), true); |
310 | 319 | } |
311 | 320 | 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 |
453 | 462 | } |
454 | 463 | } |
455 | 464 |
|
| 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 | + |
456 | 490 | private void copyFile(String filename, DocPath targetPath) throws DocFileIOException { |
457 | 491 | if (filename.isEmpty()) { |
458 | 492 | return; |
|
0 commit comments