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

Method StringToPath

Rendering/Matplotlib/vtkMatplotlibMathTextUtilities.cxx:1478–1711  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1476
1477//------------------------------------------------------------------------------
1478bool vtkMatplotlibMathTextUtilities::StringToPath(
1479 const char* str, vtkPath* path, vtkTextProperty* tprop, int dpi)
1480{
1481 if (!this->IsAvailable())
1482 {
1483 vtkErrorMacro(<< "Matplotlib rendering is unavailable.");
1484 return false;
1485 }
1486
1487 if (!this->PathParser)
1488 {
1489 if (!this->InitializePathParser())
1490 {
1491 vtkErrorMacro(<< "PathParser is not initialized!");
1492 return false;
1493 }
1494 }
1495
1496 vtkDebugMacro(<< "Converting '" << str << "' into a vtkPath...");
1497
1498 // Matplotlib path codes:
1499 const int pathStop = 0;
1500 const int pathMoveTo = 1;
1501 const int pathLineTo = 2;
1502 const int pathCurve3 = 3;
1503 const int pathCurve4 = 4;
1504 const int pathClosePoly = 0x4f;
1505
1506 // List sizes:
1507 Py_ssize_t numCodes;
1508 Py_ssize_t numVerts;
1509
1510 // Temp vars:
1511 float origin[2] = { 0.0, 0.0 };
1512 float vert[2];
1513 float delta[2] = { 0.0, 0.0 };
1514 int code;
1515 bool hasOrigin = false;
1516
1517 // Bounding box for all control points, used for justification
1518 float cbox[4] = { VTK_FLOAT_MAX, VTK_FLOAT_MAX, VTK_FLOAT_MIN, VTK_FLOAT_MIN };
1519
1520 // The path is always generated using a 100pt font @72 dpi. Use this factor to
1521 // recover the font.
1522 const float fontScale = (tprop->GetFontSize() / 100.f) * (dpi / 72.f);
1523
1524 path->Reset();
1525
1526 // Create the font property
1527 vtkSmartPyObject pyFontProp(this->GetFontProperties(tprop));
1528 if (this->CheckForError(pyFontProp))
1529 {
1530 return false;
1531 }
1532
1533 vtkPythonScopeGilEnsurer gilEnsurer;
1534 vtkSmartPyObject pyResultTuple(PyObject_CallMethod(this->PathParser,
1535 const_cast<char*>("get_text_path"), const_cast<char*>("Osi"),

Callers 2

TestStringToPathFunction · 0.45

Calls 15

IsAvailableMethod · 0.95
InitializePathParserMethod · 0.95
GetFontPropertiesMethod · 0.95
CheckForErrorMethod · 0.95
minFunction · 0.50
maxFunction · 0.50
sinFunction · 0.50
cosFunction · 0.50
ResetMethod · 0.45
GetPointerMethod · 0.45
AllocateMethod · 0.45
InsertNextPointMethod · 0.45

Tested by 1

TestStringToPathFunction · 0.36