📄 htmlrenderer.java
字号:
writer.write("font-size: 11px;" + NEW_LINE); writer.write("font-weight: bold;" + NEW_LINE); writer.write("color: #9E001C;" + NEW_LINE); writer.write("}" + NEW_LINE); writer.write("td.tc {" + NEW_LINE); writer.write( "font-family: \"Arial Unicode MS\", Verdana, Helvetica, sans-serif;" + NEW_LINE); writer.write("font-size: 11px;" + NEW_LINE); writer.write("font-weight: bold;" + NEW_LINE); writer.write("color: #9E001C;" + NEW_LINE); writer.write("}" + NEW_LINE); // invisible cells writer.write("td.hide {" + NEW_LINE); writer.write("border: 0px;" + NEW_LINE); writer.write("}" + NEW_LINE); // add a per tier class with font size and (in the future) font name writer.write("/* a style class for each visible tier */" + NEW_LINE); Set keys = tierMap.keySet(); String key; String val; Iterator keit = keys.iterator(); while (keit.hasNext()) { key = (String) keit.next(); val = (String) tierMap.get(key); writer.write("tr." + val + " { " + "/* " + key + " */" + NEW_LINE); // next line should print the preferred font name // writer.write("font-family: \"Arial Unicode MS\", Verdana, Helvetica, sans-serif;" + NEW_LINE); writer.write("/* add font-family: nnn; to use a custom font */" + NEW_LINE); writer.write("font-size: " + interlinear.getFontSize(key) + "px;" + NEW_LINE); writer.write("}" + NEW_LINE); } writer.write("--></style>"); writer.write(NEW_LINE); } /** * Adds the contents of the annotation blocks to the body of the html file. * @param writer the writer * @throws IOException any io exception */ private void writeBlocks(Writer writer) throws IOException { ArrayList blocks = interlinear.getMetrics().getPrintBlocks(); InterlinearBlock printBlock = null; for (int i = 0; i < blocks.size(); i++) { printBlock = (InterlinearBlock) blocks.get(i); writer.write("<tr class=\"out\"><td class=\"out\">" + NEW_LINE); writeBlock(writer, printBlock); writer.write("</td></tr>" + NEW_LINE); writer.write("<tr class=\"out\"><td class=\"out\">" + NBSP); for (int j = 0; j < interlinear.getBlockSpacing(); j++) { writer.write(BREAK); } writer.write("</td></tr>" + NEW_LINE); } } /** * Converts each block of annotations to an html table, that is inserted in a cell of * an enclosing table. * @param writer the writer * @param block the annotation/print block * @throws IOException any ioexception */ private void writeBlock(Writer writer, InterlinearBlock block) throws IOException { InterlinearTier it = null; InterlinearAnnotation ia = null; writer.write("<table>" + NEW_LINE); for (int i = 0; i < block.getPrintTiers().size(); i++) { it = (InterlinearTier) block.getPrintTiers().get(i); writer.write("<tr class=\"" + (String) tierMap.get(it.getTierName()) + "\">"); if (interlinear.isTierLabelsShown()) { if (it.isTimeCode()) { writer.write("<td class=\"tclabel\">"); writer.write(interlinear.getMetrics().TC_TIER_NAME); } else { writer.write("<td class=\"label\">"); writer.write(it.getTierName()); } writer.write("</td>"); } for (int j = 0; j < it.getAnnotations().size(); j++) { ia = (InterlinearAnnotation) it.getAnnotations().get(j); if (ia.hidden) { writer.write("<td colspan=\"" + ia.colSpan + "\" class=\"hide\">" + "</td>"); } else { if (it.isTimeCode()) { writer.write("<td colspan=\"" + ia.colSpan + "\" class=\"tc\">" + ia.getValue() + "</td>"); } else { if (ia.nrOfLines == 1) { writer.write("<td colspan=\"" + ia.colSpan + "\">" + ia.getValue() + "</td>"); } else { writer.write("<td colspan=\"" + ia.colSpan + "\">"); for (int k = 0; k < ia.nrOfLines; k++) { writer.write(ia.getLines()[k]); if (k < (ia.nrOfLines - 1)) { writer.write(BREAK); } } writer.write("</td>"); } } } } writer.write("</tr>" + NEW_LINE); } writer.write("</table>" + NEW_LINE); } /** * Finishes the html document. * @param writer the writer * @throws IOException any io exception */ private void writeFooter(Writer writer) throws IOException { writer.write("</table>" + NEW_LINE); writer.write("</body>" + NEW_LINE); writer.write("</html>"); } /** * Special html generation for the preview using the Java (1.4.x) JEditorPane and the HTMLEditor kit, * which doesn't seem to support all css attributes etc. * @param writer the StringWriter * @throws IOException any io exception */ private void writePreviewHTML(Writer writer) throws IOException { writer.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"" + NEW_LINE + "\"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd\">"); writer.write(NEW_LINE); writer.write("<html>" + NEW_LINE + "<head>" + NEW_LINE); //writer.write("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">" + NEW_LINE); writer.write("<title>" + interlinear.getTranscription().getName() + "</title>" + NEW_LINE); writer.write("</head>" + NEW_LINE); writer.write( "<body style=\"background-color: #FFFFF2; font-family: \"Arial Unicode MS\", Verdana, Helvetica, sans-serif;\">" + NEW_LINE); writer.write("<h4 style=\"color: #ff0000\">"); writer.write( "NOTE: this preview may differ considerably from the appearance in most modern browsers!"); writer.write("</h4>"); writer.write("<h3>"); writer.write(interlinear.getTranscription().getFullPath()); writer.write("</h3>"); writer.write(NEW_LINE); writer.write("<p>"); writer.write(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, Locale.getDefault()).format(new Date( System.currentTimeMillis()))); writer.write("</p>" + NEW_LINE); // start outer table writer.write("<table width=\"100%\" border=\"0px\">" + NEW_LINE); ArrayList blocks = interlinear.getMetrics().getPrintBlocks(); InterlinearBlock printBlock = null; for (int i = 0; i < blocks.size(); i++) { printBlock = (InterlinearBlock) blocks.get(i); writer.write("<tr border=\"0px\"><td border=\"0px\">" + NEW_LINE); writePreviewBlock(writer, printBlock); writer.write("</td></tr>" + NEW_LINE); writer.write("<tr border=\"0px\"><td border=\"0px\">" + NBSP); for (int j = 0; j < interlinear.getBlockSpacing(); j++) { writer.write(BREAK); } writer.write("</td></tr>" + NEW_LINE); } writer.write("</table>" + NEW_LINE); writer.write(NEW_LINE); writer.write("</body>" + NEW_LINE); writer.write("</html>"); } /** * Special html generation for the preview using the Java JEditorPane and the HTMLEditor kit, * which doesn't seem to support all css attributes etc. * @param writer the StringWriter * @param block the print block to convert * @throws IOException any io exception */ private void writePreviewBlock(Writer writer, InterlinearBlock block) throws IOException { InterlinearTier it = null; InterlinearAnnotation ia = null; writer.write( "<table width=\"auto\" border=\"1px\" style=\"border-color: #666666; border-collapse: collapse; border-style: solid;\">" + NEW_LINE); for (int i = 0; i < block.getPrintTiers().size(); i++) { it = (InterlinearTier) block.getPrintTiers().get(i); writer.write("<tr border=\"1px\" style=\"font-size: " + interlinear.getFontSize(it.getTierName()) + "px; border-color: #dddddd; border-collapse: collapse; border-style: solid;\">"); if (interlinear.isTierLabelsShown()) { if (it.isTimeCode()) { writer.write("<td border=\"1px\" width=\"" + (int) (1.2 * interlinear.getMetrics().getLeftMargin()) + "\"" + " style=\"font-weight: bold; border-color: #666666; border-collapse: collapse; border-style: solid; font-size: 10px; color: #9E001C;\">"); writer.write(interlinear.getMetrics().TC_TIER_NAME); } else { writer.write("<td border=\"1px\" width=\"" + (int) (1.2 * interlinear.getMetrics().getLeftMargin()) + "\"" + " style=\"font-weight: bold; border-color: #666666; border-collapse: collapse; border-style: solid; font-size: 12px; color: #444444;\">"); writer.write(it.getTierName()); } writer.write("</td>"); } for (int j = 0; j < it.getAnnotations().size(); j++) { ia = (InterlinearAnnotation) it.getAnnotations().get(j); if (ia.hidden) { writer.write("<td colspan=\"" + ia.colSpan + "\" border=\"1px\"" + " style=\"border-color: #dddddd; border-collapse: collapse; border-style: solid;\">" + "</td>"); } else { if (it.isTimeCode()) { writer.write("<td colspan=\"" + ia.colSpan + "\" border=\"1px\"" + " style=\"font-weight: bold; border-color: #666666; border-collapse: collapse; border-style: solid; font-size: 10px; color: #9E001C;\">" + ia.getValue() + "</td>"); } else { if (ia.nrOfLines == 1) { writer.write("<td colspan=\"" + ia.colSpan + "\" border=\"1px\"" + " style=\"border-color: #666666; border-collapse: collapse; border-style: solid;\">" + ia.getValue() + "</td>"); } else { writer.write("<td colspan=\"" + ia.colSpan + "\" border=\"1px\"" + " style=\"border-color: #666666; border-collapse: collapse; border-style: solid;\">"); for (int k = 0; k < ia.nrOfLines; k++) { writer.write(ia.getLines()[k]); if (k < (ia.nrOfLines - 1)) { writer.write(BREAK); } } writer.write("</td>"); } } } } writer.write("</tr>" + NEW_LINE); } writer.write("</table>" + NEW_LINE); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -