2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 Desc: Tell how many characters will fit into a box.
8 #include "graphics_intern.h"
10 /*****************************************************************************
13 #include <graphics/rastport.h>
14 #include <graphics/text.h>
15 #include <proto/graphics.h>
17 AROS_LH8(ULONG
, TextFit
,
20 AROS_LHA(struct RastPort
*, rp
, A1
),
21 AROS_LHA(CONST_STRPTR
, string
, A0
),
22 AROS_LHA(ULONG
, strLen
, D0
),
23 AROS_LHA(struct TextExtent
*, textExtent
, A2
),
24 AROS_LHA(struct TextExtent
*, constrainingExtent
, A3
),
25 AROS_LHA(LONG
, strDirection
, D1
),
26 AROS_LHA(ULONG
, constrainingBitWidth
, D2
),
27 AROS_LHA(ULONG
, constrainingBitHeight
, D3
),
30 struct GfxBase
*, GfxBase
, 116, Graphics
)
33 Tries to fill the given space with as many characters of the
34 font in rp as possible and returns that number.
37 rp - Use the settings in this RastPort (e.g. Font)
38 string - Use this string
39 strLen - The length of the string
40 textExtent - The size actually occupied will be returned here
41 constrainingExtent - If non-NULL, the routine will use the
42 dimensions of the box described here
43 strDirection - In which is the next character. Must be either 1
44 or -1. If it is -1, then string must point to the end (the
45 first character to check) of the text to fit (this is for
46 checking text which runs from right to left).
47 constrainingBitWidth - If constrainingExtent is NULL, then this
48 is the width of the bounding box.
49 constrainingBitHeight - If constrainingExtent is NULL, then this
50 is the height of the bounding box.
53 The number of characters which fit in the bounding box.
54 If any characters fit in the bounding box, then textExtent will
55 tell how large the minimal bounding box for the string is.
68 *****************************************************************************/
72 struct TextFont
*tf
= rp
->Font
;
75 if (strLen
&& (constrainingBitHeight
>= tf
->tf_YSize
))
79 textExtent
->te_Extent
.MinX
= 0;
80 textExtent
->te_Extent
.MinY
= -tf
->tf_Baseline
;
81 textExtent
->te_Extent
.MaxX
= 0;
82 textExtent
->te_Extent
.MaxY
= tf
->tf_YSize
- tf
->tf_Baseline
- 1;
83 textExtent
->te_Width
= 0;
84 textExtent
->te_Height
= tf
->tf_YSize
;
86 if (constrainingExtent
)
88 if (constrainingExtent
->te_Extent
.MinY
> textExtent
->te_Extent
.MinY
90 constrainingExtent
->te_Extent
.MaxY
< textExtent
->te_Extent
.MaxY
92 constrainingExtent
->te_Height
< textExtent
->te_Height
)
102 struct TextExtent char_extent
;
103 WORD newwidth
, newminx
, newmaxx
, minx
, maxx
;
105 TextExtent(rp
, string
, 1, &char_extent
);
106 string
+= strDirection
;
108 newwidth
= textExtent
->te_Width
+ char_extent
.te_Width
;
109 minx
= textExtent
->te_Width
+ char_extent
.te_Extent
.MinX
;
110 maxx
= textExtent
->te_Width
+ char_extent
.te_Extent
.MaxX
;
112 newminx
= (minx
< textExtent
->te_Extent
.MinX
) ?
113 minx
: textExtent
->te_Extent
.MinX
;
114 newmaxx
= (maxx
> textExtent
->te_Extent
.MaxX
) ?
115 maxx
: textExtent
->te_Extent
.MaxX
;
117 if ((ULONG
)(newmaxx
- newminx
+ 1) > constrainingBitWidth
)
120 if (constrainingExtent
)
122 if (constrainingExtent
->te_Extent
.MinX
> newminx
) break;
123 if (constrainingExtent
->te_Extent
.MaxX
< newmaxx
) break;
124 if (constrainingExtent
->te_Width
< newwidth
) break;
127 textExtent
->te_Width
= newwidth
;
128 textExtent
->te_Extent
.MinX
= newminx
;
129 textExtent
->te_Extent
.MaxX
= newmaxx
;
133 } /* while(strLen--) */
137 } /* if (strLen && (constrainingBitHeight >= tf->tf_YSize)) */
141 textExtent
->te_Width
= 0;
142 textExtent
->te_Height
= 0;
143 textExtent
->te_Extent
.MinX
= 0;
144 textExtent
->te_Extent
.MinY
= 0;
145 textExtent
->te_Extent
.MaxX
= 0;
146 textExtent
->te_Extent
.MaxY
= 0;