Algorithm for estimating text width based on contents

前端 未结 8 2159
傲寒
傲寒 2021-02-08 09:11

This is a long shot, but does anyone know of an algorithm for estimating and categorising text width (for a variable width font) based on its contents?

For example, I\'d

8条回答
  •  一个人的身影
    2021-02-08 09:28

    I think you should choose one of these solutions:

    • Exact solution: Sum up the width for every character in the string (most APIs will give you this information)
    • Quick estimate: Either take the maximum or the minimum width and multiply it with the numbers of characters.

    Of course some mixed estimate is possible, but I think this is too much effort in the wrong direction.

提交回复
热议问题