Change Font for DrawString


i want to draw a text within a conduit.

If i try to write text with
CRhinoViewport::DrawString Method (wchar_t*, int, ON_3dPoint&, int, int, int, wchar_t*)
i do not know how to change the font. The parameter fontface does not work. It always uses something like Arial.

And if i try to use
CRhinoViewport::DrawString Method (ON_Plane&, ON_2dPoint, ON_2dVector, CRhinoText&)
i cannot change the text height because CRhinoText does not have any method to change the size.
Also if i try to change the font on CRhinoText it always uses something like Arial.

Is there an example to draw text within a conduit where also the font and the font size can be changed?

There is an overload to CRhinoViewport::DrawString that takes, as an argument, a font face name.

i know dale, i wrote already that i tried this method.

But can you please explain, how i can draw a string in bold and italian with this method?

Both of these seem to work:

vp.DrawString(str, str.Length(), screenpoint, false, 0, 24, L"Times New Roman");
vp.DrawString(str, str.Length(), screenpoint, false, 0, 24, L"Times New Roman Bold");

I don’t understand the “Italian” part…

Drawing strings using a CRhinoText object is a little more cumbersome because this object is really just a helper class for one of the many annotation objects (e.g. CRhinoAnnotationObject, CRhinoAnnotationText, etc.). These objects get their font from the document’s font table.

sorry dale, i meant “italic” not “italian”. Seems we live to close to Italy :wink:

I tried now following code:

vp.DrawString(text, text.GetLength(), scp, true, 0, 14, L"Arial");
vp.DrawString(text, text.GetLength(), scp + ON_3dVector(0,-10,0), true, 0, 14, L"Arial Bold");

There should be now one line in Arial and one in Bold Arial. But as you can see in the picture, both line have the same font style.

Maybe it’s different drawing in a conduit. Have you tried this code also in a conduit in the CSupportChannels::SC_DRAWFOREGROUND event?

Hi Wolfgang,

My tests were done in a CRhinoGetPoint::DynamicDraw overide, which draws in the SC_DRAWOVERLAY channel. But I’ve modified the SampleViewportDecorations sample, which does draw in the SC_DRAWFOREGROUND channel, and it seems to work just fine.

// Draw text
dp.DrawString(str, str.Length(), RGB(0,0,0), point);
point.y -= 20.0;
dp.DrawString(str, str.Length(), RGB(0,0,0), point, false, 0, 12, L"Arial Bold");

– Dale

Sorry Dale,

does not work on my computer. I used the SampleViewportDecorations and changed it like this:

 // Draw text
 dp.DrawString( str, str.Length(), RGB(255,255,255), point );
 point.y -= 20.0;
 dp.DrawString(str, str.Length(), RGB(0, 0, 0), point, false, 0, 12, L"Arial Bold");

But i does not change the font style as it does on your side:

As you can see, the black one should be bold, but it looks like the white text.

By the way, i use Rhino 5 SR12 and the SDK SR9, maybe this is relevant.

Rhino 5 SR12 should be fine.

I’ve modified the sample a bit - you might want to download and try.

Here is the output on my Windows 10 x64, Rhino 5 x64 SR13 system.

For clarification: it works as designed in Rhino. The Problem was, that on a german operating system i must enter the face language dependent, so instead of “Arial Bold” i have to enter “Arial Fett”. Stupid microsoft!