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: Font scaling using AffineTransform



You were right, Wilhelm. It appears that the text isn't visible because it has been shifted completely outside the bounds of the component. Applying an (apparently arbitrary?) translation drags it back to where it should have been:

import java.awt.*;
import java.awt.geom.*;
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);

        Font f = new Font("SansSerif", Font.BOLD, 12);
        AffineTransform a;

        JButton normal = new JButton("Hello, world");
        normal.setOpaque(false);
        a = AffineTransform.getScaleInstance(1.0, 1.0);
        Font f1 = f.deriveFont(a);
        normal.setFont(f1);

        JButton scaled = new JButton("Hello, world");
        scaled.setOpaque(false);
        a = AffineTransform.getScaleInstance(2.0, 2.0);
        a.translate(-6.5,-13); // Why??????????
        Font f2 = f.deriveFont(a);
        scaled.setFont(f2);

        JButton larger = new JButton("Hello, world");
        larger.setOpaque(false);
        Font f3 = new Font("SansSerif",Font.BOLD,24);
        larger.setFont(f3);

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

I can't work out any coherent rules for what translation to apply in any situation, so this doesn't seem to be the basis for a workaround.


On 18-Mar-05, at 4:59 PM, Wilhelm Fitzpatrick wrote:


On Mar 18, 2005, at 4:54 PM, Jim Douglas wrote:

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

We use AffineTransforms to scale fonts,
...
On my PowerBook, the first button works as expected, and the second button is correctly scaled, but the text isn't visible. Any thoughts?

I wrote some code to manipulate text via AffineTransforms a few months ago and found that under 1.4 on the Mac, not only would it scale the text but it would also radically reposition it within the drawing area. I'm guessing your text isn't visible because it's been moved out the visible part of your drawing area. I'm pretty sure this has to be a bug.


However, everything thing seemed to work correctly under 1.3 on the Mac.

-wilhelm


_______________________________________________ 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


_______________________________________________ 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: 
 >Font scaling using AffineTransform (From: Jim Douglas <email@hidden>)
 >Re: Font scaling using AffineTransform (From: Wilhelm Fitzpatrick <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.