JUCE 8.0.1 - Mac/Windows
Let’s say: you don’t want the text in any labels or ComboBoxes to auto-squish; you always want it full-size, and you want an ellipsis when it’s too long.
So you use Font::setDefaultMinimumHorizontalScaleFactor(1.0f);
Then, you want to horizontally scale your font a bit (to your own taste). So you override LookAndFeel::getLabelFont():
Font getLabelFont(Label &label) override
{
return label.getFont().withHorizontalScale(horizontalScale);
}
float horizontalScale = 1.0f;
When Graphics::drawFittedText() is used (as in drawLabel(), which handles both labels and the display state of ComboBoxes), if an ellipsis is displayed (or the name in the label is greater than half the width of the label), using Font::setHorizontalScale() has no effect. This is because of a bug in GlyphArrangement::addFittedText().
Example project demonstrating the bug:
HorizScaleBug.zip (13.0 KB)
So in this example, we have two ComboBoxes with menu items of varying length. The last item “An Even Longer Name” will cause an ellipsis. The Slider controls the horizontalScale value above.
The second last item “A Longer Name” is wider than half the width of the comboBox.
Here it is with horizontal scale at 1.0f (normal):
Now change the slider to 1.2f. The top ComboBox, Slider and Label horizontally scale, but the ComboBox with the ellipsis does not.
Here is 1.4f:
Here is 0.8f:
Now set the top ComboBox to item 3 “A Longer Name” and the slider to 1.4f. Even though no ellipsis is displayed on the top ComboBox, because this item is greater than half the width (I think?) of the label, it also has no horizontal scaling applied.
The culprit (or one of them) appears to be line 286 of juce_GlyphArrangement.cpp:
.withFont (f.withHorizontalScale (minimumHorizontalScale))
Here, the font is being used while replacing the (passed in) font’s horizontal scale value.
If you call like this, the problem is fixed (although it’s probably not that simple):
if (maximumLines <= 1)
{
ShapedText squashed { trimmed,
ShapedText::Options{}
// .withFont (f.withHorizontalScale (minimumHorizontalScale))
.withFont(f)
.withMaxWidth (width)
.withHeight (height)
.withJustification (layout)
.withMaxNumLines (1)
.withEllipsis() };
addGlyphsFromShapedText (*this, squashed, x, y);
return;
}
I used large horizontal scaling factors here to illustrate the problem; but in my project I want to tweak the width of the font slightly, and what happens is: that change is carried across all displayed text EXCEPT in some comboBoxes when an ellipsis is displayed or the width of the text displayed is greater than some arbitrary value. Thanks.





