RE: Set font dynamically to fit text
This is how I fit text into fields and buttons. This the first LC code I wrote back in LC 4.6. I did not follow best practices back then. After looking at it again I see that I optimized it so you don't have to set the textsize to some huge number. https://tinyurl.com/y2jtt877 Ralph DiMola IT Director Evergreen Information Services rdim...@evergreeninfo.net -Original Message- From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On Behalf Of Sannyasin Brahmanathaswami via use-livecode Sent: Monday, October 14, 2019 3:21 PM To: How to use LiveCode Cc: Sannyasin Brahmanathaswami Subject: Re: Set font dynamically to fit text Dan: Thanks for the handler! Ralph: Actually that last solution offered was fromr Dan Friedman not mine. Can you put your two handlers on the list? " I also have an option to fit either by height or width." Doc Hawk: I give in 😊, " Font scaling itself is nonlinear enough, but the way margins scale with font size is downright psychotic " that's two unknowns in the equation. So iterationis required Ralph wrote I use the same technique as BR with a couple of diffs. I originally went down by 1's like BR but changed it for increased performance. I set the textsize to a large number(I like BR's initial size option) I then go down by 8s, add 7, down by 4s, add 3, down by 2s, add 1 finally down by ones until it fits. Each of the 4 loops has a check for min size so it down not go down below 2. I guess 2 is too low but it's been working. I also have an option to fit either by height or width. ___ use-livecode mailing list use-livecode@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
RE: Set font dynamically to fit text
Will share handler later today. I am in the middle of a pressing project. Ralph DiMola IT Director Evergreen Information Services rdim...@evergreeninfo.net Phone: 518-636-3998 Ex:11 Cell: 518-796-9332 -Original Message- From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On Behalf Of Sannyasin Brahmanathaswami via use-livecode Sent: Monday, October 14, 2019 3:21 PM To: How to use LiveCode Cc: Sannyasin Brahmanathaswami Subject: Re: Set font dynamically to fit text Dan: Thanks for the handler! Ralph: Actually that last solution offered was fromr Dan Friedman not mine. Can you put your two handlers on the list? " I also have an option to fit either by height or width." Doc Hawk: I give in 😊, " Font scaling itself is nonlinear enough, but the way margins scale with font size is downright psychotic " that's two unknowns in the equation. So iterationis required Ralph wrote I use the same technique as BR with a couple of diffs. I originally went down by 1's like BR but changed it for increased performance. I set the textsize to a large number(I like BR's initial size option) I then go down by 8s, add 7, down by 4s, add 3, down by 2s, add 1 finally down by ones until it fits. Each of the 4 loops has a check for min size so it down not go down below 2. I guess 2 is too low but it's been working. I also have an option to fit either by height or width. ___ use-livecode mailing list use-livecode@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Set font dynamically to fit text
Dan: Thanks for the handler! Ralph: Actually that last solution offered was fromr Dan Friedman not mine. Can you put your two handlers on the list? " I also have an option to fit either by height or width." Doc Hawk: I give in 😊, " Font scaling itself is nonlinear enough, but the way margins scale with font size is downright psychotic " that's two unknowns in the equation. So iterationis required Ralph wrote I use the same technique as BR with a couple of diffs. I originally went down by 1's like BR but changed it for increased performance. I set the textsize to a large number(I like BR's initial size option) I then go down by 8s, add 7, down by 4s, add 3, down by 2s, add 1 finally down by ones until it fits. Each of the 4 loops has a check for min size so it down not go down below 2. I guess 2 is too low but it's been working. I also have an option to fit either by height or width. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
RE: Set font dynamically to fit text
I use the same technique as BR with a couple of diffs. I originally went down by 1's like BR but changed it for increased performance. I set the textsize to a large number(I like BR's initial size option) I then go down by 8s, add 7, down by 4s, add 3, down by 2s, add 1 finally down by ones until it fits. Each of the 4 loops has a check for min size so it down not go down below 2. I guess 2 is too low but it's been working. I also have an option to fit either by height or width. Ralph DiMola IT Director Evergreen Information Services rdim...@evergreeninfo.net ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Set font dynamically to fit text
On Oct 12, 2019, at 8:05 PM, Brian Milby via use-livecode wrote: > > You probably could get close with math but line breaks would not be uniform > and will introduce variability. You could probably get it down to 2 or 3 > checks. This. Font scaling itself is nonlinear enough, but the way margins scale with font size is downright psychotic (enough so, that I’d advocate for redoing it with a useOldMarginBehavior property that can be set.). Changing margin size can change what size font fits in the wrong direction, or by more points than the change, or . . . But the approach of an initial mathematical computation , followed by the iterations—which must happen in both directions unless a hit is made. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Set font dynamically to fit text
Sannyasin, I've been doing this for years. Works well... on doShrinkToFit lFldID,startingSize,minSize set the textSize of lFldID to startingSize repeat until the formattedHeight of lFldID <= the height of lFldID set the textSize of lFldID to (the textSize of lFldID - 1) if the textSize of lFldID < minSize then exit repeat end if end repeat end doShrinkToFit Of course, the moment you start with this type of work, you'll immediately wish LiveCode would support fractional font sizes! Hope that helps... -Dan On 10/12/19, 5:21 PM, "use-livecode on behalf of Sannyasin Brahmanathaswami via use-livecode" wrote: Assuming one is not putting whole pages into small fields, does any one have an efficient run time LC algorithm that will set the font size so that the formatted text will all appear in the field without needing to scroll? BR Satchiai Iru - Be a Witness ___ use-livecode mailing list use-livecode@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Set font dynamically to fit text
In the repeat loop set the attributes of the empty field and use measureText (or measureUnicodeText) to compute the textSize. As a last step fill the field. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Set font dynamically to fit text
But "line breaks" is another known factor, based on X… which still leaves us on variable to find. Brian wrote: You probably could get close with math but line breaks would not be uniform and will introduce variability. You could probably get it down to 2 or 3 checks. BR: Hmm I figured that a repeat loop would do that, but was look for a "one-off-equation" According to the "laws of math" (ha... algebrait has been such a long time; I could be wrong) if you have single unknown variable , X, and all others are known factors, you would, in theory, be able to work out X "in one go." The [number of characters, in a given font size/face, that can fit on one line of the field with a given length] is, in theory, among "what can be the known" These little repeat loops are costly on mobile Paul wrote: your essentially want a repeat loop where you reduce the textSize of char 1 to -1 of the field until the formattedHeight of the field is less than or equal to the height of the field You probably will need a condition in the loop to prevent the textSize from going below 9 BR question Assuming one is not putting whole pages into small fields, does any one have an efficient run time LC algorithm that will set the font size so that the formatted text will all appear in the field without needing to scroll? BR ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Set font dynamically to fit text
You probably could get close with math but line breaks would not be uniform and will introduce variability. Â You could probably get it down to 2 or 3 checks. Thanks, Brian On Oct 12, 2019, 11:02 PM -0400, Sannyasin Brahmanathaswami via use-livecode , wrote: > BR: Hmm I figured that a repeat loop would do that, but was look for a > "one-off-equation" > > According to the "laws of math" (ha... algebrait has been such a long > time; I could be wrong) if you have single unknown variable , X, and all > others are known factors, you would, in theory, be able to work out X "in one > go." > The [number of characters, in a given font size/face, that can fit on one > line of the field with a given length] is, in theory, among "what can be the > known" > > These little repeat loops are costly on mobile > > Paul wrote: > your essentially want a repeat loop where you reduce the textSize of > char 1 to -1 of the field until the formattedHeight of the field is less > than or equal to the height of the field > > You probably will need a condition in the loop to prevent the textSize > from going below 9 > > BR question > Assuming one is not putting whole pages into small fields, does any one have > an efficient run time LC algorithm that will set the font size so that the > formatted text will all appear in the field without needing to scroll? > > BR > > > > ___ > use-livecode mailing list > use-livecode@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Set font dynamically to fit text
BR: Hmm I figured that a repeat loop would do that, but was look for a "one-off-equation" According to the "laws of math" (ha... algebrait has been such a long time; I could be wrong) if you have single unknown variable , X, and all others are known factors, you would, in theory, be able to work out X "in one go." The [number of characters, in a given font size/face, that can fit on one line of the field with a given length] is, in theory, among "what can be the known" These little repeat loops are costly on mobile Paul wrote: your essentially want a repeat loop where you reduce the textSize of char 1 to -1 of the field until the formattedHeight of the field is less than or equal to the height of the field You probably will need a condition in the loop to prevent the textSize from going below 9 BR question Assuming one is not putting whole pages into small fields, does any one have an efficient run time LC algorithm that will set the font size so that the formatted text will all appear in the field without needing to scroll? BR ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Set font dynamically to fit text
On 10/12/2019 8:20 PM, Sannyasin Brahmanathaswami via use-livecode wrote: Assuming one is not putting whole pages into small fields, does any one have an efficient run time LC algorithm that will set the font size so that the formatted text will all appear in the field without needing to scroll? BR Satchiai Iru - Be a Witness ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode your essentially want a repeat loop where you reduce the textSize of char 1 to -1 of the field until the formattedHeight of the field is less than or equal to the height of the field You probably will need a condition in the loop to prevent the textSize from going below 9 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode