Sophie

Sophie

distrib > * > 2008.0 > x86_64 > media > contrib-release > by-pkgid > 1c9187ee0e02176ceabec4f9819fe7fb > files > 311

itext-manual-2.0.4-3mdv2008.0.x86_64.rpm

/*
 * $Id: ExtendedFontStyles.java,v 1.1 2006/10/05 21:25:53 hallm Exp $
 * $Name: HEAD $
 *
 * This code is free software. It may only be copied or modified
 * if you include the following copyright notice:
 *
 * --> Copyright 2006 by Mark Hall <--
 *
 * This code is part of the 'iText Tutorial'.
 * You can find the complete tutorial at the following address:
 * http://itextdocs.lowagie.com/tutorial/
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * itext-questions@lists.sourceforge.net
 */
package com.lowagie.examples.rtf.extensions.font;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.rtf.RtfWriter2;
import com.lowagie.text.rtf.style.RtfFont;

/**
 * The ExtendedFontStyles class demonstrates the use of the extended
 * font styles provided by the RtfFont class. These styles can be used
 * in place or combined with the existing font styles in Font.
 * 
 * @version $Revision: 1.1 $
 * @author Mark Hall (mhall@edu.uni-klu.ac.at)
 * @see com.lowagie.text.rtf.style.RtfFont
 */
public class ExtendedFontStyles {
    /**
     * Extended font styles example.
     * 
     * @param args Unused
     */
    public static void main(String[] args) {
        System.out.println("Demonstrates the extended font styles");
        try {
            Document document = new Document();
            RtfWriter2.getInstance(document, new FileOutputStream("ExtendedFontStyles.rtf"));
            document.open();
            
            // Use the RtfFont.STYLE_* instead of the Font styles.
            RtfFont doubleStrikethrough = new RtfFont("Arial", RtfFont.UNDEFINED,
                    RtfFont.STYLE_DOUBLE_STRIKETHROUGH);
            RtfFont shadow = new RtfFont("Arial", RtfFont.UNDEFINED,
                    RtfFont.STYLE_SHADOW);
            
            // Or combine them with Font styles.
            RtfFont engravedItalic = new RtfFont("Arial", RtfFont.UNDEFINED,
                    RtfFont.STYLE_ENGRAVED | Font.ITALIC);
            
            // The hidden style is special since it hides text.
            RtfFont hidden = new RtfFont("Arial", RtfFont.UNDEFINED,
                    RtfFont.STYLE_HIDDEN);
            
            Paragraph paragraph = new Paragraph("This text is ", new RtfFont("Arial", 12));
            
            // Use the RtfFonts when creating the text.
            paragraph.add(new Chunk("deleted,", doubleStrikethrough));
            paragraph.add(new Chunk(" shady,", shadow));
            paragraph.add(new Chunk(" engraved and italic", engravedItalic));
            paragraph.add(" and");
            paragraph.add(new Chunk(" you won't see this", hidden));
            paragraph.add(" nothing.");
            
            document.add(paragraph);
            document.close();
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (DocumentException de) {
            de.printStackTrace();
        }
    }
}