Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Derived fonts

Status
Not open for further replies.

JackMH

Programmer
Nov 9, 2001
18
US
I have some Java code that is essentially, as follows:

AffineTransform _1 = AffineTransform(getScaledInstance(1.2, 1.1);

Font f1 = (new Font("Dialog", Font.BOLD, 12)).deriveFont(_1);
...

if (...)
f1 = f1.deriveFont(AffineTransform.getRotateInstance(Math.toRadian(90));

...

setFont(f1)


All works well when the if condition is false, the font is scaled appropriately. However when the if condition is true while the font rotation occurs correctly the size appears to be the base 12pt font, it is *not* scaled. It as if the method deriveFont() does not actually create a new transformed font but merely sets a property of the font object and the transformation occurs when the font is used. Thus when deriveFont() is invoked for the second time that property is changed and the initial transformation is lost.

If you have any insight as to how best dela with this situation it would be greatly apperciated if you would let me know.
 
Maybe you could 'use' the font in some way before the if to force it to 'create' the new font at that point. Then the second deriveFont might work.

I've no idea if this will work, or if the behaviour of deriveFont is actually as it seems from your example, but it's worth a try.

Tim
 
... however, looking at Sun's source for java.awt.Font (JDK1.4) the defineFont method does indeed appear to store the transform as an attribute in the new Font.

Maybe another way would be to check if the font already has a transformation in your if clause and if so then get this from the font (getTransform) and somehow combines it with the new transformation. Without checking I'm not sure how transforms could be combined, but I know mathematically that this is possible.

Tim
 
Instances of the AffineTransform class can be concatenated.

Tim
 
Tim,

Thanks for the research and advice. Since there is a Font getTransform() method your suggestion will likely work. I will give it a shot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top