Re: XForms: text justification

Steve Lamont (spl@szechuan.ucsd.edu)
Wed, 19 Nov 97 07:04:41 PST

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> Does anyone know how to right justify text in an input object's input field?

I assume you don't mean right align, which is a different.

There's no way to do it as far as I can tell. Text justification
would require being able to control interword spacing at a pixel
accurate level and there's no facility to do that. I think you'd have
to concoct your own special object to do it.

Then the process is relatively straightforward as long as you don't
want to get involved with kerning or other fancy bits of typography.
Basically, you have to measure and sum each word in the line of text
using the fl_get_string_width() function, figure out how much space is
left over in the line, and distribute the space left over more or less
evenly between words.

If, perchance, you do mean right align, then I think the way to do it
would be through using the input filter mechanism. You could do
something like:

[...]

fl_set_input_filter( fd_try->input, filter );
filter( fd_try->input, "", "", '\0' );

[...]

#define SLOP fl_get_char_width( obj->lstyle, obj->lsize )

int filter( FL_OBJECT *obj, const char *old, const char *cur, int c )

{

int w = fl_get_string_width( obj->lstyle, obj->lsize,
cur, strlen( cur ) );

fl_set_input_xoffset( obj, -( obj->w - w - SLOP ) );

return FL_VALID;

}

You may want to play with SLOP to get things to look nice.

This, of course, only works for a single line Input object. Multiline
Input objects would be much more elaborate to handle (if not
impossible).

spl

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/