问题描述
我的应用程序允许用户在画布上创建文本对象。该对象可以保存到项目文件中,以便以后加载。
为了使对象在各种平台上加载后看起来相同,我将文本对象实现为路径。这也允许用户使用下载的字体,然后在不使用该字体的其他设备上打开项目文件-文本不会更改外观。
使用TTextLayout.ConvertToPath
创建路径,并使用TCanvas.FillPath
绘制路径。这对于大多数字体都可以正常工作,但在其他字体上存在问题。
下图显示了带有Bahnschrift字体的结果(顶部)。底部显示了使用MS Paint时的外观。这种字体似乎具有相交的路径,我认为问题在于FillPath使用的是替代填充模式,这似乎不是更改的选项。
我还通过创建文本并将其转换为路径,在Inkscape中测试了与SVG相同的字体,但是绘制正确。 Delphi和Inkscape创建的路径数据本质上是相同的(t包含2个彼此交叉的封闭区域),因此绘制它们的方式必须不同。
有人可以为此提出建议吗?
这是代码
procedure TMainForm.Button1Click(Sender: TObject);
Var
LPath : TPathData;
LLayout : TTextLayout;
begin
LLayout := TTextLayoutManager.DefaultTextLayout.Create;
LLayout.Text := 'test';
LLayout.Font.Family := 'Bahnschrift';
LPath := TPathData.Create;
LLayout.ConvertToPath(LPath);
// Draw the path to a bitmap
SavePathBitmap(LPath,'Path_test');
LLayout.Free;
LPath.Free;
end;
procedure TMainForm.SavePathBitmap(APath : TPathData ; AFileName : String);
var
bmp : TBitmap;
rect : TRectF;
begin
APath.Scale(10,10); // Enlarge
rect := APath.GetBounds;
APath.Translate(-rect.Left + 5,-rect.Top + 5); // offset onto bitmap
bmp := TBitmap.Create(Trunc(rect.Width)+10,Trunc(rect.Height)+10);
with bmp.Canvas do if BeginScene then begin
Clear(TAlphaColorRec.White);
Fill.Color := TAlphaColorRec.Black;
FillPath(APath,1);
EndScene;
bmp.SavetoFile(AFileName + '.png');
end;
bmp.Free;
end;
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)