Skip to content

Commit

Permalink
Merge pull request #11162 from unknownbrackets/qt-resources
Browse files Browse the repository at this point in the history
Fix resource handling on Qt and use Roboto
  • Loading branch information
hrydgard committed Jun 9, 2018
2 parents d1b06bb + cc1fa20 commit 6884751
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 99 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -763,7 +763,7 @@ elseif(USING_QT_UI)
Qt/mainwindow.h
)
add_definitions(-DUSING_QT_UI)
include_directories(${CMAKE_CURRENT_BINARY_DIR} Qt Qt/Debugger)
include_directories(${CMAKE_CURRENT_BINARY_DIR} Qt)
set(nativeExtraLibs ${nativeExtraLibs} Qt5::OpenGL Qt5::Gui Qt5::Core)
set(TargetBin PPSSPPQt)

Expand Down
4 changes: 3 additions & 1 deletion Core/Config.h
Expand Up @@ -106,10 +106,12 @@ struct Config {
#if defined(USING_WIN_UI)
bool bPauseOnLostFocus;
bool bTopMost;
std::string sFont;
bool bIgnoreWindowsKey;
bool bRestartRequired;
#endif
#if defined(USING_WIN_UI) || defined(USING_QT_UI)
std::string sFont;
#endif

bool bPauseWhenMinimized;

Expand Down
16 changes: 0 additions & 16 deletions Qt/desktop_assets.qrc

This file was deleted.

29 changes: 23 additions & 6 deletions UI/NativeApp.cpp
Expand Up @@ -105,6 +105,9 @@
#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI)
#include "Qt/QtHost.h"
#endif
#if defined(USING_QT_UI)
#include <QFontDatabase>
#endif

// The new UI framework, for initialization

Expand Down Expand Up @@ -276,7 +279,7 @@ void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, boo
#endif
}

#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
#if defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)
static bool CheckFontIsUsable(const wchar_t *fontFace) {
wchar_t actualFontFace[1024] = { 0 };

Expand Down Expand Up @@ -360,9 +363,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
#endif

// We want this to be FIRST.
#ifdef USING_QT_UI
VFSRegister("", new AssetsAssetReader());
#elif defined(IOS)
#if defined(IOS)
// Packed assets are included in app
VFSRegister("", new DirectoryAssetReader(external_dir));
#endif
Expand Down Expand Up @@ -560,7 +561,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
// Note to translators: do not translate this/add this to PPSSPP-lang's files.
// It's intended to be custom for every user.
// Only add it to your own personal copies of PPSSPP.
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
#if defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)
// TODO: Could allow a setting to specify a font file to load?
// TODO: Make this a constant if we can sanely load the font on other systems?
AddFontResourceEx(L"assets/Roboto-Condensed.ttf", FR_PRIVATE, NULL);
Expand All @@ -570,6 +571,22 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
} else {
g_Config.sFont = des->T("Font", "Roboto");
}
#elif defined(USING_QT_UI)
size_t fontSize = 0;
uint8_t *fontData = VFSReadFile("Roboto-Condensed.ttf", &fontSize);
if (fontData) {
int fontID = QFontDatabase::addApplicationFontFromData(QByteArray((const char *)fontData, fontSize));
delete [] fontData;

QStringList fontsFound = QFontDatabase::applicationFontFamilies(fontID);
if (fontsFound.size() >= 1) {
// Might be "Roboto" or "Roboto Condensed".
g_Config.sFont = des->T("Font", fontsFound.at(0).toUtf8().constData());
}
} else {
// Let's try for it being a system font.
g_Config.sFont = des->T("Font", "Roboto Condensed");
}
#endif

if (!boot_filename.empty() && stateToLoad != NULL) {
Expand Down Expand Up @@ -620,7 +637,7 @@ static UI::Style MakeStyle(uint32_t fg, uint32_t bg) {
}

static void UIThemeInit() {
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
#if (defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)) || defined(USING_QT_UI)
ui_theme.uiFont = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 22);
ui_theme.uiFontSmall = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 15);
ui_theme.uiFontSmaller = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 12);
Expand Down
57 changes: 0 additions & 57 deletions ext/native/file/zip_read.cpp
Expand Up @@ -3,11 +3,6 @@
#include <set>
#include <stdio.h>

