[vtkusers] VTK 6.1 no longer supports ASCII characters > 128? (5.10.1 was ok)

David E DeMarle dave.demarle at kitware.com
Wed Jan 21 16:22:47 EST 2015

Thanks for posting a solution to the list Serge!

Mind adding a note on the vtk wiki about it so this tidbit doesn't get
A short note containing a markmail url to your post somewhere on
http://www.vtk.org/Wiki/VTK/Roadmap around the 6.0 transition pages will

David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909

On Wed, Jan 21, 2015 at 3:26 PM, Serge Lalonde <serge at infolytica.com> wrote:

>  Dear VTK Users,
> So I finally got it working. Many thanks to all who replied, particularly
> David Gobbi.
> Here's the summary so that anyone trying to do this in the future will
> find it easier.
> To pass a Unicode C++/CLI .NET string from a String^ to a VTK 6.1 UTF-8
> encoded string for display:
>    m_VTKScalarBarActor->SetTitle(*vtkUnicodeString**::**from_utf16**((**const* *vtkTypeUInt16** *) **marshal_as**<**std**::**wstring**>(**colormap_title**).**c_str**()).**utf8_str**()*);
> Basically, marshal the .NET String^ to a std::wstring to get it in UCS-2
> Unicode for C++, cast its contents to vtkUInt16* (small cheat here, but VTK
> or the UTF-8 lib should accept wchar_t* instead) and then pass that to
> vtkUnicodeString which will convert it to UTF-8. Phew!
> Note that this also requires that the vtkTextProperty of the text being
> drawn (in this case the Title of the vtkScalarBarActor) also needs to have
> it's font family set to VTK_FONT_FILE and the font file must point to a
> valid font:
>    m_VTKScalarBarActor->GetTitleTextProperty()->SetFontFamily(VTK_FONT_FILE);
>    m_VTKScalarBarActor->GetTitleTextProperty()->SetFontFile("C:\\Windows\\winsxs\\amd64_microsoft-windows-font-truetype-arial_31bf3856ad364e35_6.1.7601.18528_none_d0a29012c3ff391b\\arial.ttf");
> You can use system TTF files (like I did here) or free ones, like DejaVu
> fonts. I'm still looking at how to get the font file automatically, since
> this was used as a test, I just searched my C:\Windows folder to find an
> Arial font to try out. I'll post again once I get this working. Note that I
> did actually test the DejaVu fonts and they worked.
> If, on the other hand, you're happy with Latin1 encoded characters, you
> can do this instead:
>    m_VTKScalarBarActor->SetTitle(marshal_as<std::string>(System::Text::Encoding::GetEncoding("ISO-8859-1")->GetString(System::Text::Encoding::UTF8->GetBytes(colormap_title))).c_str());
> This can display fewer characters, but doesn't require that the font
> family and font file be set.
> The same must be done to handle file names coming from a user in case it
> also contains Unicode characters:
>    pWriter->SetFileName(vtkUnicodeString::from_utf16((const vtkTypeUInt16 *) marshal_as<std::wstring>(file_path).c_str()).utf8_str());
> Unfortunately, the writers (and probably the readers) still use fopen() in
> the internal code which can't handle UTF-8 encoded filenames.
> So a filename like "C:\Users\serge\Desktop\Test Ύ Δ δ Ϡ.png" becomes
> "C:\Users\serge\Desktop\Test ÎŽ Δ δ Ï .png". Not great, but if you ignore
> the conversion, you get errors and the file isn't written for writers or
> (presumably) read for readers (you get Debug messages in the error
> console). So it's still better to do the conversion and it will be ready
> when this is improved in VTK. BTW, is this on the roadmap to be fixed?
> I hope that this will help others in the future.
> --
> www.infolytica.com
> 300 Leo Pariseau, Suite 2222, Montreal, QC, Canada, H2X 4B3
> (514) 849-8752 x236, Fax: (514) 849-4239
> _______________________________________________
> Powered by www.kitware.com
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Search the list archives at: http://markmail.org/search/?q=vtkusers
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150121/3ac24d59/attachment.html>

More information about the vtkusers mailing list