Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
fontsdb.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Twilight
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16#pragma once
17#include <QObject>
18#include <QString>
19#include <QHash>
20#include <QVector>
21#include <QJsonValue>
22#include <QScopedPointer>
23
24#include "./db_autoport.h"
25
26class FontSearch;
27class FontDBEntry;
28class QQmlEngine;
29
49class DB_AUTOPORT FontsDB : public QObject
50{
51 Q_OBJECT
52 Q_PROPERTY(int getStoreSize READ getStoreSize CONSTANT)
53 Q_PROPERTY(FontSearch* search READ searchRaw STORED false)
54
55public:
56 // Get Instance
57 static FontsDB* inst();
58
59 // Get Properties, includes QML array helpers
60 const QVector<FontDBEntry*> getStore() const;
61 const QHash<QString, FontDBEntry*> getInd() const;
62 int getStoreSize() const;
63
64 // QML Methods that can't be a property or slot because they take an argument
65 Q_INVOKABLE FontDBEntry* getStoreAt(const int ind) const;
66 Q_INVOKABLE FontDBEntry* getIndAt(const QString val) const;
67 Q_INVOKABLE const FontDBEntry* getStoreByVal(int ind) const;
68
69 // QML-friendly aliases used throughout the UI
70 Q_INVOKABLE FontDBEntry* fontAt(int ind) const;
71 Q_INVOKABLE int fontCount() const;
72
73 // Pull up a finder to narrow down fonts based on criteria
74 // You must delete this when done
75 // If you want to change parameters or startover you must obtain a new one
76 // everytime
77
78 // QML has such limited type compatibility, searchRaw is ambiguously owned and
79 // must be manually deleted which works for QML. search is incompatible with
80 // qml but is handled through a smart pointer and is explcitly owned by C++
81 FontSearch* searchRaw() const;
82 QScopedPointer<FontSearch, QScopedPointerDeleteLater> search() const;
83
84 // Converts a string to in-game font characters
85 // The string represents font characters, so special characters like
86 // <m> or <pic01> also apply allowing for all 255 font chracters to be
87 // leveraged with a simple keyboard
88 // Very complex and expensive operation
89 const QVector<int> convertToCode(
90 QString str, int maxLen = 11, const bool autoEnd = true) const;
91
92 // The opposite, converts a series of codes to a string
93 // Very simple and fast operation
94 const QString convertFromCode(const QVector<int> codes,
95 const int maxLen = 11) const;
96
97 // Converts an english format string to code represented as how it would be
98 // in-game
99 const QString expandStr(const QString msg, const int maxLen,
100 const QString rival, const QString player) const;
101
102 // Because counting text size is complicated, this makes it just 1 function
103 // call and accessible from QML
104 // Like most of these methods, countSizeOf can be very expensive on each call
105 Q_INVOKABLE int countSizeOf(const QString val) const;
106 Q_INVOKABLE int countSizeOfExpanded(const QString val) const;
107
108public slots:
109 void load();
110 void index();
111 void qmlProtect(const QQmlEngine* const engine) const;
112
113private slots:
114 void qmlRegister() const;
115
116private:
117 // Singleton Constructor
118 FontsDB();
119
120 QVector<FontDBEntry*> store;
121 QHash<QString, FontDBEntry*> ind;
122
123 // Something like splice, Kind of miss splice in Javascript
124 void splice(QVector<int>& out, const QString in, const int position) const;
125};
A chainable filter ("finder") over the font glyphs.
Definition fontsearch.h:40
const QHash< QString, FontDBEntry * > getInd() const
Name->glyph index.
Definition fontsdb.cpp:378
FontDBEntry * getIndAt(const QString val) const
Glyph by name key (for QML).
Definition fontsdb.cpp:396
static FontsDB * inst()
< Number of font glyphs.
Definition fontsdb.cpp:367
FontSearch * searchRaw() const
Raw finder for QML (caller must delete; see note).
Definition fontsdb.cpp:93
FontDBEntry * getStoreAt(const int ind) const
Glyph by store index (for QML).
Definition fontsdb.cpp:388
void load()
Load glyphs from JSON.
Definition fontsdb.cpp:32
const QVector< int > convertToCode(QString str, int maxLen=11, const bool autoEnd=true) const
String -> font codes (see note; expensive).
Definition fontsdb.cpp:109
void index()
Build the name->glyph index.
Definition fontsdb.cpp:54
int countSizeOfExpanded(const QString val) const
Rendered length after expandStr (expensive).
Definition fontsdb.cpp:429
FontDBEntry * fontAt(int ind) const
Alias for getStoreAt (1-based-friendly UI accessor).
Definition fontsdb.cpp:413
int countSizeOf(const QString val) const
Rendered length of val (expensive).
Definition fontsdb.cpp:423
int getStoreSize() const
Glyph count.
Definition fontsdb.cpp:383
const QString convertFromCode(const QVector< int > codes, const int maxLen=11) const
Font codes -> string (fast).
Definition fontsdb.cpp:174
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition fontsdb.cpp:70
int fontCount() const
Alias for getStoreSize.
Definition fontsdb.cpp:418
const QString expandStr(const QString msg, const int maxLen, const QString rival, const QString player) const
Expand English text to in-game form (substitutes rival/player).
Definition fontsdb.cpp:205
const FontDBEntry * getStoreByVal(int ind) const
Glyph by its font-code value.
Definition fontsdb.cpp:401
const QVector< FontDBEntry * > getStore() const
All glyphs.
Definition fontsdb.cpp:373
QScopedPointer< FontSearch, QScopedPointerDeleteLater > search() const
C++-owned finder (smart pointer).
Definition fontsdb.cpp:98
Import/export macro for the db library, plus the central list of DB entry pointer types declared opaq...
#define DB_AUTOPORT
Expands to the correct dllexport/dllimport decoration for this library.
Definition db_autoport.h:37
One in-game font character: its code, output text, and classification flags.
Definition fontdbentry.h:43