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

Remove the RenderingFreeTypeOpenGL module.

This is not supported by the new OpenGL2 backend, and doesn't support
new text features, like MathText, FontConfig, or custom font files.

It only implements vtkTextMapper, which now will use a texture-based
implementation, similar to vtkTextActor and friends.
parent 953d3b7c
......@@ -56,7 +56,7 @@ add_executable(SimpleCocoaVTK MACOSX_BUNDLE ${SimpleCocoaVTK_SRCS} ${SimpleCocoa
# Probably a better way to set the framework link libraries.
target_link_libraries(SimpleCocoaVTK "-framework Cocoa -framework OpenGL"
vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL vtkInteractionStyle )
vtkRenderingOpenGL vtkInteractionStyle )
# Set a custom plist file for the app bundle
set_target_properties(SimpleCocoaVTK PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${SimpleCocoaVTK_SOURCE_DIR}/Info-CMake.plist)
......
......@@ -4,5 +4,5 @@
// Required for proper object factory initialization.
// It happens automatically when building with CMake,
// but not when building with Xcode.
#define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
#define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingOpenGL)
#define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL)
......@@ -20,7 +20,6 @@ find_package(VTK COMPONENTS
vtkGUISupportQt
vtkGUISupportQtOpenGL
vtkIOInfovis
vtkRenderingFreeTypeOpenGL
vtkViewsInfovis
)
include(${VTK_USE_FILE})
......
......@@ -18,7 +18,6 @@ find_package(VTK COMPONENTS
vtkFiltersCore
vtkInfovisCore
vtkInteractionStyle
vtkRenderingFreeType${VTK_RENDERING_BACKEND}
vtkViewsQt
)
include(${VTK_USE_FILE})
......
......@@ -23,4 +23,4 @@ set(HyperTreeGridSphere_SRCS
# Add example showing use use of synthetic vtkHyperTreeGrid along with various filters
add_executable(HyperTreeGridSphere ${HyperTreeGridSphere_SRCS})
target_link_libraries(HyperTreeGridSphere vtkCommonCore vtkCommonSystem vtkCommonDataModel vtkCommonExecutionModel vtkIOCore vtkIOLegacy vtkFiltersCore vtkFiltersGeometry vtkFiltersHyperTree vtkInteractionStyle vtkRenderingCore vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL)
target_link_libraries(HyperTreeGridSphere vtkCommonCore vtkCommonSystem vtkCommonDataModel vtkCommonExecutionModel vtkIOCore vtkIOLegacy vtkFiltersCore vtkFiltersGeometry vtkFiltersHyperTree vtkInteractionStyle vtkRenderingCore vtkRenderingOpenGL)
......@@ -10,7 +10,6 @@ vtk_module(vtkFiltersGeneral
vtkImagingMath
vtkInteractionStyle
vtkRendering${VTK_RENDERING_BACKEND}
vtkRenderingFreeType${VTK_RENDERING_BACKEND}
vtkRenderingAnnotation
vtkRenderingLabel
vtkTestingRendering
......
......@@ -8,7 +8,6 @@ vtk_module(vtkFiltersGeneric
vtkIOXML
vtkIOLegacy
vtkRendering${VTK_RENDERING_BACKEND}
vtkRenderingFreeType${VTK_RENDERING_BACKEND}
vtkFiltersModeling
vtkRenderingLabel
vtkTestingRendering
......
......@@ -10,7 +10,7 @@ vtk_module(vtkFiltersHyperTree
vtkRenderingAnnotation
vtkTestingRendering
vtkInteractionStyle
vtkRenderingFreeType${VTK_RENDERING_BACKEND}
vtkRendering${VTK_RENDERING_BACKEND}
KIT
vtkFilters
)
......@@ -9,7 +9,6 @@ vtk_module(vtkFiltersSelection
vtkIOLegacy
vtkIOXML
vtkRendering${VTK_RENDERING_BACKEND}
vtkRenderingFreeType${VTK_RENDERING_BACKEND}
vtkRenderingAnnotation
vtkTestingRendering
vtkInteractionStyle
......
......@@ -9,7 +9,6 @@ vtk_module(vtkFiltersSources
vtkTestingRendering
vtkInteractionStyle
vtkRendering${VTK_RENDERING_BACKEND}
vtkRenderingFreeType${VTK_RENDERING_BACKEND}
vtkFiltersModeling
vtkIOXML
KIT
......
......@@ -14,7 +14,6 @@ vtk_module(vtkGeovisCore
vtkViewsInfovis
vtkRenderingCore
vtkRendering${VTK_RENDERING_BACKEND}
vtkRenderingFreeType${VTK_RENDERING_BACKEND}
vtkTestingRendering
vtkInteractionStyle
)
......@@ -26,7 +26,6 @@ vtk_module(vtkIOExport
vtkTestingRendering
vtkInteractionStyle
vtkRenderingAnnotation
vtkRenderingFreeType${VTK_RENDERING_BACKEND}
vtkRenderingVolume${VTK_RENDERING_BACKEND}
vtkRenderingContext${VTK_RENDERING_BACKEND}
vtkViewsContext2D
......
......@@ -8,7 +8,6 @@ vtk_module(vtkInfovisBoostGraphAlgorithms
vtkInteractionStyle
vtkIOInfovis
vtkViewsInfovis
vtkRenderingFreeType${VTK_RENDERING_BACKEND}
vtkChartsCore
vtkViewsContext2D
)
......@@ -14,7 +14,6 @@ vtk_module(vtkInteractionWidgets
vtkIOLegacy
vtkIOXML
vtkRenderingVolume${VTK_RENDERING_BACKEND}
vtkRenderingFreeType${VTK_RENDERING_BACKEND}
vtkTestingRendering
vtkInteractionImage
vtkInteractionStyle
......
......@@ -8,7 +8,7 @@ vtk_module(vtkRenderingAnnotation
vtkFiltersSources
TEST_DEPENDS
vtkIOGeometry
vtkRenderingFreeType${VTK_RENDERING_BACKEND}
vtkRendering${VTK_RENDERING_BACKEND}
vtkTestingRendering
vtkInteractionStyle
vtkRenderingLOD
......
......@@ -22,13 +22,6 @@
//
// .SECTION See Also
// vtkActor2D vtkTextActor vtkTextActor3D vtkTextProperty vtkTextRenderer
//
// .SECTION Note
// This class will be overridden by the older vtkOpenGLFreeTypeTextMapper when
// the vtkRenderingFreeTypeOpenGL library is linked into the executable. That
// class provides legacy support for regression testing, but lacks many of the
// newer features provided by this implementation (such as unicode and MathText
// strings). Do not link with that library if such features are needed.
#ifndef vtkTextMapper_h
#define vtkTextMapper_h
......
include(vtkObjectFactory)
set(Module_SRCS
vtkOpenGLFreeTypeTextMapper.cxx
)
set(vtk_module_overrides "vtkTextMapper")
set(vtk_module_vtkTextMapper_override "vtkOpenGLFreeTypeTextMapper")
vtk_object_factory_configure("${vtk_module_overrides}")
list(APPEND Module_SRCS
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx)
set_source_files_properties(${vtk-module}ObjectFactory.cxx WRAP_EXCLUDE)
vtk_module_library(${vtk-module} ${Module_SRCS})
vtk_module(vtkRenderingFreeTypeOpenGL
IMPLEMENTS
vtkRenderingCore
BACKEND
OpenGL
DEPENDS
vtkRenderingFreeType
vtkRenderingOpenGL
TEST_DEPENDS
vtkTestingCore
vtkTestingRendering
vtkInteractionStyle
KIT
vtkOpenGL
)
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGLFreeTypeTextMapper.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 "vtkOpenGLFreeTypeTextMapper.h"
#include "vtkActor2D.h"
#include "vtkObjectFactory.h"
#include "vtkProperty2D.h"
#include "vtkTextProperty.h"
#include "vtkViewport.h"
#include "vtkWindow.h"
#include "vtkOpenGLError.h"
#include "vtkFreeTypeUtilities.h"
#include "vtkftglConfig.h"
#include "vtkgluPickMatrix.h"
#include "FTFont.h"
#ifdef FTGL_USE_NAMESPACE
using namespace ftgl;
#endif
namespace {
inline int GetNumberOfLinesImpl(const char *str)
{
if (str == NULL || *str == '\0')
{
return 0;
}
int result = 1;
while (str != NULL)
{
if ((str = strstr(str, "\n")) != NULL)
{
result++;
str++; // Skip '\n'
}
}
return result;
}
}
//----------------------------------------------------------------------------
// Print debug info
#define VTK_FTTM_DEBUG 0
//----------------------------------------------------------------------------
// GL2PS related internal helper functions.
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkOpenGLFreeTypeTextMapper);
//----------------------------------------------------------------------------
vtkOpenGLFreeTypeTextMapper::vtkOpenGLFreeTypeTextMapper()
{
this->LastSize[0] = 0;
this->LastSize[1] = 0;
this->TextLines = NULL;
this->NumberOfLines = 0;
this->NumberOfLinesAllocated = 0;
}
//----------------------------------------------------------------------------
vtkOpenGLFreeTypeTextMapper::~vtkOpenGLFreeTypeTextMapper()
{
if (this->TextLines != NULL)
{
for (int i=0; i < this->NumberOfLinesAllocated; i++)
{
this->TextLines[i]->Delete();
}
delete [] this->TextLines;
}
if (this->LastWindow)
{
this->ReleaseGraphicsResources(this->LastWindow);
}
}
//----------------------------------------------------------------------------
char *vtkOpenGLFreeTypeTextMapper::NextLine(const char *input, int lineNum)
{
const char *ptr, *ptrEnd;
int strLen;
char *line;
ptr = input;
for (int i=0; i != lineNum; i++)
{
ptr = strstr(ptr,"\n");
ptr++;
}
ptrEnd = strstr(ptr,"\n");
if ( ptrEnd == NULL )
{
ptrEnd = strchr(ptr, '\0');
}
strLen = ptrEnd - ptr;
line = new char[strLen+1];
strncpy(line, ptr, strLen);
line[strLen] = '\0';
return line;
}
//----------------------------------------------------------------------------
void vtkOpenGLFreeTypeTextMapper::GetMultiLineSize(vtkViewport *viewport,
int size[])
{
int i;
int lineSize[2];
vtkTextProperty *tprop = this->GetTextProperty();
if (!tprop)
{
vtkErrorMacro(<<"Need text property to get multiline size of mapper");
size[0] = size[1] = 0;
return;
}
lineSize[0] = lineSize[1] = size[0] = size[1] = 0;
for ( i=0; i < this->NumberOfLines; i++ )
{
this->TextLines[i]->GetTextProperty()->ShallowCopy(tprop);
this->TextLines[i]->GetSize(viewport, lineSize);
size[0] = (lineSize[0] > size[0] ? lineSize[0] : size[0]);
size[1] = (lineSize[1] > size[1] ? lineSize[1] : size[1]);
}
// add in the line spacing
this->LineSize = size[1];
size[1] = static_cast<int>(
size[1] * (1.0 + (this->NumberOfLines - 1) * tprop->GetLineSpacing()));
}
//----------------------------------------------------------------------------
void vtkOpenGLFreeTypeTextMapper::RenderOverlayMultipleLines(
vtkViewport *viewport, vtkActor2D *actor)
{
float offset = 0.0f;
int size[2];
// make sure LineSize is up to date
this->GetMultiLineSize(viewport,size);
vtkTextProperty *tprop = this->GetTextProperty();
if (!tprop)
{
vtkErrorMacro(<<"Need text property to render multiple lines of mapper");
return;
}
switch (tprop->GetVerticalJustification())
{
case VTK_TEXT_TOP:
offset = 0.0f;
break;
case VTK_TEXT_CENTERED:
offset = (-this->NumberOfLines + 1.0f) / 2.0f;
break;
case VTK_TEXT_BOTTOM:
offset = -this->NumberOfLines + 1.0f;
break;
}
for (int lineNum=0; lineNum < this->NumberOfLines; lineNum++)
{
this->TextLines[lineNum]->GetTextProperty()->ShallowCopy(tprop);
this->TextLines[lineNum]->GetTextProperty()->SetLineOffset
(tprop->GetLineOffset() +
static_cast<int>(this->LineSize * (lineNum + offset)
* tprop->GetLineSpacing()));
this->TextLines[lineNum]->RenderOverlay(viewport,actor);
}
}
//----------------------------------------------------------------------------
void vtkOpenGLFreeTypeTextMapper::ReleaseGraphicsResources(vtkWindow *)
{
#if VTK_FTTM_DEBUG
printf("vtkOpenGLFreeTypeTextMapper::ReleaseGraphicsResources\n");
#endif
this->LastWindow = NULL;
// Very important
// the release of graphics resources indicates that significant changes have
// occurred. Old fonts, cached sizes etc are all no longer valid, so we send
// ourselves a general modified message.
// this->Modified();
}
//----------------------------------------------------------------------------
void vtkOpenGLFreeTypeTextMapper::GetSize(vtkViewport* viewport, int *size)
{
// Check for multiline
if (this->NumberOfLines > 1)
{
this->GetMultiLineSize(viewport, size);
return;
}
// Check for input
if (this->Input == NULL || this->Input[0] == '\0')
{
size[0] = size[1] = 0;
return;
}
vtkTextProperty *tprop = this->GetTextProperty();
if (!tprop)
{
vtkErrorMacro(<< "Need a text property to get size");
size[0] = size[1] = 0;
return;
}
// Check to see whether we have to rebuild anything
if (this->GetMTime() < this->SizeBuildTime &&
tprop->GetMTime() < this->SizeBuildTime)
{
#if VTK_FTTM_DEBUG
printf("vtkOpenGLFreeTypeTextMapper::GetSize: In cache!\n");
#endif
size[0] = this->LastSize[0];
size[1] = this->LastSize[1];
return;
}
// Check for font and try to set the size
vtkFreeTypeUtilities::Entry *entry =
vtkFreeTypeUtilities::GetInstance()->GetFont(tprop);
FTFont *font = entry ? entry->Font : NULL;
if (!font)
{
vtkErrorMacro(<< "Render - No font");
size[0] = size[1] = 0;
return;
}
// The font global ascender and descender might just be too high
// for given a face. Let's get a compromise by computing these values
// from some usual ascii chars.
if (entry->LargestAscender < 0 || entry->LargestDescender < 0)
{
float llx, lly, llz, urx, ury, urz;
font->BBox("_/7Agfy", llx, lly, llz, urx, ury, urz);
entry->LargestAscender = ury;
entry->LargestDescender = lly;
}
this->LastSize[0] = size[0] = static_cast<int>(font->Advance(this->Input));
this->LastSize[1] = size[1] =
static_cast<int>(entry->LargestAscender - entry->LargestDescender);
this->LastLargestDescender = static_cast<int>(entry->LargestDescender);
this->SizeBuildTime.Modified();
}
//----------------------------------------------------------------------------
void vtkOpenGLFreeTypeTextMapper::RenderOverlay(vtkViewport* viewport,
vtkActor2D* actor)
{
vtkDebugMacro (<< "RenderOverlay");
// Check for input
if (this->Input == NULL || this->Input[0] == '\0')
{
return;
}
// Check for multi-lines
if (this->NumberOfLines > 1)
{
this->RenderOverlayMultipleLines(viewport, actor);
return;
}
// Get text property
vtkTextProperty *tprop = this->GetTextProperty();
if (!tprop)
{
vtkErrorMacro(<< "Need a text property to render mapper");
return;
}
vtkOpenGLClearErrorMacro();
// Get the window information for display
vtkWindow* window = viewport->GetVTKWindow();
if (this->LastWindow && this->LastWindow != window)
{
this->ReleaseGraphicsResources(this->LastWindow);
}
this->LastWindow = window;
// Get size of text
int size[2];
this->GetSize(viewport, size);
// Get the position of the text actor
int* actorPos;
actorPos =
actor->GetActualPositionCoordinate()->GetComputedViewportValue(viewport);
// Define bounding rectangle
int pos[2];
pos[0] = actorPos[0];
pos[1] = static_cast<int>(actorPos[1] - tprop->GetLineOffset());
switch (tprop->GetJustification())
{
case VTK_TEXT_LEFT:
break;
case VTK_TEXT_CENTERED:
pos[0] = pos[0] - size[0] / 2;
break;
case VTK_TEXT_RIGHT:
pos[0] = pos[0] - size[0];
break;
}
switch (tprop->GetVerticalJustification())
{
case VTK_TEXT_TOP:
pos[1] = pos[1] - size[1] - this->LastLargestDescender;
break;
case VTK_TEXT_CENTERED:
pos[1] = pos[1] - size[1] / 2 - this->LastLargestDescender / 2;
break;
case VTK_TEXT_BOTTOM:
break;
}
// Push a 2D matrix on the stack
int *vsize = viewport->GetSize();
double *vport = viewport->GetViewport();
double *tileViewport = viewport->GetVTKWindow()->GetTileViewport();
double visVP[4];
visVP[0] = (vport[0] >= tileViewport[0]) ? vport[0] : tileViewport[0];
visVP[1] = (vport[1] >= tileViewport[1]) ? vport[1] : tileViewport[1];
visVP[2] = (vport[2] <= tileViewport[2]) ? vport[2] : tileViewport[2];
visVP[3] = (vport[3] <= tileViewport[3]) ? vport[3] : tileViewport[3];
if (visVP[0] == visVP[2] || visVP[1] == visVP[3])
{
return;
}
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
if(viewport->GetIsPicking())
{
vtkgluPickMatrix(viewport->GetPickX(), viewport->GetPickY(),
viewport->GetPickWidth(),
viewport->GetPickHeight(),
viewport->GetOrigin(), viewport->GetSize());
}
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// Store the state of the attributes we are about to change
GLboolean lightingEnabled = glIsEnabled(GL_LIGHTING);
GLint depthFunc;
glGetIntegerv(GL_DEPTH_FUNC, &depthFunc);
glDisable(GL_LIGHTING);
glDepthFunc(GL_ALWAYS);
if (actor->GetProperty()->GetDisplayLocation() == VTK_FOREGROUND_LOCATION)
{
glOrtho(0, vsize[0] - 1, 0, vsize[1] - 1, 0, 1);
}
else
{
glOrtho(0, vsize[0] - 1, 0, vsize[1] - 1, -1, 0);
}
int *winSize = viewport->GetVTKWindow()->GetSize();
int xoff = static_cast<int>(pos[0] - winSize[0] * (visVP[0]