Example usage for com.lowagie.text Font getCalculatedSize

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

Introduction

In this page you can find the example usage for com.lowagie.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:com.dlya.facturews.DlyaPdfExporter2.java

License:Open Source License

/**
 *
 *//*from   w ww  .  j  a va  2  s .  co  m*/
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:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableParagraph.java

License:Open Source License

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

    StyleTextProperties textProperties = style.getTextProperties();
    if (textProperties != null) {
        // font/*from w  w  w. j  ava 2s.co  m*/
        Font font = textProperties.getFont();
        if (font != null) {
            super.setFont(font);
        }
    }

    StyleParagraphProperties paragraphProperties = style.getParagraphProperties();
    if (paragraphProperties != null) {
        // break-before
        StyleBreak breakBefore = paragraphProperties.getBreakBefore();
        if (breakBefore != null) {
            handleBreak(breakBefore);
        }

        // alignment
        int alignment = paragraphProperties.getAlignment();
        if (alignment != Element.ALIGN_UNDEFINED) {
            super.setAlignment(alignment);
        }

        // first line indentation
        Boolean autoTextIndent = paragraphProperties.getAutoTextIndent();
        if (Boolean.TRUE.equals(autoTextIndent)) {
            float fontSize = font != null ? font.getCalculatedSize() : Font.DEFAULTSIZE;
            super.setFirstLineIndent(1.3f * fontSize);
        } else {
            Float textIndent = paragraphProperties.getTextIndent();
            if (textIndent != null) {
                // text indent can be negative. 
                // See https://code.google.com/p/xdocreport/issues/detail?id=366 
                super.setFirstLineIndent(textIndent);
            }
        }

        // line height
        StyleLineHeight lineHeight = paragraphProperties.getLineHeight();
        if (lineHeight != null && lineHeight.getLineHeight() != null) {
            if (lineHeight.isLineHeightProportional()) {
                super.setMultipliedLeading(lineHeight.getLineHeight());
            } else {
                super.setLeading(lineHeight.getLineHeight());
            }
        }

        // keep together on the same page
        Boolean keepTogether = paragraphProperties.getKeepTogether();
        if (keepTogether != null) {
            super.setKeepTogether(keepTogether);
        }
    }
}

From source file:org.apache.maven.doxia.module.itext.ITextFont.java

License:Apache License

/**
 * Return the font name/* ww w .  jav a2 s. c  om*/
 *
 * @return the font name
 */
public String getFontSize() {
    Font font = getCurrentFont();

    return String.valueOf(font.getCalculatedSize());
}

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

License:Open Source License

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

    StyleTextProperties textProperties = style.getTextProperties();
    if (textProperties != null) {
        // Font//from w ww .j a  va 2 s .  co  m
        Font font = textProperties.getFont();
        if (font != null) {
            super.setFont(font);
        }
    }

    StyleParagraphProperties paragraphProperties = style.getParagraphProperties();
    if (paragraphProperties != null) {
        // break-before
        StyleBreak breakBefore = paragraphProperties.getBreakBefore();
        if (breakBefore != null) {
            handleBreak(breakBefore);
        }

        // alignment
        int alignment = paragraphProperties.getAlignment();
        if (alignment != Element.ALIGN_UNDEFINED) {
            super.setAlignment(alignment);
        }

        // paragraph indentation
        Float margin = paragraphProperties.getMargin();
        if (margin != null) {
            super.setIndentationLeft(margin);
            super.setIndentationRight(margin);
            super.setSpacingBefore(margin);
            super.setSpacingAfter(margin);
        }
        Float marginLeft = paragraphProperties.getMarginLeft();
        if (marginLeft != null) {
            super.setIndentationLeft(marginLeft);
        }
        Float marginRight = paragraphProperties.getMarginRight();
        if (marginRight != null) {
            super.setIndentationRight(marginRight);
        }
        Float marginTop = paragraphProperties.getMarginTop();
        if (marginTop != null) {
            super.setSpacingBefore(marginTop);
        }
        Float marginBottom = paragraphProperties.getMarginBottom();
        if (marginBottom != null) {
            super.setSpacingAfter(marginBottom);
        }

        // first line indentation
        Boolean autoTextIndent = paragraphProperties.getAutoTextIndent();
        if (Boolean.TRUE.equals(autoTextIndent)) {
            float fontSize = font != null ? font.getCalculatedSize() : Font.DEFAULTSIZE;
            super.setFirstLineIndent(1.3f * fontSize);
        } else {
            Float textIndent = paragraphProperties.getTextIndent();
            if (textIndent != null) {
                super.setFirstLineIndent(textIndent);
            }
        }

        // line height
        StyleLineHeight lineHeight = paragraphProperties.getLineHeight();
        if (lineHeight != null && lineHeight.getLineHeight() != null) {
            if (lineHeight.isLineHeightProportional()) {
                super.setMultipliedLeading(lineHeight.getLineHeight());
            } else {
                super.setLeading(lineHeight.getLineHeight());
            }
        }

        // keep together on the same page
        Boolean keepTogether = paragraphProperties.getKeepTogether();
        if (keepTogether != null) {
            super.setKeepTogether(keepTogether);
        }

        // background color
        Color backgroundColor = paragraphProperties.getBackgroundColor();
        if (backgroundColor != null) {
            getWrapperCell().setBackgroundColor(backgroundColor);
        }

        // border
        StyleBorder border = paragraphProperties.getBorder();
        if (border != null) {
            StyleUtils.applyStyles(border, getWrapperCell());
        }

        // border-left
        StyleBorder borderLeft = paragraphProperties.getBorderLeft();
        if (borderLeft != null) {
            StyleUtils.applyStyles(borderLeft, getWrapperCell());
        }

        // border-right
        StyleBorder borderRight = paragraphProperties.getBorderRight();
        if (borderRight != null) {
            StyleUtils.applyStyles(borderRight, getWrapperCell());
        }

        // border-top
        StyleBorder borderTop = paragraphProperties.getBorderTop();
        if (borderTop != null) {
            StyleUtils.applyStyles(borderTop, getWrapperCell());
        }

        // border-bottom
        StyleBorder borderBottom = paragraphProperties.getBorderBottom();
        if (borderBottom != null) {
            StyleUtils.applyStyles(borderBottom, getWrapperCell());
        }
    }
}