| stringfit |
(String str, double width [, String suffix [, String substitute [, int fractionalmetrics [, int antialiasing]]]]) |
typedict.Font |
| stringfit |
(String str, double width [, String suffix [, String substitute [, Object target]]]) |
|
| |
|
Returns a
String
built from
str
by removing one character at a time from the end until its width,
when printed using this font, is less than or equal to
width.
If no characters need to be removed
str
is returned.
The optional
suffix
argument, if supplied and not
NULL,
is attached to the end of every modified string,
but only after enough extra characters are removed so that the modified
string with
suffix
attached fits in
width.
If
suffix
itself does not fit in
width
then the optional
substitute
string is used if it is not
NULL,
and if none of the choices fit the empty string (i.e.,
"")
is returned.
The optional
fractionalmetrics
and
antialiasing
arguments can be used to set hints that can affect how
str
would be rendered, which in turn can affect the width measurements of strings.
By default
fractionalmetrics
is
TRUE
while
antialiasing
is
FALSE.
Alternatively the optional
target
argument, which should be a
Graphics
object or a drawable component (e.g., a
JCanvas)
can be supplied and in that case the
fractionalmetrics
and
antialiasing
hints are derived from
target.
| |
| Example: |
The program
import yoix.*.*;
Font font = {String name = "Helvetica-12";};
String source = "1234567890";
String target[] = source;
String str;
while (target@sizeof > 0) {
str = font.stringfit(source, font.stringwidth(target), "...", "|");
printf("target=%s, str=%s\n", target, str);
target = new String[target@sizeof - 1] source;
}
prints
target=1234567890, str=1234567890
target=123456789, str=12345678...
target=12345678, str=1234567...
target=1234567, str=123456...
target=123456, str=12345...
target=12345, str=1234...
target=1234, str=123...
target=123, str=12...
target=12, str=1...
target=1, str=|
on standard output.
Notice how we used the empty square brackets in the declaration of
target
to make a copy of
source,
and how we did something similar in the while loop to where we wanted
to make a substring of
target.
| | |
| Return: |
String
| | |
| See Also: |
stringbounds,
stringsize,
stringwidth
|
|
Yoix is a registered trademark of AT&T Inc.
|