自定义文本编辑器字符宽度问题 [英] Custom text editor character width issue

查看:117
本文介绍了自定义文本编辑器字符宽度问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用16px的等宽字体Consolas编写自定义文本编辑器。当光标向右移动每个光标时,光标会获得额外8.8px的左边距。但是,对于长行,这与字符不同步,因此它们的宽度不能精确地为8.8px。我在互联网上找不到关于Consolas宽高比的任何内容,所以我不确定应该做什么。



如果你能提供任何指导,那就是' d真的很有用。



评论中提到的代码:



Hi,

I'm writing a custom text editor using the monospace font Consolas at 16px. The cursor gets an additional 8.8px of left margin as it moves over every cursor towards the right. However, with long lines, this becomes out of sync with the characters so their width can't be exactly 8.8px. I can't find anything on the internet about Consolas' aspect ratio so I'm not sure what I should do.

If you could provide any guidance, that'd be really useful.

Code referred to in comments:

var start_pos = LineOperations.convert_char_focused_to_actual_char(start_index) * (CHAR_WIDTH + 0.35);
	var end_pos = (LineOperations.convert_char_focused_to_actual_char(end_index) * (CHAR_WIDTH + 0.35)) - start_pos;
	
	text_highlight_history.push(fill_rect(text_highlight_overlay_context, Math.round(start_pos), 23 * line_focused, Math.round(end_pos), 23, Config.text_highlight_colour));

< br $>


注意: convert_char_focused_to_actual_char 已经过全面测试并按预期工作。它找到所选字符在该行上的位置,将标签视为4个字符。



我尝试过:



缩小数字,但我不习惯使用这样精确的小数,因为我不能保证它看起来对于任何给定的行长度都是正确的。



Note: convert_char_focused_to_actual_char has been thoroughly tested and works as expected. It finds the position of the selected character on the line, treating tabs as 4 characters.

What I have tried:

Narrowing down the number but I'm not comfortable using such precise decimals as I cannot guarantee it'll look right for any given line length.

推荐答案

Quill - 功能强大的富文本编辑器 [ ^ ]



5个免费的JavaScript库,用于向Web应用程序添加文本编辑 [ ^ ]


这篇关于自定义文本编辑器字符宽度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