aboutsummaryrefslogtreecommitdiff
path: root/include/smttfont.hpp
blob: 08860ce3bf34cc1efef921e09fbd8839f1708217 (plain) (blame)
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
// -*- C++ -*-
/*
 * Simple MultimEdia LiTerator(SMELT)
 * by Chris Xiong 2015
 * Truetype font support header
 *
 * WARNING: This library is in development and interfaces would be very
 * unstable.
 * This library is developed for the BLR series games.
 */
#ifndef SMTTFONT_H
#define SMTTFONT_H
#include "smelt.hpp"
#include <cwchar>
#include <map>
#include <ft2build.h>
#include FT_FREETYPE_H

#ifndef ALIGN_LEFT
#define ALIGN_LEFT 0
#define ALIGN_RIGHT 1
#define ALIGN_CENTER 2
#endif

class smTTChar
{
private:
	smQuad quad;
	int rw,rh,_w,_h,xofs,yofs;
	static SMELT *sm;
public:
	float w(){return (float)_w;}
	float h(){return (float)_h;}
	void free();
	bool setChar(wchar_t c,FT_Face ttface);
	void render(float x,float y,float z,DWORD col,float scalex,float scaley,bool rtl);
};

class smTTFont
{
protected:
	FT_Library ftlib;
	FT_Face ttface;
private:
	wchar_t buf[1025];
	std::map<wchar_t,smTTChar> chars;
	float w,h;
public:
	bool loadTTF(const char* path,int pt);
	bool loadTTFFromMemory(char* ptr,DWORD size,int pt);
	void releaseTTF();
	float getWidth(){return w;}
	float getHeight(){return h;}
	void updateString(const wchar_t *format,...);
	void render(float x,float y,float z,DWORD col,int align,float scalex=1,float scaley=1);
	DWORD getCacheSize();
	void clearCache();
};
#endif