Example usage for org.apache.poi.xwpf.usermodel UnderlinePatterns NONE

List of usage examples for org.apache.poi.xwpf.usermodel UnderlinePatterns NONE

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel UnderlinePatterns NONE.

Prototype

UnderlinePatterns NONE

To view the source code for org.apache.poi.xwpf.usermodel UnderlinePatterns NONE.

Click Source Link

Document

Specifies no underline beneath this run.

Usage

From source file:org.apache.tika.parser.microsoft.ooxml.OOXMLTikaBodyPartHandler.java

License:Apache License

@Override
public void run(RunProperties runProperties, String contents) {
    try {//from   www  .  j  a  va 2  s. c  om

        // True if we are currently in the named style tag:
        if (runProperties.isBold() != isBold) {
            if (isStrikeThrough) {
                xhtml.endElement("strike");
                isStrikeThrough = false;
            }
            if (isUnderline) {
                xhtml.endElement("u");
                isUnderline = false;
                ;
            }
            if (isItalics) {
                xhtml.endElement("i");
                isItalics = false;
            }
            if (runProperties.isBold()) {
                xhtml.startElement("b");
            } else {
                xhtml.endElement("b");
            }
            isBold = runProperties.isBold();
        }

        if (runProperties.isItalics() != isItalics) {
            if (isStrikeThrough) {
                xhtml.endElement("strike");
                isStrikeThrough = false;
            }
            if (isUnderline) {
                xhtml.endElement("u");
                isUnderline = false;
            }
            if (runProperties.isItalics()) {
                xhtml.startElement("i");
            } else {
                xhtml.endElement("i");
            }
            isItalics = runProperties.isItalics();
        }

        if (runProperties.isStrikeThrough() != isStrikeThrough) {
            if (isUnderline) {
                xhtml.endElement("u");
                isUnderline = false;
            }
            if (runProperties.isStrikeThrough()) {
                xhtml.startElement("strike");
            } else {
                xhtml.endElement("strike");
            }
            isStrikeThrough = runProperties.isStrikeThrough();
        }

        boolean runIsUnderlined = runProperties.getUnderline() != UnderlinePatterns.NONE;
        if (runIsUnderlined != isUnderline) {
            if (runIsUnderlined) {
                xhtml.startElement("u");
            } else {
                xhtml.endElement("u");
            }
            isUnderline = runIsUnderlined;
        }

        xhtml.characters(contents);

    } catch (SAXException e) {

    }
}

From source file:org.apache.tika.parser.microsoft.ooxml.OOXMLWordAndPowerPointTextHandler.java

License:Apache License

private void handleEndOfRun() {
    bodyContentsHandler.run(currRunProperties, runBuffer.toString());
    if (inHlinkClick) {
        bodyContentsHandler.hyperlinkEnd();
        inHlinkClick = false;//  w ww .j  av a2s .  c o  m
    }
    inR = false;
    runBuffer.setLength(0);
    currRunProperties.setBold(false);
    currRunProperties.setItalics(false);
    currRunProperties.setStrike(false);
    currRunProperties.setUnderline(UnderlinePatterns.NONE.name());
}

From source file:org.apache.tika.parser.microsoft.ooxml.RunProperties.java

License:Apache License

public void setUnderline(String underlineString) {
    if (underlineString == null || underlineString.equals("")) {
        underline = UnderlinePatterns.SINGLE;
    } else if (UnderlinePatterns.NONE.name().equals(underlineString)) {
        underline = UnderlinePatterns.NONE;
    } else {//from w  w w .j  ava2 s.  c om
        //TODO -- fill out rest
        underline = UnderlinePatterns.SINGLE;
    }
}

From source file:org.articleEditor.insertContent.DocumentUpdater1.java

License:Apache License

