[vtkusers] Does vtkCaptionActor2D support chinese characters?

Liu_tj tjlp at netease.com
Fri Sep 16 13:20:37 EDT 2016


Hi, Serge,

I use pure C# code instead of C# with managed C++. Before I set the caption I transform the C# utf16 Chinese string to utf8. But it does not work. The code is as follow.

public static string Utf16ToUtf8(string utf16String)
{
   byte[] utf16Bytes = Encoding.Unicode.GetBytes(utf16String);
   byte[] utf8Bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, utf16Bytes);
   string utf8String = Encoding.Default.GetString(utf8Bytes);
   return utf8String;
}

vtkCaptionRepresentation rep = vtkCaptionRepresentation.New();
rep.GetCaptionActor2D().ThreeDimensionalLeaderOff();
rep.GetCaptionActor2D().GetTextActor().GetTextProperty().SetFontSize(25);
rep.GetCaptionActor2D().GetTextActor().GetTextProperty().SetFontFamily(4);
rep.GetCaptionActor2D().GetTextActor().GetTextProperty().SetFontFile("simsunb.ttf");
rep.GetCaptionActor2D().GetCaptionTextProperty().SetColor(0.0, 1.0, 0.0);
string utf8text = Utilities.Utf16ToUtf8(@"ab12测试");
rep.GetCaptionActor2D().SetCaption(utf8text);


....


在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/20160917/fbfb19b3/attachment.html>


More information about the vtkusers mailing list