🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12357

Font problems (can't bold or italic!)

#12357
From: Kerry Sainsbury
Date: Thu, 14 Jan 1999 00:00
70 lines
2496 bytes
Hi Folks,

I can't figure out why I can't derive new fonts (from
GraphicsEnvironment.geAllFonts, for example)
and have them honour Font.ITALIC or Font.BOLD.

I'm starting to get desperate!

Here's some (complete) sample code to illustrate the problem - it
generates JPEG)

Thanks,
Kerry Sainsbury
Auckland, New Zealand
---------------------------------------


import java.awt.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
import java.io.*;

public class JPEGproof {
    public void drawDemo() {

      // Get a list of all available fonts
      GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
      Font[] f = ge.getAllFonts();

      // Build a buffered image that's big enough
      BufferedImage bi = new BufferedImage(600, f.length * 20,
BufferedImage.TYPE_USHORT_GRAY ); //TYPE_INT_RGB );

      Graphics2D big = bi.createGraphics();

      big.setColor(Color.white);

      // Loop through all available fonts, and put them in the image
      for (int fcnt = 1; fcnt < f.length; fcnt++) {
        System.out.println(fcnt + " " + f[fcnt].getFontName() );

        // Draw a regular font
  	  big.setFont(f[fcnt].deriveFont ( Font.PLAIN, 24));
	    big.drawString(f[fcnt].getFontName(), 4, (fcnt) * 20);

        // Draw an italic font (NOT!)
  	  big.setFont(f[fcnt].deriveFont ( Font.ITALIC, 24));
	    big.drawString(f[fcnt].getFontName(), 350, (fcnt) * 20);
      }

      // Stick the image into a JPEG
      try {
         File file = new File(".", "fonts.jpg");
         FileOutputStream out = new FileOutputStream(file);

         JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
         encoder.encode(bi);

      } catch (Exception ex) {
         System.out.println(ex.getMessage());
      }

    }

    public static void main(String[] args) {
        new JPEGproof().drawDemo();
//        System.exit(0);
    }
}
Technical Details
Message-ID: <369D8B9C.9AF9B88C@kcbbs.gen.nz>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,923d72c419e989d,start
X-Google-Attributes: gid111d45,public
From: Kerry Sainsbury <kerry@kcbbs.gen.nz>
Subject: Font problems (can't bold or italic!)
Date: 1999/01/14
Message-ID: <369D8B9C.9AF9B88C@kcbbs.gen.nz>
X-Deja-AN: 432439740
Content-Transfer-Encoding: 7bit
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing