Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Outlining the font 
 

By outlining the font , we make the characters more stylish and impressive. We are providing you an example which outlines the text.

 

Outlining the font

                         

This section illustrates you how to outline the font.

By outlining the font , we make the characters more stylish and impressive. We are providing you an example which outlines the text. The Font class represents fonts to render text in a visible way. The class FontRenderContext measures the text specified.

Following code defines the font:

Font font = new Font("Monotype Corsiva", 2, 50);

To give the graphical representation of styled character data, we have used the class TextLayout. The class AffineTransform provides the properties like translation, shearing, scaling, and rotation. The getBounds() method provides the boundaries displayed on the design surface. The method setClip(shape) sets the clipping of text specified as shape.

Following code outlines the string specified:

Shape shape = text.getOutline(null);

Here is the code of FontOutline.java 

import java.awt.*;
import javax.swing.*;
import java.awt.font.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;

public class FontOutline extends JApplet {
    public void initialize() {
    FontPaint font1 = new FontPaint();
    getContentPane().add(font1, BorderLayout.CENTER);
  }
 public static void main(String[] args) {
    FontPaint font2 = new FontPaint();
    JFrame frame = new JFrame("Outlining Font");
    frame.getContentPane().add(font2, BorderLayout.CENTER);
    frame.setSize(new Dimension(350200));
    frame.setVisible(true);
  }
}
class FontPaint extends JPanel {
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(Color.white);
    int w = getSize().width;
    int h = getSize().height;
    Graphics2D g2d = (Graphics2D) g;
  FontRenderContext fontRendContext = g2d.getFontRenderContext();
    Font font = new Font("Monotype Corsiva"250);
    String st = new String("Hello World.");
    TextLayout text = new TextLayout(st, font, fontRendContext);
    AffineTransform affineTransform = new AffineTransform();
    Shape shape = text.getOutline(null);
    Rectangle rect = shape.getBounds();
    affineTransform = g2d.getTransform();
    affineTransform.translate(w / - (rect.width / 2), h / 2
        + (rect.height / 2));
    g2d.transform(affineTransform);
    g2d.setColor(Color.red);
    g2d.draw(shape);
    g2d.setClip(shape);
  }
}

Output will be displayed as:

Download Source Code

 

                         

» View all related tutorials
Related Tags: c class orm form io method sed format 2d get ip translation return instance transform show for transformation to draw

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.