尝试调整lazasrus的SynEdit字距

秋·风 / 2023-07-21 / 原文

lazasrus的SynEdit的字距和lazarus自带的控件使用相同的字体时是不一样的,当使用不同字体,字距相差非常大。lazarus IDE的代码编辑器使用SynEdit,也存在同样情况,为改善这情况,近日抽空修改了SynEdit的代码,用最简单的方法处理这个问题(不算完善)。
修改方法:
打开/lazarus/components/synedit/syntextdrawer.pp,定位function TheTextDrawer.GetCharWidth: Integer;增加以下黄色代码,并重新编译lazarus就可以。

function TheTextDrawer.GetCharWidth: Integer;
begin
  FBaseCharWidth:=round( FFontStock.BaseFont.size*0.75);//新增代码
  CharExtra:=0;   //新增代码
  Result := FBaseCharWidth+ CharExtra;
end;

修复前:


左图是修复后的,右图修复前的: