forked from Kiberchaika/juce_murka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjuce_fontStash.h
63 lines (47 loc) · 1.36 KB
/
juce_fontStash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#ifdef OF_VERSION_MAJOR
#include "ofMain.h"
#else
#include <stddef.h>
#include <string>
#include <vector>
#endif
#ifdef WIN32
#include <windows.h>
#endif
extern "C" {
#include "fontstash.h"
}
#if defined(MURKA_OF) || defined(MURKA_JUCE)
#include "murkafontstash.h"
#else
#include "offontstash.h"
#endif
class juceFontStash {
int font = FONS_INVALID;
FONScontext* fs = nullptr;
void cleanup();
public:
struct Rectangle {
float x;
float y;
float width;
float height;
};
juceFontStash();
~juceFontStash();
juceFontStash& operator=(const juceFontStash& obj);
bool load(const std::string filename, float fontsize, bool isAbsolutePath = false, void* renderer = nullptr);
bool load(const char* data, int dataSize, float fontsize, bool isAbsolutePath = false, void* renderer = nullptr);
void updateTexture(void* renderer = nullptr);
void clearTexture();
float getLineHeight();
float stringWidth(const std::string& s);
float stringHeight(const std::string& s);
Rectangle getStringBoundingBox(const std::string &s, float x, float y);
// custom function
std::vector<Rectangle> getStringSymbolsBoundingBoxes(const std::string &s, float x, float y, bool needJoin = false);
void drawString(const std::string &s, float x, float y);
/// static C error handler
static void stashError(void* uptr, int error, int val);
};