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



Interesting, thanks Seth.

And here's another complication; this problem affects each kind of component differently. With this JTextArea sample, the text looks ok, but if you try to select it with the mouse, you can see the problem immediately. This sample works fine on Windows:

import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.text.*;

public class ScaledFont
{
    public static void main(String[] args)
    {
        JTextArea text = new JTextArea();
        text.setLineWrap(true);
        text.setWrapStyleWord(true);
        AffineTransform a = AffineTransform.getScaleInstance(1.5,1.5);
        text.setFont(text.getFont().deriveFont(a));
        JScrollPane scroll = new JScrollPane(text);

text.append("Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.\n\n");
text.append("Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.\n\n");
text.append("But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth.\n");


        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(scroll, java.awt.BorderLayout.CENTER);
        f.setSize(400,400);
        f.setVisible(true);
    }
}


On 20-Mar-05, at 9:23 AM, Seth Tager wrote:

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
References: 
 >Re: Java-dev Digest, Vol 2, Issue 152 (From: Seth Tager <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.