Unicode labels, fonts for components?

R

Roedy Green

As far as I know, Microsoft didn't write the JRE implementation. I don't
see how they are responsible.

Because in AWT, Java uses the native widgets. If they have strange
behaviours, Java exhibits them. In Swing, Java uses basically asks the
OS to render a rectangle of bits. It does not use the native widgets.
It does its own font rendering. Further it just gets the screen X,Y
and figures out itself which widget a mouse click applies to.

The look and feel is Spartan in AWT, the intersection of what native
widgets on all platforms support. For your application Swing would
give you the font and L&F control you desire. Today, AWT apps are
rare. Why are you using AWT?
 
R

Roedy Green

I'm not interested in subclassing any controls just so that I can use
Canvas.drawString() to display the text in the control. So again, the web
page you directed me to still seems to suggest that I cannot set the
Button control's font to any arbitrary font, and in particular I can't set
it to something that will display these characters.

That is correct. If you insist on using unsubclassed AWT components
you are limited to the 5 logical fonts.

The usual way out of this fix is to use Swing which lets you use most
of the supported fonts. The essay gives details of which ones.

The masochists way out is to use AWT and drawString. See
http://mindprod.com/jgloss/canvas.html
http://mindprod.com/products2.html#JDISPLAY
http://mindprod.com/products2.html#SCREWS

There is no reasonable way to use other fonts on AWT components.
 
R

Roedy Green

All due respect, and I do appreciate you sharing your thoughts on the
page, but you directed to me to a very specific part of that page,

I also twice sent you to the whole page.
 
P

Peter Duniho

I also twice sent you to the whole page.

Um, well if by "twice" you include the page in which you complain that I
didn't read the whole page. That seems like a silly inclusion to me. And
the only other time was in a post that I read after reading your complaint.

I think you've got your britches in a bunch over nothing, personally. I
guess if you want to get all insulted though, that's your choice.
 
W

Wayne

Roedy said:
I explain all this at http://mindprod.com/jgloss/font.html

the rules are different for
AWT components
AWT drawString
Swing

Then there is the matter of whether you can have anti-aliasing.

Most people use Swing nowadays where you have the most flexibility
with Fonts.

Roedy,

I have some updates for your font page:

I used the following on a Linux Fedora 8 system today:

<sscce>
import java.awt.*;
import java.awt.event.*;

public class FontLister {
public static void main ( String [] args ) {
Frame frame = new Frame( "AWT Font Lister" );
frame.setSize( 800, 900 );
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent we ) {
System.exit( 0 );
}
});
Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getAllFonts(); // A list of all Fonts, at 1 pt PLAIN.
int length = fonts.length;
if ( length > 82 ) length = 82; // Limit on Fedora 8 ???
Panel p = new Panel();
p.setLayout( new GridLayout(length, 0) );

for ( int i = 0; i < length; ++i ) {
String s = fonts.getFontName() + " - "
+ fonts.getFamily() + " (" + fonts.getName() + ")";
Label l = new Label( s );
l.setFont( fonts.deriveFont( 12.0f ) );
p.add( l );
}
ScrollPane sp = new ScrollPane();
sp.add( p );
frame.add( sp );
frame.setVisible( true );
}
}
</sscce>

As you can see this is pure AWT. Each Component (Label) is
drawn using a different Font. All my fonts (~195) are found,
but for some reason if I add more than 82 to the Panel, the
"frame.setVisible( true );" statement throws an
ArrayIndexOutOfBoundsException. (Using Sun JDK 1.6.)

But the 82 fonts display fine!

So it seems the AWT limit for logical fonts applies only to
Windows (I tested only on Windows XP).

Also it seems my TrueType fonts work on Fedora 8 as well.
I have to check into that more carefully before I'm
certain which font file formats work.

-----------
"You can simply the cache, sacrifice a small reptile and reboot."
I think you meant "...simply delete the cache, ...".
-----------
"If you want to include custom fonts in your application, you either
have to get the customer to install them or uses this trick to use
them directly from a jar."

"uses" should be "use".
-----------
canDisplay() doesn't actually "lie". I believe it is implemented by
checking to see if a code point is within the range covered by
that font. The problem is fonts are not required to provide
glyphs for each code point in the range they claim to cover.
-----------

I'd like to see you start a JSR for updating the specs to include
minimal font, graphic, and system standard sounds (and encodings).
The platform-dependencies and lack of methods to work around these
limitations is very annoying and confusing.

-Wayne
 
R

Roedy Green

I'd like to see you start a JSR for updating the specs to include
minimal font, graphic, and system standard sounds (and encodings).
The platform-dependencies and lack of methods to work around these
limitations is very annoying and confusing.

It would be nice to have a standard set of icons, perhaps customised
to the platform, ditto standard sounds.

I have added your notes.

Is this just Fedora? All 1.6 Linux? When did they develop this
ability or have they always had it?

Any way, my latest cut is available at
http://mindprod.com/jgloss/font.html
 
W

Wayne

Roedy said:
...
Is this just Fedora? All 1.6 Linux? When did they develop this
ability or have they always had it?

AFAIK:
I would say it has less to do with the distro or Linux version,
and more to do with the X window server. The earliest ones
only supported very limited types of fonts, in the B.J.
(before-Java) era. Some years ago the XFree86 X window
server added support for XFS, the X font server. That
added some TrueType support.

The current X server shipped with Fedora is a re-write of
XFree86 called xorg. This is the one I tested with and
that does support (apparently) all available fonts for
either swing or AWT, including AWT components.

XFree86 still exists, so it is possible some Linux systems
still use it. Or BSD Unix systems such as FreeBSD I don't
know which X server / font server is used.

I suppose a font lister could be made into a clickable jar,
and a link to it posted in various Linux/Unix groups with a
request to run it and report the results (OS and version,
X server and version, and if the fonts displayed correctly.

Hope that helps!

-Wayne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Positioning CSS components 1
Unicode fonts in Java 3
Custom fonts 11
Fonts 4
problem with java displaying unicode, under ms-windows 13
I need help fixing my website 2
Components 5
How can I add arrows to my FAQ 0

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top