Example usage for com.lowagie.text Font ITALIC

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

Introduction

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

Prototype

int ITALIC

To view the source code for com.lowagie.text Font ITALIC.

Click Source Link

Document

this is a possible style.

Usage

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

License:Open Source License

private Font toFont(Struct sct) throws PageException {
    Cast caster = engine.getCastUtil();// www  .  ja va 2s  .c  o  m
    Font f = getDefaultFont();
    // size
    float size = caster.toFloatValue(sct.get("size", null), 0);
    if (size > 0)
        f.setSize(size);

    // family
    Set fonts = FontFactory.getRegisteredFonts();
    String family = caster.toString(sct.get("family", null), null);
    if (!Util.isEmpty(family)) {
        String lc = family.toLowerCase();
        if (!fonts.contains(lc)) {
            StringBuilder sb = new StringBuilder();
            Iterator it = fonts.iterator();
            while (it.hasNext()) {
                if (sb.length() > 0)
                    sb.append(", ");
                sb.append(it.next());
            }
            throw engine.getExceptionUtil().createApplicationException(
                    "font family [" + family + "] is not available, available font families are [" + sb + "]");
        }
        f.setFamily(lc);
    }

    int style = 0;
    // bold
    boolean bold = caster.toBooleanValue(sct.get("bold", null), false);
    if (bold)
        style |= Font.BOLD;
    // italic
    boolean italic = caster.toBooleanValue(sct.get("italic", null), false);
    if (italic)
        style |= Font.ITALIC;
    // underline
    boolean underline = caster.toBooleanValue(sct.get("underline", null), false);
    if (underline)
        style |= Font.UNDERLINE;
    // strike
    boolean strike = caster.toBooleanValue(sct.get("strike", null), false);
    if (strike)
        style |= Font.STRIKETHRU;
    if (style != 0)
        f.setStyle(style);

    return f;
}

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

License:Open Source License

public static BaseFont getBaseFont(String fontFamily, String fontSize, String fontWeight) {
    int myFontValue;
    float myFontSize;
    int myFontWeight;
    if (fontFamily.toUpperCase().contains("COURIER")) {
        myFontValue = Font.COURIER;
    } else if (fontFamily.toUpperCase().contains("HELVETICA")) {
        myFontValue = Font.HELVETICA;
    } else if (fontFamily.toUpperCase().contains("ROMAN")) {
        myFontValue = Font.TIMES_ROMAN;
    } else {//from   ww w . j  ava  2 s  . co  m
        myFontValue = Font.HELVETICA;
    }
    myFontSize = (float) Double.parseDouble(fontSize.toLowerCase().replaceAll("px", ""));
    if (fontWeight.toUpperCase().contains("NORMAL")) {
        myFontWeight = Font.NORMAL;
    } else if (fontWeight.toUpperCase().contains("BOLD")) {
        myFontWeight = Font.BOLD;
    } else if (fontWeight.toUpperCase().contains("ITALIC")) {
        myFontWeight = Font.ITALIC;
    } else {
        myFontWeight = Font.NORMAL;
    }
    Font pdfFont = new Font(myFontValue, myFontSize, myFontWeight);
    BaseFont bf = pdfFont.getCalculatedBaseFont(false);
    return bf;
}

From source file:org.oscarehr.phr.web.PHRUserManagementAction.java

License:Open Source License

