<div dir="ltr">Thanks for posting a solution to the list Serge!<div><br></div><div>Mind adding a note on the vtk wiki about it so this tidbit doesn't get forgotten?<div>A short note containing a markmail url to your post somewhere on <br></div><div><a href="http://www.vtk.org/Wiki/VTK/Roadmap">http://www.vtk.org/Wiki/VTK/Roadmap</a> around the 6.0 transition pages will suffice.</div><div><br></div><div><div><div><br></div><div><br></div></div></div></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">David E DeMarle<br>Kitware, Inc.<br>R&D Engineer<br>21 Corporate Drive<br>Clifton Park, NY 12065-8662<br>Phone: 518-881-4909</div></div>
<br><div class="gmail_quote">On Wed, Jan 21, 2015 at 3:26 PM, Serge Lalonde <span dir="ltr"><<a href="mailto:serge@infolytica.com" target="_blank">serge@infolytica.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Dear VTK Users,<br>
<br>
So I finally got it working. Many thanks to all who replied,
particularly David Gobbi.<br>
Here's the summary so that anyone trying to do this in the future
will find it easier.<br>
<br>
To pass a Unicode C++/CLI .NET string from a String^ to a VTK 6.1
UTF-8 encoded string for display:<br>
<pre style="font-family:Consolas;font-size:13;color:black;background:white"> <span style="color:navy">m_VTKScalarBarActor</span>-><span style="color:#880000">SetTitle</span>(<b><span style="color:blue">vtkUnicodeString</span></b><b>::</b><b><span style="color:#880000">from_utf16</span></b><b>((</b><b><span style="color:blue">const</span></b><b> </b><b><span style="color:blue">vtkTypeUInt16</span></b><b> *) </b><b><span style="color:#880000">marshal_as</span></b><b><</b><b><span style="color:blue">std</span></b><b>::</b><b><span style="color:blue">wstring</span></b><b>>(</b><b><span style="color:navy">colormap_title</span></b><b>).</b><b><span style="color:#880000">c_str</span></b><b>()).</b><b><span style="color:#880000">utf8_str</span></b><b>()</b>);
</pre>
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!<br>
<br>
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:<br>
<pre style="font-family:Consolas;font-size:13;color:black;background:white"> <span style="color:navy">m_VTKScalarBarActor</span>-><span style="color:#880000">GetTitleTextProperty</span>()-><span style="color:#880000">SetFontFamily</span>(<span style="color:#a000a0">VTK_FONT_FILE</span>);
<span style="color:navy">m_VTKScalarBarActor</span>-><span style="color:#880000">GetTitleTextProperty</span>()-><span style="color:#880000">SetFontFile</span>(<span style="color:#a31515">"C:\\Windows\\winsxs\\amd64_microsoft-windows-font-truetype-arial_31bf3856ad364e35_6.1.7601.18528_none_d0a29012c3ff391b\\arial.ttf"</span>);
</pre>
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.<br>
<br>
If, on the other hand, you're happy with Latin1 encoded characters,
you can do this instead:<br>
<pre style="font-family:Consolas;font-size:13;color:black;background:white"> <span style="color:navy">m_VTKScalarBarActor</span>-><span style="color:#880000">SetTitle</span>(<span style="color:#880000">marshal_as</span><<span style="color:blue">std</span>::<span style="color:blue">string</span>>(<span style="color:blue">System</span>::<span style="color:blue">Text</span>::<span style="color:blue">Encoding</span>::<span style="color:#880000">GetEncoding</span>(<span style="color:#a31515">"ISO-8859-1"</span>)-><span style="color:#880000">GetString</span>(<span style="color:blue">System</span>::<span style="color:blue">Text</span>::<span style="color:blue">Encoding</span>::<span style="color:navy">UTF8</span>-><span style="color:#880000">GetBytes</span>(<span style="color:navy">colormap_title</span>))).<span style="color:#880000">c_str</span>());
</pre>
This can display fewer characters, but doesn't require that the font
family and font file be set.<br>
<br>
The same must be done to handle file names coming from a user in
case it also contains Unicode characters:<br>
<pre style="font-family:Consolas;font-size:13;color:black;background:white"> <span style="color:navy">pWriter</span>-><span style="color:#880000">SetFileName</span>(<span style="color:blue">vtkUnicodeString</span>::<span style="color:#880000">from_utf16</span>((<span style="color:blue">const</span> <span style="color:blue">vtkTypeUInt16</span> *) <span style="color:#880000">marshal_as</span><<span style="color:blue">std</span>::<span style="color:blue">wstring</span>>(<span style="color:navy">file_path</span>).<span style="color:#880000">c_str</span>()).<span style="color:#880000">utf8_str</span>());
</pre>
Unfortunately, the writers (and probably the readers) still use
fopen() in the internal code which can't handle UTF-8 encoded
filenames.<br>
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?<br>
<br>
I hope that this will help others in the future.<span class="HOEnZb"><font color="#888888"><br>
<div>-- <br>
<a href="http:://www.infolytica.com" target="_blank">www.infolytica.com </a><br>
300 Leo Pariseau, Suite 2222, Montreal, QC, Canada, H2X 4B3<br>
<a href="tel:%28514%29%20849-8752%20x236" value="+15148498752" target="_blank">(514) 849-8752 x236</a>, Fax: <a href="tel:%28514%29%20849-4239" value="+15148494239" target="_blank">(514) 849-4239</a>
</div>
</font></span></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>