vtkCaptionActor2D可以创建带引线的标签,下载中文开源字库,通过设置字体文件实现中文显示。
字库链接:https://github.com/adobe-fonts/source-han-serif/tree/release#downloading-source-han-serif
int dumNote::CreateOrUpdateNote(vtkSmartPointer<vtkCaptionActor2D> NoteActor,const char* Text, Standard_Real Location3, int H,Standard_Real Notecolor3, Standard_Real Backgroundcolor3)
{
NoteActor->SetCaption(dmuTools::CharToUtf8(Text));//文字
//NoteActor->DragableOn(); //不能拖动
NoteActor->SetAttachmentPoint(Location0, Location1, Location2);
NoteActor->BorderOff();//无边框
NoteActor->GetProperty()->SetColor(1,1, 1);
NoteActor->GetProperty()->SetLineWidth(1.0);
NoteActor->SetPosition(50*H, -50 ); // 左上角偏移
//NoteActor->LeaderOff(); //有链接线
std::string path = TZTEK::dmuTools::GetProgramDir();
path = path + "\\dmu\\SourceHanSerifSC-VF.ttf";
NoteActor->GetCaptionTextProperty()->SetVerticalJustificationToBottom();
NoteActor->GetCaptionTextProperty()->SetFontSize(30);
NoteActor->GetCaptionTextProperty()->SetFontFamily(VTK_FONT_FILE);
NoteActor->GetCaptionTextProperty()->SetFontFile(path.c_str());//字库考虑动态位置
NoteActor->GetCaptionTextProperty()->SetColor(Notecolor0, Notecolor1, Notecolor2);//文字颜色
NoteActor->GetCaptionTextProperty()->SetBackgroundColor(Backgroundcolor0, Backgroundcolor1, Backgroundcolor2);
NoteActor->GetCaptionTextProperty()->SetBackgroundOpacity(1); // 设置背景透明度
NoteActor->GetCaptionTextProperty()->BoldOn();
NoteActor->GetCaptionTextProperty()->ShadowOff();//文字无阴影
//NoteActor->GetCaptionTextProperty()->SetFrame(1);
//NoteActor->GetCaptionTextProperty()->SetFrameWidth(30);
NoteActor->SetPickable(0);
NoteActor->SetVisibility(1);
char* cCharUtf = dmuTools::CharToUtf8(Text);
//NoteActor->SetCaption(cCharUtf);
int size = strlen(cCharUtf);
int num = 1;
int max = 0;
while (cCharUtf != NULL)
{
char* a = strstr((char*)cCharUtf, "\n");
if (a != NULL)
{
size = strlen(cCharUtf);
if (max < size - strlen(a))
max = size - strlen(a);
num++;
cCharUtf = a + 1;
}
else
{
if (max < strlen(cCharUtf))
max = strlen(cCharUtf);
break;
}
}
NoteActor->SetWidth(2*0.009 * max);
NoteActor->SetHeight(2*0.025 * num);
//double w = NoteActor->GetPosition2()0;
//double h = NoteActor->GetPosition2()1;
NoteActor->LeaderOn(); //有链接线
return 0;