public ByteArrayOutputStream generateUserRegistrationLetter(String demographicNo, String username,
        String password) throws Exception {
    log.debug("Demographic " + demographicNo + " username " + username + " password " + password);
    DemographicDao demographicDao = (DemographicDao) SpringUtils.getBean("demographicDao");
    Demographic demographic = demographicDao.getDemographic(demographicNo);

    final String PAGESIZE = "printPageSize";
    Document document = new Document();

    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    PdfWriter writer = null;//from www  .  j ava  2 s. com

    try {
        writer = PdfWriter.getInstance(document, baosPDF);

        String title = "TITLE";
        String template = "MyOscarLetterHead.pdf";

        Properties printCfg = getCfgProp();

        String[] cfgVal = null;
        StringBuilder tempName = null;

        // get the print prop values

        Properties props = new Properties();
        props.setProperty("letterDate", UtilDateUtilities.getToday("yyyy-MM-dd"));
        props.setProperty("name", demographic.getFirstName() + " " + demographic.getLastName());
        props.setProperty("dearname", demographic.getFirstName() + " " + demographic.getLastName());
        props.setProperty("address", demographic.getAddress());
        props.setProperty("city", demographic.getCity() + ", " + demographic.getProvince());
        props.setProperty("postalCode", demographic.getPostal());
        props.setProperty("credHeading", "MyOscar User Account Details");
        props.setProperty("username", "Username: " + username);
        props.setProperty("password", "Password: " + password);
        //Temporary - the intro will change to be dynamic
        props.setProperty("intro",
                "We are pleased to provide you with a log in and password for your new MyOSCAR Personal Health Record. This account will allow you to connect electronically with our clinic. Please take a few minutes to review the accompanying literature for further information.We look forward to you benefiting from this service.");

        document.addTitle(title);
        document.addSubject("");
        document.addKeywords("pdf, itext");
        document.addCreator("OSCAR");
        document.addAuthor("");
        document.addHeader("Expires", "0");

        Rectangle pageSize = PageSize.LETTER;

        document.setPageSize(pageSize);
        document.open();

        // create a reader for a certain document
        String propFilename = oscar.OscarProperties.getInstance().getProperty("pdfFORMDIR", "") + "/"
                + template;
        PdfReader reader = null;
        try {
            reader = new PdfReader(propFilename);
            log.debug("Found template at " + propFilename);
        } catch (Exception dex) {
            log.debug("change path to inside oscar from :" + propFilename);
            reader = new PdfReader("/oscar/form/prop/" + template);
            log.debug("Found template at /oscar/form/prop/" + template);
        }

        // retrieve the total number of pages
        int n = reader.getNumberOfPages();
        // retrieve the size of the first page
        Rectangle pSize = reader.getPageSize(1);
        float width = pSize.getWidth();
        float height = pSize.getHeight();
        log.debug("Width :" + width + " Height: " + height);

        PdfContentByte cb = writer.getDirectContent();
        ColumnText ct = new ColumnText(cb);
        int fontFlags = 0;

        document.newPage();
        PdfImportedPage page1 = writer.getImportedPage(reader, 1);
        cb.addTemplate(page1, 1, 0, 0, 1, 0, 0);

        BaseFont bf; // = normFont;
        String encoding;

        cb.setRGBColorStroke(0, 0, 255);

        String[] fontType;
        for (Enumeration e = printCfg.propertyNames(); e.hasMoreElements();) {
            tempName = new StringBuilder(e.nextElement().toString());
            cfgVal = printCfg.getProperty(tempName.toString()).split(" *, *");

            if (cfgVal[4].indexOf(";") > -1) {
                fontType = cfgVal[4].split(";");
                if (fontType[1].trim().equals("italic"))
                    fontFlags = Font.ITALIC;
                else if (fontType[1].trim().equals("bold"))
                    fontFlags = Font.BOLD;
                else if (fontType[1].trim().equals("bolditalic"))
                    fontFlags = Font.BOLDITALIC;
                else
                    fontFlags = Font.NORMAL;
            } else {
                fontFlags = Font.NORMAL;
                fontType = new String[] { cfgVal[4].trim() };
            }

            if (fontType[0].trim().equals("BaseFont.HELVETICA")) {
                fontType[0] = BaseFont.HELVETICA;
                encoding = BaseFont.CP1252; //latin1 encoding
            } else if (fontType[0].trim().equals("BaseFont.HELVETICA_OBLIQUE")) {
                fontType[0] = BaseFont.HELVETICA_OBLIQUE;
                encoding = BaseFont.CP1252;
            } else if (fontType[0].trim().equals("BaseFont.ZAPFDINGBATS")) {
                fontType[0] = BaseFont.ZAPFDINGBATS;
                encoding = BaseFont.ZAPFDINGBATS;
            } else {
                fontType[0] = BaseFont.COURIER;
                encoding = BaseFont.CP1252;
            }

            bf = BaseFont.createFont(fontType[0], encoding, BaseFont.NOT_EMBEDDED);

            // write in a rectangle area
            if (cfgVal.length >= 9) {
                Font font = new Font(bf, Integer.parseInt(cfgVal[5].trim()), fontFlags);
                ct.setSimpleColumn(Integer.parseInt(cfgVal[1].trim()),
                        (height - Integer.parseInt(cfgVal[2].trim())), Integer.parseInt(cfgVal[7].trim()),
                        (height - Integer.parseInt(cfgVal[8].trim())), Integer.parseInt(cfgVal[9].trim()),
                        (cfgVal[0].trim().equals("left") ? Element.ALIGN_LEFT
                                : (cfgVal[0].trim().equals("right") ? Element.ALIGN_RIGHT
                                        : Element.ALIGN_CENTER)));

                ct.setText(new Phrase(12, props.getProperty(tempName.toString(), ""), font));
                ct.go();
                continue;
            }

            // draw line directly
            if (tempName.toString().startsWith("__$line")) {
                cb.setRGBColorStrokeF(0f, 0f, 0f);
                cb.setLineWidth(Float.parseFloat(cfgVal[4].trim()));
                cb.moveTo(Float.parseFloat(cfgVal[0].trim()), Float.parseFloat(cfgVal[1].trim()));
                cb.lineTo(Float.parseFloat(cfgVal[2].trim()), Float.parseFloat(cfgVal[3].trim()));
                // stroke the lines
                cb.stroke();
                // write text directly

            } else if (tempName.toString().startsWith("__")) {
                cb.beginText();
                cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim()));
                cb.showTextAligned(
                        (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT
                                : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT
                                        : PdfContentByte.ALIGN_CENTER)),
                        (cfgVal.length >= 7 ? (cfgVal[6].trim()) : props.getProperty(tempName.toString(), "")),
                        Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0);

                cb.endText();
            } else if (tempName.toString().equals("forms_promotext")) {
                if (OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT") != null) {
                    cb.beginText();
                    cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim()));
                    cb.showTextAligned(
                            (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT
                                    : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT
                                            : PdfContentByte.ALIGN_CENTER)),
                            OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT"),
                            Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())),
                            0);

                    cb.endText();
                }
            } else { // write prop text

                cb.beginText();
                cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim()));
                cb.showTextAligned(
                        (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT
                                : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT
                                        : PdfContentByte.ALIGN_CENTER)),
                        (cfgVal.length >= 7 ? ((props.getProperty(tempName.toString(), "").equals("") ? ""
                                : cfgVal[6].trim())) : props.getProperty(tempName.toString(), "")),
                        Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0);

                cb.endText();
            }
        }

    } catch (DocumentException dex) {
        baosPDF.reset();
        throw dex;
    } finally {
        if (document != null)
            document.close();
        if (writer != null)
            writer.close();
    }
    return baosPDF;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfLogicalPageDrawable.java

