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:ambit.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

protected int getText(org.w3c.dom.Node node, Phrase phrase, Font currentFont, ScriptMode scriptMode,
        boolean trim, int paragraphs) {

    if (node.getNodeType() == node.ELEMENT_NODE) {
        if ("head".equals(node.getNodeName()))
            return paragraphs;
        if ("html".equals(node.getNodeName()))
            trim = true;/*from   w w  w  . j a v a 2 s  .  com*/
        else if ("body".equals(node.getNodeName()))
            trim = true;
        else if ("p".equals(node.getNodeName()))
            trim = true;
        else
            trim = false;
        //if ("p".equals(node.getNodeName())) trim=true;
        //           System.out.println(node.getNodeName() + ' ' + trim);   
        //System.out.println(paragraphs);   
        Font f = currentFont;
        int fweight = currentFont.style();
        float fsize = currentFont.size();
        Color clr = currentFont.color();
        boolean modify = false;
        if ("b".equals(node.getNodeName())) {
            if ((currentFont.style() == Font.ITALIC) || (currentFont.style() == Font.BOLDITALIC))
                fweight = Font.BOLDITALIC;
            else
                fweight = Font.BOLD;
            modify = true;
        }
        if ("i".equals(node.getNodeName())) {
            if ((currentFont.style() == Font.BOLD) || (currentFont.style() == Font.BOLDITALIC))
                fweight = Font.BOLDITALIC;
            else
                fweight = Font.ITALIC;
            modify = true;
        }
        if ("sub".equals(node.getNodeName())) {
            scriptMode = ScriptMode.subscript;
        }
        if ("sup".equals(node.getNodeName())) {
            scriptMode = ScriptMode.superscript;
        }
        if ("font".equals(node.getNodeName())) {
            String r = ((org.w3c.dom.Element) node).getAttribute("color");
            if (r != null)
                try {
                    clr = Hex2Color(r.substring(1));
                    modify = true;
                } catch (Exception x) {
                    clr = currentFont.color();
                }
            String z = ((org.w3c.dom.Element) node).getAttribute("size");
            if (z != null) {
                try {
                    fsize = Integer.parseInt(z);
                    modify = true;
                } catch (Exception x) {
                    fsize = currentFont.size();
                }
            }
        }
        if (modify) {
            f = FontFactory.getFont(currentFont.getFamilyname(), fsize, fweight, clr);
        }
        if ("p".equals(node.getNodeName())) {
            if (paragraphs > 0)
                phrase.add(new Chunk('\n', f));
            paragraphs++;

        }

        //f = FontFactory.getFont(currentFont.getFamilyname(),curr)
        NodeList nodes = node.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++)
            paragraphs += getText(nodes.item(i), phrase, f, scriptMode, trim, paragraphs);

    } else if (node.getNodeType() == node.TEXT_NODE) {

        String value = node.getNodeValue();
        if (trim)
            value = replaceNewLine(value);
        if ("".equals(value))
            return paragraphs;
        //System.out.println(value);
        Chunk chunk = new Chunk(value, currentFont);
        HyphenationAuto autoEN = new HyphenationAuto("en", "GB", 2, 2);
        chunk.setHyphenation(autoEN);
        switch (scriptMode) {
        case superscript:
            chunk.setTextRise(currentFont.size() * 0.3f);
            break;
        case subscript:
            chunk.setTextRise(-currentFont.size() * 0.3f);
            break;

        default:
            break;
        }
        phrase.add(chunk);
    }
    return paragraphs;
}

From source file:com.dlya.facturews.DlyaPdfExporter2.java

License:Open Source License

/**
 *
 *///from  w  ww.j av a  2 s  .  c  om
