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-dev Digest, Vol 2, Issue 152



Your numbers aren't quite right. (they're off by a pixel for scale by
2. I did it for 3 and 4 as well and got:
scale, x translate, y translate
2, -7, -13
3, -4.5, -12.5
4, -3.5, -12

The formula is not obvious to me. Maybe some other math wizard will see it.
Here's modified code that makes it easier to play around with using

java MacFontTest scale positiveXOffset positiveYOffset

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);
     
     double scale = Double.valueOf(p_argv[0]).doubleValue();

     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(scale, scale);
     a.translate(-Double.valueOf(p_argv[1]).doubleValue(),-Double.valueOf(p_argv[2]).doubleValue());
// 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,(int)  (12 * scale));
     larger.setFont(f3);

     frame.getContentPane().add(normal);
     frame.getContentPane().add(scaled);
     frame.getContentPane().add(larger);
     frame.pack();
     frame.setSize((int) (100 * scale),(int) (100 * scale));
     frame.show();
   }
}



On Sat, 19 Mar 2005 12:07:18 -0800 (PST), Jim Douglas <email@hidden>
 wrote:
> 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.
 _______________________________________________
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.