License:Open Source License

private int computeStyle(final TypedMapWrapper<Attribute, Object> attributes, final PdfTextSpec pdfTextSpec) {
    final Float weight = attributes.get(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR, Float.class);
    final Float italics = attributes.get(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, Float.class);
    final boolean underlined = attributes.exists(TextAttribute.UNDERLINE);
    final boolean strikethrough = attributes.exists(TextAttribute.STRIKETHROUGH);

    FontNativeContext nativeContext = pdfTextSpec.getFontMetrics().getNativeContext();

    int style = 0;
    if (nativeContext.isNativeBold() == false && weight >= TextAttribute.WEIGHT_DEMIBOLD) {
        style |= Font.BOLD;//from w w w.  j  av a2s .  com
    }
    if (nativeContext.isNativeItalics() == false && italics >= TextAttribute.POSTURE_OBLIQUE) {
        style |= Font.ITALIC;
    }
    if (underlined) {
        style |= Font.UNDERLINE;
    }
    if (strikethrough) {
        style |= Font.STRIKETHRU;
    }
    return style;
}

From source file:org.primefaces.component.export.PDFExporter.java

License:Open Source License

protected void applyFacetOptions(ExporterOptions options) {
    String facetBackground = options.getFacetBgColor();
    if (facetBackground != null) {
        facetBgColor = Color.decode(facetBackground);
    }/*from   www. ja v a2 s.co m*/

    String facetFontColor = options.getFacetFontColor();
    if (facetFontColor != null) {
        facetFont.setColor(Color.decode(facetFontColor));
    }

    String facetFontSize = options.getFacetFontSize();
    if (facetFontSize != null) {
        facetFont.setSize(Integer.valueOf(facetFontSize));
    }

    String facetFontStyle = options.getFacetFontStyle();
    if (facetFontStyle != null) {
        if (facetFontStyle.equalsIgnoreCase("NORMAL")) {
            facetFontStyle = "" + Font.NORMAL;
        }
        if (facetFontStyle.equalsIgnoreCase("BOLD")) {
            facetFontStyle = "" + Font.BOLD;
        }
        if (facetFontStyle.equalsIgnoreCase("ITALIC")) {
            facetFontStyle = "" + Font.ITALIC;
        }

        facetFont.setStyle(facetFontStyle);
    }
}

From source file:org.primefaces.component.export.PDFExporter.java

License:Open Source License

