OCCT live Draw Harness examples

Visualization / Text formatter

Script demonstrates usage of AIS_TextLabel and Font_TextFormatter properties.

Graphic3d_HorizontalTextAlignment (Prs3d_TextAspect::SetHorizontalJustification())


Graphic3d_VerticalTextAlignment (Prs3d_TextAspect::SetVerticalJustification())


Aspect_TypeOfDisplayText (Graphic3d_Aspects::SetTextStyle())


Font_FontAspect (Graphic3d_Aspects::SetTextFontAspect())


Font height (Prs3d_TextAspect::SetHeight())

Rotation angle (Graphic3d_Aspects::SetTextAngle())

Font name (Graphic3d_Aspects::SetTextFont())
Specifies font family name registered within Font_FontMgr global object. The Font Manager fills in the list with fonts available in the system. Developers may also register additional fonts distributed within application itself.

Main color (Graphic3d_Aspects::SetColor())

Secondary color (Graphic3d_Aspects::SetColorSubTitle())
The color of shadow, contour or background rectangle depending on the type of display text.

Wrapping width (Font_TextFormatter::SetWrapping())
The width to wrap the text (continue long text on the next line(s)).

AIS_TextLabel is an interactive object for creating a text label as a separate object. Custom AIS objects may use Graphic3d_Text directly to put text labels within more complex presentations.

Text position could be defined either as an anchor point in 3D (text will be always orientated towards the viewer as in case of Graphic3d_TMF_ZoomRotatePers), or within specified plane (text will be rotated in 3D space). When plane is provided AIS_TextLabel::SetOrientation3D(), one may also ask to automatically flip text orientation AIS_TextLabel::SetFlipping() to keep it readable.

AIS_TextLabel/Graphic3d_Text perform text rendering using cached textured fonts. This is quite efficient approach for rendering non-zoomable text labels, but consider also StdPrs_BRepTextBuilder/StdPrs_BRepFont tools, when you need to put text alongside the geometry or to perform modeling operations with them.

AIS_TextLabel mostly wraps properties of text presentation, which otherwise are stored within:

  • Graphic3d_Aspects - low-level aspects for rendering text via textured fonts;
  • Prs3d_TextAspect - aspects for constructing text presentations;
  • Font_TextFormatter - tool for formatting the text using specified font;
  • Font_FTFont/StdPrs_BRepFont - explicitly loaded font.

pload MODELING VISUALIZATION

# text presentation parameters
if {[info exists tparams]} { unset tparams }
array set tparams {
-font     "sans"
-height   30
-aspect   "REGULAR"
-wrapping 0
-halign   "LEFT"
-valign   "BOTTOM"
-angle    0
-dispType "NORMAL"
-color    "BLACK"
-subcolor "GRAY"
-flipping 0
}
# text itself
set ttext "My text\nlabel"
# text anchor point in 3D
set tpos {100 0 300}

# display a box in the background
vinit View1
vbackground -color WHITE
box b 100 200 300
vdisplay -dispMode 1 b -noselect
vpoint p1 {*}$tpos
vpoint p0 0 0 0
vpoint p2 200 0 0
vsegment s p0 p2
vremove p2
vaspects s -color BLACK
vdisplay s -trsfPers zoomRotate -trsfPersPos {*}$tpos
vfit

# display text label
puts "vdrawtext t \"$ttext\" -pos $tpos [array get tparams]"
vdrawtext t "$ttext" -pos {*}$tpos {*}[array get tparams]

 

Copyright © Kirill Gavrilov Tartynskih, 2021