justify text
Richard Gaskin
ambassador at fourthworld.com
Tue Nov 23 11:12:30 EST 2004
xbury.cs at clearstream.com wrote:
> You can get the length of any part of the field (word, items) with some
> exceptions
>
> put the formattedwidth of word 3 of fld 1
>
> so you can recurse and find what you need.
> But after line 1... you have to fake the justification by breaking
> paragraph 1 into
> it's line components. Then adjust the formattedwidth of each line by
> inserting
> spaces between the words (will look ugly!) so it matches the "effective
> formattedwidth" of the field.
>
> If you resize the field, it's all broken, start over...
>
> It's easy with monospace fonts and a fixed width.
Under the hood, a lot of paragraph-level formatting is roughly akin to
having multiple TextEdit records displayed at one time (for those Mac
ToolBox fans out there, yes, I know that's a very loose analogy; please
forgive).
So to get this effect in Rev you could use multiple fields in a
scrolling group. It won't do much for you if you need to edit text
(hats off to anyone who could script such an interface gracefully), but
for display it can be an acceptable workaround while we wait for that
enhancement.
> But other factors such as the runrev definition of a word (which grabs any
> chars together regardless of punctuation, or grammar rules as a single word)
> will make this a nightmare to parse!
The traditional HyperTalk definition of a word attempts to provide
convenience for isolating quoted strings. If you need a more accurate
word count you can put the text into a var, replace the quotes with a
non-printing character like some low ASCII char and then parse the
string, replacing those low-ASCII chars with quotes again for display.
I sometimes find the "token" chunk type useful. While most xTalk
implementations only support chars, words, and lines, Transcript also
provides a token type, so if you type something like this in the Message
Box:
put token 2 of "Hello, world!"
...you get ","
Its use for parsing common text is limited, but in some cases it can be
valuable. Worth knowing about, anyway; sooner or later it'll come in
handy, if not for the problem at hand than for something else down the road.
--
Richard Gaskin
Fourth World Media Corporation
__________________________________________________
Rev tools and more: http://www.fourthworld.com/rev
More information about the use-livecode
mailing list