mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 06:18:52 +02:00
Fix leaking Font
This commit is contained in:
parent
7b5075cce5
commit
2e4e1dd590
4 changed files with 12 additions and 16 deletions
|
@ -54,9 +54,6 @@ TextRenderer3D::TextRenderer3D(const char* family, float pointSize, int weight,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextRenderer3D::~TextRenderer3D() {
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec2 TextRenderer3D::computeExtent(const QString& str) const {
|
glm::vec2 TextRenderer3D::computeExtent(const QString& str) const {
|
||||||
if (_font) {
|
if (_font) {
|
||||||
return _font->computeExtent(str);
|
return _font->computeExtent(str);
|
||||||
|
|
|
@ -12,11 +12,10 @@
|
||||||
#ifndef hifi_TextRenderer3D_h
|
#ifndef hifi_TextRenderer3D_h
|
||||||
#define hifi_TextRenderer3D_h
|
#define hifi_TextRenderer3D_h
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace gpu {
|
namespace gpu {
|
||||||
class Batch;
|
class Batch;
|
||||||
}
|
}
|
||||||
|
@ -34,8 +33,6 @@ public:
|
||||||
static TextRenderer3D* getInstance(const char* family, float pointSize = DEFAULT_POINT_SIZE,
|
static TextRenderer3D* getInstance(const char* family, float pointSize = DEFAULT_POINT_SIZE,
|
||||||
bool bold = false, bool italic = false, EffectType effect = NO_EFFECT, int effectThickness = 1);
|
bool bold = false, bool italic = false, EffectType effect = NO_EFFECT, int effectThickness = 1);
|
||||||
|
|
||||||
~TextRenderer3D();
|
|
||||||
|
|
||||||
glm::vec2 computeExtent(const QString& str) const;
|
glm::vec2 computeExtent(const QString& str) const;
|
||||||
float getFontSize() const; // Pixel size
|
float getFontSize() const; // Pixel size
|
||||||
|
|
||||||
|
@ -55,7 +52,7 @@ private:
|
||||||
// text color
|
// text color
|
||||||
glm::vec4 _color;
|
glm::vec4 _color;
|
||||||
|
|
||||||
Font* _font;
|
std::shared_ptr<Font> _font;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,15 +47,15 @@ struct QuadBuilder {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static QHash<QString, Font*> LOADED_FONTS;
|
static QHash<QString, Font::Pointer> LOADED_FONTS;
|
||||||
|
|
||||||
Font* Font::load(QIODevice& fontFile) {
|
Font::Pointer Font::load(QIODevice& fontFile) {
|
||||||
Font* result = new Font();
|
Pointer font = std::make_shared<Font>();
|
||||||
result->read(fontFile);
|
font->read(fontFile);
|
||||||
return result;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
Font* Font::load(const QString& family) {
|
Font::Pointer Font::load(const QString& family) {
|
||||||
if (!LOADED_FONTS.contains(family)) {
|
if (!LOADED_FONTS.contains(family)) {
|
||||||
|
|
||||||
static const QString SDFF_COURIER_PRIME_FILENAME{ ":/CourierPrime.sdff" };
|
static const QString SDFF_COURIER_PRIME_FILENAME{ ":/CourierPrime.sdff" };
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
class Font {
|
class Font {
|
||||||
public:
|
public:
|
||||||
|
using Pointer = std::shared_ptr<Font>;
|
||||||
|
|
||||||
Font();
|
Font();
|
||||||
|
|
||||||
void read(QIODevice& path);
|
void read(QIODevice& path);
|
||||||
|
@ -29,8 +31,8 @@ public:
|
||||||
const glm::vec4* color, EffectType effectType,
|
const glm::vec4* color, EffectType effectType,
|
||||||
const glm::vec2& bound, bool layered = false);
|
const glm::vec2& bound, bool layered = false);
|
||||||
|
|
||||||
static Font* load(QIODevice& fontFile);
|
static Pointer load(QIODevice& fontFile);
|
||||||
static Font* load(const QString& family);
|
static Pointer load(const QString& family);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList tokenizeForWrapping(const QString& str) const;
|
QStringList tokenizeForWrapping(const QString& str) const;
|
||||||
|
|
Loading…
Reference in a new issue