16 #include "TextEffect.h"
17 #include "TextAlignment.h"
18 #include <gpu/Batch.h>
19 #include <gpu/Pipeline.h>
21 class Font :
public QObject {
25 using Pointer = std::shared_ptr<Font>;
29 void read(QIODevice& path);
34 vec3 effectColor { 0 };
35 float effectThickness { 0 };
39 #if defined(__clang__)
40 __attribute__((unused))
46 gpu::BufferPointer verticesBuffer {
nullptr };
47 gpu::BufferPointer indicesBuffer {
nullptr };
48 gpu::BufferPointer paramsBuffer {
nullptr };
57 glm::vec2 computeExtent(
const QString& str)
const;
58 float getFontSize()
const {
return _fontSize; }
61 void drawString(gpu::Batch& batch, DrawInfo& drawInfo,
const QString& str,
const glm::vec4& color,
62 const glm::vec3& effectColor,
float effectThickness, TextEffect effect, TextAlignment alignment,
63 const glm::vec2& origin,
const glm::vec2& bound,
float scale,
bool unlit,
bool forward);
65 static Pointer load(
const QString& family);
67 bool isLoaded()
const {
return _loaded; }
68 void setLoaded(
bool loaded) { _loaded = loaded; }
71 void handleFontNetworkReply();
74 static Pointer load(QIODevice& fontFile);
75 QStringList tokenizeForWrapping(
const QString& str)
const;
76 QStringList splitLines(
const QString& str)
const;
77 glm::vec2 computeTokenExtent(
const QString& str)
const;
79 const Glyph& getGlyph(
const QChar& c)
const;
80 void buildVertices(DrawInfo& drawInfo,
const QString& str,
const glm::vec2& origin,
const glm::vec2& bounds,
float scale,
bool enlargeForShadows,
81 TextAlignment alignment);
90 mutable QHash<QChar, Glyph> _glyphs;
94 float _fontSize { 0.0f };
95 float _leading { 0.0f };
96 float _ascent { 0.0f };
97 float _descent { 0.0f };
98 float _spaceWidth { 0.0f };
100 float _scale { 0.0f };
101 TextAlignment _alignment;
103 bool _loaded {
true };
105 gpu::TexturePointer _texture;
106 gpu::BufferStreamPointer _stream;
108 static std::map<std::tuple<bool, bool, bool>, gpu::PipelinePointer> _pipelines;
109 static gpu::Stream::FormatPointer _format;