------------------------------------------------------------------------------
| 723 | |
| 724 | //------------------------------------------------------------------------------ |
| 725 | bool vtkMatplotlibMathTextUtilities::ComputeRowsAndCols(const GridOfStrings& strGrid, |
| 726 | const std::size_t& maxNumberOfCells, vtkTextProperty* tprop, PyObject* pyFontProp, int dpi, |
| 727 | std::uint64_t& rows, std::uint64_t& cols) |
| 728 | { |
| 729 | // All columns must have the same width |
| 730 | // so store the maximum number of cols |
| 731 | // for each column |
| 732 | std::vector<std::uint64_t> vecColumnWidth; |
| 733 | vecColumnWidth.resize(maxNumberOfCells); |
| 734 | std::fill(vecColumnWidth.begin(), vecColumnWidth.end(), 0); |
| 735 | |
| 736 | // For each line |
| 737 | for (std::size_t i = 0; i < strGrid.size(); ++i) |
| 738 | { |
| 739 | const std::size_t lineNumberOfCells = strGrid[i].size(); |
| 740 | |
| 741 | // Number of rows of this line. This |
| 742 | // is the maximum number of rows of |
| 743 | // all cells of the line |
| 744 | std::uint64_t lineRows = 0; |
| 745 | |
| 746 | // For each cells |
| 747 | for (std::size_t j = 0; j < lineNumberOfCells; ++j) |
| 748 | { |
| 749 | const std::string& cell = strGrid[i][j]; |
| 750 | |
| 751 | std::uint64_t cellPythonRows = 0; |
| 752 | std::uint64_t cellPythonCols = 0; |
| 753 | if (!this->ComputeCellRowsAndCols( |
| 754 | cell.c_str(), pyFontProp, dpi, cellPythonRows, cellPythonCols, nullptr)) |
| 755 | { |
| 756 | vtkWarningMacro(<< "Failed to compute rows and cols for cell : " << cell); |
| 757 | return false; |
| 758 | } |
| 759 | |
| 760 | lineRows = std::max(lineRows, cellPythonRows); |
| 761 | |
| 762 | // Store the maximum number of cols for each column |
| 763 | vecColumnWidth[j] = std::max(vecColumnWidth[j], cellPythonCols); |
| 764 | } |
| 765 | |
| 766 | lineRows *= (tprop->GetLineSpacing() < 1.0) ? 1.0 : tprop->GetLineSpacing(); |
| 767 | lineRows += tprop->GetLineOffset(); |
| 768 | |
| 769 | rows += lineRows; |
| 770 | |
| 771 | // Store cell height |
| 772 | if (i < (strGrid.size() - 1)) |
| 773 | { |
| 774 | this->HorizontalLinesPosition[i] = lineRows; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | // The total number of cols is the sum of the maximum number of cols |
| 779 | // of cells for each column |
| 780 | cols = std::accumulate(vecColumnWidth.begin(), vecColumnWidth.end(), 0); |
| 781 | |
| 782 | // Handle horizontal offset between cells |
no test coverage detected