Need a way to scale a font to fit a rectangle

前端 未结 6 1259
耶瑟儿~
耶瑟儿~ 2021-01-01 19:46

I just wrote some code to scale a font to fit within (the length of) a rectangle. It starts at 18 width and iterates down until it fits.

This seems horribly ineffic

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-01 20:37

    You can improve the efficiency using a binary search pattern - high/low with some granularity - either 1, 0.5 or 0.25 points.

    For example, guess at 18, too high? Move to 9, too Low? 13.5, too low? 15.75, too high? 14!

提交回复
热议问题