#ifdef USING_QT_UI
#include <QFileInfo>
#include <QDir>
#endif

#ifdef __ANDROID__
#include <zip.h>
#endif
Expand Down Expand Up @@ -66,58 +61,6 @@ uint8_t *ReadLocalFile(const char *filename, size_t *size) {
return contents;
}

#ifdef USING_QT_UI
uint8_t *AssetsAssetReader::ReadAsset(const char *path, size_t *size) {
QFile asset(QString(":/assets/") + path);
if (!asset.open(QIODevice::ReadOnly))
return 0;

uint8_t *contents = new uint8_t[asset.size()+1];
memcpy(contents, (uint8_t*)asset.readAll().data(), asset.size());
contents[asset.size()] = 0;
*size = asset.size();
asset.close();
return contents;
}

bool AssetsAssetReader::GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter = 0)
{
QDir assetDir(QString(":/assets/") + path);
QStringList filters = QString(filter).split(':', QString::SkipEmptyParts);
for (int i = 0; i < filters.count(); i++)
filters[i].prepend("*.");

QFileInfoList infoList = assetDir.entryInfoList(filters, QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name);
foreach(QFileInfo qinfo, infoList) {
FileInfo info;
info.name = qinfo.fileName().toStdString();
info.fullName = qinfo.absoluteFilePath().remove(":/assets/").toStdString();
info.exists = true;
info.isWritable = false;
info.isDirectory = qinfo.isDir();
listing->push_back(info);
}
return true;
}

bool AssetsAssetReader::GetFileInfo(const char *path, FileInfo *info) {
QFileInfo qinfo(QString(":/assets/") + path);
if (!qinfo.exists()) {
info->exists = false;
info->size = 0;
return false;
}

info->fullName = path;
info->exists = true;
info->isWritable = false;
info->isDirectory = qinfo.isDir();
info->size = qinfo.size();
return true;
}

#endif

#ifdef __ANDROID__

ZipAssetReader::ZipAssetReader(const char *zip_file, const char *in_zip_path) {
Expand Down
15 changes: 0 additions & 15 deletions ext/native/file/zip_read.h
Expand Up @@ -26,21 +26,6 @@ class AssetReader {
virtual std::string toString() const = 0;
};

#ifdef USING_QT_UI
class AssetsAssetReader : public AssetReader {
public:
AssetsAssetReader() {}
~AssetsAssetReader() {}
// use delete[]
virtual uint8_t *ReadAsset(const char *path, size_t *size);
virtual bool GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter);
virtual bool GetFileInfo(const char *path, FileInfo *info);
virtual std::string toString() const {
return ":assets/";
}
};
#endif

#ifdef __ANDROID__
uint8_t *ReadFromZip(zip *archive, const char* filename, size_t *size);
class ZipAssetReader : public AssetReader {
Expand Down
5 changes: 2 additions & 3 deletions ext/native/gfx_es2/draw_text_qt.cpp
Expand Up @@ -23,8 +23,7 @@ TextDrawerQt::~TextDrawerQt() {
}

uint32_t TextDrawerQt::SetFont(const char *fontName, int size, int flags) {
// We will only use the default font
uint32_t fontHash = 0; //hash::Adler32((const uint8_t *)fontName, strlen(fontName));
uint32_t fontHash = fontName && strlen(fontName) ? hash::Adler32((const uint8_t *)fontName, strlen(fontName)) : 0;
fontHash ^= size;
fontHash ^= flags << 10;

Expand All @@ -34,7 +33,7 @@ uint32_t TextDrawerQt::SetFont(const char *fontName, int size, int flags) {
return fontHash;
}

QFont* font = new QFont();
QFont* font = fontName ? new QFont(fontName) : new QFont();
font->setPixelSize(size + 6);
fontMap_[fontHash] = font;
fontHash_ = fontHash;
Expand Down

0 comments on commit 6884751

Please sign in to comment.