Commit dd736dc2 authored by David C. Lonie's avatar David C. Lonie

Add option to convert text in GL2PS exports to path data.

Turns out that the GL2PS PDF backend silently ignores alignment
settings for data. This provides a workable alternative.

Change-Id: I09abbbd74fa3787e641020f038d9915a2145341e
parent c8dc3927
......@@ -142,6 +142,7 @@ void vtkGL2PSExporter::WriteData()
// Setup the helper class.
vtkGL2PSUtilities::SetRenderWindow(this->RenderWindow);
vtkGL2PSUtilities::SetTextAsPath(this->TextAsPath != 0);
// Store the "properly" rendered image's pixel data for special actors that
// need to copy bitmaps into the output (e.g. paraview's scalar bar actor)
......@@ -245,6 +246,7 @@ void vtkGL2PSExporter::WriteData()
// Clean up:
vtkGL2PSUtilities::SetRenderWindow(NULL);
vtkGL2PSUtilities::SetTextAsPath(false);
// Re-enable depth peeling if needed
for (int i = 0; i < static_cast<int>(origDepthPeeling.size()); ++i)
{
......
......@@ -258,6 +258,14 @@ public:
vtkGetMacro(Write3DPropsAsRasterImage, int);
vtkBooleanMacro(Write3DPropsAsRasterImage, int);
// Description:
// Turn on/off exporting text as path information, rather than character data.
// This is useful for the PDF backend, which does not properly
// support aligned text otherwise. Defaults to Off.
vtkSetMacro(TextAsPath, bool);
vtkGetMacro(TextAsPath, bool);
vtkBooleanMacro(TextAsPath, bool);
// Description:
// Collection of 3D Props to exclude from rasterization. These will be
// rendered as 2D vector primitives in the output. This setting is ignored if
......@@ -330,6 +338,7 @@ protected:
int PS3Shading;
int OcclusionCull;
int Write3DPropsAsRasterImage;
bool TextAsPath;
float *PixelData;
int PixelDataSize[2];
......
......@@ -18,6 +18,7 @@
#include "vtkImageData.h"
#include "vtkIntArray.h"
#include "vtkFloatArray.h"
#include "vtkFreeTypeTools.h"
#include "vtkMath.h"
#include "vtkMatrix4x4.h"
#include "vtkNew.h"
......@@ -33,31 +34,64 @@
#include <string>
vtkStandardNewMacro(vtkGL2PSUtilities)
bool vtkGL2PSUtilities::TextAsPath = false;
vtkRenderWindow *vtkGL2PSUtilities::RenderWindow = NULL;
void vtkGL2PSUtilities::DrawString(const char *str,
vtkTextProperty *tprop, double pos[])
{
if (!vtkGL2PSUtilities::TextAsPath)
{
const char *fontname = vtkGL2PSUtilities::TextPropertyToPSFontName(tprop);
const char *fontname = vtkGL2PSUtilities::TextPropertyToPSFontName(tprop);
GLint align = static_cast<GLint>(
vtkGL2PSUtilities::TextPropertyToGL2PSAlignment(tprop));
GLint align = static_cast<GLint>(
vtkGL2PSUtilities::TextPropertyToGL2PSAlignment(tprop));
GLfloat angle = static_cast<GLfloat>(tprop->GetOrientation());
GLfloat angle = static_cast<GLfloat>(tprop->GetOrientation());
GLint fontSize = static_cast<GLint>(tprop->GetFontSize());
GLint fontSize = static_cast<GLint>(tprop->GetFontSize());
GL2PSrgba rgba;
double rgbad[3];
tprop->GetColor(rgbad[0], rgbad[1], rgbad[2]);
rgba[0] = static_cast<GLfloat>(rgbad[0]);
rgba[1] = static_cast<GLfloat>(rgbad[1]);
rgba[2] = static_cast<GLfloat>(rgbad[2]);
rgba[3] = tprop->GetOpacity();
GL2PSrgba rgba;
double rgbad[3];
tprop->GetColor(rgbad[0], rgbad[1], rgbad[2]);
rgba[0] = static_cast<GLfloat>(rgbad[0]);
rgba[1] = static_cast<GLfloat>(rgbad[1]);
rgba[2] = static_cast<GLfloat>(rgbad[2]);
rgba[3] = tprop->GetOpacity();
glRasterPos3dv(pos);
gl2psTextOptColor(str, fontname, fontSize, align, angle, rgba);
glRasterPos3dv(pos);
gl2psTextOptColor(str, fontname, fontSize, align, angle, rgba);
}
else
{
// Render the string to a path and then draw it to GL2PS:
vtkNew<vtkPath> path;
if (vtkFreeTypeTools *tools = vtkFreeTypeTools::GetInstance())
{
tools->StringToPath(tprop, str, path.GetPointer());
}
else
{
vtkNew<vtkGL2PSUtilities> dummy;
vtkErrorWithObjectMacro(dummy.GetPointer(), <<"Cannot access freetype "
"tools!");
return;
}
// Get color
double rgbd[3];
tprop->GetColor(rgbd[0], rgbd[1], rgbd[2]);
unsigned char rgba[4] = {
static_cast<unsigned char>(rgbd[0]*255),
static_cast<unsigned char>(rgbd[1]*255),
static_cast<unsigned char>(rgbd[2]*255),
static_cast<unsigned char>(tprop->GetOpacity()*255)};
// Get device coordinate
double devicePos[3] = {pos[0], pos[1], pos[2]};
vtkGL2PSUtilities::ProjectPoint(devicePos);
vtkGL2PSUtilities::DrawPath(path.GetPointer(), pos, devicePos, rgba);
}
}
const char *vtkGL2PSUtilities::TextPropertyToPSFontName(vtkTextProperty *tprop)
......
......@@ -82,6 +82,16 @@ public:
unsigned char rgba[4], double scale[2] = NULL,
double rotateAngle = 0.0, float strokeWidth = -1);
// Set/Get whether all text will be exported as paths.
static void SetTextAsPath(bool b)
{
vtkGL2PSUtilities::TextAsPath = b;
}
static bool GetTextAsPath()
{
return vtkGL2PSUtilities::TextAsPath;
}
protected:
static void DrawPathPS(vtkPath *path, double rasterPos[3],
double windowPos[2], unsigned char rgba[4],
......@@ -102,7 +112,9 @@ protected:
private:
vtkGL2PSUtilities(const vtkGL2PSUtilities &); // Not implemented
void operator=(const vtkGL2PSUtilities&); // Not implemented
static vtkRenderWindow *RenderWindow;
static bool TextAsPath;
// Description:
// Project the point from world coordinates into device coordinates.
......
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