Example usage for com.lowagie.text Chunk setTextRise

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

Introduction

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

Prototype


public Chunk setTextRise(float rise) 

Source Link

Document

Sets the text displacement relative to the baseline.

Usage

From source file:org.jcryptool.visual.crt.export.FileExporter.java

License:Open Source License

/**
 * creates the PDF output-file using iText library
 *//*ww  w . j a  va 2  s  . co m*/
public void exportToPDF() {
    Font fontSupscript = new Font(Font.HELVETICA, 6, Font.NORMAL);
    Font fontSymbol = new Font(Font.SYMBOL, 12, Font.NORMAL);

    try {
        PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();

        document.add(new Paragraph("Chinese Remainder Theorem"));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("Equations:"));
        document.add(new Paragraph(" "));
        for (int i = 0; i < valueA.length; i++) {
            document.add(new Paragraph("x = " + valueA[i] + " mod " + valueModuli[i]));
        }
        document.add(new Paragraph(" "));
        document.add(new Paragraph("Compute"));
        document.add(new Paragraph(" "));

        Chunk space = new Chunk(" ");
        Chunk spaceBig = new Chunk("    ");
        Chunk index = new Chunk("i", fontSupscript);
        index.setTextRise(-3.0f);
        Chunk m = new Chunk("m");
        Chunk equal = new Chunk("=");
        Chunk openB = new Chunk("(");
        Chunk closeB = new Chunk(")");
        Chunk p = new Chunk("P", fontSymbol);
        Chunk comma = new Chunk(",");
        Chunk range = new Chunk("i=0 to n-1");
        Chunk bigM = new Chunk("M");
        Chunk div = new Chunk("/");

        document.add(m);
        document.add(space);
        document.add(equal);
        document.add(space);
        document.add(p);
        document.add(space);
        document.add(openB);
        document.add(space);
        document.add(m);
        document.add(index);
        document.add(space);
        document.add(closeB);
        document.add(comma);
        document.add(spaceBig);
        document.add(bigM);
        document.add(space);
        document.add(equal);
        document.add(space);
        document.add(m);
        document.add(space);
        document.add(div);
        document.add(space);
        document.add(m);
        document.add(index);
        document.add(comma);
        document.add(spaceBig);
        document.add(range);

        document.add(new Paragraph(" "));
        document.add(new Paragraph("m = " + crt.getModulus()));
        document.add(new Paragraph(" "));
        for (int i = 0; i < valueBigM.length; i++) {
            m = new Chunk("m");
            index = new Chunk(String.valueOf(i), fontSupscript);
            index.setTextRise(-3.0f);
            Chunk value = new Chunk(valueBigM[i].toString());

            document.add(m);
            document.add(index);
            document.add(new Chunk(" = "));
            document.add(value);
            document.add(new Paragraph());
        }
        document.add(new Paragraph(" "));
        document.add(new Paragraph("To get the inverse you can use the extended euclidean."));
        document.add(new Paragraph(" "));

        Chunk y = new Chunk("y");
        Chunk equiv = new Chunk("=");
        Chunk mod = new Chunk("mod");
        index = new Chunk("i", fontSupscript);
        index.setTextRise(-3.0f);

        document.add(y);
        document.add(index);
        document.add(bigM);
        document.add(index);
        document.add(space);
        document.add(equiv);
        document.add(space);
        document.add(new Chunk("1"));
        document.add(space);
        document.add(mod);
        document.add(space);
        document.add(m);
        document.add(index);
        document.add(comma);
        document.add(spaceBig);
        document.add(range);

        document.add(new Paragraph(" "));
        for (int i = 0; i < valueBigM.length; i++) {
            index = new Chunk(String.valueOf(i), fontSupscript);
            index.setTextRise(-3.0f);
            Chunk value = new Chunk(valueInverse[i].toString());

            document.add(new Chunk("y"));
            document.add(index);
            document.add(new Chunk(" = "));
            document.add(value);
            document.add(new Paragraph());
        }
        document.add(new Paragraph(" "));
        document.add(new Paragraph("To get one solution of the simultaneous congruences."));
        document.add(new Paragraph(" "));

        Chunk sum = new Chunk("S", fontSymbol);
        index = new Chunk("i", fontSupscript);
        index.setTextRise(-3.0f);

        document.add(new Chunk("x = "));
        document.add(sum);
        document.add(space);
        document.add(new Chunk());
        document.add(new Chunk("a"));
        document.add(index);
        document.add(new Chunk("y"));
        document.add(index);
        document.add(bigM);
        document.add(index);
        document.add(space);
        document.add(new Chunk("mod"));
        document.add(space);
        document.add(m);
        document.add(comma);
        document.add(spaceBig);
        document.add(range);
        document.add(new Chunk("."));

        document.add(new Paragraph(" "));
        document.add(new Paragraph("One solution is: " + crt.getFinalResult()));

        document.close();

    } catch (FileNotFoundException e) {
        LogUtil.logError(e);
    } catch (DocumentException e) {
        LogUtil.logError(e);
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public Element getElement() {
    if (!elementPostProcessed) {
        elementPostProcessed = true;/*from ww  w. ja v  a2 s  . c o m*/

        // add space if this paragraph is empty
        // otherwise it's height will be zero
        boolean empty = true;
        ArrayList<Chunk> chunks = getChunks();
        for (Chunk chunk : chunks) {
            if (chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0) {
                empty = false;
                break;
            }
        }
        if (empty) {
            super.add(new Chunk("\u00A0")); // non breaking space
        }

        // adjust line height and baseline
        if (font != null && font.getBaseFont() != null) {
            // iText and open office computes proportional line height differently
            // [iText] line height = coefficient * font size
            // [open office] line height = coefficient * (font ascender + font descender + font extra margin)
            // we have to increase paragraph line height to generate pdf similar to open office document
            // this algorithm may be inaccurate if fonts with different multipliers are used in this paragraph
            float size = font.getSize();
            float ascender = font.getBaseFont().getFontDescriptor(BaseFont.AWT_ASCENT, size);
            float descender = -font.getBaseFont().getFontDescriptor(BaseFont.AWT_DESCENT, size); // negative value
            float margin = font.getBaseFont().getFontDescriptor(BaseFont.AWT_LEADING, size);
            float multiplier = (ascender + descender + margin) / size;
            if (multipliedLeading > 0.0f) {
                setMultipliedLeading(getMultipliedLeading() * multiplier);
            }

            // iText seems to output text with baseline lower than open office
            // we raise all paragraph text by some amount
            // again this may be inaccurate if fonts with different size are used in this paragraph
            float itextdescender = -font.getBaseFont().getFontDescriptor(BaseFont.DESCENT, size); // negative
            float textRise = itextdescender + getTotalLeading() - font.getSize() * multiplier;
            chunks = getChunks();
            for (Chunk chunk : chunks) {
                Font f = chunk.getFont();
                if (f != null) {
                    // have to raise underline and strikethru as well
                    float s = f.getSize();
                    if (f.isUnderlined()) {
                        f.setStyle(f.getStyle() & ~Font.UNDERLINE);
                        chunk.setUnderline(s * 1 / 17, s * -1 / 7 + textRise);
                    }
                    if (f.isStrikethru()) {
                        f.setStyle(f.getStyle() & ~Font.STRIKETHRU);
                        chunk.setUnderline(s * 1 / 17, s * 1 / 4 + textRise);
                    }
                }
                chunk.setTextRise(chunk.getTextRise() + textRise);
            }
        }

        // wrap this paragraph into a table if necessary
        if (wrapperCell != null) {
            // background color or borders were set
            wrapperCell.addElement(this);
            wrapperTable = createTable(wrapperCell);
            if (getIndentationLeft() > 0.0f || getIndentationRight() > 0.0f || getSpacingBefore() > 0.0f
                    || getSpacingAfter() > 0.0f) {
                // margins were set, have to wrap the cell again
                PdfPCell outerCell = createCell();
                outerCell.setPaddingLeft(getIndentationLeft());
                setIndentationLeft(0.0f);
                outerCell.setPaddingRight(getIndentationRight());
                setIndentationRight(0.0f);
                outerCell.setPaddingTop(getSpacingBefore());
                setSpacingBefore(0.0f);
                outerCell.setPaddingBottom(getSpacingAfter());
                setSpacingAfter(0.0f);
                outerCell.addElement(wrapperTable);
                wrapperTable = createTable(outerCell);
            }
        }
    }
    return wrapperTable != null ? wrapperTable : this;
}

From source file:textdisplay.TagFilter.java

License:Educational Community License

/**Apply a style (font) to a chunk of pdf text*/
private void styleChunk(Chunk c, styles s) {
    try {/*from  w w  w. j a  va  2  s .  c  om*/

        BaseFont bf = BaseFont.createFont("/usr/Junicode.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        BaseFont ita = BaseFont.createFont("/usr/Junicode-Italic.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        BaseFont bol = BaseFont.createFont("/usr/Junicode-Italic.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        if (bf.charExists(540)) {
            System.out.print("font cant do 540\n");
        }
        Font italic = new Font(ita, 12, Font.ITALIC);
        Font bold = new Font(bol, 12, Font.BOLD);
        Font underlined = new Font(bf, 12, Font.UNDERLINE);
        Font superscript = new Font(bf, 9, Font.NORMAL);

        if (s == styles.bold) {
            c.setFont(bold);
        }
        if (s == styles.italic) {
            c.setFont(italic);
        }
        if (s == styles.underlined) {
            c.setFont(underlined);
        }
        if (s == styles.superscript) {
            c.setTextRise(7.0f);
            c.setFont(superscript);

        }

        //wipe out that content

    } catch (DocumentException ex) {
        Logger.getLogger(TagFilter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(TagFilter.class.getName()).log(Level.SEVERE, null, ex);
    }
}