Example usage for org.apache.poi.hwpf.usermodel CharacterRun getColor

List of usage examples for org.apache.poi.hwpf.usermodel CharacterRun getColor

Introduction

In this page you can find the example usage for org.apache.poi.hwpf.usermodel CharacterRun getColor.

Prototype

public int getColor() 

Source Link

Usage

From source file:com.example.minireader.WordViewActivity.java

License:Apache License

/**html*/
public void writeParagraphContent(Paragraph paragraph) {
    Paragraph p = paragraph;//from w w  w . ja v a  2 s  .com
    int pnumCharacterRuns = p.numCharacterRuns();

    for (int j = 0; j < pnumCharacterRuns; j++) {

        CharacterRun run = p.getCharacterRun(j);

        if (run.getPicOffset() == 0 || run.getPicOffset() >= 1000) {
            if (presentPicture < pictures.size()) {
                //
                writePicture();
            }
        } else {
            try {
                String text = run.text();
                if (text.length() >= 2 && pnumCharacterRuns < 2) {
                    //
                    output.write(text.getBytes());
                } else {
                    //
                    int size = run.getFontSize();
                    int color = run.getColor();
                    String fontSizeBegin = "<font size=\"" + decideSize(size) + "\">";
                    String fontColorBegin = "<font color=\"" + decideColor(color) + "\">";
                    String fontEnd = "</font>";
                    String boldBegin = "<b>";
                    String boldEnd = "</b>";
                    String islaBegin = "<i>";
                    String islaEnd = "</i>";

                    output.write(fontSizeBegin.getBytes());
                    output.write(fontColorBegin.getBytes());

                    if (run.isBold()) {
                        output.write(boldBegin.getBytes());
                    }
                    if (run.isItalic()) {
                        output.write(islaBegin.getBytes());
                    }

                    output.write(text.getBytes());

                    if (run.isBold()) {
                        output.write(boldEnd.getBytes());
                    }
                    if (run.isItalic()) {
                        output.write(islaEnd.getBytes());
                    }
                    output.write(fontEnd.getBytes());
                    output.write(fontEnd.getBytes());
                }
            } catch (Exception e) {
                System.out.println("Write File Exception");
            }
        }
    }
}