[vtkusers] Problems Rendering UTF8 strings
Oliver Kania
kania.oliver at googlemail.com
Fri May 14 07:52:36 EDT 2010
Hello,
the following test-application should print the greek letter "MU" (micro
sign)
but it does print an "A with a hat" plus a MU.
The same happens with other UTF8 encoded letters.
===================================================================
int main()
{
VTK_CREATE(vtkRenderer,ren1);
ren1->SetBackground( 0.2, 0.3, 0.5 );
VTK_CREATE(vtkRenderWindow,renWin);
renWin->AddRenderer( ren1 );
renWin->SetSize( 300, 300 );
vtkUnicodeString
l_vtkUnicodeStr(vtkUnicodeString::from_utf8("\xc2\xb5"));
VTK_CREATE(CStringItem,l_item);
vtkStdString
l_str(l_vtkUnicodeStr.utf8_str(),l_vtkUnicodeStr.byte_count());
l_item->SetLabel(l_str);
VTK_CREATE(vtkContextActor,l_actor);
l_actor->GetScene()->AddItem(l_item);
vtkOpenGLContextDevice2D::SafeDownCast(l_actor->GetContext()->GetDevice())
->SetStringRendererToQt();
ren1->AddActor(l_actor);
VTK_CREATE(vtkRenderWindowInteractor, interactor);
interactor->SetRenderWindow(renWin);
renWin->SetMultiSamples(0);
renWin->Render();
interactor->Start();
}
/// code for class CStringItem used above: (Header)
class CStringItem : public vtkContextItem
{
public:
//TODO : add reset string, set position of label etc.
virtual bool Paint(vtkContext2D *painter);
//CStringItem(const vtkStdString& p_vtkStrDefault);
static CStringItem *New();
vtkTypeRevisionMacro(CStringItem, vtkContextItem);
void SetLabel(const vtkStdString& p_vtkStrLabel);
private:
vtkStdString m_vtkStr;
};
/// CPP file:
bool CStringItem::Paint( vtkContext2D *painter )
{
painter->GetTextProp()->SetVerticalJustificationToCentered();
painter->GetTextProp()->SetJustificationToCentered();
painter->GetTextProp()->SetColor(1.0, 1.0, 1.0);
painter->GetTextProp()->SetFontSize(13);
painter->GetTextProp()->SetFontFamilyToCourier();
painter->DrawString(100, 100, m_vtkStr);
// TODO return sth meaningfull
return true;
}
void CStringItem::SetLabel(const vtkStdString& p_vtkStrLabel )
{
m_vtkStr = p_vtkStrLabel;
}
vtkStandardNewMacro(CStringItem);
vtkCxxRevisionMacro(CStringItem, "$Revision: 1.5 $");
=====================================================================
In the above code, i could simply pass "\xc2\xb5" to the SetLabel method and
the same happens.
Any help would be greatly appreciated.
Best Regards,
Oliver Kania
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100514/d83016a4/attachment.htm>
More information about the vtkusers
mailing list