Date: Fri, 7 Jul 1995 03:18:19 -0400 From: "Terry R. Schussler (gray matter design)" <Schussler@AOL.COM> Subject: justifying text- can it be done? > Does anyone know of a way to justify text flush left _and_ right? Is > there an Xobject that will do this trick? Any help appreciated. Thanks.Yes! Here's a function I wrote for The MediaBook CD for Director which provides what you need. You could call it in a repeat loop to format a series of lines if desired. Enjoy.
Terry R. Schussler
gray matter design
mediabook@aol.com
justifyString(theString, justification, displayWidth)
theString -- a string justification -- a symbol representing the justification desired - #left, #right, #center displayWidth -- an integer number of characters to format the string within
on justifyString theString, justification, displayWidth
-- record the length of theString
put length(theString) into theChars
-- left justification
if justification = #left then
-- add the necessary spaces to the end of theString
put spaces(displayWidth - theChars) after theString
-- return the formatted string
return theString
exit
end if
-- right justification
if justification = #right then
-- add the necessary spaces to the beginning of theString
put spaces(displayWidth - theChars) before theString
-- return the formatted string
return theString
exit
end if
-- center justification
if justification = #center then
-- how many characters are not being used by theString?
put displayWidth - theChars into blanks
-- divide the result in half
put blanks/2 into half
-- put half of the spaces at the beginning of theString
put spaces(half) before theString
-- put half of the spaces at the end of theString
put spaces(blanks-half) after theString
-- return the formatted string
return theString
exit
end if
-- no justification was asked for so return theString as it is
return theString
end justifyString
-- this utility function will return
-- a string of howMany spaces
on spaces howMany
-- initialize the space container
put EMPTY into answer
-- start putting spaces into the container
repeat with counter = 1 to howMany
put " " after answer
end repeat
-- return the string of spaces
return answer
end spaces
You can use this function to limit or truncate a string to a specific number of characters.