Example usage for com.lowagie.text Font getSize

List of usage examples for com.lowagie.text Font getSize

Introduction

In this page you can find the example usage for com.lowagie.text Font getSize.

Prototype

public float getSize() 

Source Link

Document

Gets the size of this font.

Usage

From source file:org.displaytag.render.ItextTableWriter.java

License:Artistic License

/**
 * Makes chunk content bold.//w w w .  j  a  va 2  s.co  m
 * @param chunk The chunk whose content is to be rendered bold.
 * @param color The font color desired.
 */
private void setBoldStyle(Chunk chunk, Color color) {
    Font font = chunk.getFont();
    chunk.setFont(FontFactory.getFont(font.getFamilyname(), font.getSize(), Font.BOLD, color));
}

From source file:org.lucee.extension.pdf.tag.PDF.java

License:Open Source License

private Phrase text(String text, int page, int lastPage, int numberformat, BIF bif, Font font)
        throws PageException {
    String strPage;/*w w  w  .  j a  v a  2 s  .c  om*/
    String strLastPage;

    // number Format
    if (NUMBERFORMAT_NUMERIC == numberformat) {
        strPage = page + "";
        strLastPage = lastPage + "";
    } else {
        strPage = (String) bif.invoke(pageContext, new Object[] { page + "", "roman" });
        strLastPage = (String) bif.invoke(pageContext, new Object[] { lastPage + "", "roman" });
        if (NUMBERFORMAT_LOWERCASEROMAN == numberformat) {
            strPage = strPage.toLowerCase();
            strLastPage = strLastPage.toLowerCase();
        }
    }

    // replace placeholdrs
    Strings util = engine.getStringUtil();
    text = util.replace(text, "_PAGENUMBER", strPage, false, true);
    text = util.replace(text, "_LASTPAGENUMBER", strLastPage, false, true);

    // supress whitespace
    text = suppressWhiteSpace(text);
    System.out.println("++" + font.getFamilyname() + ":" + font.getSize());
    Phrase p = new Phrase(text, font);
    return p;
}

From source file:org.mapfish.print.TotalPageNum.java

License:Open Source License

public TotalPageNum(PdfWriter writer, Font font) {
    dc = writer.getDirectContent();
    totalPageNumFont = font.getCalculatedBaseFont(false);
    totalPageNumFontSize = font.getSize();
}

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  w  w w . j av  a2  s  .  com

        // 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:org.unitime.timetable.export.PDFPrinter.java

License:Open Source License

@Override
public void printHeader(String... fields) {
    iTable = new PdfPTable(fields.length - iHiddenColumns.size());
    iMaxWidth = new float[fields.length];
    iTable.setHeaderRows(1);/*w ww .java2s .co m*/
    iTable.setWidthPercentage(100);

    for (int idx = 0; idx < fields.length; idx++) {
        if (iHiddenColumns.contains(idx))
            continue;
        String f = fields[idx];

        PdfPCell cell = new PdfPCell();
        cell.setBorder(Rectangle.BOTTOM);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);

        Font font = PdfFont.getFont(true);
        cell.addElement(new Chunk(f, font));
        iTable.addCell(cell);

        float width = 0;
        if (f.indexOf('\n') >= 0) {
            for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();)
                width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
        } else
            width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize()));
        iMaxWidth[idx] = width;
    }
}

From source file:org.unitime.timetable.export.PDFPrinter.java

License:Open Source License

@Override
public void printLine(String... fields) {
    PdfPCellEvent setLineDashEvent = new PdfPCellEvent() {
        @Override//ww w  . j  a  v a 2  s.co m
        public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
            PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
            cb.setLineDash(new float[] { 2, 2 }, 0);
        }
    };

    for (int idx = 0; idx < fields.length; idx++) {
        if (iHiddenColumns.contains(idx))
            continue;
        String f = fields[idx];
        if (f == null || f.isEmpty() || (iCheckLast
                && f.equals(iLastLine == null || idx >= iLastLine.length ? null : iLastLine[idx])))
            f = "";

        boolean number = sNumber.matcher(f).matches();

        Font font = PdfFont.getFont();
        Phrase p = new Phrase(f, PdfFont.getSmallFont());

        PdfPCell cell = new PdfPCell(p);
        cell.setBorder(iLastLine == null ? Rectangle.TOP : Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(number ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT);
        cell.setPaddingBottom(4f);
        cell.setCellEvent(setLineDashEvent);
        if (number)
            cell.setPaddingRight(10f);
        iTable.addCell(cell);

        float width = 0;
        if (f.indexOf('\n') >= 0) {
            for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();)
                width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
        } else
            width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize()));
        iMaxWidth[idx] = Math.max(iMaxWidth[idx], width + (number ? 10 : 0));
    }
    iLastLine = fields;
}

