New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / graphics / textextent.c
blobdf76d8da7de5383a5a6df5d12ef9e1f966751c90
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Calculate the size a text needs in a specific rastport.
6 Lang: english
7 */
8 #include "graphics_intern.h"
9 #include <graphics/rastport.h>
11 /*****************************************************************************
13 NAME */
14 #include <graphics/rastport.h>
15 #include <graphics/text.h>
16 #include <proto/graphics.h>
18 AROS_LH4(void, TextExtent,
20 /* SYNOPSIS */
21 AROS_LHA(struct RastPort *, rp, A1),
22 AROS_LHA(CONST_STRPTR , string, A0),
23 AROS_LHA(ULONG , count, D0),
24 AROS_LHA(struct TextExtent *, textExtent, A2),
26 /* LOCATION */
27 struct GfxBase *, GfxBase, 115, Graphics)
29 /* FUNCTION
31 INPUTS
33 RESULT
35 NOTES
37 EXAMPLE
39 BUGS
41 SEE ALSO
43 INTERNALS
45 HISTORY
46 29-10-95 digulla automatically created from
47 graphics_lib.fd and clib/graphics_protos.h
49 *****************************************************************************/
51 AROS_LIBFUNC_INIT
52 AROS_LIBBASE_EXT_DECL(struct GfxBase *,GfxBase)
54 struct TextFont *tf = rp->Font;
56 textExtent->te_Width = TextLength(rp, string, count);
57 textExtent->te_Height = tf->tf_YSize;
58 textExtent->te_Extent.MinY = -tf->tf_Baseline;
59 textExtent->te_Extent.MaxY = textExtent->te_Height - 1 - tf->tf_Baseline;
61 /* MinX/MaxX can be a bit more complicated if there are kerning/space tables */
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 WORD x, x2;
68 UBYTE c;
70 textExtent->te_Extent.MinX = 0;
71 textExtent->te_Extent.MaxX = 0;
72 x = 0;
74 if (count)
76 while(count--)
78 c = *string++;
80 if ( c < tf->tf_LoChar || c > tf->tf_HiChar)
82 idx = defaultidx;
84 else
86 idx = c - tf->tf_LoChar;
89 #define CHECK_MINMAX(x) \
90 if ((x) < textExtent->te_Extent.MinX) textExtent->te_Extent.MinX = (x); \
91 if ((x) > textExtent->te_Extent.MaxX) textExtent->te_Extent.MaxX = (x);
93 x += ((WORD *)tf->tf_CharKern)[idx];
94 CHECK_MINMAX(x);
96 x2 = x + ( ( ((ULONG *)tf->tf_CharLoc)[idx] ) & 0xFFFF);
97 CHECK_MINMAX(x2);
99 x += ((WORD *)tf->tf_CharSpace)[idx];
100 CHECK_MINMAX(x);
102 x += rp->TxSpacing;
103 CHECK_MINMAX(x);
105 } /* while(count--) */
107 textExtent->te_Extent.MaxX--;
109 } /* if (count) */
111 } /* if ((tf->tf_Flags & FPF_PROPORTIONAL) || tf->tf_CharKern || tf->tf_CharSpace) */
112 else
114 /* Normal non-proportional Font */
115 textExtent->te_Extent.MinX = 0;
116 textExtent->te_Extent.MaxX = textExtent->te_Width - 1;
119 if (rp->AlgoStyle & FSF_BOLD)
121 textExtent->te_Extent.MaxX += tf->tf_BoldSmear;
124 if (rp->AlgoStyle & FSF_ITALIC)
126 /* ###### ######
127 ** ## ## ## ##
128 ** ## ## ## ##
129 ** ## ## ===> ## ##
130 ** ## ## ## ##
131 **..##..##.. ..##..##..
132 ** ## ## ## ##
133 ** ###### ######
136 textExtent->te_Extent.MaxX += tf->tf_Baseline / 2;
137 textExtent->te_Extent.MinX -= (tf->tf_YSize - tf->tf_Baseline) / 2;
140 AROS_LIBFUNC_EXIT
142 } /* TextExtent */