1 /**
2 Copyright: Copyright (c) 2013-2018 Andrey Penechko.
3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
4 Authors: Andrey Penechko.
5 */
6 
7 module voxelman.graphics.font.fontmanager;
8 
9 import voxelman.math;
10 import voxelman.graphics.font.font;
11 import voxelman.graphics.textureatlas;
12 
13 class FontManager
14 {
15 	public:
16 
17 	FontRef defaultFont;
18 	string fontPath;
19 
20 	this(string fontPath, TextureAtlas texAtlas)
21 	{
22 		this.fontPath = fontPath;
23 		this.texAtlas = texAtlas;
24 		//defaultFont = createFont(fontPath, "font_12_1.png", 12);
25 		//defaultFont = createFont(fontPath, "font_13.png", 13);
26 		//defaultFont = createFont(fontPath, "font_14.png", 13);
27 		defaultFont = createFont(fontPath, "font_12_2.png", 12);
28 	}
29 
30 	FontRef createFont(string path, string filename, in uint height)
31 	{
32 		//import std.array : array;
33 		import std.file : readText;
34 		import std.path;// : chainPath, withExtension, asAbsolutePath;
35 		string filenameAbs = buildPath(path, filename).absolutePath;
36 		string descriptionFilename = filenameAbs.setExtension("txt");
37 		string chars = readText(descriptionFilename);
38 		FontRef newFont = loadFont(filenameAbs, height, chars, texAtlas);
39 		newFont.sanitize();
40 
41 		fonts[filename] = newFont;
42 		return newFont;
43 	}
44 
45 	TextureAtlas texAtlas;
46 	FontRef[string] fonts;
47 }
48 
49 FontRef loadFont(in string filename, in uint height, in string chars, TextureAtlas texAtlas)
50 {
51 	import voxelman.graphics.font.bitmapfontloader;
52 	FontRef result = new Font(filename);
53 
54 	import std.path;
55 	string ext = std.path.extension(filename);
56 
57 	switch(ext)
58 	{
59 		case ".png": loadBitmapFont(result, texAtlas, chars); break;
60 		default: break;
61 	}
62 
63 	return result;
64 }