Commit 5fff9333 authored by David C. Lonie's avatar David C. Lonie

Fix bug in text rendering.

The bounding box for FreeType strings did not include the first
character's horizontal bearing, leading to vtkImageData that was
not wide enough, and ultimately wrapping artifacts on terminal
glyphs.

The included test reproduces the wrapping artifacts when the bbox
minima are initialized to VTK_INT_MAX, and renders correctly when
they are initialized to 0 (the initial pen position).

Change-Id: Ibd99290220811546c9d6d87f4883e3ca89461186
parent eca0fc4f
......@@ -4,6 +4,7 @@
TestContextScene.cxx
TestControlPointsItem.cxx
TestControlPointsItemEvents.cxx
TestSimpleFontRendering.cxx
)
if(VTK_DATA_ROOT)
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestContext.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkContext2D.h"
#include "vtkContextItem.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkTextProperty.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLContextDevice2D.h"
#include "vtkNew.h"
#include "vtkRegressionTestImage.h"
//----------------------------------------------------------------------------
class SimpleFontRenderTest : public vtkContextItem
{
public:
static SimpleFontRenderTest *New();
vtkTypeMacro(SimpleFontRenderTest, vtkContextItem);
// Paint event for the chart, called whenever the chart needs to be drawn
virtual bool Paint(vtkContext2D *painter);
};
//----------------------------------------------------------------------------
int TestSimpleFontRendering( int, char * [] )
{
// Set up a 2D context view, context test object and add it to the scene
vtkNew<vtkContextView> view;
view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
view->GetRenderWindow()->SetSize(150, 30);
vtkNew<SimpleFontRenderTest> test;
view->GetScene()->AddItem(test.GetPointer());
// Force the use of the freetype based rendering strategy
vtkOpenGLContextDevice2D::SafeDownCast(view->GetContext()->GetDevice())
->SetStringRendererToFreeType();
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
// Make our new derived class to draw a diagram
vtkStandardNewMacro(SimpleFontRenderTest);
bool SimpleFontRenderTest::Paint(vtkContext2D *painter)
{
painter->GetTextProp()->SetColor(0.0, 0.0, 0.0);
painter->GetTextProp()->SetFontFamilyToArial();
painter->GetTextProp()->SetFontSize(24);
painter->DrawString(5, 5, "1");
painter->DrawString(50, 5, "1.5");
painter->DrawString(100, 5, "10");
return true;
}
......@@ -871,8 +871,10 @@ bool vtkFreeTypeTools::CalculateBoundingBox(vtkTextProperty *tprop,
const T& str,
int bbox[4])
{
// Initialize bbox to some large values
bbox[0] = bbox[2] = VTK_INT_MAX;
// Initialize bbox minima to 0 -- this is the starting point of the pen,
// omitting it will not consider the first character's bearing.
bbox[0] = bbox[2] = 0;
// This will be updated as the glyphs bboxes are tested:
bbox[1] = bbox[3] = VTK_INT_MIN;
// Map the text property to a unique id that will be used as face id, get the
......
......@@ -853,8 +853,10 @@ int vtkFreeTypeUtilities::GetBoundingBox(vtkTextProperty *tprop,
return 0;
}
// Initialize bbox to some large values
bbox[0] = bbox[2] = VTK_INT_MAX;
// Initialize bbox minima to 0 -- this is the starting point of the pen,
// omitting it will not consider the first character's bearing.
bbox[0] = bbox[2] = 0;
// This will be updated as the glyphs bboxes are tested:
bbox[1] = bbox[3] = VTK_INT_MIN;
// No string to render, bail out now
......
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