public void applyAttributes(XWPFRun run, AttributeSet attributes) {
    Enumeration attributeNames = attributes.getAttributeNames();
    while (attributeNames.hasMoreElements()) {
        Object attributeName = attributeNames.nextElement();
        Object attributeValue = attributes.getAttribute(attributeName);
        if (attributeName == Bold) {
            run.setBold((Boolean) attributeValue);
        } else if (attributeName == Italic) {
            run.setItalic((Boolean) attributeValue);
        } else if (attributeName == Underline) {
            run.setUnderline((Boolean) attributeValue ? UnderlinePatterns.SINGLE : UnderlinePatterns.NONE);
        } else if (attributeName == FontFamily || attributeName == Family) {
            run.setFontFamily((String) attributeValue);
        } else if (attributeName == FontSize) {
            run.setFontSize(((Number) attributeValue).intValue());
        } else if (attributeName == Foreground) {
            Color color = (Color) attributeValue;
            String rgb = Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1);
            run.setColor(rgb);/*from   www .jav  a  2  s. c o m*/
        } else if (attributeName == Background) {
            Color color = (Color) attributeValue;
            String rgb = Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1);
            //run.getCTR().getRPr().setHighlight();
        } else if (attributeName == Subscript) {
            run.setSubscript((Boolean) attributeValue ? VerticalAlign.SUBSCRIPT : VerticalAlign.BASELINE);
        } else if (attributeName == Superscript) {
            run.setSubscript((Boolean) attributeValue ? VerticalAlign.SUPERSCRIPT : VerticalAlign.BASELINE);
        } else if (attributeName == StrikeThrough) {
            run.setStrike((Boolean) attributeValue);
        } else if (attributeName == Alignment) {
            ParagraphAlignment alignment = documentToPOI((Integer) attributeValue);
            run.getParagraph().setAlignment(alignment);
        }
    }
}

From source file:org.articleEditor.insertContent.POIDocxReader.java

License:Apache License

protected void processRun(XWPFRun run) throws BadLocationException {
    charAttrs = new SimpleAttributeSet();

    if (run.getFontSize() > 0) {
        int size = run.getFontSize();
        StyleConstants.setFontSize(charAttrs, size);
    }/*from ww w .  j av a 2s  .  c om*/
    StyleConstants.setBold(charAttrs, run.isBold());
    StyleConstants.setItalic(charAttrs, run.isItalic());
    StyleConstants.setStrikeThrough(charAttrs, run.isStrike());
    boolean underlined = run.getUnderline() != UnderlinePatterns.NONE;
    StyleConstants.setUnderline(charAttrs, underlined);
    VerticalAlign verticalAlignment = run.getSubscript();
    if (verticalAlignment == VerticalAlign.SUBSCRIPT) {
        StyleConstants.setSubscript(parAttrs, true);
    } else if (verticalAlignment == VerticalAlign.SUPERSCRIPT) {
        StyleConstants.setSuperscript(parAttrs, true);
    } else {
        StyleConstants.setSubscript(parAttrs, false);
        StyleConstants.setSuperscript(parAttrs, false);
    }
    if (run.getFontFamily() != null) {
        StyleConstants.setFontFamily(charAttrs, run.getFontFamily());
    }
    if (run.getColor() != null) {
        String name = run.getColor();
        if (!name.toLowerCase().equals("auto")) {
            Color color = Color.decode("#" + name);
            StyleConstants.setForeground(charAttrs, color);
        }
    }

    // Not working
    if (run.getCTR().getRPr() != null && run.getCTR().getRPr().getHighlight() != null) {
        STHighlightColor.Enum colorEnum = run.getCTR().getRPr().getHighlight().getVal();
        Color color = decodeHighlightName(colorEnum);
        StyleConstants.setBackground(charAttrs, color);
    }

    for (XWPFPicture picture : run.getEmbeddedPictures()) {
        processPicture(picture);
    }
    String text = run.toString();
    document.insertString(currentOffset, text, charAttrs);
    currentOffset += text.length();
}

From source file:org.obeonetwork.m2doc.generator.test.TableClientProcessorWithStyleTest.java

License:Open Source License

