[vtkusers] Does vtkCaptionActor2D support chinese characters?
Liu_tj
tjlp at netease.com
Wed Feb 8 10:38:52 EST 2017
Hi, Serge,
As we switch to C# GUI with Managed C++, I follow your solution and try to display chinese characters. It doesn't work.
Below is my C++ code:
void MDKCaptionWidget::SetCaption(String^ aCaption)
{
vtkCaptionActor2D* captionActor = _captionRep->GetCaptionActor2D();
captionActor->GetCaptionTextProperty()->SetFontFamily(VTK_FONT_FILE);
captionActor->GetCaptionTextProperty()->SetFontFile("C:\\Windows\\winsxs\\amd64_microsoft-windows-font-truetype-simsun_31bf3856ad364e35_6.1.7600.16385_none_56fe10b1895fd80b\\simsun.ttc");
captionActor->SetCaption(vtkUnicodeString::from_utf16((const vtkTypeUInt16 *)marshal_as<std::wstring>(aCaption).c_str()).utf8_str());
//captionActor->SetCaption("\xE4\xB8\xAD\xE6\x96\x87");
}
simsun.ttc is the chinese truetype font file installed on my computer. The chinese string I pass is "中文", whose utf-8 code is "\xE4\xB8\xAD\xE6\x96\x87". But if I use vtkUnicodeString::from_utf16() to decode, I get "\x00\xB8\xAD\xE6\x96\x87".
Even I directly write as follow:
captionActor->SetCaption("\xE4\xB8\xAD\xE6\x96\x87");
The chinese words are not displayed.
Thanks
Liu Peng
在2016-09-12,"Serge Lalonde" <serge at infolytica.com> 写道: -----原始邮件-----
发件人:"Serge Lalonde" <serge at infolytica.com>
发送时间:2016年09月12日 星期一
收件人:"vtkusers" <vtkusers at vtk.org>
主题:Re: [vtkusers] Does vtkCaptionActor2D support chinese characters?
I had summarized the steps in the VTK Users mailing list back in Jan 2015.
Search for "VTK 6.1 no longer supports ASCII characters > 128? (5.10.1 was ok)" in the archives.
On 9/12/2016 9:20 AM, David Lonie wrote:
On Sun, Sep 11, 2016 at 12:18 PM, Liu_tj <tjlp at netease.com> wrote:
I want to give Chinese text annotation on 3D model.Does vtkCaptionActor2D support chinese characters? If no, what class should I use?
vtkCaptionActor2D will work.
You'll need to provide a unicode font file (the embedded fonts in VTK only support ASCII) via the caption actor's GetCaptionTextProperty:
captionActor->GetCaptionTextProperty()->SetFontFamily(VTK_FONT_FILE);
captionActor->GetCaptionTextProperty()->SetFontFile("/path/to/some/unicode/font/file");
and then encode the caption text as UTF-8.
Hope this helps,
Dave
_______________________________________________
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
--
www.infolytica.com
300 Leo Pariseau, Suite 2222, Montreal, QC, Canada, H2X 4B3
(514) 849-8752 x236, Fax: (514) 849-4239
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170208/3e75e233/attachment.html>
More information about the vtkusers
mailing list