From source file:org.unitime.timetable.export.rooms.RoomFeaturesExportPDF.java

License:Apache License

protected A rooms(FeatureInterface feature) {
    A ret = new A();
    if (feature.hasRooms()) {
        Font font = PdfFont.getFont(true);
        String rooms = "";
        for (Iterator<Entity> i = feature.getRooms().iterator(); i.hasNext();) {
            String chip = name(i.next()) + (i.hasNext() ? ", " : "");
            if (font.getBaseFont().getWidthPoint(rooms + chip, font.getSize()) < 500f)
                rooms += chip;/* w w  w.  jav a 2s.  co  m*/
            else {
                ret.add(new A(rooms));
                rooms = chip;
            }
        }
        if (!rooms.isEmpty())
            ret.add(new A(rooms));

    }
    return ret;
}

From source file:org.unitime.timetable.export.rooms.RoomGroupsExportPDF.java

License:Apache License

protected A rooms(GroupInterface group) {
    A ret = new A();
    if (group.hasRooms()) {
        Font font = PdfFont.getFont(true);
        String rooms = "";
        for (Iterator<Entity> i = group.getRooms().iterator(); i.hasNext();) {
            String chip = name(i.next()) + (i.hasNext() ? ", " : "");
            if (font.getBaseFont().getWidthPoint(rooms + chip, font.getSize()) < 500f)
                rooms += chip;/*  ww w.  j a  v  a  2  s .co  m*/
            else {
                ret.add(new A(rooms));
                rooms = chip;
            }
        }
        if (!rooms.isEmpty())
            ret.add(new A(rooms));

    }
    return ret;
}

From source file:org.unitime.timetable.export.solver.ExportTimetablePDF.java

License:Apache License

protected static float textWidth(Font font, TimetableGridCell cell, boolean showRoom, boolean showInstructor,
        boolean showTime, boolean showPreference, boolean showDate) {
    float width = 0;
    if (cell.getNrNames() > 0) {
        for (String name : cell.getNames())
            width = Math.max(width, font.getBaseFont().getWidthPoint(name, font.getSize()));
    }//www . ja  v  a  2  s .  com
    if (showTime && cell.hasTime())
        width = Math.max(width, font.getBaseFont().getWidthPoint(cell.getTime(), font.getSize()));
    if (showDate && cell.hasDate())
        width = Math.max(width, font.getBaseFont().getWidthPoint(cell.getDate(), font.getSize()));
    if (showRoom && cell.getNrRooms() > 0)
        for (String room : cell.getRooms())
            width = Math.max(width, font.getBaseFont().getWidthPoint(room, font.getSize()));
    if (showInstructor && cell.getNrInstructors() > 0)
        for (String instructor : cell.getInstructors())
            width = Math.max(width, font.getBaseFont().getWidthPoint(instructor, font.getSize()));
    if (showPreference && cell.hasPreference())
        width = Math.max(width, font.getBaseFont()
                .getWidthPoint(cell.getPreference().replaceAll("\\<[^>]*>", ""), font.getSize()));
    return width;
}

From source file:org.unitime.timetable.util.PdfEventHandler.java

License:Open Source License

/**
 * Constructor for PdfEventHandler/*  w  w w  .  j  ava  2  s . c  om*/
 * 
 */
public PdfEventHandler() throws DocumentException, IOException {

    super();

    Font font = PdfFont.getSmallFont();
    setBaseFont(font.getBaseFont());
    setFontSize(font.getSize());

    return;
}