🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #5827

How find width of prop. Font character?

#5827
From: Lee_Robert_Willis
Date: Sun, 14 Oct 1990 00:24
59 lines
2280 bytes

Does anyone know how to find the width of a single character within 
a proportional font, without using 'TextLength()'?  (The font/character 
pair may not be the current font of the RastPort.) 

Using the RKM section on Text (1.3 Chapter 24), I constructed the
following function.  It checks if the font is proportional or not,
If it is, it then returns the sum of 'tf_CharSpace' + 'tf_CharKern' 
for the supplied character 'c'.  

Unfortunately, this does not appear to be correct.  It comes close,
but I appear to be short a pixel or two with each character.  I'm stuck.

Thanx in advance,
   Lee

   (Lee_Robert_Willis@cup.portal.com)

-----------------------------------------------------------------------
                           Source Code
-----------------------------------------------------------------------

#define FONT_IS_PROPORTIONAL(f) (f->tf_Flags & FPF_PROPORTIONAL)

short Width_of_Char( unsigned char c, struct TextFont *Font )
{
   short  width; /* pixels */
   USHORT char_index;
   UWORD *CharSpacing, *CharKerning;
   

   if FONT_IS_PROPORTIONAL( Font ) 
   {
      /* Make sure 'c' is within the legal character set 
       * for 'Font'.
       */
      if ((c >= Font->tf_LoChar) && (c <= Font->tf_HiChar))
      {
         /* map 'c' into the appropriate index for the
          * 'Font->tf_CharSpace' array.
          */
         char_index  = c - Font->tf_LoChar;
         
         CharSpacing = (UWORD *) Font->tf_CharSpace;
         width       = CharSpacing[ char_index ];
         
         /* Add in kerning, if applicable. */
         if ((CharKerning = (UWORD *) Font->tf_CharKern))
            width += CharKerning[ char_index ];
      }
      else
         width = Font->tf_XSize; /* ERROR: 'c' is not in range. */
   }
   else  /* All font characters are the same size. */
      width = Font->tf_XSize;

   return width;
}
Technical Details
Message-ID: <34830@cup.portal.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!usc!apple!portal!cup.portal.com!Lee_Robert_Willis

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!usc!apple!portal!cup.portal.com!Lee_Robert_Willis
From: Lee_Robert_Willis@cup.portal.com
Newsgroups: comp.sys.amiga.tech
Subject: How find width of prop. Font character?
Message-ID: <34830@cup.portal.com>
Date: 14 Oct 90 00:24:09 GMT
Organization: The Portal System (TM)
Lines: 59