Example usage for com.itextpdf.text Font getCalculatedSize

List of usage examples for com.itextpdf.text Font getCalculatedSize

Introduction

In this page you can find the example usage for com.itextpdf.text Font getCalculatedSize.

Prototype

public float getCalculatedSize() 

Source Link

Document

Gets the size that can be used with the calculated BaseFont .

Usage

From source file:org.javad.pdf.PageTitle.java

License:Apache License

@Override
public OutputBounds generate(PdfContentByte content) {
    int maxWidth = 0;
    content.setColorStroke(BaseColor.BLACK);
    Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.Title);
    content.setFontAndSize(f.getBaseFont(), f.getSize());
    float top = getY();
    content.setHorizontalScaling(110.0f);
    if (getTitle() != null && !getTitle().isEmpty()) {
        maxWidth = (int) f.getBaseFont().getWidthPoint(getTitle().toUpperCase(), f.getSize());
        PdfUtil.renderConstrainedText(content, getTitle().toUpperCase(), f, getX(), top,
                (int) (maxWidth * 1.1));
    }/*from   ww  w  . j  a va  2s .  co m*/
    if (getSubTitle() != null && !getSubTitle().isEmpty()) {
        Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.Subtitle);
        top -= subFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f);
        content.setFontAndSize(subFont.getBaseFont(), subFont.getSize());
        maxWidth = Math.max(maxWidth,
                (int) subFont.getBaseFont().getWidthPoint(getSubTitle().toUpperCase(), subFont.getSize()));
        PdfUtil.renderConstrainedText(content, getSubTitle().toUpperCase(), subFont, getX(), top,
                (int) (maxWidth * 1.10));

    }
    content.setHorizontalScaling(100.0f);
    if (getClassifier() != null && !getClassifier().isEmpty()) {
        Font classFont = FontRegistry.getInstance().getFont(PdfFontDefinition.Classifier);
        content.setFontAndSize(classFont.getBaseFont(), classFont.getSize());
        top -= classFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f);
        float width = classFont.getBaseFont().getWidthPoint(getClassifier(), classFont.getCalculatedSize()) + 4;
        maxWidth = Math.max(maxWidth, (int) width + (2 * DASH_LENGTH));
        content.setLineWidth(0.8f);
        float lineTop = top + ((int) classFont.getSize() / 2 - 1);
        content.moveTo(getX() - (width / 2) - DASH_LENGTH, lineTop);
        content.lineTo(getX() - (width / 2), lineTop);
        content.moveTo(getX() + (width / 2), lineTop);
        content.lineTo(getX() + (width / 2) + DASH_LENGTH, lineTop);
        content.stroke();
        PdfUtil.renderConstrainedText(content, getClassifier(), classFont, getX(), top,
                (int) (maxWidth * 1.10));
    }
    OutputBounds rect = new OutputBounds(getX() - maxWidth / 2, getY(), maxWidth, getY() - top);
    return rect;
}

From source file:org.javad.pdf.TitlePageContent.java

License:Apache License

@Override
public OutputBounds generate(PdfContentByte content) {
    if (isSkipped()) {
        return new OutputBounds(getX(), getY(), 0, 0);
    }/*from w  w w  . j ava  2 s.com*/
    int maxWidth = 0;
    float top = getY() - PdfUtil.convertFromMillimeters(
            (configuration.getHeight() - configuration.getMarginBottom() - configuration.getMarginTop()) / 2);
    if (getImage() != null) {
        try {
            com.itextpdf.text.Image img = determineScaledImage(getImage());
            if (img != null) {
                content.addImage(img);
                top = img.getAbsoluteY() - PdfUtil.convertFromMillimeters(25.0f);
            }
        } catch (Exception e) {
            logger.log(Level.FINER, "An error occured scaling the image. ", e);
        }
    }
    content.setColorStroke(BaseColor.BLACK);

    Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumTitle);
    content.setFontAndSize(f.getBaseFont(), f.getSize());

    content.setHorizontalScaling(110.0f);
    if (getTitle() != null && !getTitle().isEmpty()) {
        maxWidth = (int) f.getBaseFont().getWidthPoint(getTitle().toUpperCase(), f.getSize());
        PdfUtil.renderConstrainedText(content, getTitle().toUpperCase(), f, getX(), top, maxWidth);
    }
    if (getSubTitle() != null && !getSubTitle().isEmpty()) {
        Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumSubtitle);
        top -= subFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f);
        content.setFontAndSize(subFont.getBaseFont(), subFont.getSize());
        maxWidth = Math.max(maxWidth,
                (int) content.getEffectiveStringWidth(getSubTitle().toUpperCase(), false));
        PdfUtil.renderConstrainedText(content, getSubTitle().toUpperCase(), subFont, getX(), top, maxWidth);
    }
    if (getDescription() != null && !getDescription().isEmpty()) {
        Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumDescription);
        top -= PdfUtil.convertFromMillimeters(15.0f);
        float width = PdfUtil.convertFromMillimeters(
                (configuration.getWidth() - configuration.getMarginLeft() - configuration.getMarginRight())
                        / 2);
        content.setFontAndSize(subFont.getBaseFont(), subFont.getSize());
        top += PdfUtil.renderConstrainedText(content, getDescription(), subFont,
                width + PdfUtil.convertFromMillimeters(configuration.getMarginLeft()), top,
                (int) (width * 0.7f));
    }
    if (!getItems().isEmpty()) {
        Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumContents);
        top -= subFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(6.0f);
        content.setFontAndSize(subFont.getBaseFont(), subFont.getSize());
        for (String s : getItems()) {
            maxWidth = Math.max(maxWidth, (int) subFont.getBaseFont().getWidthPoint(s, subFont.getSize()));
            PdfUtil.renderConstrainedText(content, s, subFont, getX(), top, maxWidth);
            top -= PdfUtil.convertFromMillimeters(3.0f);
        }
    }
    content.setHorizontalScaling(100.0f);

    OutputBounds rect = new OutputBounds(getX() - maxWidth / 2, getY(), maxWidth, getY() - top);
    return rect;
}

From source file:org.javad.stamp.pdf.ColumnSet.java

License:Apache License

@Override
public OutputBounds generate(PdfContentByte content) {
    if (isSkipped()) {
        return new OutputBounds(getX(), getY(), 0, 0);
    }/*from www.  ja va2  s .c  om*/
    float totalWidth = 0.0f;
    float maxHeight = 0.0f;
    float cur_x = getX();
    float top = getY();
    if (getIssue() != null && !getIssue().isEmpty()) {
        top -= PdfUtil.convertFromMillimeters(5.0f);
        Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.SetIssue);

        content.setFontAndSize(f.getBaseFont(), f.getSize());
        String is = getIssue().replace("\\n", "\n");
        StringTokenizer tokenizer = new StringTokenizer(is, "\n", true);
        float x = PdfUtil
                .convertFromMillimeters(configuration.getUsableWidth() / 2 + configuration.getMarginLeft());
        while (tokenizer.hasMoreTokens()) {
            is = tokenizer.nextToken();
            if (is.equals("\n")) {
                top -= f.getCalculatedSize() + 2;
            } else {
                PdfUtil.renderConstrainedText(content, is, f, x, top,
                        (int) PdfUtil.convertFromMillimeters(configuration.getUsableWidth()));
                if (tokenizer.hasMoreTokens()) {
                    top -= f.getCalculatedSize() + 2;
                }
            }
        }

        top -= PdfUtil.convertFromMillimeters(3.0f);
    }
    float spacing = PdfUtil.convertFromMillimeters(getSpacingMode().getSpacing(box_spacing));
    int count = 0;
    for (int i = 0; i < columns.size(); i++) {
        StampSet set = columns.get(i);
        if (set.isSkipped()) {
            continue;
        }
        float s_w = PdfUtil.findMaximumWidth(set, content);
        set.setX(cur_x + s_w / 2);
        set.setY(top);
        OutputBounds rect = set.generate(content);

        totalWidth += rect.width + ((count > 0) ? spacing : 0.0f);
        cur_x += rect.width + spacing;
        maxHeight = Math.max(maxHeight, rect.height);
        count++;
    }
    return new OutputBounds(getX() - (totalWidth / 2.0f), getY(), totalWidth, maxHeight + (getY() - top));
}

