Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2005

Tip: Looking for answers? Try searching our database.

Font Creation from TTF file in JDK 1.3

Thread view: 
Sameer - 08 Mar 2005 17:17 GMT
Hello,

In JDK1.5.0 there is a static method in Font class having syntax

Font.createFont(int fontFormat, File fontFile).

This let you create a font using the supplied font file.
Thus it is not necessary whether a particular font is installed on the
machine, we can use font created by this method(?).

The method available previously (in 1.3) has the syntax:

Font.createFont(int fontFormat, InputStream fontStream).

Can we use the functionality of JDK 1.5 in JDK 1.3?
i.e Can we get the InputStream from the TTF file and pass it to the
function to work it like the function available in 1.5 and create a new
Font?

If it is possible, how to do it?
Please help me ASAP.
-Sameer
Thomas Weidenfeller - 09 Mar 2005 10:42 GMT
> Can we use the functionality of JDK 1.5 in JDK 1.3?
> i.e Can we get the InputStream from the TTF file and pass it to the
> function to work it like the function available in 1.5 and create a new
> Font?

Yes. Why didn't you just try it?

> Please help me ASAP.

ASAP? But you couldn't be bothered to write ten lines of code to try it?

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

Sameer - 12 Mar 2005 10:01 GMT
Dear Sir,
I created the font using the method createFont using JDK1.3 and apply
it to a JTextField, but the text displayed is toooo small. Why is it
so? The method font.deriveFont(int) is used and given a big value...
still the text was not displaying.
What may be the problem?
Sameer - 09 Mar 2005 14:08 GMT
Thank you very much for this 'Brain Washing'. I will definately try to
write the code for the same. But I am not confident whether it will
work or not so I want assistance from expert peoples like you and I
just tried whether anybody is kind enough to give me lines for the
same.
-Sameer
Viator - 09 Mar 2005 18:13 GMT
Here are the lines!
try{
   Font font=Font.createFont(yourFormat,new
FileInputStream(yourFontFile));
}catch(Exception e){
  playWith(e);
}//end try catch
Sameer - 10 Mar 2005 13:54 GMT
Here is the code:
------------------------------

import java.io.*;
import javax.swing.*;
import java.awt.*;

//using JDK 1.3
public class FontTest {
   public static void main(String args[]) {
       JFrame app= new JFrame("Font Test");
       JLabel jl= new JLabel("Hello World");
       app.setVisible(true);
       app.setSize(400,400);
       app.getContentPane().add(jl);
       app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       Font f=null;
       try {
           //A fontfile for the regional language Marathi(Devnagari)
in India
           FileInputStream fis= new
FileInputStream("c:\\winnt\\fonts\\krdev050.ttf");
           f= Font.createFont(Font.TRUETYPE_FONT,fis);
       } catch (FontFormatException ffe) {
           System.out.println(ffe);
       } catch (IOException ioe) {
           System.out.println(ioe);
       }
       jl.setFont(f.deriveFont(Font.BOLD,150));
       // You will see something in the language Marathi in the frame
   }
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.