character to justify text -- spacer graphic implementation
J. Landman Gay
jacque at hyperactivesw.com
Wed Jun 27 01:35:48 EDT 2007
Wow. While everybody else is yakking, you write a script. :) This is
very cool and there's not even a noticable lag.
It would need a custom "copy" though to remove the spacers. Maybe:
on commandKeyDown which -- copykey
if which <> "c" then pass commandKeyDown
put the selectedText into tData
replace numToChar(0) with empty in tData
set the clipboardData["text"] to tData
end commandKeyDown -- copykey
Ideally the handler should use "copyKey" but I couldn't get it to trigger.
Brian Yennie wrote:
> This uses a naive algorithm and has limitations, but it's a fun experiment.
> Create a scrolling text field and a 1x1 empty image object.
>
> Paste this into the field script and type away.
>
> on keyDown c
> lock screen
> do "put c into"&& (the selectedChunk)
> fullJustify (the id of me), (the id of image "spacer")
> unlock screen
> end keyDown
>
> on fullJustify fldID, imageID
> local i, targetWidth
>
> put fullFieldLineWidth(fldID) into targetWidth
>
> put 1 into i
>
> lock screen
> replace numToChar(0) with empty in fld id fldID
> put the formattedText of fld id fldID into fld id fldID
>
> repeat for each line l in fld id fldID
> put (targetWidth - the formattedWidth of line i of fld id fldID)
> into tLineGaps[i]
> add 1 to i
> end repeat
>
> put 1 into i
> repeat for each line l in fld id fldID
> put padLine(l, tLineGaps[i], numToChar(0)) into line i of fld id fldID
> add 1 to i
> end repeat
>
> put 1 into i
> repeat for each char c in fld id fldID
> if (char i of fld 1 is numToChar(0)) then
> set the imageSource of char i of fld id fldID to imageID
> end if
> add 1 to i
> end repeat
> unlock screen
>
> end fullJustify
>
> function fullFieldLineWidth fldID
> put (the width of fld id fldID) into targetWidth
> subtract (2* the borderWidth of fld id fldID) from targetWidth
> subtract (item 1 of the margins of fld id fldID) from targetWidth
> get (item 3 of the margins of fld id fldID)
> if (it is empty) then subtract (item 1 of the margins of fld id fldID)
> from targetWidth
> else subtract (item 3 of the margins of fld id fldID) from targetWidth
> if (the vScrollbar of fld id fldID) then subtract the scrollbarWidth
> of fld id fldID from targetWidth
> return targetWidth
> end fullFieldLineWidth
>
> function padLine l, pixels
> put empty into tmp1
> put 0 into spaceCount
> repeat for each char c in l
> if (c is space) then add 1 to spaceCount
> end repeat
> if (spaceCount = 0) then return l
> put (pixels div spaceCount) into spacePadding
> put (pixels mod spaceCount) into leftoverPads
> repeat for each char c in l
> if (c is space) then
> repeat spacePadding
> put numToChar(0) after tmp1
> end repeat
> end if
> put c after tmp1
> end repeat
> repeat for each char c in tmp1
> if (c is space) AND (leftoverPads > 0) then
> put numToChar(0) after tmp2
> subtract 1 from leftoverPads
> end if
> put c after tmp2
> end repeat
>
> return tmp2
> end padLine
>
>
>
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
--
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode
mailing list