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 / GUI / April 2005

Tip: Looking for answers? Try searching our database.

Default font trouble

Thread view: 
Jonas Svensson - 16 Apr 2005 12:15 GMT
Recently I upgraded from 1.4 to 1.5. Now I got a strange font trouble.
It seems like each line gets double height reserved and then the text is
only written in the upper half. See for example the "Avbryt" (cancel in
English)-button in the standard file dialogue here
<http://www.lysator.liu.se/~jonass/tmp/file.gif>. My java-version is
shown in <http://www.lysator.liu.se/~jonass/tmp/ek.gif>.

I have verified this with jdk 1.5, 1.5.0_01 and 1.5.0_02. The problem
seems to go away if I set default font explicit to Arial. Did I get a
bad Dialog-font somehow? Is there an actual Dialog-font, shouln't it be
substituted with Arial on Windows-systems?

Any suggestions?
John McGrath - 17 Apr 2005 18:16 GMT
> Any suggestions?

Post a runnable example of the problem.

Signature

Regards,

John McGrath

Jonas Svensson - 17 Apr 2005 19:11 GMT
>>Any suggestions?
>
> Post a runnable example of the problem.

Friends has already tried it for me and they can't reproduce the problem
so it is probably something on my system (like a broken font or such)
rather than an error in my source.

But sure, here is an example:
<http://www.lysator.liu.se/~jonass/tmp/foo.java> and precompiled
<http://www.lysator.liu.se/~jonass/tmp/file.class>

This is it:
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;

/**
 * An application ...
 */
public final class foo extends JPanel {
    public foo() {
    final JFileChooser chooser = new JFileChooser();
    final int returnVal = chooser.showOpenDialog(this);
    }

    public static void main(final String[] s) {
    final foo bar = new foo();
    }
}
John McGrath - 18 Apr 2005 21:03 GMT
> Friends has already tried it for me and they can't reproduce the problem
> so it is probably something on my system (like a broken font or such)
> rather than an error in my source.

Yes, there is nothing wrong with that program, save all of the extraneous
code in it.  An equivalent program would have been:

  public class foo {
     public static void main( final String[] args ) {
        new JFileChooser().showOpenDialog( new JPanel() );
     }
  }

You might try looking at the fonts that are created on your system - check
the attributes of the Font objects that are returned.  The Java toolkits
are set up to always return a valid font, depending on what is available.
It may be that different fonts are available on your system than on the
others you have tried.

Signature

Regards,

John McGrath

Jonas Svensson - 19 Apr 2005 19:21 GMT
> You might try looking at the fonts that are created on your system - check
> the attributes of the Font objects that are returned.  The Java toolkits
> are set up to always return a valid font, depending on what is available.
> It may be that different fonts are available on your system than on the
> others you have tried.

I can't see any difference in the attributes between the default font
and Arial which looks fine. Is there a way to see at runtime which
actual systemfont is used?
I got this output from the program below:

******  Default font   ******
Family:Dialog
FontName:Dialog.plain
Name:Default
PSName:Dialog.plain
toString:javax.swing.plaf.FontUIResource[family=Dialog,name=Default,style=plain,size=11]
attr:java.awt.font.TextAttribute(family)=Default
attr:java.awt.font.TextAttribute(superscript)=0
attr:java.awt.font.TextAttribute(posture)=0.0
attr:java.awt.font.TextAttribute(transform)=java.awt.font.TransformAttribute@9cab16
attr:java.awt.font.TextAttribute(size)=11.0
attr:java.awt.font.TextAttribute(weight)=1.0
attr:java.awt.font.TextAttribute(width)=1.0

******  Arial font   ******
Family:Arial
FontName:Arial
Name:Arial
PSName:ArialMT
toString:javax.swing.plaf.FontUIResource[family=Arial,name=Arial,style=plain,size=11]
attr:java.awt.font.TextAttribute(family)=Arial
attr:java.awt.font.TextAttribute(superscript)=0
attr:java.awt.font.TextAttribute(posture)=0.0
attr:java.awt.font.TextAttribute(transform)=java.awt.font.TransformAttribute@9cab16
attr:java.awt.font.TextAttribute(size)=11.0
attr:java.awt.font.TextAttribute(weight)=1.0
attr:java.awt.font.TextAttribute(width)=1.0

This is the program I used to list the attributes:

import java.awt.Font;
import java.util.Set;
import java.util.Iterator;

public final class foo {
    private static void dumpFont(Font f) {
    javax.swing.plaf.FontUIResource fr = new
javax.swing.plaf.FontUIResource(f);
    System.out.println("Family:"+fr.getFamily());
    System.out.println("FontName:"+fr.getFontName());
    System.out.println("Name:"+fr.getName());
    System.out.println("PSName:"+fr.getPSName());
    System.out.println("toString:"+fr.toString());

    java.util.Set attrs = f.getAttributes().entrySet();
    java.util.Iterator i = attrs.iterator();
    while(i.hasNext()) {
       Object foo = i.next();
       System.out.println("attr:"+foo);
    }
    }

