No problem.
A binary search is an order log(N) method for finding something in an
ordered list of elements, as compared to linear search, which is order N.
(N is the number of elements, in this case, font sizes you are willing to
use.)
You have a sequence of font sizes. For each size, it either makes the
TextField too tall, or it doesn't. You want to find the biggest size which
isn't too tall.
The linear approach is to start from one end of the font size list or the
other and try sizes one by one until the TextField height crosses the
threshold.
The binary approach is to try both ends first, say 1 and 50. If 1 is too
big or 50 is too small, you already have your answer. If not, try the
middle: 25. If 25 is too big, move your idea of "biggest" down to 25, and
try the middle between 25 and 1: 13. Maybe 13 is too small, so change your
idea of "smallest" to 13. Then try the middle between 13 and 25: 19, and so
on. Once the two ends ("smallest" and "biggest") are adjacent elements (say
one point difference in font size), the one marked "smallest" is your
answer.
Binary search is only a little more complicated than a linear search to
implement, and if you are searching over a large number of font sizes, the
savings can be significant. If it's just 4 or 5 font sizes it's probably
not worth the trouble.
Binary search is a very classic computer science algorithm, so I'm sure you
can find good descriptions on the web.
Dave
On 11/12/08, Latcho <[EMAIL PROTECTED]> wrote:
>
> Hi Joel, Jonathan anf Dave for your answers
> Dave could you explain what you mean with a binary search ?
> Stijn
>
> David Hershberger wrote:
>
> Text flow of variable-width fonts with word-wrapping is inherently messy...
> there's no way to compute the number of lines with some nice math, you just
> have to run the text-flow machinery and measure the result, which is exactly
> what you have suggested. I'm pretty certain there is nothing built into
> flash or flex to choose a font size for you automatically.
>
> My only suggestion is a speed optimization: use a binary search instead of
> trying every font size.
>
> Dave
>
> On 11/12/08, Latcho <[EMAIL PROTECTED]> wrote:
>>
>>
>> I'm talking about font size, not stretching a container.
>> Increasing / decreasing font size to get an optimal fill of a box which
>> will have a fixed width and a certain height which can only be determined
>> during load time.
>> I could increase the font size of a textfield in a loop and measure it's
>> height on every point increase; when it overflows my wanted box-height I
>> take the font size of the previous step.
>> Is there an easier way ?
>> Stijn
>>
>> Joel Stransky wrote:
>>
>>> Sounds like a bad design decision to make titles of the same category
>>> various sizes. But I think you can just set the .width property, then set
>>> the .scaleY equal to the .scaleX or visa versa depending on which dimension
>>> is more important.
>>>
>>> On Wed, Nov 12, 2008 at 9:40 AM, Latcho <[EMAIL PROTECTED] <mailto:
>>> [EMAIL PROTECTED]>> wrote:
>>>
>>> I need to place project-titles in a multiline textfield, wherof
>>> the width will be fixed, but sometimes this box might be of less
>>> height because of more space used by other displaying project
>>> elements.
>>> Is there a class that can dynamically regulate the font it's size
>>> to fit the loaded text to a certian textfield height of a multile
>>> textfield?
>>> The project titles are variable in character word length. How is
>>> this solvable.
>>> Thanks !
>>> Stijn
>>>
>>> _______________________________________________
>>> Flashcoders mailing list
>>> [email protected]
>>> <mailto:[email protected]>
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>>>
>>>
>>>
>>> --
>>> --Joel
>>>
>>
>> _______________________________________________
>> Flashcoders mailing list
>> [email protected]
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>
>
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders