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

Method RenderString

Rendering/Matplotlib/vtkMatplotlibMathTextUtilities.cxx:1219–1475  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1217
1218//------------------------------------------------------------------------------
1219bool vtkMatplotlibMathTextUtilities::RenderString(
1220 const char* str, vtkImageData* image, vtkTextProperty* tprop, int dpi, int textDims[2])
1221{
1222 if (!this->IsAvailable())
1223 {
1224 vtkErrorMacro(<< "Matplotlib rendering is unavailable.");
1225 return false;
1226 }
1227
1228 if (!this->MaskParser)
1229 {
1230 if (!this->InitializeMaskParser())
1231 {
1232 vtkErrorMacro(<< "MaskParser is not initialized!");
1233 return false;
1234 }
1235 }
1236
1237 TextColors tcolors;
1238 this->ComputeTextColors(tprop, tcolors);
1239
1240 // To customize math text font, we must use rcParams
1241 // (see https://matplotlib.org/stable/tutorials/introductory/customizing.html)
1242 if (!this->SetMathTextFont(tprop))
1243 {
1244 return false;
1245 }
1246
1247 // Create the font property used for all non math text
1248 vtkSmartPyObject pyFontProp(this->GetFontProperties(tprop));
1249 if (this->CheckForError(pyFontProp))
1250 {
1251 return false;
1252 }
1253
1254 // Parse the string by lines and columns and store
1255 // each cell string in the string grid
1256 GridOfStrings strGrid;
1257 std::size_t maxNumberOfCells;
1258 if (!this->ParseString(str, strGrid, maxNumberOfCells))
1259 {
1260 vtkWarningMacro(<< "Failed to parse string.");
1261 return false;
1262 }
1263
1264 // For each line, render all the cells
1265 // And store each cell python representation
1266 // and the associated rows and cols
1267 std::vector<std::vector<vtkSmartPyObject>> gridPythonData;
1268 std::vector<std::vector<std::uint64_t>> gridRowsAndCols;
1269
1270 // All columns must have the same width
1271 // so store the maximum number of cols
1272 // for each column
1273 std::vector<std::uint64_t> vecColumnWidth;
1274 vecColumnWidth.resize(maxNumberOfCells);
1275 std::fill(vecColumnWidth.begin(), vecColumnWidth.end(), 0);
1276

Callers 2

TestRenderStringFunction · 0.45

Calls 15

IsAvailableMethod · 0.95
InitializeMaskParserMethod · 0.95
ComputeTextColorsMethod · 0.95
SetMathTextFontMethod · 0.95
GetFontPropertiesMethod · 0.95
CheckForErrorMethod · 0.95
ParseStringMethod · 0.95
GetJustifiedBBoxMethod · 0.95
PrepareImageDataMethod · 0.95
RenderOneCellMethod · 0.95
DrawInteriorLinesMethod · 0.95

Tested by 1

TestRenderStringFunction · 0.36