Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  using fonts problem  (Read 943 times)
0 Members and 1 Guest are viewing this topic.
Offline VirtuaCasper

Junior Newbie




Java games rock!


« Posted 2006-04-28 11:05:48 »

im having problems trying to load a font and display a string. all i seem to get is a little red blob.
heres the source code.

import java.io.*;
import java.awt.*;
import java.awt.event.*;

// font found @ http://www.1001fonts.com/fonts/win/ttf/2932/myscars.zip

class FrameResponce extends WindowAdapter
{
   public void windowClosing(WindowEvent e)
   {
      System.exit(0);
   }
}

class FrameExt extends Frame
{
   private Font gameFont;

   public FrameExt()
   {
      try
      {
         gameFont = Font.createFont(Font.TRUETYPE_FONT,new File("MYSCARS_.ttf"));
         
         setTitle("Font Test");
         setSize(640,480);
         setResizable(false);
         addWindowListener(new FrameResponce());
         setVisible(true);
      }
      catch(Exception e)
      {
         System.out.println("*** Exception ***");
         System.out.println("Message: "+e.getMessage());
         System.out.println("Cause:   "+e.getCause());
         System.exit(0);
      }
   }
   
   public void paint(Graphics g)
   {
      g.setColor(Color.black);
      g.fillRect(0,0,getWidth(),getHeight());
      g.setColor(Color.red);
      g.setFont(gameFont);
      gameFont.deriveFont(64.0f);
      g.drawString("Loading...",getWidth()/2,getHeight()/2);
   }
}

class FontTest
{
   public static void main(String arg[])
   {
      FrameExt fext = new FrameExt();
   }
}
Offline Kova

Senior Member





« Reply #1 - Posted 2006-04-28 12:20:14 »

first of all
1  
use code tags


second, for your font to display correctly you need to:

a) have a true type font (.ttf) or adobe type1 font.
b) make sure that font has unicode support (must contain a unicode glyphe map)

It's probably unicode problem.
was trying to use custom (non-system) font few days ago and I was greatly dissapointed. I mean if font dosen't support unicode why not properly display things that it supports? I don't even need something other then standard english letters. Anyway I was told to search for some converter that would convert font to unicode one, I didn't searched yet.
Offline VirtuaCasper

Junior Newbie




Java games rock!


« Reply #2 - Posted 2006-04-30 19:38:04 »

i have fixed the problem by placing the above font in c:\windows\font folder and then replacing Font.createFont with the Font contstructor and now it works fine.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Kova

Senior Member





« Reply #3 - Posted 2006-04-30 21:24:33 »

well it might work but it's not a solution since you put stuff into user's windows folder... but since it works that means createFont() should work also (or  Huh). I have the font in fonts directory and it dosen't work.
Offline woogley
« Reply #4 - Posted 2006-04-30 21:43:22 »

you might as well just bitmap the entire font and then just draw each letter as an image. that will give you a boost in FPS anyway ..
Offline Kova

Senior Member





« Reply #5 - Posted 2006-05-01 01:32:43 »

that's a good idea, but it would be pain in the ass to cut out all characters in good size and there's always font size problem.
Actually since I don't have any important runtime created text I was planning to do all text in photoshop and then use pictures (if I don't find proper unicode font).
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (15 views)
2014-07-24 01:59:36

Riven (14 views)
2014-07-23 21:16:32

Riven (13 views)
2014-07-23 21:07:15

Riven (15 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!