mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Same for Qt
This commit is contained in:
1 parent
59ab9e5682
commit
582c2e28ca
5 files changed
+53
-52
No files matched your search
@@ -14,6 +14,8 @@ enum class FontStyleFlags : u8 {
|
||||
Bold = 1,
|
||||
Light = 2,
|
||||
Italic = 16,
|
||||
Underline = 32, // Future use.
|
||||
Strikethrough = 64, // Future use.
|
||||
};
|
||||
ENUM_CLASS_BITOPS(FontStyleFlags);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// draw_text
|
||||
|
||||
// Uses system fonts to draw text.
|
||||
// Uses system fonts to draw text.
|
||||
// Platform support will be added over time, initially just Win32.
|
||||
|
||||
// Caches strings in individual textures. Might later combine them into a big one
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Common/Data/Hash/Hash.h"
|
||||
#include "Common/Data/Text/WrapText.h"
|
||||
#include "Common/Data/Encoding/Utf8.h"
|
||||
#include "Common/File/VFS/VFS.h"
|
||||
#include "Common/Render/Text/draw_text.h"
|
||||
#include "Common/Render/Text/draw_text_qt.h"
|
||||
|
||||
@@ -14,44 +15,66 @@
|
||||
#include <QtGui/QImage>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QFontMetrics>
|
||||
#include <QFontDatabase>
|
||||
#include <QtOpenGL/QGLWidget>
|
||||
|
||||
TextDrawerQt::TextDrawerQt(Draw::DrawContext *draw) : TextDrawer(draw) {}
|
||||
TextDrawerQt::TextDrawerQt(Draw::DrawContext *draw) : TextDrawer(draw) {
|
||||
// Add all fonts we ship with.
|
||||
|
||||
std::vector<std::string> filenames = GetAllFontFilenames();
|
||||
|
||||
for (const auto &iter : filenames) {
|
||||
std::string fn = "assets/" + iter + ".ttf";
|
||||
size_t fontSize = 0;
|
||||
uint8_t *fontData = g_VFS.ReadFile(fn.c_str(), &fontSize);
|
||||
if (fontData) {
|
||||
int fontID = QFontDatabase::addApplicationFontFromData(QByteArray((const char *)fontData, fontSize));
|
||||
delete[] fontData;
|
||||
QStringList fontsFound = QFontDatabase::applicationFontFamilies(fontID);
|
||||
if (fontsFound.size() == 0) {
|
||||
WARN_LOG(Log::G3D, "Failed to load font from %s", fn.c_str());
|
||||
} else {
|
||||
for (const auto &f : fontsFound) {
|
||||
WARN_LOG(Log::G3D, "Loaded font %s from %s", f.toUtf8().constData(), fn.c_str());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ERROR_LOG(Log::G3D, "Failed to load font file %s", fn.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TextDrawerQt::~TextDrawerQt() {
|
||||
ClearCache();
|
||||
ClearFonts();
|
||||
}
|
||||
|
||||
uint32_t TextDrawerQt::SetOrCreateFont(const FontStyle &style) {
|
||||
const uint32_t fontHash = style.Hash();
|
||||
|
||||
auto iter = fontMap_.find(fontHash);
|
||||
void TextDrawerQt::SetOrCreateFont(const FontStyle &style) {
|
||||
auto iter = fontMap_.find(style);
|
||||
if (iter != fontMap_.end()) {
|
||||
fontHash_ = fontHash;
|
||||
return fontHash;
|
||||
fontStyle_ = style;
|
||||
return;
|
||||
}
|
||||
|
||||
QFont *font = !style.fontName.empty() ? new QFont(style.fontName.c_str()) : new QFont();
|
||||
FontStyleFlags styleFlags;
|
||||
std::string fontName = GetFontNameForFontStyle(style, &styleFlags);
|
||||
|
||||
QFont *font = new QFont(fontName.c_str());
|
||||
font->setPixelSize((int)((style.sizePts + 6) / dpiScale_));
|
||||
|
||||
fontMap_[fontHash] = font;
|
||||
fontHash_ = fontHash;
|
||||
return fontHash;
|
||||
}
|
||||
|
||||
void TextDrawerQt::SetFont(uint32_t fontHandle) {
|
||||
uint32_t fontHash = fontHandle;
|
||||
auto iter = fontMap_.find(fontHash);
|
||||
if (iter != fontMap_.end()) {
|
||||
fontHash_ = fontHandle;
|
||||
} else {
|
||||
ERROR_LOG(Log::G3D, "Invalid font handle %08x", fontHandle);
|
||||
font->setBold(styleFlags & FontStyleFlags::Bold);
|
||||
if (styleFlags & FontStyleFlags::Light) {
|
||||
font->setWeight(QFont::Light);
|
||||
}
|
||||
font->setItalic(styleFlags & FontStyleFlags::Italic);
|
||||
font->setUnderline(styleFlags & FontStyleFlags::Underline);
|
||||
font->setStrikeOut(styleFlags & FontStyleFlags::Strikethrough);
|
||||
|
||||
fontMap_[style] = font;
|
||||
fontStyle_ = style;
|
||||
}
|
||||
|
||||
void TextDrawerQt::MeasureStringInternal(std::string_view str, float *w, float *h) {
|
||||
QFont* font = fontMap_.find(fontHash_)->second;
|
||||
QFont* font = fontMap_.find(fontStyle_)->second;
|
||||
QFontMetrics fm(*font);
|
||||
QSize size = fm.size(0, QString::fromUtf8(str.data(), str.length()));
|
||||
|
||||
@@ -67,7 +90,7 @@ bool TextDrawerQt::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextString
|
||||
return false;
|
||||
}
|
||||
|
||||
QFont *font = fontMap_.find(fontHash_)->second;
|
||||
QFont *font = fontMap_.find(fontStyle_)->second;
|
||||
QFontMetrics fm(*font);
|
||||
QSize size = fm.size(0, QString::fromUtf8(str.data(), str.length()));
|
||||
QImage image((size.width() + 3) & ~3, (size.height() + 3) & ~3, QImage::Format_ARGB32_Premultiplied);
|
||||
@@ -117,7 +140,7 @@ void TextDrawerQt::ClearFonts() {
|
||||
delete iter.second;
|
||||
}
|
||||
fontMap_.clear();
|
||||
fontHash_ = 0;
|
||||
fontStyle_ = {};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -14,8 +14,7 @@ public:
|
||||
TextDrawerQt(Draw::DrawContext *draw);
|
||||
~TextDrawerQt();
|
||||
|
||||
uint32_t SetOrCreateFont(const FontStyle &style) override;
|
||||
void SetFont(uint32_t fontHandle) override; // Shortcut once you've set the font once.
|
||||
void SetOrCreateFont(const FontStyle &style) override;
|
||||
bool DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align, bool fullColor) override;
|
||||
|
||||
protected:
|
||||
@@ -24,7 +23,7 @@ protected:
|
||||
|
||||
void ClearFonts() override;
|
||||
|
||||
std::map<uint32_t, QFont *> fontMap_;
|
||||
std::map<FontStyle, QFont *> fontMap_;
|
||||
};
|
||||
|
||||
#endif
|
||||
+1
-24
@@ -134,9 +134,6 @@
|
||||
#include "UI/Theme.h"
|
||||
#include "UI/UIAtlas.h"
|
||||
|
||||
#if defined(USING_QT_UI)
|
||||
#include <QFontDatabase>
|
||||
#endif
|
||||
#if PPSSPP_PLATFORM(UWP)
|
||||
#include <dwrite_3.h>
|
||||
#include "UWP/UWPHelpers/InputHelpers.h"
|
||||
@@ -696,26 +693,6 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
|
||||
}
|
||||
}
|
||||
|
||||
auto des = GetI18NCategory(I18NCat::DESKTOPUI);
|
||||
|
||||
#if defined(USING_QT_UI)
|
||||
size_t fontSize = 0;
|
||||
uint8_t *fontData = g_VFS.ReadFile("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
|
||||
|
||||
g_BackgroundAudio.SFX().Init();
|
||||
|
||||
if (!boot_filename.empty() && stateToLoad.Valid()) {
|
||||
@@ -1386,7 +1363,7 @@ bool NativeKey(const KeyInput &key) {
|
||||
}
|
||||
|
||||
#if PPSSPP_PLATFORM(UWP)
|
||||
// Ignore if key sent from OnKeyDown/OnKeyUp/XInput while text edit active
|
||||
// Ignore if key sent from OnKeyDown/OnKeyUp/XInput while text edit active
|
||||
// it's already handled by `OnCharacterReceived`
|
||||
if (IgnoreInput(key.keyCode) && !(key.flags & KEY_CHAR)) {
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user