Font.deriveFont does work and is the only supported way to get a different
size or style from a Font loaded by Font.createFont.
Any other mechanism that works is working by pure fluke, and may stop working
at any time.
The problem you are seeing is that you are using the wrong case of
deriveFont.
Note we have (amongst others), these two deriveFont methods:
Font.deriveFont(float size)
Creates a new Font object by replicating the
current Font object and applying a new size to it.
and
Font.deriveFont(int style)
Creates a new Font object by replicating the
current Font object and applying a new size to it.
you should be calling the former, but are calling the latter which
is intended to be called with a style like Font.ITALIC which is an int.
You need to use 12.0f to get the floating point case which changes the
size.
-phil.
> Date: Fri, 6 Apr 2001 18:19:38 +0600
> From: Sellathurai Selvaratnarajah <[EMAIL PROTECTED]>
> Subject: [JAVA2D] Dynamic Font Loading-Fails
> To: [EMAIL PROTECTED]
>
> I use JDK1.3 winNT. JDK1.3 claims that it can load fonts dynamically.
>
> The problem I have is I am unable to use this feature because by default
> Font.createFont() method returns a font with size=1. But when I tried to
> change the size by deriveFont(int size) method I doesn't change the
size too.
> Only place where it works correctly is when I tried to get the font family
> name by getFamily(). It works as expected.
>
> Has anyone tried this? did it work? is it a known bg?
> Any information regarding this will be appreciated.
> Thanks in advance,
> Rajan
> ====
> P.S: The code fragment I tried is as follows:
>
> FileInputStream in=null;
> Font myFont =null;
>
> try{
> in = new FileInputStream("Sri-tsc.ttf");
> myFont = Font.createFont(Font.TRUETYPE_FONT,in);
>
>
> }
> catch(Exception ex)
> {
> System.out.println(ex);
> }
> System.out.println(myFont.getSize()); // size 1
> System.out.println(myFont.getFamily());
> myFont = myFont.deriveFont(12);
> System.out.println(myFont.getSize()); // even this is size
one
>
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".