Added basic implementation of destroying a GPT table: just delete the
[AROS.git] / rom / graphics / textlength.c
blobbeffe9c3e30c0a84defc809a10c7ceab7e550730
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$ $Log
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 HISTORY
53 29-10-95 digulla automatically created from
54 graphics_lib.fd and clib/graphics_protos.h
56 *****************************************************************************/
58 AROS_LIBFUNC_INIT
60 struct TextFont *tf = rp->Font;
61 WORD strlen;
63 if ((tf->tf_Flags & FPF_PROPORTIONAL) || tf->tf_CharKern || tf->tf_CharSpace)
65 WORD idx;
66 WORD defaultidx = NUMCHARS(tf) - 1; /* Last glyph is the default glyph */
67 UBYTE c;
69 for(strlen = 0; count; count--)
71 c = *string++;
73 if ( c < tf->tf_LoChar || c > tf->tf_HiChar)
75 idx = defaultidx;
77 else
79 idx = c - tf->tf_LoChar;
82 strlen += ((WORD *)tf->tf_CharKern)[idx];
83 strlen += ((WORD *)tf->tf_CharSpace)[idx];
84 strlen += rp->TxSpacing;
87 else
89 strlen = count * (tf->tf_XSize + rp->TxSpacing);
92 return strlen;
94 AROS_LIBFUNC_EXIT
96 } /* TextLength */