Java Code Examples for com.lowagie.text.Font#BOLDITALIC
The following examples show how to use
com.lowagie.text.Font#BOLDITALIC .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardType1FontsTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Generates a PDF file with the 14 standard Type 1 Fonts * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document PdfWriter.getInstance(document, PdfTestBase.getOutputStream("StandardType1Fonts.pdf")); // step 3: we open the document document.open(); // step 4: // the 14 standard fonts in PDF: do not use this Font constructor! // this is for demonstration purposes only, use FontFactory! Font[] fonts = new Font[14]; fonts[0] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.NORMAL); fonts[1] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.ITALIC); fonts[2] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.BOLD); fonts[3] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.BOLD | Font.ITALIC); fonts[4] = new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.NORMAL); fonts[5] = new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.ITALIC); fonts[6] = new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.BOLD); fonts[7] = new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.BOLDITALIC); fonts[8] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE, Font.NORMAL); fonts[9] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE, Font.ITALIC); fonts[10] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD); fonts[11] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLDITALIC); fonts[12] = new Font(Font.SYMBOL); fonts[13] = new Font(Font.ZAPFDINGBATS); // add the content for (int i = 0; i < 14; i++) { document.add(new Paragraph("quick brown fox jumps over the lazy dog", fonts[i])); } // step 5: we close the document document.close(); }
Example 2
Source File: TextArea.java From birt with Eclipse Public License 1.0 | 5 votes |
public int getWidth( ) { int fontStyle = fi.getFontStyle( ); //get width for text with simulated italic font. if ( fi.getSimulation( ) && ( Font.ITALIC == fontStyle || Font.BOLDITALIC == fontStyle ) ) { width = (int) ( width + height * EmitterUtil.getItalicHorizontalCoefficient( ) ); } return width; }
Example 3
Source File: FontHandler.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * If the BaseFont can NOT find the correct physical glyph, we need to * simulate the proper style for the font. The "simulate" flag will be set * if we need to simulate it. */ private boolean needSimulate( BaseFont font ) { if ( fontStyle == Font.NORMAL ) { return false; } String[][] fullNames = bf.getFullFontName( ); String fullName = getEnglishName( fullNames ); String lcf = fullName.toLowerCase( ); int fs = Font.NORMAL; if ( lcf.indexOf( "bold" ) != -1 ) { fs |= Font.BOLD; } if ( lcf.indexOf( "italic" ) != -1 || lcf.indexOf( "oblique" ) != -1 ) { fs |= Font.ITALIC; } if ( ( fontStyle & Font.BOLDITALIC ) == fs ) { if ( fontWeight > 400 && fontWeight != 700 ) { // not a regular bold font. return true; } else { return false; } } return true; }
Example 4
Source File: FontInfo.java From birt with Eclipse Public License 1.0 | 5 votes |
public int getItalicAdjust( ) { // get width for text with simulated italic font. if ( simulation && ( Font.ITALIC == fontStyle || Font.BOLDITALIC == fontStyle ) ) { return (int) ( fontHeight * EmitterUtil.getItalicHorizontalCoefficient( ) ); } return 0; }
Example 5
Source File: PDFPage.java From birt with Eclipse Public License 1.0 | 5 votes |
private void setTextMatrix( PdfContentByte cb, FontInfo fi, float x, float y ) { cb.concatCTM( 1, 0, 0, 1, x, y ); if ( !fi.getSimulation( ) ) { cb.setTextMatrix( 0, 0 ); return; } switch ( fi.getFontStyle( ) ) { case Font.ITALIC : { simulateItalic( cb ); break; } case Font.BOLD : { simulateBold( cb, fi.getFontWeight( ) ); break; } case Font.BOLDITALIC : { simulateBold( cb, fi.getFontWeight( ) ); simulateItalic( cb ); break; } } }
Example 6
Source File: HtmlWriter.java From gcs with Mozilla Public License 2.0 | 4 votes |
/** * Writes the representation of a <CODE>Font</CODE>. * * @param font a <CODE>Font</CODE> * @param styleAttributes the style of the font * @throws IOException */ protected void write(Font font, Properties styleAttributes) throws IOException { if (font == null || !isOtherFont(font) /* || styleAttributes == null*/) { return; } write(" "); write(HtmlTags.STYLE); write("=\""); if (styleAttributes != null) { String key; for (Enumeration e = styleAttributes.propertyNames(); e.hasMoreElements();) { key = (String) e.nextElement(); writeCssProperty(key, styleAttributes.getProperty(key)); } } if (isOtherFont(font)) { writeCssProperty(Markup.CSS_KEY_FONTFAMILY, font.getFamilyname()); if (font.getSize() != Font.UNDEFINED) { writeCssProperty(Markup.CSS_KEY_FONTSIZE, font.getSize() + "pt"); } if (font.getColor() != null) { writeCssProperty(Markup.CSS_KEY_COLOR, HtmlEncoder.encode(font.getColor())); } int fontstyle = font.getStyle(); BaseFont bf = font.getBaseFont(); if (bf != null) { String ps = bf.getPostscriptFontName().toLowerCase(); if (ps.indexOf("bold") >= 0) { if (fontstyle == Font.UNDEFINED) { fontstyle = 0; } fontstyle |= Font.BOLD; } if (ps.indexOf("italic") >= 0 || ps.indexOf("oblique") >= 0) { if (fontstyle == Font.UNDEFINED) { fontstyle = 0; } fontstyle |= Font.ITALIC; } } if (fontstyle != Font.UNDEFINED && fontstyle != Font.NORMAL) { switch (fontstyle & Font.BOLDITALIC) { case Font.BOLD: writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); break; case Font.ITALIC: writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC); break; case Font.BOLDITALIC: writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC); break; } // CSS only supports one decoration tag so if both are specified // only one of the two will display if ((fontstyle & Font.UNDERLINE) > 0) { writeCssProperty(Markup.CSS_KEY_TEXTDECORATION, Markup.CSS_VALUE_UNDERLINE); } if ((fontstyle & Font.STRIKETHRU) > 0) { writeCssProperty(Markup.CSS_KEY_TEXTDECORATION, Markup.CSS_VALUE_LINETHROUGH); } } } write("\""); }
Example 7
Source File: HtmlWriter.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Writes the representation of a <CODE>Font</CODE>. * * @param font a <CODE>Font</CODE> * @param styleAttributes the style of the font * @throws IOException */ protected void write(Font font, Properties styleAttributes) throws IOException { if (font == null || !isOtherFont(font) /* || styleAttributes == null*/) return; write(" "); write(HtmlTags.STYLE); write("=\""); if (styleAttributes != null) { String key; for (Enumeration e = styleAttributes.propertyNames(); e.hasMoreElements(); ) { key = (String)e.nextElement(); writeCssProperty(key, styleAttributes.getProperty(key)); } } if (isOtherFont(font)) { writeCssProperty(Markup.CSS_KEY_FONTFAMILY, font.getFamilyname()); if (font.getSize() != Font.UNDEFINED) { writeCssProperty(Markup.CSS_KEY_FONTSIZE, font.getSize() + "pt"); } if (font.getColor() != null) { writeCssProperty(Markup.CSS_KEY_COLOR, HtmlEncoder.encode(font.getColor())); } int fontstyle = font.getStyle(); BaseFont bf = font.getBaseFont(); if (bf != null) { String ps = bf.getPostscriptFontName().toLowerCase(); if (ps.indexOf("bold") >= 0) { if (fontstyle == Font.UNDEFINED) fontstyle = 0; fontstyle |= Font.BOLD; } if (ps.indexOf("italic") >= 0 || ps.indexOf("oblique") >= 0) { if (fontstyle == Font.UNDEFINED) fontstyle = 0; fontstyle |= Font.ITALIC; } } if (fontstyle != Font.UNDEFINED && fontstyle != Font.NORMAL) { switch (fontstyle & Font.BOLDITALIC) { case Font.BOLD: writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); break; case Font.ITALIC: writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC); break; case Font.BOLDITALIC: writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC); break; } // CSS only supports one decoration tag so if both are specified // only one of the two will display if ((fontstyle & Font.UNDERLINE) > 0) { writeCssProperty(Markup.CSS_KEY_TEXTDECORATION, Markup.CSS_VALUE_UNDERLINE); } if ((fontstyle & Font.STRIKETHRU) > 0) { writeCssProperty(Markup.CSS_KEY_TEXTDECORATION, Markup.CSS_VALUE_LINETHROUGH); } } } write("\""); }
Example 8
Source File: PostscriptWriter.java From birt with Eclipse Public License 1.0 | 4 votes |
public void drawString( String str, float x, float y, FontInfo fontInfo, float letterSpacing, float wordSpacing, Color color, boolean linethrough, boolean overline, boolean underline, CSSValue align ) { y = transformY( y ); String text = str; boolean needSimulateItalic = false; boolean needSimulateBold = false; boolean hasSpace = wordSpacing != 0 || letterSpacing != 0; float offset = 0; if ( fontInfo != null ) { float fontSize = fontInfo.getFontSize( ); int fontStyle = fontInfo.getFontStyle( ); if ( fontInfo.getSimulation( ) ) { if ( fontStyle == Font.BOLD || fontStyle == Font.BOLDITALIC ) { offset = (float) ( fontSize * Math.log10( fontSize ) / 100 ); needSimulateBold = true; } if ( fontStyle == Font.ITALIC || fontStyle == Font.BOLDITALIC ) { needSimulateItalic = true; } } BaseFont baseFont = fontInfo.getBaseFont( ); String fontName = baseFont.getPostscriptFontName( ); text = applyFont( fontName, fontStyle, fontSize, text ); } outputColor( color ); out.print( x + " " + y + " " ); if ( hasSpace ) out.print( wordSpacing + " " + letterSpacing + " " ); out.print( text + " " ); if ( needSimulateBold ) out.print( offset + " " ); String command = getCommand( hasSpace, needSimulateBold, needSimulateItalic ); out.println( command ); }