OpenCasCade(OCC) 中文显示

问题描述
OpenCasCade中正常汉字无法显示,在参考eryar的博客OpenCascade Chinese Text Rendering后,发现之前的版本可以在OCCT中的VDrawText 函数中添加Resource_Unicode::ConvertGBToUnicode()这个命令可以实现,在7.2版本中,原型函数发生了很大的变化,顺着这个思路,在AIS_LabelText中实现了这个功能。

代码实现

    TCollection_ExtendedString tostr;
	Standard_CString str= "OpenCasCade 你好啊";
	Resource_Unicode::ConvertGBToUnicode(str,tostr);
	Handle(AIS_TextLabel) aLabel = new AIS_TextLabel();
	aLabel -> SetText(tostr);
	aLabel -> SetColor(Quantity_NOC_RED);
	aLabel -> SetFont("SimHei");//一定要设置合适的字体,不然不能实现功能
	Handle(AIS_InteractiveContext) myAISContext = GetDocument()->GetIC();
	myAISContext->Display(aLabel,Standard_False);

效果显示
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_40247982/article/details/106765819