Algorithm for estimating text width based on contents

前端 未结 8 2138
傲寒
傲寒 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:53

    This is actually an attempt to build some smarts into a string truncation method [...]

    Is it really worth the effort? We had this exact problem. And this was across languages. The fix was to leave it as-is. The complexity of keeping this intelligence up increases rapidly (and probably exponentially) with every language that you add support for. Hence our decision.

    [...] an algorithm for estimating and categorising text width (for a variable width font) based on its contents?

    Most font-libraries will give you this information. But this is pretty low-level stuff. The basic idea is to pass in a string and get back the width in points.

提交回复
热议问题