}
}
+float GetPreOffsetVerticalLineAlignment(LineRun line, DevelText::VerticalLineAlignment::Type verLineAlign)
+{
+ // Calculate vertical line alignment
+ float offset = 0.0f;
+
+ switch(verLineAlign)
+ {
+ case DevelText::VerticalLineAlignment::TOP:
+ {
+ break;
+ }
+ case DevelText::VerticalLineAlignment::MIDDLE:
+ {
+ offset = line.lineSpacing * 0.5f;
+ break;
+ }
+ case DevelText::VerticalLineAlignment::BOTTOM:
+ {
+ offset = line.lineSpacing;
+ break;
+ }
+ }
+
+ return offset;
+}
+
+float GetPostOffsetVerticalLineAlignment(LineRun line, DevelText::VerticalLineAlignment::Type verLineAlign)
+{
+ // Calculate vertical line alignment
+ float offset = 0.0f;
+
+ switch(verLineAlign)
+ {
+ case DevelText::VerticalLineAlignment::TOP:
+ {
+ offset = line.lineSpacing;
+ break;
+ }
+ case DevelText::VerticalLineAlignment::MIDDLE:
+ {
+ offset = line.lineSpacing * 0.5f;
+ break;
+ }
+ case DevelText::VerticalLineAlignment::BOTTOM:
+ {
+ break;
+ }
+ }
+
+ return offset;
+}
+
Devel::PixelBuffer DrawGlyphsBackground(const ViewModel* model, Devel::PixelBuffer& buffer, const uint32_t& bufferWidth, const uint32_t& bufferHeight, bool ignoreHorizontalAlignment, int32_t horizontalOffset, int32_t verticalOffset)
{
// Retrieve lines, glyphs, positions and colors from the view model.
const Vector4* const backgroundColorsBuffer = model->GetBackgroundColors();
const ColorIndex* const backgroundColorIndicesBuffer = model->GetBackgroundColorIndices();
+ const DevelText::VerticalLineAlignment::Type verLineAlign = model->GetVerticalLineAlignment();
+
// Create and initialize the pixel buffer.
GlyphData glyphData;
glyphData.verticalOffset = verticalOffset;
glyphData.horizontalOffset += horizontalOffset;
// Increases the vertical offset with the line's ascender.
- glyphData.verticalOffset += static_cast<int32_t>(line.ascender);
-
- // Include line spacing after first line
- if(lineIndex > 0u)
- {
- glyphData.verticalOffset += static_cast<int32_t>(line.lineSpacing);
- }
+ glyphData.verticalOffset += static_cast<int32_t>(line.ascender + GetPreOffsetVerticalLineAlignment(line, verLineAlign));
float left = bufferWidth;
float right = 0.0f;
}
// Increases the vertical offset with the line's descender.
- glyphData.verticalOffset += static_cast<int32_t>(-line.descender);
+ glyphData.verticalOffset += static_cast<int32_t>(-line.descender + GetPostOffsetVerticalLineAlignment(line, verLineAlign));
}
return glyphData.bitmapBuffer;
}
}
- // Calculate vertical line alignment
- switch(mModel->GetVerticalLineAlignment())
- {
- case DevelText::VerticalLineAlignment::TOP:
- {
- break;
- }
- case DevelText::VerticalLineAlignment::MIDDLE:
- {
- const auto& line = *mModel->GetLines();
- penY -= line.descender;
- penY += static_cast<int32_t>(line.lineSpacing * 0.5f + line.descender);
- break;
- }
- case DevelText::VerticalLineAlignment::BOTTOM:
- {
- const auto& line = *mModel->GetLines();
- const auto lineHeight = line.ascender + (-line.descender) + line.lineSpacing;
- penY += static_cast<int32_t>(lineHeight - (line.ascender - line.descender));
- break;
- }
- }
-
// Generate the image buffers of the text for each different style first,
// then combine all of them together as one final image buffer. We try to
// do all of these in CPU only, so that once the final texture is generated,
const Vector<CharacterIndex>& glyphToCharacterMap = mModel->GetGlyphsToCharacters();
const CharacterIndex* glyphToCharacterMapBuffer = glyphToCharacterMap.Begin();
+ const DevelText::VerticalLineAlignment::Type verLineAlign = mModel->GetVerticalLineAlignment();
+
// Traverses the lines of the text.
for(LineIndex lineIndex = 0u; lineIndex < modelNumberOfLines; ++lineIndex)
{
glyphData.horizontalOffset += horizontalOffset;
// Increases the vertical offset with the line's ascender.
- glyphData.verticalOffset += static_cast<int32_t>(line.ascender);
+ glyphData.verticalOffset += static_cast<int32_t>(line.ascender + GetPreOffsetVerticalLineAlignment(line, verLineAlign));
// Retrieves the glyph's outline width
float outlineWidth = static_cast<float>(mModel->GetOutlineWidth());
}
// Increases the vertical offset with the line's descender & line spacing.
- glyphData.verticalOffset += static_cast<int32_t>(-line.descender + line.lineSpacing);
+ glyphData.verticalOffset += static_cast<int32_t>(-line.descender + GetPostOffsetVerticalLineAlignment(line, verLineAlign));
}
return glyphData.bitmapBuffer;