From source file:org.javad.stamp.pdf.CompositeRow.java

License:Apache License

@Override
public OutputBounds generate(PdfContentByte content) {
    if (isSkipped()) {
        return new OutputBounds(getX(), getY(), 0, 0);
    }/*from w w w .j av  a 2  s . c  om*/
    float maxHeight = 0.0f;
    float maxWidth = 0.0f;
    float top = getY();

    if (getDescription() != null && !getDescription().isEmpty()) {
        content.setColorStroke(BaseColor.BLACK);
        Font descFont = FontRegistry.getInstance().getFont(PdfFontDefinition.CompositeSetDescription);
        content.setFontAndSize(descFont.getBaseFont(), descFont.getSize());

        top -= descFont.getCalculatedSize();
        int count = 0;
        int tc = getDescription().split("\n").length;
        for (String desc : getDescription().split("\n")) {
            maxWidth = Math.max(maxWidth, content.getEffectiveStringWidth(desc, false));
            PdfUtil.renderConstrainedText(content, desc, descFont, getX(), top, (int) maxWidth);
            count++;
            top -= descFont.getCalculatedSize() + ((count < tc) ? 2 : 4);
        }

    }

    float totalWidth = 0.0f;
    float totalHeight = getY() - top;
    float spacing = PdfUtil.convertFromMillimeters(getSpacingMode().getSpacing(box_spacing));
    int count = 0;
    for (int i = 0; i < rows.size(); i++) {
        StampRow set = rows.get(i);
        if (set.isSkipped()) {
            continue;
        }
        totalWidth += PdfUtil.findMaximumWidth(set, content) + ((count > 0) ? spacing : 0.0f);
        count++;
    }
    float cur_x = getX() - totalWidth / 2.0f;
    count = 0;
    for (StampRow set : rows) {
        if (set.isSkipped()) {
            continue;
        }
        set.setX(cur_x + PdfUtil.findMaximumWidth(set, content) / 2.0f);
        set.setY(top);
        OutputBounds rect = set.generate(content);
        count++;
        cur_x += rect.width + ((count > 0) ? spacing : 0);
        maxHeight = Math.max(maxHeight, rect.height);

    }
    maxWidth = Math.max(maxWidth, totalWidth);
    totalHeight += maxHeight;
    return new OutputBounds(getX() - (maxWidth / 2.0f), getY(), maxWidth, totalHeight);
}

From source file:org.javad.stamp.pdf.StampBox.java

License:Apache License

@Override
public OutputBounds generate(PdfContentByte content) {
    if (isSkipped()) {
        return new OutputBounds(getX(), getY(), 0, 0);
    }/*from  w ww  .j  a  v  a2s.co m*/
    OutputBounds rect = new OutputBounds(getX(), getY(),
            PdfUtil.convertFromMillimeters(getWidth() + getPadding()),
            PdfUtil.convertFromMillimeters(getHeight() + getVerticalPadding()));
    if (bisect != Bisect.none && isBorder()) {
        drawBisect(content, rect);
    }
    if (getSetTenantPosition() == null) {
        drawShape(content, rect);
    }

    float verticalPadding = PdfUtil.convertFromMillimeters(getVerticalPadding());
    float w = rect.width;
    Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.Stampbox);
    float center = getX() + w / 2;
    float top = getY() + verticalPadding + f.getCalculatedSize() * 6
            + PdfUtil.convertFromMillimeters(getTextPadding());

    if (image != null) {
        try {
            com.itextpdf.text.Image img = determineScaledImage(rect, f.getCalculatedSize(), top, isImageOnly());
            if (img != null) {
                content.addImage(img);
            }
        } catch (Exception e) {
            logger.log(Level.FINER, "An error occured scaling the image. ", e);
        }
    }
    if (!isImageOnly()) {
        if (shape == Shape.diamond || shape == Shape.triangleInverted) {
            top = getY() + rect.height / 2.0f + f.getCalculatedSize() * 1.5f;
        }
        top += PdfUtil.renderConstrainedText(content, getDenomination(), f, center, top, getWidth());
        top -= f.getCalculatedSize() + 1;
        float d_delta = PdfUtil.renderConstrainedText(content, getDescription(), f, center, top, getWidth());
        float rows = (float) Math.ceil(d_delta / f.getCalculatedSize());
        top += d_delta;
        Font f2 = FontRegistry.getInstance().getFont(PdfFontDefinition.StampboxOther);
        float delta = PdfUtil.renderConstrainedText(content, getDescriptionSecondary(), f2, center, top,
                getWidth());
        if (delta < 1.0f && rows > -3.00) {
            delta = -1 * (f.getSize() + 1);
        }
        if (d_delta >= -1 * (f.getSize() + 1)) { // handle one line descriptions
            top -= f.getSize() + 1;
        }
        top += delta;
        PdfUtil.renderConstrainedText(content, getCatalogueNumber(), f, center, top, getWidth());
    }
    return rect;
}

