List of usage examples for com.lowagie.text Font UNDEFINED
int UNDEFINED
To view the source code for com.lowagie.text Font UNDEFINED.
Click Source Link
From source file:com.dlya.facturews.DlyaPdfExporter2.java
License:Open Source License
/** * Creates a PDF font./*from w ww .java2s. c o m*/ * * @param attributes the text attributes of the font * @param locale the locale for which to create the font * @param setFontLines whether to set underline and strikethrough as font style * @return the PDF font for the specified attributes */ @SuppressWarnings("deprecation") protected Font getFont(Map<Attribute, Object> attributes, Locale locale, boolean setFontLines) { JRFont jrFont = new JRBaseFont(attributes); Exception initialException = null; Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND); // use the same font scale ratio as in JRStyledText.getAwtAttributedString float fontSizeScale = 1f; Integer scriptStyle = (Integer) attributes.get(TextAttribute.SUPERSCRIPT); if (scriptStyle != null && (TextAttribute.SUPERSCRIPT_SUB.equals(scriptStyle) || TextAttribute.SUPERSCRIPT_SUPER.equals(scriptStyle))) { fontSizeScale = 2f / 3; } Font font = null; PdfFont pdfFont = null; FontKey key = new FontKey(jrFont.getFontName(), jrFont.isBold(), jrFont.isItalic()); if (fontMap != null && fontMap.containsKey(key)) { pdfFont = pdfFontMap.get(key); } else { FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(jrFont.getFontName(), locale); if (fontInfo == null) { //fontName NOT found in font extensions pdfFont = new PdfFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded()); } else { //fontName found in font extensions FontFamily family = fontInfo.getFontFamily(); FontFace face = fontInfo.getFontFace(); int faceStyle = java.awt.Font.PLAIN; if (face == null) { //fontName matches family name in font extension if (jrFont.isBold() && jrFont.isItalic()) { face = family.getBoldItalicFace(); faceStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC; } if (face == null && jrFont.isBold()) { face = family.getBoldFace(); faceStyle = java.awt.Font.BOLD; } if (face == null && jrFont.isItalic()) { face = family.getItalicFace(); faceStyle = java.awt.Font.ITALIC; } if (face == null) { face = family.getNormalFace(); faceStyle = java.awt.Font.PLAIN; } // if (face == null) // { // throw new JRRuntimeException("Font family '" + family.getName() + "' does not have the normal font face."); // } } else { //fontName matches face name in font extension; not family name faceStyle = fontInfo.getStyle(); } String pdfFontName = null; int pdfFontStyle = java.awt.Font.PLAIN; if (jrFont.isBold() && jrFont.isItalic()) { pdfFontName = family.getBoldItalicPdfFont(); pdfFontStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC; } if (pdfFontName == null && jrFont.isBold()) { pdfFontName = family.getBoldPdfFont(); pdfFontStyle = java.awt.Font.BOLD; } if (pdfFontName == null && jrFont.isItalic()) { pdfFontName = family.getItalicPdfFont(); pdfFontStyle = java.awt.Font.ITALIC; } if (pdfFontName == null) { pdfFontName = family.getNormalPdfFont(); pdfFontStyle = java.awt.Font.PLAIN; } if (pdfFontName == null) { //in theory, face file cannot be null here pdfFontName = (face == null || face.getFile() == null ? jrFont.getPdfFontName() : face.getFile()); pdfFontStyle = faceStyle;//FIXMEFONT not sure this is correct, in case we inherit pdfFontName from default properties } // String ttf = face.getFile(); // if (ttf == null) // { // throw new JRRuntimeException("The '" + face.getName() + "' font face in family '" + family.getName() + "' returns a null file."); // } pdfFont = new PdfFont(pdfFontName, family.getPdfEncoding() == null ? jrFont.getPdfEncoding() : family.getPdfEncoding(), family.isPdfEmbedded() == null ? jrFont.isPdfEmbedded() : family.isPdfEmbedded().booleanValue(), jrFont.isBold() && ((pdfFontStyle & java.awt.Font.BOLD) == 0), jrFont.isItalic() && ((pdfFontStyle & java.awt.Font.ITALIC) == 0)); } } int pdfFontStyle = (pdfFont.isPdfSimulatedBold() ? Font.BOLD : 0) | (pdfFont.isPdfSimulatedItalic() ? Font.ITALIC : 0); if (setFontLines) { pdfFontStyle |= (jrFont.isUnderline() ? Font.UNDERLINE : 0) | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0); } try { font = FontFactory.getFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(), pdfFont.isPdfEmbedded(), jrFont.getFontSize() * fontSizeScale, pdfFontStyle, forecolor); // check if FontFactory didn't find the font if (font.getBaseFont() == null && font.family() == Font.UNDEFINED) { font = null; } } catch (Exception e) { initialException = e; } if (font == null) { byte[] bytes = null; try { bytes = RepositoryUtil.getInstance(jasperReportsContext) .getBytesFromLocation(pdfFont.getPdfFontName()); } catch (JRException e) { throw //NOPMD new JRRuntimeException("Could not load the following font : " + "\npdfFontName : " + pdfFont.getPdfFontName() + "\npdfEncoding : " + pdfFont.getPdfEncoding() + "\nisPdfEmbedded : " + pdfFont.isPdfEmbedded(), initialException); } BaseFont baseFont = null; try { baseFont = BaseFont.createFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(), pdfFont.isPdfEmbedded(), true, bytes, null); } catch (DocumentException e) { throw new JRRuntimeException(e); } catch (IOException e) { throw new JRRuntimeException(e); } font = new Font(baseFont, jrFont.getFontSize() * fontSizeScale, pdfFontStyle, forecolor); } return font; }
From source file:com.stratelia.webactiv.kmelia.control.Callback.java
License:Open Source License
@Override public void handleText(char[] data, int pos) throws KmeliaRuntimeException { SilverTrace.info("kmelia", "Callback.handleText", "root.MSG_ENTRY_METHOD", "data = " + data.toString()); String toParse = new String(data); Font fnt = new Font(Font.UNDEFINED, font_size, font_properties); try {//from w ww . ja v a 2s . c o m StringBuilder out = new StringBuilder(100); int posit = toParse.indexOf("%WA"); while (posit != -1) { if (posit > 0) { out.append(toParse.substring(0, posit)); toParse = toParse.substring(posit); } if (toParse.startsWith("%WATXTDATA%")) { if (textIterator.hasNext()) { InfoTextDetail textDetail = textIterator.next(); out.append(textDetail.getContent()); } else { out.append(" "); } toParse = toParse.substring(11); } else if (toParse.startsWith("%WAIMGDATA%")) { if (imageIterator.hasNext()) { if (out.length() > 0) { addText(out.toString(), fnt); } out.delete(0, out.length()); InfoImageDetail imageDetail = imageIterator.next(); String currentImagePath = FileRepositoryManager .getAbsolutePath(imageDetail.getPK().getComponentName()) + getImagePath() + File.separator + imageDetail.getPhysicalName(); SilverTrace.info("kmelia", "Callback.handleText", "root.MSG_PARAM_VALUE", "imagePath = " + currentImagePath); Image image = Image.getInstance(currentImagePath); document.add(image); } toParse = toParse.substring(11); } else { // we have to do this for avoid infinite loop i case // wrong tag posit = toParse.indexOf('%', 2); if (posit >= 0) { toParse = toParse.substring(posit + 1); } else { toParse = toParse.substring(1); } } posit = toParse.indexOf("%WA"); } if (toParse.length() > 0) { out.append(toParse); } addText(out.toString(), fnt); } catch (Exception ex) { throw new KmeliaRuntimeException("Callback.handleText", SilverpeasRuntimeException.WARNING, "kmelia.EX_CANNOT_SHOW_PDF_GENERATION", ex); } }
From source file:corner.orm.tapestry.jasper.exporter.CornerPdfExporter.java
License:Apache License
/** * ?,,.// www. java2s. c o m * @see net.sf.jasperreports.engine.export.JRPdfExporter#getFont(java.util.Map) */ protected Font getFont(Map attributes) { JRFont jrFont = new JRBaseFont(attributes); Exception initialException = null; Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND); /* if (forecolor == null) { forecolor = Color.black; } */ Font font = null; PdfFont pdfFont = null; FontKey key = new FontKey(jrFont.getFontName(), jrFont.isBold(), jrFont.isItalic()); if (fontMap != null && fontMap.containsKey(key)) { pdfFont = (PdfFont) fontMap.get(key); } else { pdfFont = new PdfFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded(), jrFont.isBold(), jrFont.isItalic()); } try { font = FontFactory.getFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(), pdfFont.isPdfEmbedded(), jrFont.getFontSize(), (pdfFont.isPdfSimulatedBold() ? Font.BOLD : 0) | (pdfFont.isPdfSimulatedItalic() ? Font.ITALIC : 0) | (jrFont.isUnderline() ? Font.UNDERLINE : 0) | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0), forecolor); // check if FontFactory didn't find the font if (font.getBaseFont() == null && font.family() == Font.UNDEFINED) { font = null; } } catch (Exception e) { initialException = e; } if (font == null) { byte[] bytes = null; try { bytes = JRLoader.loadBytesFromLocation(pdfFont.getPdfFontName(), classLoader, urlHandlerFactory); } catch (JRException e) { throw new JRRuntimeException("Could not load the following font : " + "\npdfFontName : " + pdfFont.getPdfFontName() + "\npdfEncoding : " + pdfFont.getPdfEncoding() + "\nisPdfEmbedded : " + pdfFont.isPdfEmbedded(), initialException); } BaseFont baseFont = null; try { baseFont = BaseFont.createFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(), pdfFont.isPdfEmbedded(), true, bytes, null); } catch (DocumentException e) { throw new JRRuntimeException(e); } catch (IOException e) { throw new JRRuntimeException(e); } font = new Font(baseFont, jrFont.getFontSize(), ((pdfFont.isPdfSimulatedBold()) ? Font.BOLD : 0) | ((pdfFont.isPdfSimulatedItalic()) ? Font.ITALIC : 0) | (jrFont.isUnderline() ? Font.UNDERLINE : 0) | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0), forecolor); } return font; }
From source file:corner.orm.tapestry.pdf.PdfUtils.java
License:Apache License
/** * .//from ww w. j a v a 2s .c o m * @param size ? * @return */ public static final Font createSongLightFont(int size) { BaseFont bf = createSongLightBaseFont(); if (size <= 0) { size = Font.UNDEFINED; } Font font = new Font(bf, size); return font; }
From source file:corner.orm.tapestry.pdf.PdfUtils.java
License:Apache License
/** * ()/*from ww w . j ava2 s. c om*/ * @param size * @return */ public static final Font createHeaderSongLightFont(int size) { BaseFont bf = createSongLightBaseFont(); if (size <= 0) { size = Font.UNDEFINED; } Font font = new Font(bf, size, Font.BOLD); return font; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.StyleEngineForIText.java
License:Open Source License
@Override public void visit(StyleTextPropertiesElement ele) { StyleTextProperties textProperties = currentStyle.getTextProperties(); if (textProperties == null) { textProperties = new StyleTextProperties(options.getFontProvider()); currentStyle.setTextProperties(textProperties); }//www. j a va 2 s. c o m // set font encoding from options textProperties.setFontEncoding(options.getFontEncoding()); // background-color String backgroundColor = ele.getFoBackgroundColorAttribute(); if (StringUtils.isNotEmpty(backgroundColor)) { textProperties.setBackgroundColor(ColorRegistry.getInstance().getColor(backgroundColor)); } // color String color = ele.getFoColorAttribute(); if (StringUtils.isNotEmpty(color)) { textProperties.setFontColor(ColorRegistry.getInstance().getColor(color)); } // font-family String fontFamily = ele.getFoFontFamilyAttribute(); if (StringUtils.isNotEmpty(fontFamily)) { textProperties.setFontName(ODFUtils.stripTrailingDigits(fontFamily)); } String fontFamilyAsian = ele.getStyleFontFamilyAsianAttribute(); if (StringUtils.isNotEmpty(fontFamilyAsian)) { textProperties.setFontNameAsian(ODFUtils.stripTrailingDigits(fontFamilyAsian)); } String fontFamilyComplex = ele.getStyleFontFamilyComplexAttribute(); if (StringUtils.isNotEmpty(fontFamilyComplex)) { textProperties.setFontNameComplex(ODFUtils.stripTrailingDigits(fontFamilyComplex)); } // font-name String fontName = ele.getStyleFontNameAttribute(); if (StringUtils.isNotEmpty(fontName)) { textProperties.setFontName(ODFUtils.stripTrailingDigits(fontName)); } String fontNameAsian = ele.getStyleFontNameAsianAttribute(); if (StringUtils.isNotEmpty(fontNameAsian)) { textProperties.setFontNameAsian(ODFUtils.stripTrailingDigits(fontNameAsian)); } String fontNameComplex = ele.getStyleFontNameComplexAttribute(); if (StringUtils.isNotEmpty(fontNameComplex)) { textProperties.setFontNameComplex(ODFUtils.stripTrailingDigits(fontNameComplex)); } // font-size String fontSize = ele.getFoFontSizeAttribute(); if (StringUtils.isNotEmpty(fontSize)) { if (ODFUtils.hasPercentUnit(fontSize)) { // relative if (textProperties.getFontSize() != Font.UNDEFINED) { textProperties .setFontSize(textProperties.getFontSize() * ODFUtils.getDimensionAsPoint(fontSize)); } } else { // absolute textProperties.setFontSize(ODFUtils.getDimensionAsPoint(fontSize)); } } String fontSizeAsian = ele.getStyleFontSizeAsianAttribute(); if (StringUtils.isNotEmpty(fontSizeAsian)) { if (ODFUtils.hasPercentUnit(fontSizeAsian)) { // relative if (textProperties.getFontSizeAsian() != Font.UNDEFINED) { textProperties.setFontSizeAsian( textProperties.getFontSizeAsian() * ODFUtils.getDimensionAsPoint(fontSizeAsian)); } } else { // absolute textProperties.setFontSizeAsian(ODFUtils.getDimensionAsPoint(fontSizeAsian)); } } String fontSizeComplex = ele.getStyleFontSizeComplexAttribute(); if (StringUtils.isNotEmpty(fontSizeComplex)) { if (ODFUtils.hasPercentUnit(fontSizeComplex)) { // relative if (textProperties.getFontSizeComplex() != Font.UNDEFINED) { textProperties.setFontSizeComplex( textProperties.getFontSizeComplex() * ODFUtils.getDimensionAsPoint(fontSizeComplex)); } } else { // absolute textProperties.setFontSizeComplex(ODFUtils.getDimensionAsPoint(fontSizeComplex)); } } // font-style String fontStyle = ele.getFoFontStyleAttribute(); if (StringUtils.isNotEmpty(fontStyle)) { if (FoFontStyleAttribute.Value.NORMAL.toString().equals(fontStyle)) { textProperties.setFontItalic(Boolean.FALSE); } else { // interpret other values as italic textProperties.setFontItalic(Boolean.TRUE); } } String fontStyleAsian = ele.getStyleFontStyleAsianAttribute(); if (StringUtils.isNotEmpty(fontStyleAsian)) { if (StyleFontStyleAsianAttribute.Value.NORMAL.toString().equals(fontStyleAsian)) { textProperties.setFontItalicAsian(Boolean.FALSE); } else { // interpret other values as italic textProperties.setFontItalicAsian(Boolean.TRUE); } } String fontStyleComplex = ele.getStyleFontStyleComplexAttribute(); if (StringUtils.isNotEmpty(fontStyleComplex)) { if (StyleFontStyleComplexAttribute.Value.NORMAL.toString().equals(fontStyleComplex)) { textProperties.setFontItalicComplex(Boolean.FALSE); } else { // interpret other values as italic textProperties.setFontItalicComplex(Boolean.TRUE); } } // font-variant String fontVariant = ele.getFoFontVariantAttribute(); if (StringUtils.isNotEmpty(fontVariant)) { } // font-weight String fontWeight = ele.getFoFontWeightAttribute(); if (StringUtils.isNotEmpty(fontWeight)) { if (FoFontWeightAttribute.Value.NORMAL.toString().equals(fontWeight)) { textProperties.setFontBold(Boolean.FALSE); } else { // interpret other values as bold textProperties.setFontBold(Boolean.TRUE); } } String fontWeightAsian = ele.getStyleFontWeightAsianAttribute(); if (StringUtils.isNotEmpty(fontWeightAsian)) { if (StyleFontWeightAsianAttribute.Value.NORMAL.toString().equals(fontWeightAsian)) { textProperties.setFontBoldAsian(Boolean.FALSE); } else { // interpret other values as bold textProperties.setFontBoldAsian(Boolean.TRUE); } } String fontWeightComplex = ele.getStyleFontWeightComplexAttribute(); if (StringUtils.isNotEmpty(fontWeightComplex)) { if (StyleFontWeightComplexAttribute.Value.NORMAL.toString().equals(fontWeightComplex)) { textProperties.setFontBoldComplex(Boolean.FALSE); } else { // interpret other values as bold textProperties.setFontBoldComplex(Boolean.TRUE); } } // text-underline-style String underlineStyle = ele.getStyleTextUnderlineStyleAttribute(); if (StringUtils.isNotEmpty(underlineStyle)) { if (StyleTextUnderlineStyleAttribute.Value.NONE.toString().equals(underlineStyle)) { textProperties.setFontUnderline(Boolean.FALSE); } else { // interpret other values as underline textProperties.setFontUnderline(Boolean.TRUE); } } // text-underline-type String underlineType = ele.getStyleTextUnderlineTypeAttribute(); if (StringUtils.isNotEmpty(underlineType)) { } // text-line-through-style String lineThroughStyle = ele.getStyleTextLineThroughStyleAttribute(); if (StringUtils.isNotEmpty(lineThroughStyle)) { if (StyleTextLineThroughStyleAttribute.Value.NONE.toString().equals(lineThroughStyle)) { textProperties.setFontStrikeThru(Boolean.FALSE); } else { // interpret other values as strike thru textProperties.setFontStrikeThru(Boolean.TRUE); } } // text-position String textPositionStyle = ele.getStyleTextPositionAttribute(); if (StringUtils.isNotEmpty(textPositionStyle)) { if (textPositionStyle.contains("super")) { textProperties.setTextPosition(5.0f); } else if (textPositionStyle.contains("sub")) { textProperties.setTextPosition(-2.0f); } } super.visit(ele); }
From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java
License:Open Source License
public void merge(StyleTextProperties textProperties) { if (textProperties.getBackgroundColor() != null) { backgroundColor = textProperties.getBackgroundColor(); }// w w w.jav a 2s . c o m if (textProperties.getFontBold() != null) { fontBold = textProperties.getFontBold(); } if (textProperties.getFontBoldAsian() != null) { fontBoldAsian = textProperties.getFontBoldAsian(); } if (textProperties.getFontBoldComplex() != null) { fontBoldComplex = textProperties.getFontBoldComplex(); } if (textProperties.getFontColor() != null) { fontColor = textProperties.getFontColor(); } if (textProperties.getFontEncoding() != null) { fontEncoding = textProperties.getFontEncoding(); } if (textProperties.getFontItalic() != null) { fontItalic = textProperties.getFontItalic(); } if (textProperties.getFontItalicAsian() != null) { fontItalicAsian = textProperties.getFontItalicAsian(); } if (textProperties.getFontItalicComplex() != null) { fontItalicComplex = textProperties.getFontItalicComplex(); } if (textProperties.getFontName() != null) { fontName = textProperties.getFontName(); } if (textProperties.getFontNameAsian() != null) { fontNameAsian = textProperties.getFontNameAsian(); } if (textProperties.getFontNameComplex() != null) { fontNameComplex = textProperties.getFontNameComplex(); } if (textProperties.getFontSize() != Font.UNDEFINED) { fontSize = textProperties.getFontSize(); } if (textProperties.getFontSizeAsian() != Font.UNDEFINED) { fontSizeAsian = textProperties.getFontSizeAsian(); } if (textProperties.getFontSizeComplex() != Font.UNDEFINED) { fontSizeComplex = textProperties.getFontSizeComplex(); } if (textProperties.getFontStrikeThru() != null) { fontStrikeThru = textProperties.getFontStrikeThru(); } if (textProperties.getFontUnderline() != null) { fontUnderline = textProperties.getFontUnderline(); } if (textProperties.getTextPosition() != null) { textPosition = textProperties.getTextPosition(); } }
From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java
License:Open Source License
public boolean hasFontProperties() { return fontName != null || fontSize != Font.UNDEFINED || fontItalic != null || fontBold != null || fontUnderline != null || fontStrikeThru != null || fontColor != null; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java
License:Open Source License
public boolean hasFontPropertiesAsian() { return fontNameAsian != null || fontSizeAsian != Font.UNDEFINED || fontItalicAsian != null || fontBoldAsian != null || fontUnderline != null || fontStrikeThru != null || fontColor != null; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java
License:Open Source License
public boolean hasFontPropertiesComplex() { return fontNameComplex != null || fontSizeComplex != Font.UNDEFINED || fontItalicComplex != null || fontBoldComplex != null || fontUnderline != null || fontStrikeThru != null || fontColor != null; }