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

Method DrawString

IO/Export/vtkSVGContextDevice2D.cxx:1328–1376  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1326
1327//------------------------------------------------------------------------------
1328void vtkSVGContextDevice2D::DrawString(float* point, const vtkStdString& string)
1329{
1330 vtkTextRenderer* tren = vtkTextRenderer::GetInstance();
1331 if (!tren)
1332 {
1333 vtkErrorMacro("vtkTextRenderer unavailable. Link to vtkRenderingFreeType "
1334 "to get the default implementation.");
1335 return;
1336 }
1337
1338 int backend = this->TextAsPath ? vtkTextRenderer::Default : tren->DetectBackend(string);
1339
1340 if (backend == vtkTextRenderer::FreeType)
1341 {
1342 // Embed freetype text and fonts in the SVG:
1343 FontInfo& info = this->Impl->GetFontInfo(this->TextProp);
1344 info.ProcessString(string);
1345
1346 vtkNew<vtkXMLDataElement> text;
1347 this->ActiveNode->AddNestedElement(text);
1348 text->SetName("text");
1349 this->ApplyTextPropertyStateToNode(text, point[0], point[1]);
1350 // Position is encoded in the transform:
1351 text->SetFloatAttribute("x", 0.f);
1352 text->SetFloatAttribute("y", 0.f);
1353
1354 text->SetCharacterData(string.c_str(), static_cast<int>(string.length()));
1355 }
1356 else
1357 {
1358 // Export other text (e.g. MathText) as a path:
1359 vtkNew<vtkPath> tPath;
1360 int dpi = this->Viewport->GetVTKWindow()->GetDPI();
1361 if (!tren->StringToPath(this->TextProp, string, tPath, dpi, backend))
1362 {
1363 vtkErrorMacro("Error generating path for MathText string '" << string << "'.");
1364 return;
1365 }
1366
1367 vtkNew<vtkXMLDataElement> path;
1368 this->ActiveNode->AddNestedElement(path);
1369 path->SetName("path");
1370 this->ApplyTextPropertyStateToNodeForPath(path, point[0], point[1]);
1371
1372 std::ostringstream d;
1373 this->DrawPath(tPath, d);
1374 path->SetAttribute("d", d.str().c_str());
1375 }
1376}
1377
1378//------------------------------------------------------------------------------
1379void vtkSVGContextDevice2D::ComputeStringBounds(const vtkStdString& string, float bounds[4])

Callers 15

DrawMathTextStringMethod · 0.95
PaintMethod · 0.45
PaintMethod · 0.45
PaintMethod · 0.45
PaintMethod · 0.45
PaintLegendMethod · 0.45
PaintMethod · 0.45
DrawAxesLabelsMethod · 0.45
DrawTickMarksMethod · 0.45
PaintMethod · 0.45
DrawPointMethod · 0.45
PaintMethod · 0.45

Calls 15

DrawPathMethod · 0.95
DetectBackendMethod · 0.80
ProcessStringMethod · 0.80
AddNestedElementMethod · 0.80
SetFloatAttributeMethod · 0.80
SetCharacterDataMethod · 0.80
GetVTKWindowMethod · 0.80
SetNameMethod · 0.45
c_strMethod · 0.45
lengthMethod · 0.45

Tested by 7

PaintMethod · 0.36
PaintMethod · 0.36
PaintMethod · 0.36
PaintMethod · 0.36
PaintMethod · 0.36
PaintMethod · 0.36
PaintMethod · 0.36