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 #define max(a,b) (((a) > (b)) ? (a) : (b))
13 #define min(a,b) (((a) < (b)) ? (a) : (b))
15 /*****************************************************************************
19 AROS_LH2(void, FontExtent
,
22 AROS_LHA(struct TextFont
*, font
, A0
),
23 AROS_LHA(struct TextExtent
*, fontExtent
, A1
),
26 struct GfxBase
*, GfxBase
, 127, Graphics
)
30 Fill out a text extent structure with the maximum extent of the
31 characters for the font in question.
35 font -- The font the extent of which to calculate.
36 fontExtent -- TextExtent structure to hold the values.
40 The extent is stored in 'fontExtent'.
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.
56 TextExtent(), <graphics/text.h>
62 990617 SDuvan Implemented
64 *****************************************************************************/
68 WORD i
; /* Loop variable */
69 WORD maxwidth
= -0x7fff;
70 WORD minwidth
= 0x7fff;
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 */
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
];
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
);
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;