简体   繁体   English

html5 文本操作

[英]html5 text manipulation

I'm trying to write a piece of software to grab strings and pack them in and ordered layout, like in the image below我正在尝试编写一个软件来抓取字符串并将它们打包并有序布局,如下图所示

在此处输入图像描述

I think that to achieve that result the first step I'd take would be being able to calculate the size of a single string in the canvas in order to modify the font-size to fit the desired width.我认为要实现该结果,我将采取的第一步是能够计算 canvas 中单个字符串的大小,以便修改字体大小以适应所需的宽度。
so, if any1's got a solution to some built-in function, or a way to perform it so that I can code it myself that would be nice (very nice).所以,如果 any1 有解决一些内置 function 的方法,或者有一种方法来执行它,这样我就可以自己编写代码,那会很好(非常好)。

thanks in advance提前致谢
k ķ

If you decide to do it without CANVAS, this might come in useful: how to calculate a letter's width: http://jsfiddle.net/rudiedirkx/sCUac/ in a specific font with a specific size.如果您决定在没有 CANVAS 的情况下执行此操作,这可能会很有用:如何计算字母的宽度: http://jsfiddle.net/rudiedirkx/sCUac/使用具有特定大小的特定字体。

edit编辑
Or a sentence's width.或者一个句子的宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM