@Override protected void outputCharacters(Element pElement, CharacterRun characterRun, String text) { Element span = htmlDocumentFacade.document.createElement("span"); pElement.appendChild(span); StringBuilder style = new StringBuilder(); BlockProperies blockProperies = this.blocksProperies.peek(); Triplet triplet = getCharacterRunTriplet(characterRun); if (WordToHtmlUtils.isNotEmpty(triplet.fontName) && !WordToHtmlUtils.equals(triplet.fontName, blockProperies.pFontName)) { style.append("font-family:" + triplet.fontName + ";"); } if (characterRun.getFontSize() / 2 != blockProperies.pFontSize) { style.append("font-size:" + characterRun.getFontSize() / 2 + "pt;"); } if (triplet.bold) { style.append("font-weight:bold;"); } if (triplet.italic) { style.append("font-style:italic;"); } WordToHtmlUtils.addCharactersProperties(characterRun, style); if (style.length() != 0) htmlDocumentFacade.addStyleClass(span, "s", style.toString()); Text textNode = htmlDocumentFacade.createText(text); span.appendChild(textNode); }
protected void processNoteAutonumbered( HWPFDocument doc, String type, int noteIndex, Element block, Range noteTextRange) { final String textIndex = String.valueOf(noteIndex + 1); final String textIndexClass = htmlDocumentFacade.getOrCreateCssClass("a", "vertical-align:super;font-size:smaller;"); final String forwardNoteLink = type + "note_" + textIndex; final String backwardNoteLink = type + "note_back_" + textIndex; Element anchor = htmlDocumentFacade.createHyperlink("#" + forwardNoteLink); anchor.setAttribute("name", backwardNoteLink); anchor.setAttribute("class", textIndexClass + " " + type + "noteanchor"); anchor.setTextContent(textIndex); block.appendChild(anchor); if (notes == null) { notes = htmlDocumentFacade.createBlock(); notes.setAttribute("class", "notes"); } Element note = htmlDocumentFacade.createBlock(); note.setAttribute("class", type + "note"); notes.appendChild(note); Element bookmark = htmlDocumentFacade.createBookmark(forwardNoteLink); bookmark.setAttribute("href", "#" + backwardNoteLink); bookmark.setTextContent(textIndex); bookmark.setAttribute("class", textIndexClass + " " + type + "noteindex"); note.appendChild(bookmark); note.appendChild(htmlDocumentFacade.createText(" ")); Element span = htmlDocumentFacade.getDocument().createElement("span"); span.setAttribute("class", type + "notetext"); note.appendChild(span); this.blocksProperies.add(new BlockProperies("", -1)); try { processCharacters(doc, Integer.MIN_VALUE, noteTextRange, span); } finally { this.blocksProperies.pop(); } }
protected void processParagraph( HWPFDocument hwpfDocument, Element parentElement, int currentTableLevel, Paragraph paragraph, String bulletText) { final Element pElement = htmlDocumentFacade.createParagraph(); parentElement.appendChild(pElement); /*if(itemSymbol) System.out.println(itemSymbol);*/ if (itemSymbol) { Element span = htmlDocumentFacade.getDocument().createElement("span"); htmlDocumentFacade.addStyleClass( span, "itemSymbol", "font-size:12.0pt;line-height:150%;font-family:Wingdings;mso-ascii-font-family:Wingdings;mso-hide:none;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;font-weight:normal;mso-bidi-font-weight:normal;font-style:normal;mso-bidi-font-style:normal;text-underline:windowtext none;text-decoration:none;background:transparent"); span.setTextContent("Ø"); pElement.appendChild(span); itemSymbol = false; } StringBuilder style = new StringBuilder(); WordToHtmlUtils.addParagraphProperties(paragraph, style); final int charRuns = paragraph.numCharacterRuns(); if (charRuns == 0) { return; } { final String pFontName; final int pFontSize; final CharacterRun characterRun = paragraph.getCharacterRun(0); if ("".equals(paragraph.text().trim())) { pElement.setTextContent(String.valueOf(UNICODECHAR_NO_BREAK_SPACE)); } if (characterRun != null) { Triplet triplet = getCharacterRunTriplet(characterRun); pFontSize = characterRun.getFontSize() / 2; pFontName = triplet.fontName; WordToHtmlUtils.addFontFamily(pFontName, style); WordToHtmlUtils.addFontSize(pFontSize, style); } else { pFontSize = -1; pFontName = WordToHtmlUtils.EMPTY; } blocksProperies.push(new BlockProperies(pFontName, pFontSize)); } try { if (WordToHtmlUtils.isNotEmpty(bulletText)) { if (bulletText.endsWith("\t")) { /* * We don't know how to handle all cases in HTML, but at * least simplest case shall be handled */ final float defaultTab = TWIPS_PER_INCH / 2; float firstLinePosition = paragraph.getIndentFromLeft() + paragraph.getFirstLineIndent() + 20; // char have // some space float nextStop = (float) (Math.ceil(firstLinePosition / defaultTab) * defaultTab); final float spanMinWidth = nextStop - firstLinePosition; Element span = htmlDocumentFacade.getDocument().createElement("span"); htmlDocumentFacade.addStyleClass( span, "s", "display: inline-block; text-indent: 0; min-width: " + (spanMinWidth / TWIPS_PER_INCH) + "in;"); pElement.appendChild(span); Text textNode = htmlDocumentFacade.createText( bulletText.substring(0, bulletText.length() - 1) + UNICODECHAR_ZERO_WIDTH_SPACE + UNICODECHAR_NO_BREAK_SPACE); span.appendChild(textNode); } else { Text textNode = htmlDocumentFacade.createText(bulletText.substring(0, bulletText.length() - 1)); pElement.appendChild(textNode); } } processCharacters(hwpfDocument, currentTableLevel, paragraph, pElement); } finally { blocksProperies.pop(); } if (style.length() > 0) htmlDocumentFacade.addStyleClass(pElement, "p", style.toString()); WordToHtmlUtils.compactSpans(pElement); return; }