MCPcopy Create free account
hub / github.com/Kitware/VTK / DrawString

Method DrawString

Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:1627–1739  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1625
1626//------------------------------------------------------------------------------
1627void vtkOpenGLContextDevice2D::DrawString(float* point, const vtkStdString& string)
1628{
1629 vtkOpenGLGL2PSHelper* gl2ps = vtkOpenGLGL2PSHelper::GetInstance();
1630 if (gl2ps)
1631 {
1632 switch (gl2ps->GetActiveState())
1633 {
1634 case vtkOpenGLGL2PSHelper::Capture:
1635 {
1636 float tx = point[0];
1637 float ty = point[1];
1638 this->TransformPoint(tx, ty);
1639 double x[3] = { tx, ty, 0. };
1640 gl2ps->DrawString(string, this->TextProp, x, 0., this->Renderer);
1641 return;
1642 }
1643 case vtkOpenGLGL2PSHelper::Background:
1644 return; // Do nothing.
1645 case vtkOpenGLGL2PSHelper::Inactive:
1646 break; // Render as normal.
1647 }
1648 }
1649
1650 vtkTextRenderer* tren = vtkTextRenderer::GetInstance();
1651 if (!tren)
1652 {
1653 vtkErrorMacro("No text renderer available. Link to vtkRenderingFreeType "
1654 "to get the default implementation.");
1655 return;
1656 }
1657
1658 vtkOpenGLClearErrorMacro();
1659
1660 double* mv = this->ModelMatrix->GetMatrix()->Element[0];
1661 float xScale = mv[0];
1662 float yScale = mv[5];
1663
1664 float p[] = { std::floor(point[0] * xScale) / xScale, std::floor(point[1] * yScale) / yScale };
1665
1666 // TODO this currently ignores vtkContextScene::ScaleTiles. Not sure how to
1667 // get at that from here, but this is better than ignoring scaling altogether.
1668 // TODO Also, FreeType supports anisotropic DPI. Might be needed if the
1669 // tileScale isn't homogeneous, but we'll need to update the textrenderer API
1670 // and see if MPL/mathtext can support it.
1671 int tileScale[2];
1672 this->RenderWindow->GetTileScale(tileScale);
1673 int dpi = this->RenderWindow->GetDPI() * std::max(tileScale[0], tileScale[1]);
1674
1675 // Cache rendered text strings
1676 vtkTextureImageCache<UTF8TextPropertyKey>::CacheData& cache =
1677 this->Storage->TextTextureCache.GetCacheData(UTF8TextPropertyKey(this->TextProp, string, dpi));
1678 vtkImageData* image = cache.ImageData;
1679 if (image->GetNumberOfPoints() == 0 && image->GetNumberOfCells() == 0)
1680 {
1681 int textDims[2];
1682 if (!tren->RenderString(this->TextProp, string, image, textDims, dpi))
1683 {
1684 vtkErrorMacro("Error rendering string: " << string);

Callers 1

DrawMathTextStringMethod · 0.95

Calls 15

TransformPointMethod · 0.95
ReadyVTBOProgramMethod · 0.95
BuildVBOMethod · 0.95
SetMatricesMethod · 0.95
GetCacheDataMethod · 0.80
RenderMethod · 0.65
floorFunction · 0.50
maxFunction · 0.50
GetMatrixMethod · 0.45
GetNumberOfPointsMethod · 0.45
GetNumberOfCellsMethod · 0.45
RenderStringMethod · 0.45

Tested by

no test coverage detected