Indentation fix, cleanup.
[AROS.git] / rom / graphics / textlength.c
blob8332f402af26acb6e1d29c85ba9314a511db7e9b
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function TextLength()
6 Lang: english
7 */
8 #include "graphics_intern.h"
10 #undef NUMCHARS
11 #define NUMCHARS(tf) ((tf->tf_HiChar - tf->tf_LoChar) + 2)
13 /*****************************************************************************
15 NAME */
16 #include <graphics/rastport.h>
17 #include <proto/graphics.h>
19 AROS_LH3(WORD, TextLength,
21 /* SYNOPSIS */
22 AROS_LHA(struct RastPort *, rp, A1),
23 AROS_LHA(CONST_STRPTR , string, A0),
24 AROS_LHA(ULONG , count, D0),
26 /* LOCATION */
27 struct GfxBase *, GfxBase, 9, Graphics)
29 /* FUNCTION
30 Determines the length of a string in pixels.
32 INPUTS
33 rp - RastPort
34 string - address of string
35 count - number of characters of string
37 RESULT
38 Length of string in pixels.
40 NOTES
41 Use the newer TextExtent() to get more information.
43 EXAMPLE
45 BUGS
47 SEE ALSO
48 Text(), TextExtent()
50 INTERNALS
52 *****************************************************************************/
54 AROS_LIBFUNC_INIT
56 struct TextFont *tf = rp->Font;
57 WORD strlen;
59 if ((tf->tf_Flags & FPF_PROPORTIONAL) || tf->tf_CharKern
60 || tf->tf_CharSpace)
62 WORD idx;
63 WORD defaultidx = NUMCHARS(tf) - 1; /* Last glyph is default glyph */
64 UBYTE c;
66 for(strlen = 0; count; count--)
68 c = *string++;
70 if ( c < tf->tf_LoChar || c > tf->tf_HiChar)
72 idx = defaultidx;
74 else
76 idx = c - tf->tf_LoChar;
79 strlen += ((WORD *)tf->tf_CharKern)[idx];
80 strlen += ((WORD *)tf->tf_CharSpace)[idx];
81 strlen += rp->TxSpacing;
84 else
86 strlen = count * (tf->tf_XSize + rp->TxSpacing);
89 return strlen;
91 AROS_LIBFUNC_EXIT
93 } /* TextLength */