From source file:org.javad.stamp.pdf.StampRow.java

License:Apache License

@Override
public OutputBounds generate(PdfContentByte content) {
    if (isSkipped()) {
        return new OutputBounds(getX(), getY(), 0, 0);
    }/*from ww  w.ja  v a 2 s  . c o  m*/
    float maxWidth = 0;
    float top = getY();
    if (getDescription() != null && !getDescription().isEmpty()) {
        content.setColorStroke(BaseColor.BLACK);
        Font descFont = FontRegistry.getInstance().getFont(PdfFontDefinition.RowDescription);
        content.setFontAndSize(descFont.getBaseFont(), descFont.getSize());
        top -= descFont.getCalculatedSize();
        int count = 0;
        int tc = getDescription().split("\n").length;
        for (String desc : getDescription().split("\n")) {
            maxWidth = Math.max(maxWidth, (int) descFont.getBaseFont().getWidthPoint(desc, descFont.getSize()));
            PdfUtil.renderConstrainedText(content, desc, descFont, getX(), top, (int) (maxWidth * 1.10));
            count++;
            top -= descFont.getCalculatedSize() + ((count < tc) ? 2 : 4);

        }
    }
    float totalWidth = 0;
    int maxHeight = 0;
    int count = 0;
    for (int i = 0; i < stampContents.size(); i++) {
        if (stampContents.get(i).isSkipped()) {
            continue;
        }

        totalWidth += stampContents.get(i).getWidth() + stampContents.get(i).getPadding();
        if (count > 0) {
            totalWidth += padding;
        }
        count++;
        maxHeight = Math.max(maxHeight, stampContents.get(i).getHeight());
    }
    totalWidth = PdfUtil.convertFromMillimeters(totalWidth);
    float start_x = getX() - (totalWidth / 2.0f);
    float cur_x = start_x;
    float totalHeight = getY() - top;
    float deltaHeight = totalHeight;
    count = 0;
    for (IStampContent s : stampContents) {
        if (s.isSkipped()) {
            continue;
        }
        if (count > 0) {
            cur_x += PdfUtil.convertFromMillimeters(padding);
        }
        s.setX(cur_x);
        int delta_y = getVerticalAlignmentOffset(s, maxHeight);
        s.setY(top - PdfUtil.convertFromMillimeters(delta_y));
        OutputBounds r = s.generate(content);
        totalHeight = Math.max(r.height + deltaHeight, totalHeight);
        cur_x += r.width;
        count++;
    }
    maxWidth = (int) Math.max(maxWidth, totalWidth);
    return new OutputBounds(start_x, getY(), maxWidth, totalHeight);
}

From source file:org.javad.stamp.pdf.StampSet.java

License:Apache License

