------------------------------------------------------------------------------
| 1625 | |
| 1626 | //------------------------------------------------------------------------------ |
| 1627 | void 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); |
no test coverage detected