------------------------------------------------------------------------------
| 640 | |
| 641 | //------------------------------------------------------------------------------ |
| 642 | bool vtkMatplotlibMathTextUtilities::GetMetrics( |
| 643 | vtkTextProperty* tprop, const char* str, int dpi, vtkTextRenderer::Metrics& metrics) |
| 644 | { |
| 645 | if (!this->IsAvailable()) |
| 646 | { |
| 647 | vtkErrorMacro(<< "Matplotlib rendering is unavailable."); |
| 648 | return false; |
| 649 | } |
| 650 | |
| 651 | if (!this->MaskParser) |
| 652 | { |
| 653 | if (!this->InitializeMaskParser()) |
| 654 | { |
| 655 | vtkErrorMacro(<< "MaskParser is not initialized!"); |
| 656 | return false; |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | // Configure math text font |
| 661 | if (!this->SetMathTextFont(tprop)) |
| 662 | { |
| 663 | return false; |
| 664 | } |
| 665 | |
| 666 | // Get the font property used for all non math text. |
| 667 | vtkSmartPyObject pyFontProp(this->GetFontProperties(tprop)); |
| 668 | if (this->CheckForError(pyFontProp)) |
| 669 | { |
| 670 | return false; |
| 671 | } |
| 672 | |
| 673 | // First, parse the string |
| 674 | GridOfStrings strGrid; |
| 675 | std::size_t maxNumberOfCells; |
| 676 | if (!this->ParseString(str, strGrid, maxNumberOfCells)) |
| 677 | { |
| 678 | vtkWarningMacro(<< "Failed to parse string."); |
| 679 | return false; |
| 680 | } |
| 681 | |
| 682 | std::uint64_t rows = 0; |
| 683 | std::uint64_t cols = 0; |
| 684 | if (!this->ComputeRowsAndCols( |
| 685 | strGrid, maxNumberOfCells, tprop, pyFontProp.GetPointer(), dpi, rows, cols)) |
| 686 | { |
| 687 | vtkWarningMacro(<< "Failed to compute rows and cols."); |
| 688 | return false; |
| 689 | } |
| 690 | |
| 691 | vtkDebugMacro(<< "Calculating metrics for '" << str << "'"); |
| 692 | |
| 693 | int extent[4]; |
| 694 | this->GetJustifiedBBox(rows, cols, tprop, extent); |
| 695 | |
| 696 | // Determine the dimensions of the rotated image |
| 697 | double angleDeg = tprop->GetOrientation(); |
| 698 | // Corners of original image |
| 699 | double corners[4][2] = { { static_cast<double>(extent[0]), static_cast<double>(extent[2]) }, // TL |
no test coverage detected