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 Problem



I think you might be making this a lot harder than it needs to be?

I've looked at your code and I think you are misunderstanding the scale() method.  The scale() method does not "scale" what already has been drawn.  Rather it's a "transform" that affects what WILL be drawn.

Something like this:

// The paint method of a JPanel or similar SWING component.
public void paint(Graphics g) { 
    Graphics2D g2 = (Graphics2D)g.create();

    

    g2.setFont(new Font("Arial", Font.PLAIN, 12));

    

    // set to what ever scaling factor gets the font to the right size you need.
    g2.scale(0.5, 0.5); 

    

    // This position will be scaled too so you'll have to take that into account as well.
    // For example, assuming the example above with a 50% scaling in both vertical and
    // horizontal then a position of (100, 100) would be "transformed" to (50, 50).
    g2.drawString("Foobar", 100, 100);

    

    g2.dispose();
}

An alternative to this is to apply a transform directly to the font itself.  Take a look at Font.deriveFont(AffineTransform).  For the AffineTransform object you'd want something like AffineTransform.getScaleInstance(double, double) and pass that to deriveFont then use that font to do the drawing.  That way you don't have to apply the scale transform to the Graphics2D object so you don't have to worry about the scaling affecting the location.


On Aug 28, 2008, at 9:18 PM, xxxx xxxx wrote:

Thank you for the advice.  I tried it out, here are the results

I scaled it down before I wrote to it, and it had the output described earlier.
I scaled it down AFTERWARDS, and it plain ol' didnt scale the graphics2d object!! I tried to scale it twice after painting to it, but it also did not scale after painting to it..

Thanks though!


CC: email@hidden
From: email@hidden
To: email@hidden
Subject: Re: Font Problem
Date: Thu, 28 Aug 2008 20:40:19 -0400

Instead of drawing to the graphics2D and then scaling that down, try applying a scale transform to the graphics2d so that it draws the text the size you want it in the first place.


On Aug 28, 2008, at 7:52 PM, xxxx xxxx wrote:

hey guys,

I actually took the time today to narrow down my problem from something that contained a large number of classes, down to 2 classes that can display the problem.

I guess at this point Im looking for a little bit of help, or is it a lot of help?  Anyway, here's the issue ---

1.  I write text to a graphics2d object
2.  I scale the graphics2d object and print it to screen.
3.  The first | marks the mid-point of the scaled graphics2d image
4.  The '--Good--' designates one line of text that is printing out in the correct position - centered over the |
5. The '--Bad--' text designates the problem text - it is right aligned with the scaled graphics2d object, while it should also be centered over the pipeline - |

As a quick summary as to what is happening with the 'bad' text, the '--bad--' text SHOULD be centrally aligned to the '|', the midpoint of the scaled graphics2d object.  However, what seems to be causing the issue is that I am saving the font, and re-loading it from a file.  For some reason this seems to be causing the mis-alignment!  But the font is picked up correctly, and it even seems to calculate the print position correctly.

Anyway, I this only happens on mac computers, and I am developing on OSX 10.3.9 with java 1.4.2.

To set this up, put the "vfn" file in the running directory of the running program. The 2 files in testMe should be part of the testMe package, and the test main class should be run.

Thanks to anyone who takes a look at this!

Thanks


Be the filmmaker you always wanted to be—learn how to burn a DVD with Windows®. Make your smash hit <TestMe.zip> _______________________________________________
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



Talk to your Yahoo! Friends via Windows Live Messenger. Find Out How

 _______________________________________________
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 Problem (From: xxxx xxxx <email@hidden>)
 >Re: Font Problem (From: Galen Rhodes <email@hidden>)
 >RE: Font Problem (From: xxxx xxxx <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.