Hi UDN,
In UCanvas::MeasureStringInternal, if the current character is ‘\n’, the height of the character is set to the default char height and then the string continues being measured as normal. This means that measuring a string with multiple lines ends up being the same as if it was only one, with the DrawXL parameter becoming larger than expected. I would expect a new line character to cause the following character’s height to be added to “Parameters.DrawYL” and then for the string to continue being measured on a new line.
Is this a bug, or are we misunderstanding how this function should be used?
Thanks,
Bonita
In Canvas.cpp:
for (CurrentPos = BeginPos; CurrentPos < EndPos && *CurrentPos; ++CurrentPos)
{
float CharWidth, CharHeight;
const TCHAR Ch = *CurrentPos;
Parameters.DrawFont->GetCharSize(Ch, CharWidth, CharHeight);
if (CharHeight == 0 && Ch == TEXT('\n'))
{
CharHeight = DefaultCharHeight;
}
float CharSpacing = DefaultCharIncrement;
if (PrevPos)
{
CharSpacing += Parameters.DrawFont->GetCharKerning(*PrevPos, Ch) * ScaleX;
}
CharWidth *= ScaleX;
CharHeight *= ScaleY;
// If we have another character that isn't whitespace, append the character spacing
const TCHAR* const NextPos = CurrentPos + 1;
if (NextPos < EndPos && *NextPos && !FChar::IsWhitespace(*NextPos))
{
CharWidth += CharSpacing;
}
const float ScaledVertSpacing = Parameters.SpacingAdjust.Y * ScaleY;
Parameters.DrawXL += CharWidth;
Parameters.DrawYL = FMath::Max<float>(Parameters.DrawYL, CharHeight + ScaledVertSpacing );