Example usage for com.lowagie.text Chunk append

List of usage examples for com.lowagie.text Chunk append

Introduction

In this page you can find the example usage for com.lowagie.text Chunk append.

Prototype

public StringBuffer append(String string) 

Source Link

Document

appends some text to this Chunk.

Usage

From source file:com.aryjr.nheengatu.pdf.RomanList.java

License:Open Source License

/**
 * Adds an <CODE>Object</CODE> to the <CODE>List</CODE>.
 *
 * @param   o   the object to add./*  w  ww . ja  va 2  s . c  om*/
 * @return true if adding the object succeeded
 */
public boolean add(Object o) {
    if (o instanceof ListItem) {
        ListItem item = (ListItem) o;
        final TagsManager tm = TagsManager.getInstance();
        Chunk chunk;
        if (listStyleType != null && listStyleType.equals("lower-roman"))
            chunk = new Chunk(toRomanLowerCase(first + list.size()), tm.getFont());
        else if (listStyleType != null && listStyleType.equals("upper-roman"))
            chunk = new Chunk(toRomanUppercase(first + list.size()), tm.getFont());
        else if (listStyleType != null && listStyleType.equals("lower-alpha"))
            chunk = new Chunk(nextLetter(), tm.getFont());
        else if (listStyleType != null && listStyleType.equals("upper-alpha"))
            chunk = new Chunk(nextLetter(), tm.getFont());
        else
            chunk = new Chunk(String.valueOf(first + list.size()), tm.getFont());
        chunk.append(" - ");
        item.setListSymbol(chunk);
        item.setIndentationLeft(symbolIndent);
        item.setIndentationRight(0);
        list.add(item);
    } else if (o instanceof List) {
        List nested = (List) o;
        nested.setIndentationLeft(nested.getIndentationLeft() + symbolIndent);
        first--;
        return list.add(nested);
    } else if (o instanceof String) {
        return this.add(new ListItem((String) o));
    }
    return false;
}

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);//from  w  w  w . j av a2  s.  co 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

public void applyStyles(Style style) {
    this.lastStyleApplied = style;

    Map<Integer, StyleListProperties> listPropertiesMap = style.getListPropertiesMap();
    if (listPropertiesMap != null) {
        StyleListProperties listProperties = getListProperties(listPropertiesMap, listLevel);
        if (listProperties != null) {
            String bulletChar = listProperties.getBulletChar();
            if (bulletChar != null) {
                // list item label is a char
                Chunk symbol = new Chunk(bulletChar);

                StyleTextProperties textProperties = listProperties.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }//  w  w  w .j a v  a 2s  .c  o  m
                }

                super.setListSymbol(symbol);
            }

            Image image = listProperties.getImage();
            if (image != null) {
                // list item label is an image
                Float width = listProperties.getWidth();
                if (width != null) {
                    image.scaleAbsoluteWidth(width);
                }

                Float height = listProperties.getHeight();
                if (height != null) {
                    image.scaleAbsoluteHeight(height);
                }

                super.setListSymbol(new Chunk(image, 0.0f, 0.0f));
            }

            if (bulletChar == null && image == null) {
                // list item label is a number
                Chunk symbol = new Chunk("");

                StyleTextProperties textProperties = listProperties.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }
                }

                Integer startValue = listProperties.getStartValue();
                if (startValue != null) {
                    super.setFirst(startValue);
                }

                StyleNumFormat numFormat = listProperties.getNumFormat();
                if (numFormat != null) {
                    String numPrefix = listProperties.getNumPrefix();
                    if (numPrefix != null) {
                        super.setPreSymbol(numPrefix);
                        symbol = new Chunk(numPrefix, symbol.getFont());
                    }

                    String numSuffix = listProperties.getNumSuffix();
                    if (numSuffix != null) {
                        super.setPostSymbol(numSuffix);
                        symbol.append(numSuffix);
                    }

                    super.setNumbered(true);
                    super.setLettered(numFormat.isAlphabetical());
                    this.romanNumbered = numFormat.isRoman();
                    super.setLowercase(numFormat.isLowercase());
                }

                super.setListSymbol(symbol);
            }

            // set indentation, it is specified in different way by Open Office and MsWord
            Float marginLeft = listProperties.getMarginLeft();
            Float textIndent = listProperties.getTextIndent();
            Float spaceBefore = listProperties.getSpaceBefore();
            Float minLabelWidth = listProperties.getMinLabelWidth();
            if (marginLeft != null && textIndent != null) {
                // ODT generated by Open Office
                super.setIndentationLeft(Math.max(marginLeft + textIndent, 0.0f));
                super.setSymbolIndent(Math.max(-textIndent, 0.0f));
            } else if (spaceBefore != null && minLabelWidth != null) {
                // ODT generated by MsWord
                super.setIndentationLeft(Math.max(spaceBefore, 0.0f));
                super.setSymbolIndent(Math.max(minLabelWidth, 0.0f));
            }
        }
    }
}

From source file:org.areasy.common.doclet.document.elements.LinkPhrase.java

License:Open Source License