@Override
public OutputBounds generate(PdfContentByte content) {
    if (isSkipped()) {
        return new OutputBounds(getX(), getY(), 0, 0);
    }//from   w  w  w .j  av  a2s. c o m
    float maxWidth = 0;
    content.setColorStroke(BaseColor.BLACK);

    float top = getY();
    if (getIssue() != null && !getIssue().isEmpty()) {
        top -= PdfUtil.convertFromMillimeters(5.0f);
        Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.SetIssue);
        content.setFontAndSize(f.getBaseFont(), f.getSize());
        String is = getIssue().replace("\\n", "\n");
        StringTokenizer tokenizer = new StringTokenizer(is, "\n", true);
        while (tokenizer.hasMoreTokens()) {
            is = tokenizer.nextToken();
            maxWidth = Math.max(maxWidth, content.getEffectiveStringWidth(is, false));
            if (is.equals("\n")) {
                top -= f.getCalculatedSize() + 2;
            } else {
                PdfUtil.renderConstrainedText(content, is, f, getX(), top, (int) maxWidth);
                if (tokenizer.hasMoreTokens()) {
                    top -= f.getCalculatedSize() + 2;
                }
            }

        }
        top -= PdfUtil.convertFromMillimeters(3.0f);
    }
    if (getDescription() != null && !getDescription().isEmpty()) {
        Font descFont = FontRegistry.getInstance().getFont(PdfFontDefinition.SetDescription);
        content.setFontAndSize(descFont.getBaseFont(), descFont.getSize());
        top -= descFont.getCalculatedSize();
        int count = 0;
        int tc = getDescription().split("\n").length;
        for (String desc : getDescription().split("\n")) {
            maxWidth = Math.max(maxWidth, content.getEffectiveStringWidth(desc, false));
            PdfUtil.renderConstrainedText(content, desc, descFont, getX(), top, (int) maxWidth);
            count++;
            if (count < tc) {
                top -= descFont.getCalculatedSize() + 2;
            }

        }
    }
    if (getDescriptionSecondary() != null && !getDescriptionSecondary().isEmpty()) {
        Font secFont = FontRegistry.getInstance().getFont(PdfFontDefinition.SetDescriptionSecondary);
        content.setFontAndSize(secFont.getBaseFont(), secFont.getSize());
        top -= secFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f);
        int count = 0;
        int tc = getDescriptionSecondary().split("\n").length;
        for (String desc : getDescriptionSecondary().split("\n")) {
            maxWidth = Math.max(maxWidth, content.getEffectiveStringWidth(desc, false));
            PdfUtil.renderConstrainedText(content, desc, secFont, getX(), top, (int) maxWidth);
            count++;
            if (count < tc) {
                top -= secFont.getCalculatedSize() + 2;
            }

        }
    }

    if (!rows.isEmpty()) {
        top -= ((top != getY()) ? PdfUtil.convertFromMillimeters(3.0f) : 0);
        int count = 0;
        for (int i = 0; i < rows.size(); i++) {
            ISetContent row = rows.get(i);
            if (row.isSkipped()) {
                continue;
            }
            top -= ((count > 0) ? (PdfUtil.convertFromMillimeters(verticalPadding)) : 0.0f);
            row.setX(getX());
            row.setY(top);
            OutputBounds bounds = row.generate(content);
            count++;
            top -= bounds.height;
            maxWidth = Math.max(maxWidth, bounds.width);
        }
    }
    if (getComment() != null && !getComment().isEmpty()) {

        top -= PdfUtil.convertFromMillimeters((int) (0.75 * verticalPadding));
        Font cFont = FontRegistry.getInstance().getFont(PdfFontDefinition.SetComment);
        content.setFontAndSize(cFont.getBaseFont(), cFont.getSize());
        for (String s : getComment().split("\n")) {
            top -= cFont.getCalculatedSize();
            maxWidth = Math.max(maxWidth, content.getEffectiveStringWidth(s, false));
            PdfUtil.renderConstrainedText(content, s, cFont, getX(), top, (int) maxWidth);
        }

    }

    OutputBounds rect = new OutputBounds(getX() - maxWidth / 2, getY(), maxWidth, getY() - top);
    return rect;
}