Commit 47b6fa6e authored by David Thompson's avatar David Thompson
Browse files

Use the font scaling provided by vtkTextActor.

This will increase the size of fonts used on displays
with high pixel densities.

Also, this changes the signature of vtkTextActor::GetBoundingBox()
to take a vtkViewport. Since this is a new method for VTK6, it is
better to fix it now; having it pass a NULL viewport pointer
internally was causing crashes.

Finally, vtkTextActor::SetConstrainedFontSize() should take font
scaling into account.

Change-Id: I3cc99f99798da96f5c8e9249538ba269216e302a
parent 155b7f30
......@@ -112,6 +112,7 @@ vtkScalarBarActor::vtkScalarBarActor()
this->DrawAnnotations = 1;
this->DrawNanAnnotation = 0;
this->AnnotationTextScaling = 0;
this->FixedAnnotationLeaderLineColor = 0;
this->NanAnnotation = 0;
this->SetNanAnnotation("NaN");
......@@ -618,6 +619,8 @@ void vtkScalarBarActor::PrintSelf(ostream& os, vtkIndent indent)
<< (this->NanAnnotation ? this->NanAnnotation : "(none)") << endl;
os << indent << "AnnotationLeaderPadding: "
<< this->AnnotationLeaderPadding << endl;
os << indent << "AnnotationTextScaling: "
<< this->AnnotationTextScaling << endl;
os << indent << "DrawBackground: " << this->DrawBackground << "\n";
os << indent << "Background Property:\n";
......@@ -1420,6 +1423,11 @@ void vtkScalarBarActor::ConfigureAnnotations()
this->P->AnnotationAnchors[i] = it->first;
this->P->AnnotationColors[i] = this->P->LabelColors[it->first];
this->P->AnnotationLabels[i] = vtkSmartPointer<vtkTextActor>::New();
if (this->P->Viewport && this->AnnotationTextScaling)
{
this->P->AnnotationLabels[i]->SetTextScaleModeToViewport();
this->P->AnnotationLabels[i]->ComputeScaledFont(this->P->Viewport);
}
this->P->AnnotationLabels[i]->GetTextProperty()->ShallowCopy(
this->LabelTextProperty );
this->P->AnnotationLabels[i]->SetProperty( this->GetProperty() );
......@@ -1736,8 +1744,8 @@ int vtkScalarBarActor::PlaceAnnotationsVertically(
#define VTK_ANN_VLAYOUT(j,dir,delt) \
ctr = this->P->AnnotationAnchors[j]; \
ll[0] = lpts->InsertNextPoint(xl0, ctr, 0.); \
this->P->AnnotationLabels[j]->GetBoundingBox(bds); \
hh = (bds[3] - bds[2] + pad) / 2.; /* label half-height, incl. padding */ \
this->P->AnnotationLabels[j]->GetSize(this->P->Viewport, tsz); \
hh = (tsz[1] + pad) / 2.; /* label half-height, incl. padding */ \
if ((dir < 0 && ctr + hh > dnCum) || (dir > 0 && ctr - hh < upCum)) \
ctr = delt + dir * hh; \
this->P->AnnotationLabels[j]->GetTextProperty()->SetJustification( \
......@@ -1780,7 +1788,7 @@ int vtkScalarBarActor::PlaceAnnotationsVertically(
int ic = numNotes / 2;
int dn, up;
double dnCum, upCum, ctr, hh;
double bds[4];
double tsz[2];
// leader-line endpoint x-coordinates:
double xl0 =
barX + (this->TextPosition == PrecedeScalarBar ? +1 : -1) * pad / 2.;
......@@ -2140,7 +2148,7 @@ int vtkScalarBarActor::PlaceAnnotationsHorizontally(
// accumulating label displacement as we go.
int ic = numNotes / 2;
int lf, rt;
double bds[4];
double tsz[2];
vtkColor3ub leaderColor;
if (2 * ic == numNotes)
{
......@@ -2151,20 +2159,20 @@ int vtkScalarBarActor::PlaceAnnotationsHorizontally(
{
lf = ic - 1;
rt = ic + 1;
this->P->AnnotationLabels[ic]->GetBoundingBox(bds);
this->P->AnnotationLabels[ic]->GetSize(this->P->Viewport, tsz);
placer.Place(
ic, this->P->AnnotationAnchors[ic], bds[1] - bds[0], bds[3] - bds[2]);
ic, this->P->AnnotationAnchors[ic], tsz[0], tsz[1]);
VTK_ANN_HLAYOUT(ic, placer);
}
for ( ; lf >= 0; -- lf, ++ rt )
{
this->P->AnnotationLabels[lf]->GetBoundingBox(bds);
this->P->AnnotationLabels[lf]->GetSize(this->P->Viewport, tsz);
placer.Place(
lf, this->P->AnnotationAnchors[lf], bds[1] - bds[0], bds[3] - bds[2]);
lf, this->P->AnnotationAnchors[lf], tsz[0], tsz[1]);
VTK_ANN_HLAYOUT(lf,placer);
this->P->AnnotationLabels[rt]->GetBoundingBox(bds);
this->P->AnnotationLabels[rt]->GetSize(this->P->Viewport, tsz);
placer.Place(
rt, this->P->AnnotationAnchors[rt], bds[1] - bds[0], bds[3] - bds[2]);
rt, this->P->AnnotationAnchors[rt], tsz[0], tsz[1]);
VTK_ANN_HLAYOUT(rt,placer);
}
......
......@@ -243,6 +243,16 @@ public:
vtkSetStringMacro(NanAnnotation);
vtkGetStringMacro(NanAnnotation);
// Description:
// Set/get whether annotation labels should be scaled with the viewport.
//
// The default value is 0 (no scaling).
// If non-zero, the vtkTextActor instances used to render annotation
// labels will have their TextScaleMode set to viewport-based scaling,
// which nonlinearly scales font size with the viewport size.
vtkSetMacro(AnnotationTextScaling,int);
vtkGetMacro(AnnotationTextScaling,int);
// Description:
// Set/Get whether a background should be drawn around the scalar bar.
// Default is off.
......@@ -468,6 +478,7 @@ protected:
int DrawColorBar; // on by default
int DrawAnnotations;
int DrawNanAnnotation;
int AnnotationTextScaling; // off by default
int FixedAnnotationLeaderLineColor;
vtkProperty2D* BackgroundProperty;
vtkProperty2D* FrameProperty;
......
......@@ -131,10 +131,11 @@ vtkTextActor::~vtkTextActor()
}
// ----------------------------------------------------------------------------
void vtkTextActor::GetBoundingBox(double bbox[4])
void vtkTextActor::GetBoundingBox(
vtkViewport* vport, double bbox[4])
{
if ( this->UpdateRectangle(NULL) && this->RectanglePoints &&
this->RectanglePoints->GetNumberOfPoints() >= 4 )
if (this->UpdateRectangle(vport) && this->RectanglePoints &&
this->RectanglePoints->GetNumberOfPoints() >= 4)
{
double x[3];
this->RectanglePoints->GetPoint( 0, x );
......@@ -169,7 +170,7 @@ void vtkTextActor::GetSize(vtkViewport* vport, double size[2])
// UpdateRectange(NULL) which builds a (probably-too-low-resolution) image
// to determine its size.
this->UpdateRectangle(vport);
this->GetBoundingBox(bds);
this->GetBoundingBox(vport, bds);
size[0] = bds[1] - bds[0];
size[1] = bds[3] - bds[2];
}
......@@ -508,7 +509,6 @@ int vtkTextActor::RenderOpaqueGeometry(vtkViewport *viewport)
return 0;
}
this->ComputeScaledFont(viewport);
if ( ! this->UpdateRectangle(viewport) )
{
return 0;
......
......@@ -157,7 +157,7 @@ public:
// Return the bounding box coordinates of the text in viewport coordinates.
// The bbox array is populated with [ xmin, xmax, ymin, ymax ]
// values in that order.
virtual void GetBoundingBox(double bbox[4]);
virtual void GetBoundingBox(vtkViewport* vport, double bbox[4]);
// Description:
// Syntactic sugar to get the size of text instead of the entire bounding box.
......
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