Calculate max font size that fits in a rect?

后端 未结 3 1211
礼貌的吻别
礼貌的吻别 2021-01-02 14:31

I\'m attempting to find the maximum font size that will fit in a given rect for a given string. The goal of the algorithm is to fill as much of the rect as possible with as

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-02 15:02

    It may be impossible to fill a rectangle completely.

    Say at a certain font size you have two lines of text, both filling the screen horizontally, but vertically you have almost but not quite three lines of space.

    If you increase the font size just a tiny bit, then the lines don't fit anymore, so you need three lines, but three lines don't fit vertically.

    So you have no choice but to live with the vertical gap.

提交回复
热议问题