protected Chunk getChunk(Map<Attribute, Object> attributes, String text, Locale locale) {
    // underline and strikethrough are set on the chunk below
    Font font = getFont(attributes, locale, false);

    Chunk chunk = new Chunk(text, font);

    if (hasUnderline(attributes)) {
        // using the same values as sun.font.Fond2D
        chunk.setUnderline(null, 0, 1f / 18, 0, -1f / 12, 0);
    }

    if (hasStrikethrough(attributes)) {
        // using the same thickness as sun.font.Fond2D.
        // the position is calculated in Fond2D based on the ascent, defaulting 
        // to iText default position which depends on the font size
        chunk.setUnderline(null, 0, 1f / 18, 0, 1f / 3, 0);
    }

    Color backcolor = (Color) attributes.get(TextAttribute.BACKGROUND);
    if (backcolor != null) {
        chunk.setBackground(backcolor);
    }

    Object script = attributes.get(TextAttribute.SUPERSCRIPT);
    if (script != null) {
        if (TextAttribute.SUPERSCRIPT_SUPER.equals(script)) {
            chunk.setTextRise(font.getCalculatedSize() / 2);
        } else if (TextAttribute.SUPERSCRIPT_SUB.equals(script)) {
            chunk.setTextRise(-font.getCalculatedSize() / 2);
        }
    }

    if (splitCharacter != null) {
        //TODO use line break offsets if available?
        chunk.setSplitCharacter(splitCharacter);
    }

    return chunk;
}

From source file:com.songbook.pc.exporter.PdfExporter.java

License:Open Source License

private Paragraph buildLine(LineNode lineNode) {
    Paragraph paragraph = new Paragraph();
    for (Node node : lineNode.getContentList()) {
        if (node instanceof TextNode) {
            TextNode textNode = (TextNode) node;
            paragraph.add(new Chunk(textNode.getText(), textFont));
        } else if (node instanceof ChordNode) {
            ChordNode chordNode = (ChordNode) node;
            Chunk chunk = new Chunk(" " + chordNode.getText() + " ", chordFont);
            chunk.setTextRise(4f);
            paragraph.add(chunk);//from w  ww  .j av a 2  s .  com
            paragraph.setLeading(4f, 1.2f);
        }
    }
    return paragraph;
}

From source file:fr.aliasource.webmail.server.export.ConversationExporter.java

License:GNU General Public License

@SuppressWarnings("unchecked")
private void exportMessage(Set<ClientMessage> cm, Document d, boolean isForward) throws DocumentException {

    LineSeparator hr = new LineSeparator();
    StyleSheet styles = new StyleSheet();
    Font fnormal = new Font(Font.HELVETICA, 9, Font.NORMAL);
    Font fbold = new Font(Font.HELVETICA, 9, Font.BOLD);

    Iterator<ClientMessage> it = cm.iterator();
    Cell c = null;//w  w w.j a va2  s . c o  m
    while (it.hasNext()) {
        ClientMessage fwdCm = it.next();
        if (isForward) {
            c = new Cell();
        }

        // Subject (only if isForward)
        if (isForward) {
            String subjectText = fwdCm.getSubject();
            String dateText = formatDate(fwdCm.getDate());
            Chunk subject = new Chunk(subjectText, fbold);
            Chunk date = new Chunk(dateText, fbold);
            Paragraph subjectPar = new Paragraph(subject + ", " + date);
            subjectPar.setIndentationLeft(5.0f);
            c.add(subjectPar);
            c.add(Chunk.NEWLINE);
        } else {
            String dateText = formatDate(fwdCm.getDate());
            Chunk date = new Chunk(dateText, fbold);
            Paragraph datePar = new Paragraph(date);
            datePar.setAlignment(Element.ALIGN_RIGHT);
            d.add(datePar);
        }

        // Sender
        String senderText = formatAddress(fwdCm.getSender());
        Chunk sender = new Chunk(senderText, fbold);
        sender.setTextRise(10.0f);
        Paragraph senderPar = new Paragraph(sender);
        if (isForward) {
            senderPar.setIndentationLeft(5.0f);
            c.add(senderPar);
        } else {
            d.add(senderPar);
        }

        appendRecipients(d, c, isForward, "To:", fwdCm.getTo());
        appendRecipients(d, c, isForward, "Cc:", fwdCm.getCc());
        appendRecipients(d, c, isForward, "Bcc:", fwdCm.getBcc());
        if (isForward) {
            c.add(Chunk.NEWLINE);
        }

        // Body
        String bodyText = fwdCm.getBody().getCleanHtml();
        Paragraph bodyPar = new Paragraph();
        bodyPar.setFont(fnormal);
        if (bodyText != null && !bodyText.isEmpty()) {
            try {
                List<Element> objects = HTMLWorker.parseToList(new StringReader(bodyText), styles);
                for (Iterator<Element> iterator = objects.iterator(); iterator.hasNext();) {
                    Element el = iterator.next();
                    if (!(el instanceof Image)) {
                        // bodyPar.add(el);
                        if (isForward) {
                            c.add(el);
                        } else {
                            bodyPar.add(el);
                        }
                    }
                }
            } catch (Exception e) {
                logger.warn("Cannot generate pdf from html body use plain text instead", e);
                // bodyPar.add(fwdCm.getBody().getPlain());
                if (isForward) {
                    Chunk t = new Chunk(fwdCm.getBody().getPlain());
                    t.setFont(fnormal);
                    c.add(t);
                } else {
                    bodyPar.add(fwdCm.getBody().getPlain());
                }
            }
        } else {
            if (isForward) {
                Chunk t = new Chunk(fwdCm.getBody().getPlain());
                t.setFont(fnormal);
                c.add(t);
            } else {
                bodyPar.add(fwdCm.getBody().getPlain());
            }
        }

        if (isForward) {
            // c.add(bodyPar);
            Table t = new Table(1);
            t.setPadding(5);
            t.setBackgroundColor(new Color(242, 242, 242));
            t.addCell(c);
            d.add(t);
        } else {
            bodyPar.setIndentationLeft(15.0f);
            d.add(bodyPar);
        }

        if (fwdCm.getFwdMessages() != null) {
            this.exportMessage(fwdCm.getFwdMessages(), d, true);
        }
        d.add(hr);
    }

}