/**
 * Initializes the link chunk with given values.
 *
 * @param destination The original destination as defined
 *                    in the javadoc.//from w  ww  .  j a  va  2 s.c  o m
 * @param label       The text label for the link
 * @param font        The base font for the link (for example, could be
 *                    a bold italic font in case of a "deprecated" tag).
 */
private void init(String destination, String label, Font font) {
    if (label == null)
        label = destination;

    String createLinksProp = DefaultConfiguration.getString(ARG_CREATE_LINKS, ARG_VAL_NO);
    if (createLinksProp.equalsIgnoreCase(ARG_VAL_NO))
        destination = null;

    super.font = font;

    Chunk chunk = new Chunk("");
    chunk.append(label);

    if (destination != null && Destinations.isValid(destination))
        chunk.setLocalGoto(destination);

    add(chunk);
}

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));
                }/*  ww  w  .j  av  a  2 s. co 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);
    }
}

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

License:Open Source License

public void applyStyles(Style style) {
    this.lastStyleApplied = style;

    Map<Integer, StyleListProperties> listPropertiesMap = style.getListPropertiesMap();
    if (listPropertiesMap != null) {
        StyleListProperties listProperties = null;
        for (int i = listLevel; i >= 0 && listProperties == null; i--) {
            // find style for current or nearest lower list level
            listProperties = listPropertiesMap.get(i);
        }// w w w.j a v  a  2 s . c  o  m
        if (listProperties != null) {
            String bulletChar = listProperties.getBulletChar();
            if (bulletChar != null) {
                // list item label is a char
                Chunk symbol = new Chunk(bulletChar);

                StyleTextProperties textProperties = style.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }
                }

                super.setListSymbol(symbol);
            }

            Image image = listProperties.getImage();
            if (image != null) {
                // list item label is an image
                Float width = listProperties.getWidth();
                if (width != null) {
                    image.scaleAbsoluteWidth(width);
                }

                Float height = listProperties.getHeight();
                if (height != null) {
                    image.scaleAbsoluteHeight(height);
                }

                super.setListSymbol(new Chunk(image, 0.0f, 0.0f));
            }

            if (bulletChar == null && image == null) {
                // list item label is a number
                Chunk symbol = new Chunk("");

                StyleTextProperties textProperties = style.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }
                }

                Integer startValue = listProperties.getStartValue();
                if (startValue != null) {
                    super.setFirst(startValue);
                }

                String numPrefix = listProperties.getNumPrefix();
                if (numPrefix != null) {
                    super.setPreSymbol(numPrefix);
                    symbol = new Chunk(numPrefix, symbol.getFont());
                }

                String numSuffix = listProperties.getNumSuffix();
                if (numSuffix != null) {
                    super.setPostSymbol(numSuffix);
                    symbol.append(numSuffix);
                }

                StyleNumFormat numFormat = listProperties.getNumFormat();
                if (numFormat != null) {
                    super.setNumbered(true);
                    super.setLettered(numFormat.isAlphabetical());
                    this.romanNumbered = numFormat.isRoman();
                    super.setLowercase(numFormat.isLowercase());
                }

                super.setListSymbol(symbol);
            }

            Float marginLeft = listProperties.getMarginLeft();
            Float textIndent = listProperties.getTextIndent();
            if (marginLeft != null && textIndent != null) {
                super.setIndentationLeft(Math.max(marginLeft + textIndent, 0.0f));
                super.setSymbolIndent(Math.max(-textIndent, 0.0f));
                super.setAutoindent(false);
            }
        }
    }
}

From source file:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

private Chunk certaintyToNaturalString(String certainty) {
    Chunk c = new Chunk();

    if (certainty.equalsIgnoreCase("exact")) {
        c.append("in exactly ");
    } else if (certainty.equalsIgnoreCase("after")) {
        c.append("after ");
    } else if (certainty.equalsIgnoreCase("before")) {
        c.append("before ");
    } else {//from  w  ww  . j  a  v a  2 s  .c  o m
        c.append("in " + certainty.toLowerCase() + " ");
    }

    c.setFont(bodyFont);
    return c;
}

From source file:rtf.shapes.RTFShapeTextWrap.java

/**
 * @param args/*from   w w  w  .j  a  v  a 2  s  . c om*/
 */
public static void main(String[] args) {
    Document document = new Document();

    try {
        RtfWriter2.getInstance(document, new FileOutputStream(resultsPath + outFile));
        document.open();
        Image logo = Image.getInstance(resourcePath + inFile1);

        Paragraph p = new Paragraph();
        Chunk c = new Chunk();
        c.append(
                "This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. "
                        + "This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. "
                        + "This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. "
                        + "This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. "
                        + "This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. "
                        + "This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. "
                        + "This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. "
                        + "This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. "
                        + "This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. "
                        + "This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. ");

        RtfShapePosition position = new RtfShapePosition(2000, 6000, 10500, 4500);
        RtfShape shape = new RtfShape(RtfShape.SHAPE_RECTANGLE, position);
        shape.setWrapping(RtfShape.SHAPE_WRAP_LEFT);
        shape.setProperty(new RtfShapeProperty(RtfShapeProperty.PROPERTY_IMAGE, logo));

        p.add(shape);
        p.add(c);
        document.add(p);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (BadElementException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.close();
}