At first, you can check the source code of Draw Harness command vdrawtext,
as well as test cases in folder tests/3rdparty/fonts demonstrating various scenarios of text label usage
(just check each test in 3D viewer to see which one does something similar to what you are looking for).