When the string parser is printing on a surface, it can use the surface's existing colors as a fallback when there is no command changing the glyph. For example, if a foreground command is used and changes the color, but a background command wasn't specified, it will use the existing background color of the cell where the glyph is to be printed.
There's a bug in the calculation. The fixedSurfaceIndex variable seems to be set the index of where the character is in the INPUT string instead of the index where it's placed. This means it pulls the glyph appearance from the wrong glyph in the output surface.