2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Graphics function FontExtent()
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 /*****************************************************************************
21 AROS_LH2(void, FontExtent
,
24 AROS_LHA(struct TextFont
*, font
, A0
),
25 AROS_LHA(struct TextExtent
*, fontExtent
, A1
),
28 struct GfxBase
*, GfxBase
, 127, Graphics
)
32 Fill out a text extent structure with the maximum extent of the
33 characters for the font in question.
37 font -- The font the extent of which to calculate.
38 fontExtent -- TextExtent structure to hold the values.
42 The extent is stored in 'fontExtent'.
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.
58 TextExtent(), <graphics/text.h>
64 990617 SDuvan Implemented
66 *****************************************************************************/
70 WORD i
; /* Loop variable */
71 WORD maxwidth
= -0x7fff;
72 WORD minwidth
= 0x7fff;
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 */
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
];
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
);
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;