<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi David,<br>
<br>
Your function ConvertLatin1ToUtf8() works great and now I can at
least get the extended ASCII Latin1 encoded characters that I used
to get "out of the box" in VTK 5.10.1. I just have to preprocess the
string before passing it to SetTitle().<br>
A small hassle, but at least it works. I don't even need to bother
with FreeType fonts.<br>
<br>
Thank you David! Now at least I'm back to square 1 instead of square
0! ;-)<br>
<br>
Now, on to the bigger question, and here's where I have to give more
details...<br>
<br>
My app is actually using managed C++ to glue together the C# GUI
with the C++ VTK. This works surprisingly well.<br>
The "problem" (if you can call it that) is that C# strings are
stored internally in Unicode. Some of the text we'd like to display
is not available in the Latin1 encoding (ex: special unit symbols).
So I was hoping that since VTK 6.1 introduced Unicode support, we'd
be able to display them.<br>
If I understand the method you gave me properly, it won't help with
that.<br>
<br>
So the question comes back as: How can I display Unicode text in VTK
6.1?<br>
<br>
I'd really appreciate any help here. Thanks!<br>
<br>
<div class="moz-cite-prefix">On 1/20/2015 1:28 PM, David Gobbi
wrote:<br>
</div>
<blockquote
cite="mid:CANwS1=Gpi6rB+=oGtZvSOyVgh+fcdhk4irQ1UZ6WK9ZXzeu9Xw@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>Hi Serge,</div>
<div><br>
</div>
<div>I'm not sure if this will be useful to you, but here is a
function that I wrote a while ago</div>
<div>for converting Latin1 to utf8. A warning: even if utf8
works in some parts of VTK,</div>
<div>it definitely doesn't work in all parts of VTK. In
particular, I suspect that most readers</div>
<div>and writers do not support utf8, or only support utf8 on
certain operating systems.</div>
<div><br>
</div>
<div>Also the following unicode library is pre-installed on many
systems these days:</div>
<div><a moz-do-not-send="true"
href="http://site.icu-project.org/">http://site.icu-project.org/</a></div>
<div><br>
</div>
<div> - David </div>
<div><br>
</div>
<div><br>
</div>
<div>std::string ConvertLatin1ToUtf8(const char *text, size_t l)</div>
<div>{</div>
<div>
<div> // compute expected size of the utf8 string and
allocate it<br>
</div>
<div> const char *cp = text;</div>
<div> size_t m = l;</div>
<div> for (size_t n = 0; n < l; n++)</div>
<div> {</div>
<div> // add one byte for each 8-bit character in the
string</div>
<div> m += static_cast<unsigned char>(*cp++) >>
7;</div>
<div> }</div>
<div> s.resize(m);</div>
<div><br>
</div>
<div> // encode each latin1 character as utf8</div>
<div> cp = text;</div>
<div> size_t i = 0;</div>
<div> while (i < m)</div>
<div> {</div>
<div> while (i < m && (*cp & 0x80) == 0)</div>
<div> {</div>
<div> // convert 7-bit character to one utf8 byte</div>
<div> s[i++] = *cp++;</div>
<div> }</div>
<div> if (i < m)</div>
<div> {</div>
<div> // convert 8-bit character to two utf8 bytes</div>
<div> int code = static_cast<unsigned char>(*cp++);</div>
<div> s[i++] = (0xC0 | (code >> 6));</div>
<div> s[i++] = (0x80 | (code & 0x3F));</div>
<div> }</div>
<div> }</div>
<div> </div>
<div> return s;</div>
</div>
<div>
<div>}</div>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Tue, Jan 20, 2015 at 10:41 AM, Serge
Lalonde <span dir="ltr"><<a moz-do-not-send="true"
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"> I realized that I was
passing a TrueType font file instead of a FreeType one.<br>
So I downloaded the DejaVu fonts as recommended here: <a
moz-do-not-send="true"
href="http://vtkusers.public.kitware.narkive.com/5fy8hSRK/unicode-support"
target="_blank">http://vtkusers.public.kitware.narkive.com/5fy8hSRK/unicode-support</a><br>
But it made no difference.<br>
<br>
I also looked at the TestChartUnicode and
TextContextUnicode tests to see how it's done there and
I'm doing the same thing.<br>
<br>
So I don't see what's wrong. Anyone have any suggestions?<br>
<br>
Thanks.
<div>
<div class="h5"><br>
<br>
<div>On 1/20/2015 12:03 PM, Serge Lalonde wrote:<br>
</div>
</div>
</div>
<blockquote type="cite">
<div>
<div class="h5"> Hi Sean,<br>
<br>
Thanks for the tips on encoding. I knew that I
probably wasn't using the right terminology and I'll
read up on those soon.<br>
<br>
In the meantime, I'm no closer to being able to
display "J (A/m2)" as the title of a
vtkScalarBarActor.<br>
<br>
I tried using these APIs on the TitleTextProperty of
the vtkScalarBarActor<br>
<pre> 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");
</pre>
and then encoding the string to be a sequence of hex
escape sequences like the example here:<br>
<pre> <a moz-do-not-send="true" href="http://marc.info/?l=vtkusers&m=138868987612759&w=2" target="_blank">http://marc.info/?l=vtkusers&m=138868987612759&w=2</a>)</pre>
and it just spits out the string as-is, that is
something like
"\x4A\x20\x28\x41\x2F\x6D\xC2\xB2\x29".<br>
<br>
Is there a tutorial or a wiki that shows how to use
Unicode strings in VTK? Ideally with the system
fonts? What's the magic formula? ;-)<br>
<br>
Thanks.<br>
<br>
<div>On 1/20/2015 11:05 AM, Sean McBride wrote:<br>
</div>
<blockquote type="cite">
<pre>On Tue, 20 Jan 2015 10:18:44 -0500, Serge Lalonde said:
</pre>
<blockquote type="cite">
<pre>I'm upgrading from VTK 5.10.1 to VTK 6.1. All went smoothly until I ran
into an error rendering a vtkScalarBarActor whose title was set to "J (A/m2)".
This worked fine in 5.10.1, but in 6.1, the vtkutf8::is_valid() method
called from vtkUnicodeString::from_utf8() returns false because the
value of "2" is 0xB2 (in the extended ASCII range) but the vtkutf8 code
internally stops at 0x80 (sequence_length() in core.h returns 0). That
in turn causes a debug message "vtkUnicodeString::from_utf8(): not a
valid UTF-8 string." to appear and then other problems with vtkTextActor
not being able to calculate its bounds and so on.
</pre>
</blockquote>
<pre>I think you are a bit confused about character encodings (it's a confusing thing!).
First, there are no ASCII characters above 127. ASCII is a 7 bit code. What you mean to refer to is ISO-8859-1 aka Latin1. In that encoding, the 'square' character does indeed seem to be 0xB2:
<a moz-do-not-send="true" href="https://en.wikipedia.org/wiki/ISO/IEC_8859-1" target="_blank"><https://en.wikipedia.org/wiki/ISO/IEC_8859-1></a>
8859 is not part of Unicode at all and is not the same as UTF-8.
There are many online Unicode tools, ex:
<a moz-do-not-send="true" href="http://utf8-chartable.de" target="_blank"><http://utf8-chartable.de></a>
Where you can see the Unicode code point for 'superscript two' is U+00B2, which encoded as UTF-8 is 'c2 b2' in hex.
You might want to read this, which is a helpful classic:
<a moz-do-not-send="true" href="http://www.joelonsoftware.com/articles/Unicode.html" target="_blank"><http://www.joelonsoftware.com/articles/Unicode.html></a>
Cheers,
</pre>
</blockquote>
<br>
<div>-- <br>
<a moz-do-not-send="true"
href="http:://www.infolytica.com"
target="_blank">www.infolytica.com </a><br>
300 Leo Pariseau, Suite 2222, Montreal, QC,
Canada, H2X 4B3<br>
<a moz-do-not-send="true"
href="tel:%28514%29%20849-8752%20x236"
value="+15148498752" target="_blank">(514)
849-8752 x236</a>, Fax: <a
moz-do-not-send="true"
href="tel:%28514%29%20849-4239"
value="+15148494239" target="_blank">(514)
849-4239</a> </div>
<br>
<fieldset></fieldset>
<br>
</div>
</div>
<span class="">
<pre>_______________________________________________
Powered by <a moz-do-not-send="true" href="http://www.kitware.com" target="_blank">www.kitware.com</a>
Visit other Kitware open-source projects at <a moz-do-not-send="true" href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a>
Please keep messages on-topic and check the VTK FAQ at: <a moz-do-not-send="true" href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a>
Search the list archives at: <a moz-do-not-send="true" href="http://markmail.org/search/?q=vtkusers" target="_blank">http://markmail.org/search/?q=vtkusers</a>
Follow this link to subscribe/unsubscribe:
<a moz-do-not-send="true" href="http://public.kitware.com/mailman/listinfo/vtkusers" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a>
</pre>
</span></blockquote>
<br>
<span class="">
<div>-- <br>
<a moz-do-not-send="true"
href="http:://www.infolytica.com" target="_blank">www.infolytica.com
</a><br>
300 Leo Pariseau, Suite 2222, Montreal, QC, Canada,
H2X 4B3<br>
<a moz-do-not-send="true"
href="tel:%28514%29%20849-8752%20x236"
value="+15148498752" target="_blank">(514) 849-8752
x236</a>, Fax: <a moz-do-not-send="true"
href="tel:%28514%29%20849-4239" value="+15148494239"
target="_blank">(514) 849-4239</a> </div>
</span></div>
<br>
_______________________________________________<br>
Powered by <a moz-do-not-send="true"
href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a
moz-do-not-send="true"
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
moz-do-not-send="true"
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 moz-do-not-send="true"
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 moz-do-not-send="true"
href="http://public.kitware.com/mailman/listinfo/vtkusers"
target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
<title>Signature</title>
<a href="http:://www.infolytica.com">www.infolytica.com </a><br>
300 Leo Pariseau, Suite 2222, Montreal, QC, Canada, H2X 4B3<br>
(514) 849-8752 x236, Fax: (514) 849-4239
</div>
</body>
</html>