Mailing Lists: Apple Mailing Lists

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

Font scaling using AffineTransform



Can anyone see why this doesn't work on the Mac?

We use AffineTransforms to scale fonts, so that when a user requests "8 point", it has a predictable meaning on all platforms and all screens. This works on all platforms we've tried this on (Windows, Linux, assorted UNIXes). But the Mac refuses to play along. This sample works as expected on my Windows box -- the text on the first button is SansSerif bold 12 point; the text on the second button is the same, scaled 2x both vertically and horizontally. On my PowerBook, the first button works as expected, and the second button is correctly scaled, but the text isn't visible. Any thoughts?

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;

import javax.swing.*;

public class MacFontTest
{
    public static void main(String[] p_argv)
    {
        JFrame frame = new JFrame("test");
        frame.getContentPane().setLayout(new FlowLayout());
        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);

        JButton normal = new JButton("Hello, world");
        Font f1 = new Font("SansSerif", Font.BOLD, 12);
        f1 = f1.deriveFont(AffineTransform.getScaleInstance(1.0, 1.0));
        normal.setFont(f1);

JButton scaled = new JButton("Hello, world");
Font f2 = f1.deriveFont(AffineTransform.getScaleInstance(2.0, 2.0));
scaled.setFont(f2);


        frame.getContentPane().add(normal);
        frame.getContentPane().add(scaled);
        frame.pack();
        frame.setSize(200,200);
        frame.show();
    }
}


For what it's worth, my PowerBook is up-to-date with OS X 10.3.8; this is the Java version:


java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-141.4)
Java HotSpot(TM) Client VM (build 1.4.2-38, mixed mode)

_______________________________________________
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


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.