Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Java 5 Bold Font Rendering for GlyphVectors



My last source example was a bad example. Below is a simple example that shows getting Arial-Bold from the system fonts array. On Java 5 Mac it will render Arial-Bold plain whereas everywhere else it renders fine.

jeff


On Jan 3, 2006, at 5:15 PM, Jeff Martin wrote:

Bold fonts in my page layout application started failing under Java 5 on the mac. My app searches the system fonts for something like Arial-Bold, but when I make a glyph vector out of it, it renders as plain.

My theory is that the system fonts are being created with new Font (name, Font.PLAIN) and that is confusing Java 5 on the Mac. My test case below at least shows that Java 5 Mac behaves differently than all other platforms/versions I've used, though I've always been confused as to how the style flag conflicts with font names. On Java 5 Mac, it draws the first Arial Bold text as plain - everyone else draws it as bold. I don't know how to determine if the system fonts from GraphicsEnvironment.getAllFonts is creating fonts with Font.PLAIN.

Anyone else seen something similar? If not, I'll file a bug.

jeff

import java.awt.*; import java.awt.font.*;

public class Test {

public static void main(String args[])
{
    // Create frame
    javax.swing.JFrame frame = new javax.swing.JFrame();
    frame.setSize(300, 300);

    // Create content pane
    frame.setContentPane(new javax.swing.JComponent() {

        // Custom draw some text
        public void paintComponent(Graphics g) {

            // Get graphics 2d and font render context
            Graphics2D g2 = (Graphics2D)g;
            FontRenderContext c = g2.getFontRenderContext();

            // Draw Hello World Arial
            Font f1 = new Font("Arial", Font.PLAIN, 12);
            g.setFont(f1);
            GlyphVector gv1 = f1.createGlyphVector(c, "Hello World");
            g2.drawGlyphVector(gv1, 10, 20);

// Find Arial Bold from system fonts
Font fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
Font f2 = null;
for(int i=0; i<fonts.length && f2==null; i++)
if(fonts[i].getFontName().equals("Arial-BoldMT"))
f2 = fonts[i].deriveFont(12f);


            // Draw Hello World Arial Bold
            g.setFont(f2);
            GlyphVector gv2 = f2.createGlyphVector(c, "Hello World");
            g2.drawGlyphVector(gv2, 10, 40);
        }
    });

    // Show frame
    frame.show();
}

}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Odd classloader exception (From: Michael Hall <email@hidden>)
 >Java 5 Bold Font Rendering for GlyphVectors (From: Jeff Martin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.