show cpu number in fiq
[AROS.git] / rom / graphics / fontextent.c
blob7d25836af72e1776d544b6e16da966293285b53a
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 #include "graphics_intern.h"
14 #define max(a,b) (((a) > (b)) ? (a) : (b))
15 #define min(a,b) (((a) < (b)) ? (a) : (b))
17 /*****************************************************************************
19 NAME */
21 AROS_LH2(void, FontExtent,
23 /* SYNOPSIS */
24 AROS_LHA(struct TextFont *, font , A0),
25 AROS_LHA(struct TextExtent *, fontExtent, A1),
27 /* LOCATION */
28 struct GfxBase *, GfxBase, 127, Graphics)
30 /* FUNCTION
32 Fill out a text extent structure with the maximum extent of the
33 characters for the font in question.
35 INPUTS
37 font -- The font the extent of which to calculate.
38 fontExtent -- TextExtent structure to hold the values.
40 RESULT
42 The extent is stored in 'fontExtent'.
44 NOTES
46 Neither effects of algorithmic additions nor rp_TxSpacing is included
47 when the bounding box and font size are calculated. Note that te_Width
48 only will be negative when FPF_REVPATH is specified for the font; left
49 moving characters are ignored considering the font width (right moving
50 character when FPF_REVPATH is set), but affects the bounding box size.
52 EXAMPLE
54 BUGS
56 SEE ALSO
58 TextExtent(), <graphics/text.h>
60 INTERNALS
62 HISTORY
64 990617 SDuvan Implemented
66 *****************************************************************************/
68 AROS_LIBFUNC_INIT
70 WORD i; /* Loop variable */
71 WORD maxwidth = -0x7fff;
72 WORD minwidth = 0x7fff;
73 WORD width = 0;
75 for(i = 0; i <= font->tf_HiChar - font->tf_LoChar; i++)
77 WORD kern; /* Kerning value for the character */
78 WORD wspace; /* Width of character including CharSpace */
80 kern = 0;
82 if(font->tf_CharKern != NULL)
83 kern = ((WORD *)font->tf_CharKern)[i];
85 minwidth = min(minwidth, kern);
87 /* tf_CharLoc[2*i+1] contains the width of the glyph bitmap.
88 But in AROS tf_CharLoc is being handled like an LONG array,
89 not a WORD array, so the width is tf_CarLoc[i] & 0xFFFF */
90 maxwidth = max(maxwidth, kern + ((((LONG *)font->tf_CharLoc)[i]) & 0xFFFF));
92 if(font->tf_CharSpace != NULL)
93 wspace = kern + ((WORD *)font->tf_CharSpace)[i];
94 else
95 /* Is it possible to have kerning values but no CharSpace? */
96 wspace = kern + font->tf_XSize;
99 if(font->tf_Flags & FPF_REVPATH)
100 width = min(wspace, width);
101 else
102 width = max(wspace, width);
105 fontExtent->te_Width = width;
106 fontExtent->te_Height = font->tf_YSize;
107 fontExtent->te_Extent.MinX = minwidth;
108 fontExtent->te_Extent.MaxX = maxwidth - 1;
109 fontExtent->te_Extent.MinY = -font->tf_Baseline;
110 fontExtent->te_Extent.MaxY = font->tf_YSize - font->tf_Baseline - 1;
112 AROS_LIBFUNC_EXIT
113 } /* FontExtent */