I am trying to display text sections with different font sizes and properties. It looks like formatting in the TextEditor is broken sometimes. I see 3 problems:
When a new text section uses the font bigger than the initial one, then the upper part is cut (the top margin is not taken into account for the bigger font).
Sometimes sections with different font sizes are overlapping.
After a new font is set for the editor, the editor is not repainted correctly after gaining focus. It must be repainted additionally.
We’re in the middle of overhauling our text layout functions. It’s a huge task, but at the end of it these issues should be addressed. If all goes to plan it will be part of the initial JUCE 8 launch, but we don’t have a reasonable estimate for a release date yet.
To fix the weird top margin bug you need to move the initial setting of ‘lineHeight’ to be ABOVE the code that looks for the existing text line height. At the moment it’s overwriting the correct value with whatever is the current editor font size which could be anything.
juce_TextEditor.cpp
struct TextEditor::Iterator
{
Iterator (const TextEditor& ed)
: sections (ed.sections),
justification (ed.justification),
bottomRight ((float) ed.getMaximumTextWidth(), (float) ed.getMaximumTextHeight()),
wordWrapWidth ((float) ed.getWordWrapWidth()),
passwordCharacter (ed.passwordCharacter),
lineSpacing (ed.lineSpacing),
underlineWhitespace (ed.underlineWhitespace)
{
jassert (wordWrapWidth > 0);
lineHeight = ed.currentFont.getHeight(); // MOVE THIS HERE
if (! sections.isEmpty())
{
currentSection = sections.getUnchecked (sectionIndex);
if (currentSection != nullptr)
beginNewLine();
}
// lineHeight = ed.currentFont.getHeight(); // NOT HERE
}
I haven’t seen your other bugs but they’re possible all related to the same thing, grabbing the current editor font instead of using the correct one for the section of text.
All my TextEditor’s look correct now but it’s worth testing everything with this fix. TextEditor is quite complicated and I’m probably not testing all the possible use cases here.
And my $0.02, it’s nice to hear this was getting fixed but I kinda think critical bug fixes should go in the current version of Juce, not the next ‘pay for an upgrade’ version up.
I’ve just tested your change and yes, it works when we just change size of the font for the line. But when we have different font sizes in one line - like in the picture below - it seems that all line heights are just summed.