2 Copyright © 1995-2001, 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 *****************************************************************************/
67 AROS_LIBBASE_EXT_DECL(struct GfxBase
*,GfxBase
)
69 WORD i
; /* Loop variable */
70 WORD maxwidth
= -0x7fff;
71 WORD minwidth
= 0x7fff;
74 for(i
= 0; i
<= font
->tf_HiChar
- font
->tf_LoChar
; i
++)
76 WORD kern
; /* Kerning value for the character */
77 WORD wspace
; /* Width of character including CharSpace */
81 if(font
->tf_CharKern
!= NULL
)
82 kern
= ((WORD
*)font
->tf_CharKern
)[i
];
84 minwidth
= min(minwidth
, kern
);
86 /* tf_CharLoc[2*i+1] contains the width of the glyph bitmap.
87 But in AROS tf_CharLoc is being handled like an LONG array,
88 not a WORD array, so the width is tf_CarLoc[i] & 0xFFFF */
89 maxwidth
= max(maxwidth
, kern
+ ((((LONG
*)font
->tf_CharLoc
)[i
]) & 0xFFFF));
91 if(font
->tf_CharSpace
!= NULL
)
92 wspace
= kern
+ ((WORD
*)font
->tf_CharSpace
)[i
];
94 /* Is it possible to have kerning values but no CharSpace? */
95 wspace
= kern
+ font
->tf_XSize
;
98 if(font
->tf_Flags
& FPF_REVPATH
)
99 width
= min(wspace
, width
);
101 width
= max(wspace
, width
);
104 fontExtent
->te_Width
= width
;
105 fontExtent
->te_Height
= font
->tf_YSize
;
106 fontExtent
->te_Extent
.MinX
= minwidth
;
107 fontExtent
->te_Extent
.MaxX
= maxwidth
- 1;
108 fontExtent
->te_Extent
.MinY
= -font
->tf_Baseline
;
109 fontExtent
->te_Extent
.MaxY
= font
->tf_YSize
- font
->tf_Baseline
- 1;