Example usage for com.lowagie.text.factories RomanAlphabetFactory getString

List of usage examples for com.lowagie.text.factories RomanAlphabetFactory getString

Introduction

In this page you can find the example usage for com.lowagie.text.factories RomanAlphabetFactory getString.

Prototype

public static final String getString(int index, boolean lowercase) 

Source Link

Document

Translates a positive integer (not equal to zero) into a String using the letters 'a' to 'z' (a = 1, b = 2, ..., z = 26, aa = 27, ab = 28,...).

Usage

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableHeading.java

License:Open Source License

private Chunk formatNumber(StyleListProperties listProperties, int value) {
    Chunk symbol = new Chunk("", getFont());

    StyleTextProperties textProperties = listProperties.getTextProperties();
    if (textProperties != null) {
        Font font = textProperties.getFont();
        if (font != null) {
            symbol.setFont(font);/*www .java2s  .c  o m*/
        }
    }

    StyleNumFormat numFormat = listProperties.getNumFormat();
    if (numFormat != null) {
        StringBuilder sbuf = new StringBuilder();

        // num-prefix
        String numPrefix = listProperties.getNumPrefix();
        if (numPrefix != null) {
            sbuf.append(numPrefix);
        }

        // number
        if (numFormat.isAlphabetical()) {
            sbuf.append(RomanAlphabetFactory.getString(value, numFormat.isLowercase()));
        } else if (numFormat.isRoman()) {
            sbuf.append(RomanNumberFactory.getString(value, numFormat.isLowercase()));
        } else {
            sbuf.append(value);
        }

        // num-suffix
        String numSuffix = listProperties.getNumSuffix();
        if (numSuffix != null) {
            sbuf.append(numSuffix);
        }

        symbol.append(sbuf.toString());
    }
    return symbol;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableList.java

License:Open Source License

@SuppressWarnings("unchecked")
private void addElement(Element element, boolean addLabel) {
    if (element instanceof Chunk) {
        // may it happen?
        Chunk ch = (Chunk) element;/*from   w w w  .  j a va  2 s .c  o m*/
        StylableParagraph p = new StylableParagraph(null, null);
        p.setFont(ch.getFont());
        p.addElement(ch);
        element = p.getElement();
    }
    if (element instanceof Phrase) {
        Phrase p = (Phrase) element;
        StylableListItem li = new StylableListItem(p);
        // determine font, it may be set explicitly or use paragraph font
        Font symbolFont = symbol.getFont();
        if (symbolFont.isStandardFont()) {
            ArrayList<Chunk> chunks = p.getChunks();
            for (Chunk chunk : chunks) {
                // use first specified font
                if (!chunk.getFont().isStandardFont()) {
                    symbolFont = chunk.getFont();
                    break;
                }
            }
            if (symbolFont.isStandardFont()) {
                // use paragraph font
                symbolFont = p.getFont();
            }
        }
        // determine line height
        float lineHeight = StylableParagraph.DEFAULT_LINE_HEIGHT;
        boolean lineHeightProportional = true;
        if (element instanceof IStylableElement) {
            IStylableElement stylableElement = (IStylableElement) element;
            Style style = stylableElement.getLastStyleApplied();
            if (style != null) {
                StyleParagraphProperties paragraphProperties = style.getParagraphProperties();
                StyleLineHeight lineHeightObj = paragraphProperties.getLineHeight();
                if (lineHeightObj != null && lineHeightObj.getLineHeight() != null) {
                    lineHeight = lineHeightObj.getLineHeight();
                    lineHeightProportional = lineHeightObj.isLineHeightProportional();
                }
            }
        }
        if (addLabel) {
            if (numbered || lettered || romanNumbered) {
                StringBuilder sbuf = new StringBuilder(preSymbol);
                int index = first + list.size();
                if (lettered) {
                    sbuf.append(RomanAlphabetFactory.getString(index, lowercase));
                } else if (romanNumbered) {
                    sbuf.append(RomanNumberFactory.getString(index, lowercase));
                } else {
                    sbuf.append(index);
                }
                sbuf.append(postSymbol);
                li.setListSymbol(sbuf.toString(), symbolFont, lineHeight, lineHeightProportional);
            } else {
                li.setListSymbol(symbol.getContent(), symbolFont, lineHeight, lineHeightProportional);
            }
        } else {
            li.setListSymbol("", symbolFont, lineHeight, lineHeightProportional);
        }
        li.setIndentationLeft(symbolIndent);
        li.setIndentationRight(0.0f);
        list.add(li);
    } else if (element instanceof List) {
        List l = (List) element;
        // open office specifies absolute list indentation
        // but iText computes indentation relative to parent list
        // so we have to set difference
        l.setIndentationLeft(l.getIndentationLeft() - this.getIndentationLeft());
        first--;
        list.add(l);
    }
}

From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableList.java

License:Open Source License

@SuppressWarnings("unchecked")
private void addElement(Element element, boolean addLabel) {
    if (element instanceof Paragraph) {
        Paragraph p = (Paragraph) element;
        ListItem li = new StylableListItem(p);
        if (addLabel) {
            if (numbered || lettered || romanNumbered) {
                Chunk chunk = new Chunk(preSymbol, symbol.getFont());
                int index = first + list.size();
                if (lettered) {
                    chunk.append(RomanAlphabetFactory.getString(index, lowercase));
                } else if (romanNumbered) {
                    chunk.append(RomanNumberFactory.getString(index, lowercase));
                } else {
                    chunk.append(String.valueOf(index));
                }/*from w ww  .ja  v a  2s  .  c o m*/
                chunk.append(postSymbol);
                li.setListSymbol(chunk);
            } else {
                li.setListSymbol(symbol);
            }
        } else {
            li.setListSymbol(new Chunk("", symbol.getFont()));
        }
        li.setIndentationLeft(symbolIndent, autoindent);
        li.setIndentationRight(0.0f);
        list.add(li);
    } else if (element instanceof List) {
        List l = (List) element;
        // open office specifies absolute list indentation
        // but iText computes indentation relative to parent list
        // so we have to set difference
        l.setIndentationLeft(l.getIndentationLeft() - this.getIndentationLeft());
        first--;
        list.add(l);
    }
}