@Test
@Override//from   w w  w . j a  va 2  s .  co  m
public void testWithoutAnyParameter() throws ProviderException {
    super.testWithoutAnyParameter();

    // Check styles
    List<XWPFTable> tables = doc.getTables();
    XWPFTable table = tables.get(0);

    // First Row (header)
    XWPFTableRow row = table.getRow(0);

    // Header => no style
    XWPFTableCell cell = row.getCell(1);
    XWPFParagraph cellParagraph = cell.getParagraphs().get(0);
    XWPFRun cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // Header => no style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // First row
    row = table.getRow(1);

    // first row, row header => no style
    cell = row.getCell(0);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // first row, first cell => cell style
    cell = row.getCell(1);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertEquals(CELL_BG_COLOR, cell.getColor().toUpperCase());
    assertEquals(CELL_FG_COLOR, cellRun.getColor().toUpperCase());
    assertEquals(CELL_FONT_SIZE, cellRun.getFontSize());
    assertTrue(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.SINGLE, cellRun.getUnderline());

    // first row, second cell => row style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    assertEquals(ROW_BG_COLOR, cell.getColor().toUpperCase());
    assertTrue(cellParagraph.getRuns().isEmpty());

    // Second row
    row = table.getRow(2);

    // second row, row header => no style
    cell = row.getCell(0);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // second row, first cell => column style
    cell = row.getCell(1);
    cellParagraph = cell.getParagraphs().get(0);
    assertEquals(COL_BG_COLOR, cell.getColor().toUpperCase());
    assertTrue(cellParagraph.getRuns().isEmpty());

    // second row, second cell => cell style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertEquals(CELL_BG_COLOR, cell.getColor().toUpperCase());
    assertEquals(CELL_FG_COLOR, cellRun.getColor().toUpperCase());
    assertEquals(CELL_FONT_SIZE, cellRun.getFontSize());
    assertTrue(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.SINGLE, cellRun.getUnderline());
}

From source file:org.obeonetwork.m2doc.tests.generator.TableClientProcessorWithStyleTests.java

License:Open Source License

@Test
@Override//from  w  w w . ja  va 2  s .c o  m
public void testWithoutAnyParameter() throws ProviderException {
    super.testWithoutAnyParameter();

    // Check styles
    List<XWPFTable> tables = doc.getTables();
    XWPFTable table = tables.get(0);

    // First Row (header)
    XWPFTableRow row = table.getRow(0);

    // Header => col 1 has "column style"
    XWPFTableCell cell = row.getCell(1);
    XWPFParagraph cellParagraph = cell.getParagraphs().get(0);
    XWPFRun cellRun = cellParagraph.getRuns().get(0);
    assertEquals(COL_BG_COLOR, cell.getColor().toUpperCase());
    assertEquals(COL_FG_COLOR, cellRun.getColor().toUpperCase());
    assertEquals(COL_FONT_SIZE, cellRun.getFontSize());
    assertTrue(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // Header => no style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // First row
    row = table.getRow(1);

    // first row, row header => no style
    cell = row.getCell(0);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // first row, first cell => cell style
    cell = row.getCell(1);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertEquals(ROW_BG_COLOR, cell.getColor().toUpperCase());
    assertEquals(ROW_FG_COLOR, cellRun.getColor().toUpperCase());
    assertEquals(ROW_FONT_SIZE, cellRun.getFontSize());
    assertFalse(cellRun.isBold());
    assertTrue(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // first row, second cell => no style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    assertNull(cell.getColor());
    cellRun = cellParagraph.getRuns().get(0);
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // Second row
    row = table.getRow(2);

    // second row, row header => no style
    cell = row.getCell(0);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // second row, first cell => no style
    cell = row.getCell(1);
    cellParagraph = cell.getParagraphs().get(0);
    assertNull(cell.getColor());
    cellRun = cellParagraph.getRuns().get(0);
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // second row, second cell => cell style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertEquals(CELL_BG_COLOR, cell.getColor().toUpperCase());
    assertEquals(CELL_FG_COLOR, cellRun.getColor().toUpperCase());
    assertEquals(CELL_FONT_SIZE, cellRun.getFontSize());
    assertTrue(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.SINGLE, cellRun.getUnderline());
}