🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #707

Font Scaling problem on rotation with JDK 1.4.1

#707
From: Alex Waller
Date: Thu, 27 Feb 2003 23:07
200 lines
7298 bytes
Hello,

    I realized that I posted this to the wrong newsgroup. It is better
suited for the  API newsgroup ... more specifally Graphics2D.

    I'm using JBuilder 7 Personal Edition on a Windows 2K system. Up
until recently I've been using the JBuilder 1.3.1 JDK. I down loaded
Sun's JDK 1.4.1 and configured the JDK via the Tool menu. I've
discovered a big difference in the way rotated text gets scaled. I've
tried searching the Borland archives but have not found anything
pertaining to this particular problem with fonts.
    The 1.3.1 JDK seems to do a much better job at rendering rotated
text when one makes a window (or panel) long and narrow (the text looks
stretched but not ugly). I have some plotting code which can create
several (plot) panels on a window and this long, narrow plot can be
exactly my situation. The rotated text is the Y-axis label. The 1.4.1
JDK from Sun does not seem to scale very nicely at all. There sometimes
are large gaps between characters in words. Sometimes single characters
within words are much larger than others. Sometimes (depending on how
the panel gets sized) the letters turn out all blotchy. Really ugly.
I've also checked the Sun site and have not seen any mention of this
problem.
    Last evening I tried this on my Macintosh at home. Here we have
another non Sun 1.3.1 JDK but on a different platform. It worked pretty
much like the Borland 1.3.1 JDK on the Windows platform at work. (A nit
picking difference has to do with improper clipping of the text on the
Mac platform with my test program but I'm not worried right now about
that problem on the Mac.)
    Some extra added info that might help. It seems to be associated
with the screen rendering of fonts. A plot procedure that I have can
print several (plot) panels (JPanel) that are in a window to a single
page. The rotated fonts seem to come out OK on the printer under JDK
1.4.1 (again they looked stretched out but not illegible).
    I include source code below which demonstrates this problem. After
the window is displayed make the window long and narrow and watch what
happens to the rotated (Y-axis) text.
    ... or this all work OK for others??

    -Thanks in advance, Alex Waller
/*
   FontScalingProblem.java
*/
package fontscalingproblem;

import javax.swing.UIManager;
import java.awt.*;

/**
 * <p>Title: FontScalingProblem</p>
 * <p>Description: Minimal Demonstration of JDK 1.4.1 Font Scaling
Problem</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author A. M. Waller
 * @version 1.0
 */

public class FontScalingProblem
{
  private boolean packFrame = false;

  //Construct the application
  public FontScalingProblem()
  {
    Frame1 frame = new Frame1();
    //Validate frames that have preset sizes
    //Pack frames that have useful preferred size info, e.g. from their
layout
    if (packFrame)
    {
      frame.pack();
    }
    else
    {
      frame.validate();
    }
    //Center the window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height)
    {
      frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width)
    {
      frameSize.width = screenSize.width;
    }
    frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
    frame.setVisible(true);
  }
  //Main method
  public static void main(String[] args)
  {
    try
    {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
    new FontScalingProblem();
  }
}
/*
   Frame1.java
*/
package fontscalingproblem;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * <p>Title: FontScalingProblem</p>
 * <p>Description: Minimal Demonstration of JDK 1.4.1 Font Scaling
Problem</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author A. M. Waller
 * @version 1.0
 */

public class Frame1 extends JFrame
{
  private JPanel contentPane;
  private BorderLayout borderLayout1 = new BorderLayout();

  private static final int LABEL_PT_BASE = 36;
  private static final int windowWidth = 850, windowHeight = 850;
  private static final Font labelFont = new Font( "SansSerif",
Font.PLAIN, LABEL_PT_BASE );
  private double baseWidth, baseHeight;

  //Construct the frame
  public Frame1()
  {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception
  {

//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your

Icon]")));
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    baseWidth = windowWidth; baseHeight = windowHeight;
    this.setSize(new Dimension(windowWidth, windowHeight));
    this.setTitle("Font Rotation and Scaling Problem");
  }
  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e)
  {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING)
    {
      System.exit(0);
    }
  }

  public void paint( Graphics g )
  {
    double xScale, yScale;

    super.paint( g );

    Dimension windowSize = this.getSize();
    Graphics2D g2d = (Graphics2D)g;
// Antialias text. Is fractional metrics necessary?
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
// Set current scale from original base setting
    xScale = windowSize.width / baseWidth; yScale = windowSize.height /
baseHeight;
    g2d.scale( xScale, yScale );
// Set font
    g2d.setFont( labelFont );
    g2d.drawString( "A quick Brown Fox jumped over the lazy Dog.", 75,
800 );
// Rotate -90 degrees (Y axis label)
    g2d.rotate( Math.toRadians( 270 ) );
    g2d.drawString( "A quick Brown Fox jumped over the lazy Dog.", -800,

75 );
  }
}
Technical Details
Message-ID: <3E5E9A3D.579AEE93@fnal.gov>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!easynet-quince!mango.news.easynet.net!easynet.net!easynews.net!newsfeed3.easynews.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,cf44819e3d9d8f62,start
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2003-02-27 15:09:38 PST
Message-ID: <3E5E9A3D.579AEE93@fnal.gov>
Date: Thu, 27 Feb 2003 17:07:41 -0600
From: Alex Waller <waller@fnal.gov>
Organization: Fermilab
X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.api
Subject: Font Scaling problem on rotation with JDK 1.4.1
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 131.225.130.145
X-Trace: newsgroups.borland.com 1046387259 131.225.130.145 (27 Feb 2003 15:07:39 -0800)
Lines: 200
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!easynet-quince!mango.news.easynet.net!easynet.net!easynews.net!newsfeed3.easynews.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail