------------------------------------------------------------------------------
| 1326 | |
| 1327 | //------------------------------------------------------------------------------ |
| 1328 | void 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 | //------------------------------------------------------------------------------ |
| 1379 | void vtkSVGContextDevice2D::ComputeStringBounds(const vtkStdString& string, float bounds[4]) |