Create a 3D text
(
cls,
text: str,
size: float,
height: float,
font: str = "Arial",
fontPath: str | None = None,
kind: Literal["regular", "bold", "italic"] = "regular",
halign: Literal["center", "left", "right"] = "center",
valign: Literal["center", "top", "bottom"] = "center",
position: Plane = Plane.XY(),
)
| 4806 | |
| 4807 | @classmethod |
| 4808 | def makeText( |
| 4809 | cls, |
| 4810 | text: str, |
| 4811 | size: float, |
| 4812 | height: float, |
| 4813 | font: str = "Arial", |
| 4814 | fontPath: str | None = None, |
| 4815 | kind: Literal["regular", "bold", "italic"] = "regular", |
| 4816 | halign: Literal["center", "left", "right"] = "center", |
| 4817 | valign: Literal["center", "top", "bottom"] = "center", |
| 4818 | position: Plane = Plane.XY(), |
| 4819 | ) -> Shape: |
| 4820 | """ |
| 4821 | Create a 3D text |
| 4822 | """ |
| 4823 | |
| 4824 | font_kind = { |
| 4825 | "regular": Font_FA_Regular, |
| 4826 | "bold": Font_FA_Bold, |
| 4827 | "italic": Font_FA_Italic, |
| 4828 | }[kind] |
| 4829 | |
| 4830 | mgr = Font_FontMgr.GetInstance_s() |
| 4831 | |
| 4832 | if fontPath and mgr.CheckFont(TCollection_AsciiString(fontPath).ToCString()): |
| 4833 | font_t = Font_SystemFont(TCollection_AsciiString(fontPath)) |
| 4834 | font_t.SetFontPath(font_kind, TCollection_AsciiString(fontPath)) |
| 4835 | mgr.RegisterFont(font_t, True) |
| 4836 | |
| 4837 | else: |
| 4838 | font_t = mgr.FindFont(TCollection_AsciiString(font), font_kind) |
| 4839 | |
| 4840 | builder = Font_BRepTextBuilder() |
| 4841 | font_i = StdPrs_BRepFont( |
| 4842 | NCollection_Utf8String(font_t.FontName().ToCString()), |
| 4843 | font_kind, |
| 4844 | float(size), |
| 4845 | ) |
| 4846 | if halign == "left": |
| 4847 | theHAlign = Graphic3d_HTA_LEFT |
| 4848 | elif halign == "center": |
| 4849 | theHAlign = Graphic3d_HTA_CENTER |
| 4850 | else: # halign == "right" |
| 4851 | theHAlign = Graphic3d_HTA_RIGHT |
| 4852 | |
| 4853 | if valign == "bottom": |
| 4854 | theVAlign = Graphic3d_VTA_BOTTOM |
| 4855 | elif valign == "center": |
| 4856 | theVAlign = Graphic3d_VTA_CENTER |
| 4857 | else: # valign == "top": |
| 4858 | theVAlign = Graphic3d_VTA_TOP |
| 4859 | |
| 4860 | text_flat = Shape( |
| 4861 | builder.Perform( |
| 4862 | font_i, |
| 4863 | NCollection_Utf8String(text), |
| 4864 | theHAlign=theHAlign, |
| 4865 | theVAlign=theVAlign, |