    public static void main(final String[] s) {
    System.out.println("******  Default font   ******");
    java.awt.Font f = new java.awt.Font(null, java.awt.Font.PLAIN, 11);
    dumpFont(f);

    System.out.println("\n******  Arial font   ******");
    f = new java.awt.Font("Arial", java.awt.Font.PLAIN, 11);
    dumpFont(f);
    }
}
John McGrath - 20 Apr 2005 21:00 GMT
> I can't see any difference in the attributes between the default font
> and Arial which looks fine.

Sorry - I meant to say the font metrics.  In particular, I would look at
the font height, ascent, max ascent, descent, and max descent values.

> Is there a way to see at runtime which actual systemfont is used?  

Not that I know of, but you can look at what is supposed to be used.  The
font configuration files can be found in the JRE/lib directory.  They seem
to have changed between Java 1.4 and 1.5.

In Java 1.4, the font configuration comes from the file "font.properties".
I am not sure how the files for other locales (i.e. "font.properties.ru")
are used.  It may be that file is selected based on the locale, or it may
be that you need to rename the file to have it take effect.

In Java 1.5, it looks like the default font configuration comes from the
code .  The JRE/lib directory does contain a number of files with the
extension ".properties.src", including "fontconfig.properties.src".  If
you copy that file to "fontconfig.properties", the JRE reads the
configuration from that file.  You might try renaming that file, and see
if it makes a difference.

Signature

Regards,

John McGrath

Jonas Svensson - 21 Apr 2005 20:57 GMT
> Sorry - I meant to say the font metrics.  In particular, I would look at
> the font height, ascent, max ascent, descent, and max descent values.

Now there we got it! For all the java-fonts, the height is about double
what it should be and about all the extra height is used by "leading".
Renaming fontconfig.properties.src to fontconfig.properties did not seem
to make any difference. I can't see leading beeing mentioned anywhere in
that file so maybe that wasn't so surprising. Now is the question how
could be and what do I do about it?

Also, Thanks for all the help!

******  Default font   ******
Family:Dialog
FontName:Dialog.plain
Name:Default
PSName:Dialog.plain
toString:javax.swing.plaf.FontUIResource[family=Dialog,name=Default,style=plain,size=1]
attr:java.awt.font.TextAttribute(family)=Default
attr:java.awt.font.TextAttribute(superscript)=0
attr:java.awt.font.TextAttribute(posture)=0.0
attr:java.awt.font.TextAttribute(transform)=java.awt.font.TransformAttribute@9cab16
attr:java.awt.font.TextAttribute(size)=1.0
attr:java.awt.font.TextAttribute(weight)=1.0
attr:java.awt.font.TextAttribute(width)=1.0
ascent              = 0.92163086
descent             = 0.2109375
height              = 2.1243896
leading             = 0.9918213
StrikethroughOffset = -0.36865234
UnderlineOffset     = -0.92419624
ROMAN_BASELINE

******  Arial font   ******
Family:Arial
FontName:Arial
Name:Arial
PSName:ArialMT
toString:javax.swing.plaf.FontUIResource[family=Arial,name=Arial,style=plain,size=1]
attr:java.awt.font.TextAttribute(family)=Arial
attr:java.awt.font.TextAttribute(superscript)=0
attr:java.awt.font.TextAttribute(posture)=0.0
attr:java.awt.font.TextAttribute(transform)=java.awt.font.TransformAttribute@9cab16
attr:java.awt.font.TextAttribute(size)=1.0
attr:java.awt.font.TextAttribute(weight)=1.0
attr:java.awt.font.TextAttribute(width)=1.0
ascent              = 0.92163086
descent             = 0.19555664
height              = 1.1499023
leading             = 0.032714844
StrikethroughOffset = -0.36865234
UnderlineOffset     = -0.92419624
ROMAN_BASELINE
John McGrath - 22 Apr 2005 04:20 GMT
> Now there we got it! For all the java-fonts, the height is about double
> what it should be and about all the extra height is used by "leading".

Hmmmm.  I am a little less pleased by those results than you are.  It
looks like you have two different java.awt.Font objects with different
metrics, both based on the same system font.  I do not know enough about
how Java fonts work to understand what would cause that.

One thing that would be interesting would be to change the configuration
so that the Dialog logical font mapped to a different Windows font, such
as Times New Roman, and then see whether the Default font has extra
leading.  I suspect it will, but who knows?

Signature

Regards,

John McGrath



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.