+ const LineRun& line = *(modelLinesBuffer + lineIndex);
+
+ // Sets the horizontal offset of the line.
+ glyphData.horizontalOffset = ignoreHorizontalAlignment ? 0 : static_cast<int32_t>(line.alignmentOffset);
+ glyphData.horizontalOffset += horizontalOffset;
+
+ // Increases the vertical offset with the line's ascender.
+ glyphData.verticalOffset += static_cast<int32_t>(line.ascender + GetPreOffsetVerticalLineAlignment(line, verLineAlign));
+
+ float left = bufferWidth;
+ float right = 0.0f;
+ float baseline = 0.0f;
+
+ // Traverses the glyphs of the line.
+ const GlyphIndex endGlyphIndex = std::min(numberOfGlyphs, line.glyphRun.glyphIndex + line.glyphRun.numberOfGlyphs);
+ for(GlyphIndex glyphIndex = line.glyphRun.glyphIndex; glyphIndex < endGlyphIndex; ++glyphIndex)
+ {
+ // Retrieve the glyph's info.
+ const GlyphInfo* const glyphInfo = glyphsBuffer + glyphIndex;
+
+ if((glyphInfo->width < Math::MACHINE_EPSILON_1000) ||
+ (glyphInfo->height < Math::MACHINE_EPSILON_1000))
+ {
+ // Nothing to do if default background color, the glyph's width or height is zero.
+ continue;
+ }
+
+ backgroundColorIndex = (nullptr == backgroundColorsBuffer) ? 0u : *(backgroundColorIndicesBuffer + glyphIndex);
+
+ if((backgroundColorIndex != prevBackgroundColorIndex) &&
+ (prevBackgroundColorIndex != 0u))
+ {
+ const Vector4& backgroundColor = *(backgroundColorsBuffer + prevBackgroundColorIndex - 1u);
+ DrawBackgroundColor(backgroundColor, bufferWidth, bufferHeight, glyphData, baseline, line, left, right);
+ }
+
+ if(backgroundColorIndex == 0u)
+ {
+ prevBackgroundColorIndex = backgroundColorIndex;
+ //if background color is the default do nothing
+ continue;
+ }
+
+ // Retrieves the glyph's position.
+ const Vector2* const position = positionBuffer + glyphIndex;
+
+ if(baseline < position->y + glyphInfo->yBearing)
+ {
+ baseline = position->y + glyphInfo->yBearing;
+ }
+
+ // Calculate the positions of leftmost and rightmost glyphs in the current line
+ if(removeFrontInset)
+ {
+ if((position->x < left) || (backgroundColorIndex != prevBackgroundColorIndex))
+ {
+ left = position->x;
+ }
+ }
+ else
+ {
+ const float originPositionLeft = position->x - glyphInfo->xBearing;
+ if((originPositionLeft < left) || (backgroundColorIndex != prevBackgroundColorIndex))
+ {
+ left = originPositionLeft;
+ }
+ }
+
+ if(removeBackInset)
+ {
+ if(position->x + glyphInfo->width > right)
+ {
+ right = position->x + glyphInfo->width;
+ }
+ }
+ else
+ {
+ const float originPositionRight = position->x - glyphInfo->xBearing + glyphInfo->advance;
+ if(originPositionRight > right)
+ {
+ right = originPositionRight;
+ }
+ }
+
+ prevBackgroundColorIndex = backgroundColorIndex;
+ }
+
+ //draw last background at line end if not default
+ if(backgroundColorIndex != 0u)
+ {
+ const Vector4& backgroundColor = *(backgroundColorsBuffer + backgroundColorIndex - 1u);
+ DrawBackgroundColor(backgroundColor, bufferWidth, bufferHeight, glyphData, baseline, line, left, right);
+ }
+
+ // Increases the vertical offset with the line's descender.
+ glyphData.verticalOffset += static_cast<int32_t>(-line.descender + GetPostOffsetVerticalLineAlignment(line, verLineAlign));