protected void applyCellOptions(ExporterOptions options) {
    String cellFontColor = options.getCellFontColor();
    if (cellFontColor != null) {
        cellFont.setColor(Color.decode(cellFontColor));
    }/*from   ww w . ja  v a 2  s  .  c om*/

    String cellFontSize = options.getCellFontSize();
    if (cellFontSize != null) {
        cellFont.setSize(Integer.valueOf(cellFontSize));
    }

    String cellFontStyle = options.getCellFontStyle();
    if (cellFontStyle != null) {
        if (cellFontStyle.equalsIgnoreCase("NORMAL")) {
            cellFontStyle = "" + Font.NORMAL;
        }
        if (cellFontStyle.equalsIgnoreCase("BOLD")) {
            cellFontStyle = "" + Font.BOLD;
        }
        if (cellFontStyle.equalsIgnoreCase("ITALIC")) {
            cellFontStyle = "" + Font.ITALIC;
        }

        cellFont.setStyle(cellFontStyle);
    }
}

From source file:org.primefaces.extensions.showcase.util.PDFCustomExporter.java

License:Apache License

@Override
public void customFormat(String facetBackground, String facetFontSize, String facetFontColor,
        String facetFontStyle, String fontName, String cellFontSize, String cellFontColor, String cellFontStyle,
        String datasetPadding, String orientation) {
    this.facetFontSize = new Float(facetFontSize);
    this.cellFontSize = new Float(cellFontSize);
    this.datasetPadding = Integer.parseInt(datasetPadding);
    this.orientation = orientation;

    if (facetBackground != null) {
        this.facetBackground = Color.decode(facetBackground);
    }//  w w w  .j  av a 2 s .  co m

    if (facetFontColor != null) {
        this.facetFontColor = Color.decode(facetFontColor);
    }

    if (cellFontColor != null) {
        this.cellFontColor = Color.decode(cellFontColor);
    }

    if (fontName != null) {
        this.fontName = fontName;
    }

    if (facetFontStyle.equalsIgnoreCase("NORMAL")) {
        this.facetFontStyle = "" + Font.NORMAL;
    }

    if (facetFontStyle.equalsIgnoreCase("BOLD")) {
        this.facetFontStyle = "" + Font.BOLD;
    }

    if (facetFontStyle.equalsIgnoreCase("ITALIC")) {
        this.facetFontStyle = "" + Font.ITALIC;
    }

    if (cellFontStyle.equalsIgnoreCase("NORMAL")) {
        this.cellFontStyle = "" + Font.NORMAL;
    }

    if (cellFontStyle.equalsIgnoreCase("BOLD")) {
        this.cellFontStyle = "" + Font.BOLD;
    }

    if (cellFontStyle.equalsIgnoreCase("ITALIC")) {
        this.cellFontStyle = "" + Font.ITALIC;
    }
}

From source file:org.pz.platypus.plugin.html.HtmlFont.java

License:Open Source License

/**
 * iText font style captures bold, italic, strikethru, underline. Since we handle
 * strikethrough and underline ourselves, we use it to communicate italic and bold
 * only. This computation done here.//from   w  w w.  j  a  va  2s  .c o m
 *
 * @return the iText Style
 */
int computeItextStyle() {
    int style = 0;

    if (italics && bold) {
        style |= Font.BOLDITALIC;
    } else if (italics) {
        style |= Font.ITALIC;
    } else if (bold) {
        style |= Font.BOLD;
    }

    return (style);
}

From source file:org.pz.platypus.plugin.pdf.PdfFontFactory.java

License:Open Source License

/**
 * iText font style captures bold, italic, strikethru, underline. Since we handle
 * strikethrough and underline ourselves, we use it to communicate italic and bold
 * only. This computation done here./*from   ww w. ja  va  2 s. com*/
 *
 * @param f the PdfFont whose style is being checked
 * @return the iText Style
 */
int computeItextStyle(PdfFont f) {
    int style = 0;

    if (f.getItalics() && f.getBold()) {
        style |= Font.BOLDITALIC;
    } else if (f.getItalics()) {
        style |= Font.ITALIC;
    } else if (f.getBold()) {
        style |= Font.BOLD;
    }

    return (style);
}

From source file:org.tellervo.desktop.tridasv2.ui.TridasDefaultPropertyEditor.java

License:Open Source License

public TridasDefaultPropertyEditor() {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    panel.setOpaque(false);// w  w w . j a v a2  s.c  om

    label = new JLabel("");
    label.setForeground(Color.GRAY.brighter());
    label.setFont(label.getFont().deriveFont(Font.ITALIC));
    label.setOpaque(false);
    panel.add(label);

    // set class editor
    editor = panel;

    button = new JButton();
    button.setIcon(Builder.getIcon("cancel.png", 16));
    button.setMargin(new Insets(0, 5, 0, 5));

    panel.add(Box.createHorizontalGlue());
    panel.add(button);

    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            selectNull();
        }
    });
}