Clipping and custom fonts

Hello everyone-

Just pushed two big changes - deferred clipping and much better support for custom fonts.

Turns out the renderer was doing quite a bit of unnecessary clipping of areas that were already clipped. Now, the renderer consolidates the clipping regions and only applies the clipping when instructed to actually draw something. This makes a significant difference if you have a complex UI with many components, especially if the components have many siblings.

I also received several bug reports about handling custom fonts. Turns out that much of the DirectWrite code in JUCE was just using the system font collection, which did not include any custom fonts. Now, any custom fonts are aggregated together with the system font collection. That means if you create your custom typeface as usual:

auto hindTypeface = Typeface::createSystemTypefaceFor(BinaryData::HindRegular_ttf, BinaryData::HindRegular_ttfSize);

you should then see that same font listed if you call Font::findAllTypefaceNames and so forth. That should resolve a lot of the custom font issues.

Other changes:

  • Add support for TextLayout glyph runs
  • Don’t cache the outline path for a CalloutBox
  • Shutdown fix for AMD drivers

Matt

4 Likes

Would this help in getting textlayout fallback font working with custom font ?
Right now custom font were not considered as d2d fonts hence would not support fallback when glyph were not found

I really appreciate your work. However, I find some very strange behaviours (seems to be related to clipping). The test repo is here (I build it with github actions):

This is how it looks like without direct2D:
macOS

Let’s look at the ellipse at the left hand side. I saveState, setup a clip region and draw a bright shadow (left-top corner) and a dark shadow (right-bottom corner). Then I restoreState and draw the ellipse at the center.

However, this is how it looks like with direct2D:
direct2d

Hi @otristan

Good question - are you creating a CustomTypeface?

Matt

OK, thanks - I cloned your repo and was able to reproduce the problem. I’ll keep you posted.

Matt

OK, this is looking better, although it’s not quite identical.

It was an issue with the Direct2D shadow effect. I’ll push an update soon.

Matt

1 Like

Load from TTF on HD using typeface::createSystemTypefaceFor

OK, I would think that would work. Could you please provide a code snippet to demonstrate how you’re using the fallback font?

Hi @zsliu98 -

The drop shadow update is now available on the direct2d branch.

Matt

Thanks for the quick fix. Now the shadow looks much better :grin: I can’t wait to render the FFT spectrum with it so that I won’t freeze the DAW UI with previous CPU rendering.

I have just tried teh direct2d on the spectrum: AWESOME, fast and no more frozen UI.

However, some components look kind of blurry. I look at my code, and they are components with setBufferedToImage(true). And it seems that it cause more problems.

I am not sure whether it is related to the monitor setting (I am using Windows VM on Intel macOS right now):

Without setBufferedToImage(true) or without direct2d:

On the left hand side, you can drag a button and two sliders will move with the button. On the right hand side, if you click the black rectangle on the top, a CallOutBox which contains two sliders pops up. Everything looks correct.

With setBufferedToImage(true) and direct2d:

First, everything becomes blurry a little bit. Second, when I drag the button on the left side, it leaves some black pixels on the white background. What’s more, the first slider also disappears (randomly).

Again, here is the (same) test repo:

Thank you in advance :kissing_heart:

I’ve had a few other reports about issues with setBufferedToImage. I’ll try it with your repo.

What is your DPI scale?

Matt

250%. It is set up by my VM automatically to ‘Use full resolution for Retina Display’.

OK, I think both the black ghost lines and the blurriness are both caused by incorrect DPI scaling for the buffered component image.

Matt

1 Like

Hi @zsliu98 - Please try the latest commit on the direct2d branch.

I tried it at 250% DPI scaling and it looked good to me. I still see some ghost lines at 125% DPI scaling, but those also show up if I build with the JUCE develop branch, so it’s probably not related to Direct2D.

Matt

Hi, I have just updated the test repo to the latest commit on direct2d.

Unfortunately, the dragger disappears randomly and the two sliders (on the left panel) become invisible. The two sliders (on the right panel) also look strange. And they are still blurry.

And without setBufferedToImage(true), everything is still correct:

OK, @zsliu98 would you mind trying it again and make sure you are building against this commit?

Thanks-

Matt

Unfortunately, this does not fix the problem on my computer:

The first row is setBufferedToImage(true), the second row is without bufferedImage.

You can download the installer from here:

OK - are you running this under Parallels on a Mac?

I am using VMware Fusion (AFAIK they are very similar?)