Stroking and filling text using TextRenderMode

Q: I have been working with the Element Builder sample program and
have encountered a problem I don't seem to undertand. I have the
following section of code:

eb.Reset();
Element element =
eb.CreateTextBegin(pdftron.PDF.Font.CreateTrueTypeFont(pdfDoc, font,
false, true), font.SizeInPoints);
writer.WriteElement(element);
element = eb.CreateTextRun(str);
GState gstate = element.GetGState();
gstate.SetTransform(CreatePDFMatrix());
gstate.SetLeading(2);
element.SetTextMatrix(1.0 / 72.0, 0.0, 0.0, -1.0 / 72.0, xPos, yPos);
gstate.SetTextRenderMode(GState.TextRenderingMode.e_stroke_text);
gstate.SetStrokeColorSpace(pdftron.PDF.ColorSpace.CreateDeviceRGB());
gstate.SetStrokeColor(new pdftron.PDF.ColorPt(1, 0, 0));
writer.WriteElement(element);
writer.WriteElement(eb.CreateTextEnd());

If I run this code with a GDI font of Courier New 10pt, and xPos =
3.5, yPos = 5.0, and str="Hello World", I get a Red box in the center
of the page. If I remove the SetTextRenderMode line or replace the
e_stroke_text with e_fill_text, I get the text written in the right
position, but in black. I have compared it with the sample and run
the two side by side, but I am missing something. Can you point me to
the answer?
---------------

A: This is expected. You are setting only the stroke color space +
stroke color (not fill, which is by default black).
‘TextRenderingMode.e_stroke_text’ only strokes text (it does not fill
it - e_fill_text, which is the default).

If you would like to see text that is filled and stroked you use the
following:

gstate.SetTextRenderMode(GState.TextRenderingMode.e_stroke_fill_text);

ColorSpace cs = pdftron.PDF.ColorSpace.CreateDeviceRGB();
gstate.SetStrokeColorSpace(cs);
gstate.SetStrokeColor(new pdftron.PDF.ColorPt(1, 0, 0));
gstate.SetStrokeColorSpace(cs);
gstate.SetStrokeColor(new pdftron.PDF.ColorPt(0, 1, 0));