aboutsummaryrefslogtreecommitdiff
path: root/src/graphics/Font.cpp
blob: 09ebfd03fe8d0e918984b834f4c51e2b1b5ab5ef (plain)
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
#include "../../include/mglpp/graphics/Font.hpp"
#include "../../include/mglpp/graphics/Texture.hpp"
#include "../../include/mglpp/system/MemoryMappedFile.hpp"
#include <string.h>

namespace mgl {
    Font::Font() {
        memset(&font, 0, sizeof(font));
    }

    Font::~Font() {
        mgl_font_unload(&font);
    }

    bool Font::load_from_file(const MemoryMappedFile &mapped_file, unsigned int character_size) {
        if(font.texture.id) {
            mgl_font_unload(&font);
            memset(&font, 0, sizeof(font));
        }
        return mgl_font_load_from_file(&font, mapped_file.internal_mapped_file(), character_size) == 0;
    }

    unsigned int Font::get_character_size() const {
        return font.character_size;
    }

    FontGlyph Font::get_glyph(uint32_t codepoint) {
        FontGlyph font_glyph;
        mgl_font_get_glyph(&font, codepoint, (mgl_font_glyph*)&font_glyph);
        return font_glyph;
    }

    float Font::get_kerning(uint32_t prev_codepoint, uint32_t codepoint) {
        return mgl_font_get_kerning(&font, prev_codepoint, codepoint);
    }

    int Font::get_ascent() const {
        return font.ascent;
    }

    int Font::get_descent() const {
        return font.descent;
    }

    int Font::get_linegap() const {
        return font.linegap;
    }

    Texture Font::get_texture() const {
        return Texture::reference(font.texture);
    }

    mgl_font* Font::internal_font() {
        return &font;
    }
}