Search code examples
vtknon-ascii-characters

VTK 7.x How to show non ASCII text on TextActor


Environment:

  • Ubuntu 14.04 64 bit
  • VTK 7.1

VTK 7.x remove the ftgl. https://gitlab.kitware.com/vtk/vtk/merge_requests/660
So how to show non ASCII text now?
I try this code, but show nothing:

vtkSmartPointer<vtkTextActor> textActor =
        vtkSmartPointer<vtkTextActor>::New();
textActor->SetInput("\u5728\u7ebf\u5de5\u5177");
// or
textActor->SetInput("中文");

Any help appreciated!


Solution

  • Thanks for VTK developers.
    VTK supports non ASCII text.
    Only have to specify a font file on the vtkTextProperty -- the default fonts in VTK only support ascii.

    The following example use Droid font to display Chinese characters.

    vtkSmartPointer<vtkTextActor> textActor =
            vtkSmartPointer<vtkTextActor>::New();
    textActor->GetTextProperty()->SetFontFamily(VTK_FONT_FILE);
    textActor->GetTextProperty()->SetFontFile("/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf");
    textActor->SetInput("UTF-8 FreeType 中文: \xe4\xb8\xad\xe6\x96\x87");
    

    https://gitlab.kitware.com/vtk/vtk/issues/16904