VTK 标签中文

发布于:2025-08-12 ⋅ 阅读:(21) ⋅ 点赞:(0)

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 Location[3], int H,Standard_Real Notecolor[3], Standard_Real Backgroundcolor[3])
{
    
    NoteActor->SetCaption(dmuTools::CharToUtf8(Text));//文字
    //NoteActor->DragableOn();      //不能拖动
    NoteActor->SetAttachmentPoint(Location[0], Location[1], Location[2]);
    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(Notecolor[0], Notecolor[1], Notecolor[2]);//文字颜色
    NoteActor->GetCaptionTextProperty()->SetBackgroundColor(Backgroundcolor[0], Backgroundcolor[1], Backgroundcolor[2]);
    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;


网站公告

今日签到

点亮在社区的每一天
去签到