full justification in a text field
Peter Bogdanoff
bogdanoff at me.com
Thu Feb 10 04:17:05 EST 2022
I’ve taken a quick stab at this ...
This script adds spaces between words of a line to get it close to the full width of the field to create a quick & dirty faux fully-justified field.
In operation, It converts each visible line of text to a LiveCode line (delineated by CRs) so the final text has a CR after each visible line. Then it uses the formattedWidth property of each line to determine its current width, then adds spaces between words to fill out the full width of the line.
Note that the final width of the text is determined by tMaxWidth, which is based on the widest visible line of the field. But that could be changed to use the width property of the field itself, minus any V scrollbars.
Peter Bogdanoff
on mouseUp
set lockscreen to true
# Add CRs to the end of each line
put the formattedText of field "Text2" into field "Text2"
# Find longest line of text. This will determine the overall width of the text.
# This probably should be modified to simply get the width property of the field itself.
put 0 into tMaxWidth
repeat with x = 1 to the number of lines of field "Text2"
put the formattedWidth of line x of field"Text2" into tWidth
if tWidth > tMaxWidth then put tWidth into tMaxWidth
end repeat
# Format each line
put tMaxWidth - 5 into tMaxWidth # This number can be adjusted for best results
repeat with x = 1 to (the number of lines of field "Text2" - 1) # Don't format last line
put 100 into maxRepeats # Max number of spaces that can be added to a line
if line x of field "Text2" is empty then next repeat
if the formattedWidth of line x of field"Text2" >= tMaxWidth then next repeat
put the number of words of line x of field "Text2" into tWordNum
if char -1 of word tWordNum of line x of field "Text2" is "." then next repeat # Last word of a paragraph
repeat with z = 1 to maxRepeats
repeat with y = 1 to (tWordNum - 1) # Don't add spaces after the last word of a line
put space after word y of line x of field "Text2"
if the formattedWidth of line x of field "Text2" >= tMaxWidth then exit repeat
end repeat
if the formattedWidth of line x of field"Text2" >= tMaxWidth then put maxRepeats into z
end repeat
end repeat
end mouseUp
> On Feb 9, 2022, at 10:28 PM, Tom Glod via use-livecode <use-livecode at lists.runrev.com> wrote:
>
> Hello Curt,
>
> The only thing you can do is adjust the font size to maximize the use of
> the width of the field.....with the don't wrap enabled. :)
> Remember the margins can be adjusted individually. like so 0,5,5,0
> Also, there is a problem with the margins when the font gets too small. in
> those cases, it helps to have "showborder" enabled, even if the borderwidth
> is set to 0.
>
> All the best,
>
> Tom
>
> Founder & Developer @ MakeShyft R.D.A <https://www.makeshyft.com/>
> Build Software with AppStarterStack <https://www.appstarterstack.com/> for
> Livecode
> Save Time with The Time Saver's Toolbox <https://www.timesaverstoolbox.com/>
>
> On Wed, Feb 9, 2022 at 5:50 PM Paul Dupuis via use-livecode <
> use-livecode at lists.runrev.com> wrote:
>
>> On 2/9/2022 5:24 PM, Curt Ford via use-livecode wrote:
>>> This seems like an awfully basic question, but is it possible to have
>>> text with full justification in a field?
>>>
>>> I've looked at using WordLib, but this client's text has lots of fussy
>>> formatting (background colors, different colors for individual
>>> characters) that didn't come through well.
>>>
>>> Thanks for any ideas,
>>>
>>> Curt
>>
>> See the Dictionary entry for textAlign:
>>
>> set the textAlign [of line] of {button | field} to {left | center | right}
>>
>> There is no justified option. There is a REALLY old enhancement request
>> at https://quality.livecode.com/show_bug.cgi?id=4714
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list