------------------------------------------------------------------------------
| 1819 | |
| 1820 | //------------------------------------------------------------------------------ |
| 1821 | void vtkSVGContextDevice2D::ApplyTextPropertyStateToNode(vtkXMLDataElement* node, float x, float y) |
| 1822 | { |
| 1823 | vtkFreeTypeTools* ftt = vtkFreeTypeTools::GetInstance(); |
| 1824 | if (!ftt) |
| 1825 | { |
| 1826 | vtkErrorMacro("Error embedding fonts: No vtkFreeTypeTools instance " |
| 1827 | "available."); |
| 1828 | return; |
| 1829 | } |
| 1830 | |
| 1831 | YConverter yConv(this->CanvasHeight); |
| 1832 | |
| 1833 | using FaceMetrics = vtkFreeTypeTools::FaceMetrics; |
| 1834 | FaceMetrics faceMetrics = ftt->GetFaceMetrics(this->TextProp); |
| 1835 | |
| 1836 | vtkVector3d colord; |
| 1837 | this->TextProp->GetColor(colord.GetData()); |
| 1838 | vtkColor3ub color = { |
| 1839 | static_cast<unsigned char>((colord[0] * 255.) + 0.5), |
| 1840 | static_cast<unsigned char>((colord[1] * 255.) + 0.5), |
| 1841 | static_cast<unsigned char>((colord[2] * 255.) + 0.5), |
| 1842 | }; |
| 1843 | |
| 1844 | std::ostringstream xform; |
| 1845 | xform << "translate(" << x << "," << yConv(y) << ")"; |
| 1846 | if (this->TextProp->GetOrientation() != 0.) |
| 1847 | { |
| 1848 | xform << "rotate(" << this->TextProp->GetOrientation() << ") "; |
| 1849 | } |
| 1850 | |
| 1851 | std::ostringstream fontSize; |
| 1852 | fontSize << this->TextProp->GetFontSize() << "pt"; |
| 1853 | |
| 1854 | node->SetAttribute("fill", ColorToString(color.GetData()).c_str()); |
| 1855 | node->SetFloatAttribute("fill-opacity", static_cast<float>(this->TextProp->GetOpacity())); |
| 1856 | node->SetAttribute("font-family", faceMetrics.FamilyName.c_str()); |
| 1857 | node->SetAttribute("font-size", fontSize.str().c_str()); |
| 1858 | node->SetAttribute("font-style", this->TextProp->GetItalic() != 0 ? "italic" : "normal"); |
| 1859 | node->SetAttribute("font-weight", this->TextProp->GetBold() != 0 ? "bold" : "normal"); |
| 1860 | |
| 1861 | switch (this->TextProp->GetJustification()) |
| 1862 | { |
| 1863 | default: |
| 1864 | case VTK_TEXT_LEFT: |
| 1865 | break; |
| 1866 | |
| 1867 | case VTK_TEXT_CENTERED: |
| 1868 | node->SetAttribute("text-anchor", "middle"); |
| 1869 | break; |
| 1870 | |
| 1871 | case VTK_TEXT_RIGHT: |
| 1872 | node->SetAttribute("text-anchor", "right"); |
| 1873 | break; |
| 1874 | } |
| 1875 | |
| 1876 | switch (this->TextProp->GetVerticalJustification()) |
| 1877 | { |
| 1878 | default: |
no test coverage detected