Calculating text height
AnsweredThe Height of the text output result is greater than the height of the text box, which is an NG state. However the display effect is that the text can be displayed normally and there is no phenomenon of super frame being truncated.
1. Can you directly obtain the size of a ligature, rather than the size of the individual characters that make up the ligature., because the glyphs of the ligature can change.
2. How to calculate the height of text after automatic line wrapping?
-
1: kanzi::FontRuntime::getGlyphIndex returns the glyph of a specific unicode code point., so it will not take surrounding characters into consideration. Ligatures are determined during the text layouting&shaping process.
2: The Text-layout depends on the size that is available to use.
When you create a text format you pass the Font object and available size that you want to use.
If the available size during this calculation is bigger than the available size in the actual TextBlock, then it can explain the difference.
In addition, you need to give all the paramters from the TextBlock to the TextFormat so that the results match. For example, the setWordWrap function. Otherwise, the calculation of the TextFormat will not match the calculation of the TextBlock.In order to access the ligature data, you can use TextLayout::characters vector. The vector will contain character used while calculating the text format.
Please try the snippet below;auto& characters = textFormat->getLayout()->characters;
// All layout heights are negative.
auto minY = 0.0f;
auto maxY = -kanzi::numeric_limits<float>::infinity();
for (auto character : characters)
{
const auto glyphBoundingBox = runtimeFont->getBoundingBox(character.character);
// Character can go beyond baseline.
const auto characterY = character.y + glyphBoundingBox.getY();
// Highest point of the character.
const auto characterTop = characterY + glyphBoundingBox.getHeight();
minY = kanzi::min(minY, characterY);
maxY = kanzi::max(maxY, characterTop);
}
kzLogInfo(KZ_LOG_CATEGORY_GENERIC, ("Visible text height {}, actual text format height {}", maxY - minY, textFormat->getHeight()));0
Please sign in to leave a comment.
Comments
1 comment