jagracar / grafica

A simple and configurable plotting library for Processing
https://jagracar.com/grafica.php
Other
48 stars 26 forks source link

Specific Fonts not found on Mac causes Java Runtime to Hang Momentarily #13

Closed retiutut closed 4 years ago

retiutut commented 4 years ago

On Mac, consistently getting this message to console. This also slows down GUI session initilzation. I think this is even happening before I have the chance to change the GPlot fonts.

"SansSerif.plain" is not available, so another font will be used. Use PFont.list() to show available fonts.
"SansSerif.bold" is not available, so another font will be used. Use PFont.list() to show available fonts.

When I do PFont.list():

Serif SansSerif Monospaced Dialog DialogInput .SFNSText .SFNSText-Bold ACIDLABEL ACaslonPro-Bold ACaslonPro-BoldItalic ACaslonPro-Italic ACaslonPro-Regular ..... (no SansSerif.plain or .bold)

I see that the fontName assignment is hardCoded in GTitle.java

    public GTitle(PApplet parent, float[] dim) {
        this.parent = parent;

        this.dim = dim.clone();
        relativePos = 0.5f;
        plotPos = relativePos * this.dim[0];
        offset = 10;

        text = "";
        textAlignment = CENTER;
        fontName = "SansSerif.bold";
        fontColor = this.parent.color(100);
        fontSize = 13;
        font = this.parent.createFont(fontName, fontSize);
    }

This fix would apply to GAxisLabel.java, GHistogram.java, GLayer.java, GAxis.java, and GTitle.java .


Maybe we can detect OS and for Mac use just "SansSerif".

I can help fix this in the code if I can get assistance on how to compile this library using Eclipse.

Base Issue: https://github.com/OpenBCI/OpenBCI_GUI/issues/630

retiutut commented 4 years ago

@jagracar

jagracar commented 4 years ago

Hi!,

There is this GPlot method that changes all the font properties at once: https://github.com/jagracar/grafica/blob/master/src/grafica/GPlot.java#L2331 Would that work for you? The same method is available for the axes and the title.

jagracar commented 4 years ago

But I agree, this should be handled directly by the library. I will add some code to check the available fonts with PFont.list() and select the correct font accordingly.

Thank you for reporting the issue!

retiutut commented 4 years ago

@jagracar Seems to launch on Windows and Ubuntu Linux just fine, this is limited to Mac OS. 🛠

Haven't updated to Catalina yet, so I'm running OS X Mojave 10.14.6.

jagracar commented 4 years ago

Hi! I think I fixed the problem in my latests commits. I created a new version of the library (1.9.1). Let me know if it works!

retiutut commented 4 years ago

Great use of 1 liner ternary expressions 😃. I'll try to spin this up in the GUI.

retiutut commented 4 years ago

Yes! C'est bon: it works!