如何开始实现运行文本算法?
我有一个对话框实现,它从用户接收一定长度的文本,我想以视觉上令人愉悦的方式将其格式化为多行。用户可以在字符串中包含自己的换行符,我也想对此进行解释。
有谁知道伪代码或其他公开可用的东西我可以用作编码此类算法的参考?
I have a dialog implementation that receives a length of text from the user and I'd like to format it over multiple lines in a visually pleasing way. The user can include their own line breaks in the string which I would also like to account for.
Is anyone aware of pseudocode or something else publicly available I could use as a reference for coding such an algorithm?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您同意随机连字,那么解决方案就很简单。
只需在自动换行边界上剪切一个空格就很容易。
如果您想要非随机连字(即允许 unknown,但不允许使用 byt unk-own),
比你需要保留一个连字符的单词列表或一组规则,
如果你想要“等距”,则修改上面的算法,而不是在上面的算法之后,你需要采取少于
line_length,并增加行中间的空格。容易做到
如果您的字体是可变宽度,您将需要以物理测量单位实现该算法
而不是字符数。这也很容易做到。将维护“宽度”数组,并计算 line_length 检查。
If you okay with random hyphenation, then solution is trivial.
Just cutting a space on word-wrap boundary is easy.
If you want non-random hyphenation ( ie. un-known is allowed, byt unk-own is not ),
than you need to keep an hyphenated words list or set of rules, and modify above algorithm
if you want 'equally spaced', than after above algo, you need to take lines less than
line_length, and increases spaces in the middle of lines. Easy to do
If your font is variable width, you'll need to implement the algo in physical measurement units
rather than character count. It's also easy to do. A 'width' array is to be maintained, and line_length check is to be computed.
如果您指的是基本自动换行,我发现此帖子令人愉快的阅读。如果你谈论的是连字符、完整对齐和字距调整……我现在什么都没有。
If you mean basic word wrap, I found this posting an enjoyable read. If you're talking about hyphenation, full justification, and kerning... I'm coming up empty for now.