+ // Draw the background color from the leftmost glyph to the rightmost glyph
+ if ( style == Typesetter::STYLE_BACKGROUND )
+ {
+ Vector4 backgroundColor = mModel->GetBackgroundColor();
+
+ for( int y = glyphData.verticalOffset + baseline - line.ascender; y < glyphData.verticalOffset + baseline - line.descender; y++ )
+ {
+ if( ( y < 0 ) || ( y > static_cast<int>(bufferHeight - 1) ) )
+ {
+ // Do not write out of bounds.
+ continue;
+ }
+
+ for( int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++ )
+ {
+ if( ( x < 0 ) || ( x > static_cast<int>(bufferWidth - 1) ) )
+ {
+ // Do not write out of bounds.
+ continue;
+ }
+
+ // Always RGBA image for text with styles
+ uint32_t* bitmapBuffer = reinterpret_cast< uint32_t* >( glyphData.bitmapBuffer.GetBuffer() );
+ uint32_t backgroundPixel = *( bitmapBuffer + y * glyphData.width + x );
+ uint8_t* backgroundPixelBuffer = reinterpret_cast<uint8_t*>( &backgroundPixel );
+
+ // Write the background color to the pixel buffer
+ uint8_t colorAlpha = static_cast< uint8_t >( backgroundColor.a * 255.f );
+ *( backgroundPixelBuffer + 3u ) = colorAlpha;
+ *( backgroundPixelBuffer + 2u ) = static_cast< uint8_t >( backgroundColor.b * colorAlpha );
+ *( backgroundPixelBuffer + 1u ) = static_cast< uint8_t >( backgroundColor.g * colorAlpha );
+ *( backgroundPixelBuffer ) = static_cast< uint8_t >( backgroundColor.r * colorAlpha );
+
+ *( bitmapBuffer + y * glyphData.width + x ) = backgroundPixel;
+ }
+ }
+ }
+