🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: character spacing

#1713
From: Jeff
Date: Sun, 14 Oct 2001 13:59
46 lines
2449 bytes
I spent a lot of time researching affine transforms.  Found an excellent
site that describes how to rotate, stretch and skew text:

http://www.glyphic.com/transform/

While fooling around with what I found there, I finally came up with
this solution.  It works for two reasons -- 1) I'm working with a
fixed-pitch font, and 2) the text is not editable.  If either of these
points did not apply, a bunch more work would be needed.  I start by
creating a class called ExpandedLabel, which extends JComponent.  Then,
I override the paintComponent method with this:

 public void paintComponent(Graphics g) {
  // Define font used to draw text.
  Font f = new Font("Monospaced", Font.PLAIN, 12);
  g.setFont(f);

  // Calculate baseline origin so text is centered vertically.
  FontMetrics fm = g.getFontMetrics(f);
  int originX = 10;
  int originY = getHeight()/2 + fm.getHeight()/2 - fm.getDescent();

  // Print text with padding between each character.
  char [] textChars = this.text.toCharArray();
  int emSpace = fm.charWidth(77);
  for (int i = 0; i < this.text.length(); i++) {
   g.drawChars(textChars, i, 1, originX + ((emSpace + 2) * i), originY);
  }
 }

Aside from the fact that too many factors are hard-coded (font,
character padding, x-inset, etc), any constructive criticism is welcome.

- Jeff


"Jeff" <mevyap@hotmail.com> wrote in message news:3bc649f7$1_2@dnews...
> I have a string of characters in a fixed-pitch font.  I'd like to add
a
> pixel or two of space between each character, but just can't figure
out how
> to do it.
>
> - Jeff
>
>
Technical Details
Message-ID: <3bc99a4b$1_1@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews
References: <3bc649f7$1_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,a2b03a6d9808c012
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2001-10-14 07:03:28 PST
Reply-To: "Jeff" <mevyap@hotmail.com>
From: "Jeff" <mevyap@hotmail.com>
Newsgroups: borland.public.jbuilder.java.api
References: <3bc649f7$1_2@dnews>
Subject: Re: character spacing
Date: Sun, 14 Oct 2001 09:59:40 -0400
Lines: 48
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 66.20.183.69
Message-ID: <3bc99a4b$1_1@dnews>
X-Trace: dnews 1003067979 66.20.183.69 (14 Oct 2001 06:59:39 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews