Search in sources :

Example 1 with Triplet

use of org.apache.poi.hwpf.converter.FontReplacer.Triplet in project poi by apache.

the class AbstractWordConverter method getCharacterRunTriplet.

protected Triplet getCharacterRunTriplet(CharacterRun characterRun) {
    Triplet original = new Triplet();
    original.bold = characterRun.isBold();
    original.italic = characterRun.isItalic();
    original.fontName = characterRun.getFontName();
    Triplet updated = getFontReplacer().update(original);
    return updated;
}
Also used : Triplet(org.apache.poi.hwpf.converter.FontReplacer.Triplet)

Example 2 with Triplet

use of org.apache.poi.hwpf.converter.FontReplacer.Triplet in project poi by apache.

the class ExcelToFoConverter method processSheetName.

protected void processSheetName(HSSFSheet sheet, Element flow) {
    Element titleBlock = foDocumentFacade.createBlock();
    Triplet triplet = new Triplet();
    triplet.bold = true;
    triplet.italic = false;
    triplet.fontName = "Arial";
    getFontReplacer().update(triplet);
    setBlockProperties(titleBlock, triplet);
    titleBlock.setAttribute("font-size", "200%");
    Element titleInline = foDocumentFacade.createInline();
    titleInline.appendChild(foDocumentFacade.createText(sheet.getSheetName()));
    titleBlock.appendChild(titleInline);
    flow.appendChild(titleBlock);
    Element titleBlock2 = foDocumentFacade.createBlock();
    Element titleInline2 = foDocumentFacade.createInline();
    titleBlock2.appendChild(titleInline2);
    flow.appendChild(titleBlock2);
}
Also used : Triplet(org.apache.poi.hwpf.converter.FontReplacer.Triplet) Element(org.w3c.dom.Element)

Example 3 with Triplet

use of org.apache.poi.hwpf.converter.FontReplacer.Triplet in project poi by apache.

the class WordToFoConverter method outputCharacters.

@Override
protected void outputCharacters(Element block, CharacterRun characterRun, String text) {
    Element inline = foDocumentFacade.createInline();
    Triplet triplet = getCharacterRunTriplet(characterRun);
    if (WordToFoUtils.isNotEmpty(triplet.fontName))
        WordToFoUtils.setFontFamily(inline, triplet.fontName);
    WordToFoUtils.setBold(inline, triplet.bold);
    WordToFoUtils.setItalic(inline, triplet.italic);
    WordToFoUtils.setFontSize(inline, characterRun.getFontSize() / 2);
    WordToFoUtils.setCharactersProperties(characterRun, inline);
    if (isOutputCharactersLanguage())
        WordToFoUtils.setLanguage(characterRun, inline);
    block.appendChild(inline);
    Text textNode = foDocumentFacade.createText(text);
    inline.appendChild(textNode);
}
Also used : Triplet(org.apache.poi.hwpf.converter.FontReplacer.Triplet) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text)

Example 4 with Triplet

use of org.apache.poi.hwpf.converter.FontReplacer.Triplet in project poi by apache.

the class WordToHtmlConverter method processParagraph.

@Override
protected void processParagraph(HWPFDocumentCore hwpfDocument, Element parentElement, int currentTableLevel, Paragraph paragraph, String bulletText) {
    final Element pElement = htmlDocumentFacade.createParagraph();
    parentElement.appendChild(pElement);
    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 (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 = AbstractWordUtils.EMPTY;
        }
        blocksProperies.push(new BlockProperies(pFontName, pFontSize));
    }
    try {
        if (AbstractWordUtils.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;
                // char have some space
                float firstLinePosition = paragraph.getIndentFromLeft() + paragraph.getFirstLineIndent() + 20f;
                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;
}
Also used : Triplet(org.apache.poi.hwpf.converter.FontReplacer.Triplet) Element(org.w3c.dom.Element) CharacterRun(org.apache.poi.hwpf.usermodel.CharacterRun) Text(org.w3c.dom.Text)

Example 5 with Triplet

use of org.apache.poi.hwpf.converter.FontReplacer.Triplet in project poi by apache.

the class WordToHtmlConverter method outputCharacters.

@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 (AbstractWordUtils.isNotEmpty(triplet.fontName) && !AbstractWordUtils.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);
}
Also used : Triplet(org.apache.poi.hwpf.converter.FontReplacer.Triplet) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text)

Aggregations

Triplet (org.apache.poi.hwpf.converter.FontReplacer.Triplet)6 Element (org.w3c.dom.Element)4 Text (org.w3c.dom.Text)3 HSSFColor (org.apache.poi.hssf.util.HSSFColor)1 CharacterRun (org.apache.poi.hwpf.usermodel.CharacterRun)1