Commit edf5bcfa authored by David C. Lonie's avatar David C. Lonie
Browse files

Handle UTF-8 strings in vtkMathTextFreeTypeTextRenderer.

Treat incoming strings as UTF-8 and add tests on extended character
sets.

Change-Id: Id9c51012b263c17869073b4b72057e54d57fd07b
parent 72dd633d
......@@ -14,12 +14,16 @@ if(NOT MATPLOTLIB_FOUND)
endif()
# add tests that do not require data or produce vector output
set(TestMathTextFreeTypeTextRendererNoMath_ARGS
DATA{../Data/Fonts/DejaVuSans.ttf}
)
vtk_add_test_cxx(TestMathTextFreeTypeTextRendererNoMath.cxx)
# add tests that require data
vtk_add_test_cxx(TestFTStringToPath.cxx)
if(MATPLOTLIB_FOUND)
set(TestMathTextFreeTypeTextRenderer_ARGS DATA{../Data/Fonts/DejaVuSans.ttf})
vtk_add_test_cxx(TestMathTextFreeTypeTextRenderer.cxx)
endif()
......
......@@ -24,10 +24,19 @@
#include "vtkTextProperty.h"
#include <iostream>
#include <string>
//----------------------------------------------------------------------------
int TestMathTextFreeTypeTextRenderer(int , char *[])
int TestMathTextFreeTypeTextRenderer(int argc, char *argv[])
{
if (argc < 2)
{
cerr << "Missing font filename." << endl;
return EXIT_FAILURE;
}
std::string uncodeFontFile(argv[1]);
vtkNew<vtkTextRenderer> tren;
if (tren.GetPointer() == NULL)
{
......@@ -172,6 +181,17 @@ int TestMathTextFreeTypeTextRenderer(int , char *[])
actor14->SetInput("4.0");
actor14->SetPosition(500, 400);
// UTF-8 freetype handling:
vtkNew<vtkTextActor> actor15;
actor15->GetTextProperty()->SetFontFamily(VTK_FONT_FILE);
actor15->GetTextProperty()->SetFontFile(uncodeFontFile.c_str());
actor15->GetTextProperty()->SetJustificationToCentered();
actor15->GetTextProperty()->SetVerticalJustificationToCentered();
actor15->GetTextProperty()->SetFontSize(18);
actor15->GetTextProperty()->SetColor(0.0, 1.0, 0.7);
actor15->SetInput("UTF-8 FreeType: \xce\xa8\xd2\x94\xd2\x96\xd1\x84\xd2\xbe");
actor15->SetPosition(300, 110);
// Boring rendering setup....
vtkNew<vtkRenderer> ren;
......@@ -196,6 +216,7 @@ int TestMathTextFreeTypeTextRenderer(int , char *[])
ren->AddActor(actor12.GetPointer());
ren->AddActor(actor13.GetPointer());
ren->AddActor(actor14.GetPointer());
ren->AddActor(actor15.GetPointer());
win->SetMultiSamples(0);
win->Render();
......
......@@ -24,10 +24,19 @@
#include "vtkTextProperty.h"
#include <iostream>
#include <string>
//----------------------------------------------------------------------------
int TestMathTextFreeTypeTextRendererNoMath(int , char *[])
int TestMathTextFreeTypeTextRendererNoMath(int argc, char *argv[])
{
if (argc < 2)
{
cerr << "Missing font filename." << endl;
return EXIT_FAILURE;
}
std::string uncodeFontFile(argv[1]);
vtkNew<vtkTextRenderer> tren;
if (tren.GetPointer() == NULL)
{
......@@ -133,6 +142,17 @@ int TestMathTextFreeTypeTextRendererNoMath(int , char *[])
actor9->SetInput("4.0");
actor9->SetPosition(500, 400);
// UTF-8 freetype handling:
vtkNew<vtkTextActor> actor10;
actor10->GetTextProperty()->SetFontFamily(VTK_FONT_FILE);
actor10->GetTextProperty()->SetFontFile(uncodeFontFile.c_str());
actor10->GetTextProperty()->SetJustificationToCentered();
actor10->GetTextProperty()->SetVerticalJustificationToCentered();
actor10->GetTextProperty()->SetFontSize(18);
actor10->GetTextProperty()->SetColor(0.0, 1.0, 0.7);
actor10->SetInput("UTF-8 FreeType: \xce\xa8\xd2\x94\xd2\x96\xd1\x84\xd2\xbe");
actor10->SetPosition(300, 110);
// Boring rendering setup....
vtkNew<vtkRenderer> ren;
......@@ -152,6 +172,7 @@ int TestMathTextFreeTypeTextRendererNoMath(int , char *[])
ren->AddActor(actor7.GetPointer());
ren->AddActor(actor8.GetPointer());
ren->AddActor(actor9.GetPointer());
ren->AddActor(actor10.GetPointer());
win->SetMultiSamples(0);
win->Render();
......
......@@ -94,7 +94,9 @@ bool vtkMathTextFreeTypeTextRenderer::GetBoundingBoxInternal(
{
vtkStdString cleanString(str);
this->CleanUpFreeTypeEscapes(cleanString);
return this->FreeTypeTools->GetBoundingBox(tprop, cleanString, bbox);
// Interpret string as UTF-8, use the UTF-16 GetBoundingBox overload:
return this->FreeTypeTools->GetBoundingBox(
tprop, vtkUnicodeString::from_utf8(cleanString), bbox);
}
default:
vtkDebugMacro("Unrecognized backend requested: " << backend);
......@@ -199,8 +201,9 @@ bool vtkMathTextFreeTypeTextRenderer::RenderStringInternal(
{
vtkStdString cleanString(str);
this->CleanUpFreeTypeEscapes(cleanString);
return this->FreeTypeTools->RenderString(tprop, cleanString, data,
textDims);
// Interpret string as UTF-8, use the UTF-16 RenderString overload:
return this->FreeTypeTools->RenderString(
tprop, vtkUnicodeString::from_utf8(cleanString), data, textDims);
}
default:
vtkDebugMacro("Unrecognized backend requested: " << backend);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment