🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: character spacing

#1719
From: Rich Wilkman
Date: Mon, 15 Oct 2001 17:16
54 lines
2854 bytes
Jeff:

Interesting!  How well does it work between serif and sans-serif fixed
fonts?

-Rich

Jeff wrote:
> 
> 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: <3BCB1A05.4CD709D2@formlessvoid.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!sfo2-feed1.news.digex.net!intermedia!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!out.nntp.be!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews
References: <3bc649f7$1_2@dnews> <3bc99a4b$1_1@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-15 10:27:59 PST
Message-ID: <3BCB1A05.4CD709D2@formlessvoid.com>
Date: Mon, 15 Oct 2001 10:16:53 -0700
From: Rich Wilkman <richw@formlessvoid.com>
Reply-To: richw@formlessvoid.com
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: Re: character spacing
References: <3bc649f7$1_2@dnews> <3bc99a4b$1_1@dnews>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 208.236.69.60
X-Trace: dnews 1003166211 208.236.69.60 (15 Oct 2001 10:16:51 -0700)
Lines: 54
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!sfo2-feed1.news.digex.net!intermedia!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!out.nntp.be!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews