Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / graphics / fontextent.c
blobf0e190c58a7a9f72748d26b21851d60b3b281bb8
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function FontExtent()
6 Lang: English
7 */
9 #include <proto/graphics.h>
10 #include <graphics/text.h>
12 #define max(a,b) (((a) > (b)) ? (a) : (b))
13 #define min(a,b) (((a) < (b)) ? (a) : (b))
15 /*****************************************************************************
17 NAME */
19 AROS_LH2(void, FontExtent,
21 /* SYNOPSIS */
22 AROS_LHA(struct TextFont *, font , A0),
23 AROS_LHA(struct TextExtent *, fontExtent, A1),
25 /* LOCATION */
26 struct GfxBase *, GfxBase, 127, Graphics)
28 /* FUNCTION
30 Fill out a text extent structure with the maximum extent of the
31 characters for the font in question.
33 INPUTS
35 font -- The font the extent of which to calculate.
36 fontExtent -- TextExtent structure to hold the values.
38 RESULT
40 The extent is stored in 'fontExtent'.
42 NOTES
44 Neither effects of algorithmic additions nor rp_TxSpacing is included
45 when the bounding box and font size are calculated. Note that te_Width
46 only will be negative when FPF_REVPATH is specified for the font; left
47 moving characters are ignored considering the font width (right moving
48 character when FPF_REVPATH is set), but affects the bounding box size.
50 EXAMPLE
52 BUGS
54 SEE ALSO
56 TextExtent(), <graphics/text.h>
58 INTERNALS
60 HISTORY
62 990617 SDuvan Implemented
64 *****************************************************************************/
66 AROS_LIBFUNC_INIT
68 WORD i; /* Loop variable */
69 WORD maxwidth = -0x7fff;
70 WORD minwidth = 0x7fff;
71 WORD width = 0;
73 for(i = 0; i <= font->tf_HiChar - font->tf_LoChar; i++)
75 WORD kern; /* Kerning value for the character */
76 WORD wspace; /* Width of character including CharSpace */
78 kern = 0;
80 if(font->tf_CharKern != NULL)
81 kern = ((WORD *)font->tf_CharKern)[i];
83 minwidth = min(minwidth, kern);
85 /* tf_CharLoc[2*i+1] contains the width of the glyph bitmap.
86 But in AROS tf_CharLoc is being handled like an LONG array,
87 not a WORD array, so the width is tf_CarLoc[i] & 0xFFFF */
88 maxwidth = max(maxwidth, kern + ((((LONG *)font->tf_CharLoc)[i]) & 0xFFFF));
90 if(font->tf_CharSpace != NULL)
91 wspace = kern + ((WORD *)font->tf_CharSpace)[i];
92 else
93 /* Is it possible to have kerning values but no CharSpace? */
94 wspace = kern + font->tf_XSize;
97 if(font->tf_Flags & FPF_REVPATH)
98 width = min(wspace, width);
99 else
100 width = max(wspace, width);
103 fontExtent->te_Width = width;
104 fontExtent->te_Height = font->tf_YSize;
105 fontExtent->te_Extent.MinX = minwidth;
106 fontExtent->te_Extent.MaxX = maxwidth - 1;
107 fontExtent->te_Extent.MinY = -font->tf_Baseline;
108 fontExtent->te_Extent.MaxY = font->tf_YSize - font->tf_Baseline - 1;
110 AROS_LIBFUNC_EXIT
111 } /* FontExtent */