LookAndFeel::getTypefaceForFont() with fontHeight <= 0.1


#1

There are certain times when LookAndFeel::getTypefaceForFont() is eventually called to return a Typeface for a font with zero height. Except that Font imposes a minimum height of 0.1 (of no practical use). I would like to fix the cause of these extra calls to create zero-height Typefaces.

One is a DocumentWindow with setUsingNativeTitleBar(true), tries to draw the title bar but the height is zero on account of titleBarArea being an empty rectangle. I would like to skip all of the drawing if the titleBarArea has a zero height.

Here is my fixed version:
juce_DocumentWindow.cpp

void DocumentWindow::paint (Graphics& g)
{
    ResizableWindow::paint (g);

    if (resizableBorder == 0)
    {
        g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));

        const BorderSize border (getBorderThickness());

        g.fillRect (0, 0, getWidth(), border.getTop());
        g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
        g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight()-border.getTopAndBottom());
        g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
    }

    const Rectangle<int> titleBarArea (getTitleBarArea());
    if (titleBarArea.getHeight()>0) // new code
    {
      g.reduceClipRegion (titleBarArea);
      g.setOrigin (titleBarArea.getX(), titleBarArea.getY());

      int titleSpaceX1 = 6;
      int titleSpaceX2 = titleBarArea.getWidth() - 6;

      for (int i = 0; i < 3; ++i)
      {
          if (titleBarButtons[i] != 0)
          {
              if (positionTitleBarButtonsOnLeft)
                  titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
              else
                  titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
          }
      }

      getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
                                                   titleBarArea.getWidth(),
                                                   titleBarArea.getHeight(),
                                                   titleSpaceX1,
                                                   jmax (1, titleSpaceX2 - titleSpaceX1),
                                                   titleBarIcon.isValid() ? &titleBarIcon : 0,
                                                   ! drawTitleTextCentred);
    }
}

The second place is the MenuBarComponent::resized() function, tries to rearrange the x positions of the top level menu names even if the component width or height is zero. This is my fix:

juce_MenuBarComponent.cpp

void MenuBarComponent::resized()
{
    if (getBounds().getHeight()>0) // new code
    {
      xPositions.clear();
      int x = 0;
      xPositions.add (x);

      for (int i = 0; i < menuNames.size(); ++i)
      {
          x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
          xPositions.add (x);
      }
    }
}

Sorry for this nitpicking I know it seems insignificant but it’s there.