dalboris / vpaint

Experimental vector graphics and 2D animation editor

Home Page:http://www.vpaint.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blurry/fuzzy on macOS retina screen

dalboris opened this issue · comments

Here is how it looks on a MacBook Pro (13-inch, 2017, Four Thunderbolt 3 Ports), with Qt Creator on the background for comparison:

image

I'm not sure yet what is the cause, but it doesn't seem related to the recent changes of OpenGL initialization. For example, below is a comparison between:

  • On the back, the latest commit, compiled against Qt 5.12.5
  • On the front, VPaint 1.6 as distributed on vpaint.org, that is compiled against Qt 5.5.0:

image

Both look blurry, although they look differently blurry. This seems to be due to differences between versions of Qt, since if I recompile VPaint 1.6 against Qt 5.12.5, the "blurriness" looks like the latest commit compiled against Qt 5.12.5:

  • On the back, VPaint 1.6, compiled against Qt 5.12.5
  • On the front, VPaint 1.6 as distributed on vpaint.org, that is compiled against Qt 5.5.0:

image

Note that none of them seem to be affected by the "mouse offset bug" (#22).

When creating a new Qt project, I couldn't reproduce the bug. So I started deleting everything from VPaint and finally managed to get to a point where the bug wasn't there anymore. It seems related to the Info.plist file.

Here is my minimal main.cpp:

#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QPushButton b("Hello");
    b.show();
    return app.exec();
}

With the following Gui.pro, the bug is present:

TEMPLATE = app
TARGET = VPaint
CONFIG += c++11
QT     += core gui widgets
macx {
    QMAKE_INFO_PLIST = Info.plist
}
HEADERS +=
SOURCES += main.cpp

image

But if I remove the Info.plist, the bug is gone (note: you have to completely delete the build folder and rebuild from scratch):

TEMPLATE = app
TARGET = VPaint
CONFIG += c++11
QT     += core gui widgets
HEADERS +=
SOURCES += main.cpp

image

Note: here the the Info.plist automatically generated by Qt 5.12.5 if we do not explicitly provide one:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleExecutable</key>
	<string>VPaint</string>
	<key>CFBundleGetInfoString</key>
	<string>Created by Qt/QMake</string>
	<key>CFBundleIconFile</key>
	<string></string>
	<key>CFBundleIdentifier</key>
	<string>com.yourcompany.VPaint</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>LSMinimumSystemVersion</key>
	<string>10.12</string>
	<key>NOTE</key>
	<string>This file was generated by Qt/QMake.</string>
	<key>NSPrincipalClass</key>
	<string>NSApplication</string>
	<key>NSSupportsAutomaticGraphicsSwitching</key>
	<true/>
</dict>
</plist>

And here is VPaint's current Info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>CFBundleDevelopmentRegion</key>
        <string>en-US</string>

        <key>CFBundleDisplayName</key>
        <string>VPaint</string>

        <key>CFBundleDocumentTypes</key>
        <array>
                <dict>
                        <key>CFBundleTypeExtensions</key>
                        <array>
                                <string>vec</string>
                        </array>

                        <key>CFBundleTypeIconFile</key>
                        <string>vec.icns</string>

                        <key>CFBundleTypeName</key>
                        <string>VPaint File</string>

                        <key>CFBundleTypeRole</key>
                        <string>Editor</string>

                        <key>LSItemContentTypes</key>
                        <array>
                            <string>org.vpaint.vec</string>
                        </array>

                        <key>LSHandlerRank</key>
                        <string>Owner</string>
                </dict>
        </array>

        <key>CFBundleExecutable</key>
        <string>@EXECUTABLE@</string>

        <key>CFBundleIconFile</key>
        <string>@ICON@</string>

        <key>CFBundleIdentifier</key>
        <string>org.vpaint.VPaint</string>

        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>

        <key>CFBundleName</key>
        <string>VPaint</string>

        <key>CFBundlePackageType</key>
        <string>APPL</string>

        <key>CFBundleShortVersionString</key>
        <string>@SHORT_VERSION@</string>

        <key>CFBundleSignature</key>
        <string>@TYPEINFO@</string>

        <key>CFBundleVersion</key>
        <string>@FULL_VERSION@</string>

        <key>UTExportedTypeDeclarations</key>
        <array>
            <dict>
                <key>UTTypeIdentifier</key>
                <string>org.vpaint.vec</string>

                <key>UTTypeTagSpecification</key>
                <dict>
                    <key>public.filename-extension</key>
                    <array>
                        <string>vec</string>
                    </array>
                </dict>

                <key>UTTypeConformsTo</key>
                <array>
                    <string>public.xml</string>
                </array>

                <key>UTTypeIconFile</key>
                <string>vec.icns</string>

                <key>UTTypeDescription</key>
                <string>VPaint File</string>

                <key>UTTypeReferenceUrl</key>
                <string>https://www.vpaint.org</string>
            </dict>
        </array>
</dict>
</plist>

The following entries obviously look important, and aren't in our Info.plist:

	<key>LSMinimumSystemVersion</key>
	<string>10.12</string>
	<key>NSPrincipalClass</key>
	<string>NSApplication</string>
	<key>NSSupportsAutomaticGraphicsSwitching</key>
	<true/>

Alright, so adding just this one seems to fix the bug in the minimal example:

    <key>NSPrincipalClass</key>
    <string>NSApplication</string>

What's surprising is that in VGC, I currently don't have this entry either, but I don't have the bug.

Now that I have the solution, it made it easier to Google for other people mentioning this:

https://stackoverflow.com/questions/34465506/retina-support-in-qt5-on-os-x

Make sure your info.plist has the NSPrincipalClass and NSApplication keys. According to the Qt docs, NSHighResolutionCapable is optional and true by default.

https://www.qt.io/blog/2013/04/25/retina-display-support-for-mac-os-ios-and-x11

Enabling high-dpi for OS X Applications

High DPI mode is controlled by the following keys in the Info.Plist file:

<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<string>True</string>

Qmake will add these for you. (Strictly speaking it will only add NSPrincipalClass, NSHighResolutionCapable is optional and true by default).

If NSHighResolutionCapable is set to false, or the keys are missing, then the application will be rendered at the "normal" resolution and scaled up. This looks horrible and should be avoided, especially since the high-dpi mode is very backwards compatible and the application gets a lot of high-dpi support for free.

So it seems that this NSPrincipalClass is indeed all I need, but I'll add the three additional entries anyway: matching the default-providing Info.plist is probably a good idea, as Qt surely has thought them through.

In any case, adding the additional entries in the Info.plist does fix the bug for VPaint! I was afraid it may introduce back the mouse offset problem (#22), but it does not. The icons are still low-res though, since they are bitmaps, but it's a much less significant problem than the fonts, window decorations, and other Qt-rendered elements :-)

image