From source file:fr.aliasource.webmail.server.export.ConversationExporter.java

License:GNU General Public License

private Chunk getRecipientValue(List<EmailAddress> recipients) {
    Chunk recipientsChunk = null;
    if (recipients != null && !recipients.isEmpty()) {
        StringBuilder recipientsText = new StringBuilder(200);
        formatRecipients(recipientsText, recipients, false);
        recipientsChunk = new Chunk(recipientsText.toString(), new Font(Font.HELVETICA, 9));
        recipientsChunk.setTextRise(15.0f);
    }/*  w  w  w  .j  av  a2  s .  c  o m*/
    return recipientsChunk;
}

From source file:fr.aliasource.webmail.server.export.ConversationExporter.java

License:GNU General Public License

private Chunk getRecipientLabel(String label) {
    Chunk recipientsLabel = new Chunk(label, new Font(Font.HELVETICA, 10, Font.BOLD));
    recipientsLabel.setTextRise(15.0f);
    return recipientsLabel;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
private void postProcessLineHeightAndBaseline() {
    // adjust line height and baseline
    Font font = getMostOftenUsedFont();
    if (font == null || font.getBaseFont() == null) {
        font = this.font;
    }//w w w . ja v  a  2  s.c  om
    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;
        ArrayList<Chunk> 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);
        }
    }
}

From source file:ispyb.client.mx.results.ExportAutoProcAction.java

License:Open Source License

