MCPcopy
hub / github.com/CadQuery/cadquery / text

Function text

cadquery/occ_impl/shapes.py:6493–6546  ·  view source on GitHub ↗

Create a flat text.

(
    txt: str,
    size: Real,
    font: str = "Arial",
    path: str | None = None,
    kind: Literal["regular", "bold", "italic"] = "regular",
    halign: Literal["center", "left", "right"] = "center",
    valign: Literal["center", "top", "bottom"] = "center",
)

Source from the content-addressed store, hash-verified

6491
6492@multimethod
6493def text(
6494 txt: str,
6495 size: Real,
6496 font: str = "Arial",
6497 path: str | None = None,
6498 kind: Literal["regular", "bold", "italic"] = "regular",
6499 halign: Literal["center", "left", "right"] = "center",
6500 valign: Literal["center", "top", "bottom"] = "center",
6501) -> Shape:
6502 """
6503 Create a flat text.
6504 """
6505
6506 builder = Font_BRepTextBuilder()
6507
6508 font_kind = {
6509 "regular": Font_FA_Regular,
6510 "bold": Font_FA_Bold,
6511 "italic": Font_FA_Italic,
6512 }[kind]
6513
6514 mgr = Font_FontMgr.GetInstance_s()
6515
6516 if path and mgr.CheckFont(TCollection_AsciiString(path).ToCString()):
6517 font_t = Font_SystemFont(TCollection_AsciiString(path))
6518 font_t.SetFontPath(font_kind, TCollection_AsciiString(path))
6519 mgr.RegisterFont(font_t, True)
6520
6521 else:
6522 font_t = mgr.FindFont(TCollection_AsciiString(font), font_kind)
6523
6524 font_i = StdPrs_BRepFont(
6525 NCollection_Utf8String(font_t.FontName().ToCString()), font_kind, float(size),
6526 )
6527
6528 if halign == "left":
6529 theHAlign = Graphic3d_HTA_LEFT
6530 elif halign == "center":
6531 theHAlign = Graphic3d_HTA_CENTER
6532 else:
6533 theHAlign = Graphic3d_HTA_RIGHT
6534
6535 if valign == "bottom":
6536 theVAlign = Graphic3d_VTA_BOTTOM
6537 elif valign == "center":
6538 theVAlign = Graphic3d_VTA_CENTER
6539 else:
6540 theVAlign = Graphic3d_VTA_TOP
6541
6542 rv = builder.Perform(
6543 font_i, NCollection_Utf8String(txt), theHAlign=theHAlign, theVAlign=theVAlign
6544 )
6545
6546 return clean(compound(_compound_or_shape(rv).Faces()).fuse())
6547
6548
6549@multimethod

Callers 2

test_faceOnFunction · 0.85
test_textFunction · 0.85

Calls 15

cleanFunction · 0.85
compoundFunction · 0.85
_compound_or_shapeFunction · 0.85
_get_one_wireFunction · 0.85
_normalizeFunction · 0.85
_get_oneFunction · 0.85
appendMethod · 0.80
fuseMethod · 0.45
FacesMethod · 0.45
LengthMethod · 0.45
BoundingBoxMethod · 0.45
movedMethod · 0.45

Tested by 2

test_faceOnFunction · 0.68
test_textFunction · 0.68