-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFontTools.h
More file actions
72 lines (53 loc) · 1.52 KB
/
FontTools.h
File metadata and controls
72 lines (53 loc) · 1.52 KB
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
64
65
66
67
68
69
70
71
72
//
// FontTools.h
// Musee
//
// Created by Denis Stadniczuk on 27/06/14.
// Copyright (c) 2014 Denis Stadniczuk. All rights reserved.
//
#ifndef __Musee__FontTools__
#define __Musee__FontTools__
#include <iostream>
#include <map>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <hb.h>
#include <hb-ft.h>
struct GlyphPosition {
float x, y;
float w, h;
float u0, v0, u1, v1;
};
struct GlyphInfo {
float u0, v0, u1, v1;
float w, h;
float offsetX, offsetY;
};
class Font {
FT_Face face;
unsigned char *textureMapData;
int textureMapLength;
int lastAddedCPX;
int lastAddedCPY;
int maxH;
int currentQuadrant;
bool dirtyTexture;
std::map<int, GlyphInfo> codepointPosition; //key of map is codepoint, pair is x,y in texture
public:
Font(FT_Library lib, std::string fileName, int fontSize);
//you should first call stringInfo with the string you want to draw. Then check if the map is updated and upload it to GL if necessary
GlyphPosition* stringInfo(std::string text, int &w, int &h, int &numInfos); //you're responsible for deleting the infos
bool isTextureMapUpdated();
unsigned char* getTextureMap(int &w, int &h);
//gettexturemap
};
class FontTools {
FT_Library library;
std::map<std::string, std::pair<int, Font*>> cachedFonts;
public:
FontTools();
void loadFont(std::string fontName, int fontSize);
Font* getFont(std::string fontName, int fontSize);
void unloadFont(std::string fontName, int fontSize);
};
#endif /* defined(__Musee__FontTools__) */