private void setAutoProcInfo(Document document) throws Exception {
    // header/*from   www.java  2 s  .  c o m*/
    Table headerTable = new Table(1);
    headerTable.getDefaultCell().setBorderWidth(0);
    headerTable.setBorderWidth(0);
    headerTable.setCellsFitPage(true);
    headerTable.setAlignment(Element.ALIGN_LEFT);
    headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    headerTable.getDefaultCell().setBackgroundColor(PdfRtfExporter.LIGHT_YELLOW_COLOR);
    headerTable.getDefaultCell().setLeading(3);
    headerTable.setWidth(100); // percentage
    headerTable
            .addCell(new Paragraph("Crystal data and data-collection statistics", PdfRtfExporter.FONT_DOC_11));
    headerTable.addCell(new Paragraph("Values in parentheses are for the highest resolution shell.",
            PdfRtfExporter.FONT_DOC_11));
    document.add(headerTable);
    document.add(new Paragraph(" ", PdfRtfExporter.VERY_SMALL_FONT));
    // auto proc table
    Table autoProcTable = new Table(2);
    autoProcTable.getDefaultCell().setBorderWidth(0);
    autoProcTable.setBorderWidth(0);
    autoProcTable.setCellsFitPage(true);
    autoProcTable.setAlignment(Element.ALIGN_LEFT);
    autoProcTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    // autoProcTable.getDefaultCell().setLeading(3);
    autoProcTable.setPadding(2);
    autoProcTable.setWidth(100); // percentage
    // data
    String spaceGroup = autoProc == null ? "" : autoProc.getSpaceGroup();
    String unitCell_a = autoProc == null ? "" : autoProc.getRefinedCellA().toString();
    String unitCell_b = autoProc == null ? "" : autoProc.getRefinedCellB().toString();
    String unitCell_c = autoProc == null ? "" : autoProc.getRefinedCellC().toString();
    String unitCell_alpha = autoProc == null ? "" : autoProc.getRefinedCellAlpha().toString();
    String unitCell_beta = autoProc == null ? "" : autoProc.getRefinedCellBeta().toString();
    String unitCell_gamma = autoProc == null ? "" : autoProc.getRefinedCellGamma().toString();
    String resolutionRange = "";
    String nTotalObservations = "";
    String nTotalUniqueReflections = "";
    String completeness = "";
    String multiplicity = "";
    String isigma = "";
    String rmerge = "";
    if (autoProcStatisticsOverall != null) {
        resolutionRange = autoProcStatisticsOverall.getResolutionLimitLow() + " - "
                + autoProcStatisticsOverall.getResolutionLimitHigh();
        nTotalObservations = "" + autoProcStatisticsOverall.getnTotalObservations();
        nTotalUniqueReflections = "" + (autoProcStatisticsOverall.getnTotalUniqueObservations() == null ? ""
                : autoProcStatisticsOverall.getnTotalUniqueObservations());
        completeness = "" + autoProcStatisticsOverall.getCompleteness();
        multiplicity = "" + autoProcStatisticsOverall.getMultiplicity();
        isigma = "" + autoProcStatisticsOverall.getMeanIoverSigI();
        rmerge = ""
                + (autoProcStatisticsOverall.getRmerge() == null ? "" : autoProcStatisticsOverall.getRmerge());
    }
    if (autoProcStatisticsOuter != null) {
        resolutionRange += " (" + autoProcStatisticsOuter.getResolutionLimitLow() + " - "
                + autoProcStatisticsOuter.getResolutionLimitHigh() + ")";
        nTotalObservations += " (" + autoProcStatisticsOuter.getnTotalObservations() + ")";
        nTotalUniqueReflections += autoProcStatisticsOuter.getnTotalUniqueObservations() == null ? ""
                : (" (" + autoProcStatisticsOuter.getnTotalUniqueObservations() + ")");
        completeness += " (" + autoProcStatisticsOuter.getCompleteness() + ")";
        multiplicity += " (" + autoProcStatisticsOuter.getMultiplicity() + ")";
        isigma += " (" + autoProcStatisticsOuter.getMeanIoverSigI() + ")";
        rmerge += " ("
                + (autoProcStatisticsOuter.getRmerge() == null ? "" : autoProcStatisticsOuter.getRmerge())
                + ")";
    }
    // space group
    autoProcTable.addCell(new Paragraph("Space Group", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(spaceGroup, PdfRtfExporter.FONT_DOC_11));
    // unit cell parameters
    autoProcTable.addCell(
            new Paragraph("Unit-cell parameters (" + Constants.ANGSTROM + ")", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph("", PdfRtfExporter.FONT_DOC_11));
    Paragraph pa = new Paragraph("\t a", PdfRtfExporter.FONT_DOC_11);
    pa.setAlignment(Element.ALIGN_JUSTIFIED);
    pa.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pa);
    autoProcTable.addCell(new Paragraph(unitCell_a, PdfRtfExporter.FONT_DOC_11));
    Paragraph pb = new Paragraph("\t b", PdfRtfExporter.FONT_DOC_11);
    pb.setAlignment(Element.ALIGN_JUSTIFIED);
    pb.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pb);
    autoProcTable.addCell(new Paragraph(unitCell_b, PdfRtfExporter.FONT_DOC_11));
    Paragraph pc = new Paragraph("\t c", PdfRtfExporter.FONT_DOC_11);
    pc.setAlignment(Element.ALIGN_JUSTIFIED);
    pc.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pc);
    autoProcTable.addCell(new Paragraph(unitCell_c, PdfRtfExporter.FONT_DOC_11));
    // Issue 1733: cell angles info added
    Paragraph palpha = new Paragraph("\t alpha", PdfRtfExporter.FONT_DOC_11);
    palpha.setAlignment(Element.ALIGN_JUSTIFIED);
    palpha.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(palpha);
    autoProcTable.addCell(new Paragraph(unitCell_alpha, PdfRtfExporter.FONT_DOC_11));
    Paragraph pbeta = new Paragraph("\t beta", PdfRtfExporter.FONT_DOC_11);
    pbeta.setAlignment(Element.ALIGN_JUSTIFIED);
    pbeta.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pbeta);
    autoProcTable.addCell(new Paragraph(unitCell_beta, PdfRtfExporter.FONT_DOC_11));
    Paragraph pgamma = new Paragraph("\t gamma", PdfRtfExporter.FONT_DOC_11);
    pgamma.setAlignment(Element.ALIGN_JUSTIFIED);
    pgamma.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pgamma);
    autoProcTable.addCell(new Paragraph(unitCell_gamma, PdfRtfExporter.FONT_DOC_11));
    // resolution range
    autoProcTable.addCell(
            new Paragraph("Resolution range (" + Constants.ANGSTROM + ")", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(resolutionRange, PdfRtfExporter.FONT_DOC_11));
    // Observed reflections
    autoProcTable.addCell(new Paragraph("Observed reflections", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(nTotalObservations, PdfRtfExporter.FONT_DOC_11));
    // No. of unique reflections
    autoProcTable.addCell(new Paragraph("No. of unique reflections", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(nTotalUniqueReflections, PdfRtfExporter.FONT_DOC_11));
    // Completeness
    autoProcTable.addCell(new Paragraph("Completeness (%)", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(completeness, PdfRtfExporter.FONT_DOC_11));
    // multiplicity
    autoProcTable.addCell(new Paragraph("Multiplicity", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(multiplicity, PdfRtfExporter.FONT_DOC_11));
    new Phrase();
    // I/(I)
    Phrase p = Phrase.getInstance("<I/" + (char) 963 + "(I)>");
    p.setFont(PdfRtfExporter.FONT_DOC_11);
    autoProcTable.addCell(p);
    autoProcTable.addCell(new Paragraph(isigma, PdfRtfExporter.FONT_DOC_11));
    // Rmerge
    Chunk c1 = new Chunk("R", PdfRtfExporter.FONT_DOC_11);
    Chunk c2 = new Chunk("merge", PdfRtfExporter.FONT_DOC_EXPONENT);
    c2.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    Chunk c3 = new Chunk("(%)", PdfRtfExporter.FONT_DOC_11);
    Chunk c4 = new Chunk("#", PdfRtfExporter.FONT_DOC_EXPONENT_BLUE);
    c4.setTextRise(PdfRtfExporter.TEXT_RISE_EXP);
    Paragraph rMergeParagraph = new Paragraph();
    rMergeParagraph.add(c1);
    rMergeParagraph.add(c2);
    rMergeParagraph.add(c3);
    rMergeParagraph.add(c4);
    autoProcTable.addCell(rMergeParagraph);
    autoProcTable.addCell(new Paragraph(rmerge, PdfRtfExporter.FONT_DOC_11));
    document.add(autoProcTable);
    document.add(new Paragraph(" ", PdfRtfExporter.FONT_DOC_11));
    // nota bene info
    Paragraph nbParagraph = new Paragraph();
    nbParagraph.add(c4);
    nbParagraph.add(c1);
    nbParagraph.add(c2);
    Chunk cesp = new Chunk(" ", PdfRtfExporter.FONT_DOC_11);
    Chunk c5 = new Chunk(" = ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c5);
    Phrase pSigma = Phrase.getInstance("" + (char) 931);
    pSigma.setFont(PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(pSigma);
    Chunk chkl = new Chunk("hkl", PdfRtfExporter.FONT_DOC_EXPONENT);
    chkl.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    nbParagraph.add(chkl);
    nbParagraph.add(cesp);
    nbParagraph.add(pSigma);
    Chunk ci = new Chunk("i", PdfRtfExporter.FONT_DOC_EXPONENT);
    ci.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    nbParagraph.add(ci);
    Chunk c8 = new Chunk(" |I", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c8);
    nbParagraph.add(ci);
    Chunk c9 = new Chunk("(hkl) - (I(hkl))| / ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c9);
    nbParagraph.add(pSigma);
    nbParagraph.add(chkl);
    nbParagraph.add(cesp);
    nbParagraph.add(pSigma);
    nbParagraph.add(ci);
    nbParagraph.add(cesp);
    Chunk c10 = new Chunk("I", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c10);
    nbParagraph.add(ci);
    Chunk c11 = new Chunk("(hkl), where ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c11);
    Chunk c12 = new Chunk("I", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c12);
    Chunk cii = new Chunk("i", PdfRtfExporter.FONT_DOC_EXPONENT_ITALIC);
    cii.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    nbParagraph.add(cii);
    Chunk c13 = new Chunk("(hkl)", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c13);
    Chunk c14 = new Chunk(" is the ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c14);
    Chunk c15 = new Chunk("i", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c15);
    Chunk c16 = new Chunk("th observation of reflection ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c16);
    Chunk chklI = new Chunk("hkl", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(chklI);
    Chunk c17 = new Chunk(" and ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c17);
    Chunk c18 = new Chunk("<I(hkl)> ", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c18);
    Chunk c19 = new Chunk(" is the weighted average intensity for all observations of reflection ",
            PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c19);
    nbParagraph.add(chklI);
    Chunk c20 = new Chunk(".", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c20);
    document.add(nbParagraph);
    document.add(new Paragraph(" ", PdfRtfExporter.FONT_DOC_11));
}

From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java

License:Apache License

protected void writeHTMLText(CellStyle parentStyle, jdbreport.model.Cell cell, PdfPCell pdfCell) {
    if (cell.isNull() || cell.isChild())
        return;//from  w ww.j  av  a  2s .c  o m

    JTextComponent tc = getHTMLReportRenderer();
    tc.setText(cell.getText());
    List<Content> contentList = Content.getHTMLContentList((HTMLDocument) tc.getDocument());
    if (contentList != null) {
        Phrase phrase = new Phrase();
        for (Content content : contentList) {
            CellStyle newStyle = content.createTextStyle(parentStyle, parentStyle);
            if (newStyle == null) {
                newStyle = parentStyle;
            }
            if (newStyle != null) {
                if (newStyle.getTypeOffset() == CellStyle.SS_SUPER
                        || newStyle.getTypeOffset() == CellStyle.SS_SUB) {
                    newStyle = newStyle.deriveFont((float) newStyle.getSize() / 2);
                }
                int i = textStyles.indexOf(newStyle);
                if (i < 0) {
                    textStyles.add(newStyle);
                    i = textStyles.size() - 1;
                }
                Font font;
                String styleId = "T" + (i + 1);
                if (fonts.containsKey(styleId)) {
                    font = fonts.get(styleId);
                } else {
                    font = getFontMapper().styleToPdf(newStyle);
                    fonts.put(styleId, font);
                }
                Chunk chunk = new Chunk(content.getText(), font);
                chunk.setBackground(newStyle.getBackground());
                if (newStyle.getTypeOffset() == CellStyle.SS_SUPER) {
                    chunk.setTextRise(newStyle.getSize() / 2);
                } else if (newStyle.getTypeOffset() == CellStyle.SS_SUB) {
                    chunk.setTextRise(-newStyle.getSize() / 2);
                }
                phrase.add(chunk);
            } else {
                phrase.add(new Chunk(content.getText()));
            }
        }
        pdfCell.setPhrase(phrase);
    }
}

From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java

License:LGPL

/**
 *
 *//* w  w  w  .  j a  va 2  s .  c  o m*/
protected Chunk getChunk(Map attributes, String text) {
    Font font = getFont(attributes);

    Chunk chunk = new Chunk(text, font);

    Color backcolor = (Color) attributes.get(TextAttribute.BACKGROUND);
    if (backcolor != null) {
        chunk.setBackground(backcolor);
    }

    Object script = attributes.get(TextAttribute.SUPERSCRIPT);
    if (script != null) {
        if (TextAttribute.SUPERSCRIPT_SUPER.equals(script)) {
            chunk.setTextRise(font.leading(1f) / 2);
        } else if (script != null && TextAttribute.SUPERSCRIPT_SUB.equals(script)) {
            chunk.setTextRise(-font.leading(1f) / 2);
        }
    }

    if (splitCharacter != null) {
        chunk.setSplitCharacter(splitCharacter);
    }

    return chunk;
}