Skip to content

Commit 5dcad97

Browse files
committed
vtkTextMapper: fix rendering of empty string
vtkTextMapper improperly renders empty strings. Instead of rendering nothing, as expected for an empty string, a rectangle is rendered. The rectangle is visible only when the text property's background is not completely transparent. This commit fixes the problem at two levels: in vtkFreeTypeTools and in vtkTextMapper. vtkFreeTypeTools now checks for an empty string when rendering to an image. Without this check, rendering an empty string results in the small rectangle. vtkTextMapper::RenderOverlay() is updated to handle the case of an empty image. This also serves as a revised solution to #15787: http://www.vtk.org/Bug/view.php?id=15787 Fixes #16071: http://www.vtk.org/Bug/view.php?id=16071
1 parent 75b256a commit 5dcad97

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

Rendering/Core/vtkTextMapper.cxx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void vtkTextMapper::RenderOverlay(vtkViewport *viewport, vtkActor2D *actor)
367367
vtkDebugMacro(<<"RenderOverlay called");
368368

369369
vtkRenderer *ren = NULL;
370-
if (this->Input)
370+
if (this->Input && this->Input[0])
371371
{
372372
vtkWindow *win = viewport->GetVTKWindow();
373373
if (!win)
@@ -394,15 +394,15 @@ void vtkTextMapper::RenderOverlay(vtkViewport *viewport, vtkActor2D *actor)
394394
info->Set(vtkProp::GeneralTextureUnit(),
395395
this->Texture->GetTextureUnit());
396396
}
397-
}
398397

399-
vtkDebugMacro(<<"PolyData::RenderOverlay called");
400-
this->Mapper->RenderOverlay(viewport, actor);
398+
vtkDebugMacro(<<"PolyData::RenderOverlay called");
399+
this->Mapper->RenderOverlay(viewport, actor);
401400

402-
// clean up
403-
if (ren)
404-
{
405-
this->Texture->PostRender(ren);
401+
// clean up
402+
if (ren)
403+
{
404+
this->Texture->PostRender(ren);
405+
}
406406
}
407407

408408
vtkDebugMacro(<<"Superclass::RenderOverlay called");

Rendering/FreeType/Testing/Cxx/TestFreeTypeTextMapperNoMath.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,19 @@ int TestFreeTypeTextMapperNoMath(int argc, char *argv[])
172172
mapper11->SetInput("oTeVaVoVAW");
173173
actor11->SetPosition(300, 200);
174174

175+
// Empty string, solid background: should not render
176+
vtkNew<vtkTextMapper> mapper12;
177+
vtkNew<vtkActor2D> actor12;
178+
actor12->SetMapper(mapper12.GetPointer());
179+
mapper12->GetTextProperty()->SetFontSize(16);
180+
mapper12->GetTextProperty()->SetColor(1.0, 0.0, 0.0);
181+
mapper12->GetTextProperty()->SetBackgroundColor(1.0, 0.5, 1.0);
182+
mapper12->GetTextProperty()->SetBackgroundOpacity(1.0);
183+
mapper12->GetTextProperty()->SetJustificationToRight();
184+
mapper12->GetTextProperty()->SetVerticalJustificationToCentered();
185+
mapper12->SetInput("");
186+
actor12->SetPosition(0, 0);
187+
175188
// Boring rendering setup....
176189

177190
vtkNew<vtkRenderer> ren;
@@ -193,6 +206,7 @@ int TestFreeTypeTextMapperNoMath(int argc, char *argv[])
193206
ren->AddActor(actor9.GetPointer());
194207
ren->AddActor(actor10.GetPointer());
195208
ren->AddActor(actor11.GetPointer());
209+
ren->AddActor(actor12.GetPointer());
196210

197211
win->SetMultiSamples(0);
198212
win->Render();

Rendering/FreeType/vtkFreeTypeTools.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,14 @@ bool vtkFreeTypeTools::RenderStringInternal(vtkTextProperty *tprop,
12391239
return false;
12401240
}
12411241

1242+
if (str.empty())
1243+
{
1244+
data->Initialize();
1245+
textDims[0] = 0;
1246+
textDims[1] = 0;
1247+
return true;
1248+
}
1249+
12421250
ImageMetaData metaData;
12431251

12441252
// Setup the metadata cache

0 commit comments

Comments
 (0)