-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfont6x12.hpp
87 lines (76 loc) · 2.43 KB
/
font6x12.hpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
//=====================================================================//
/*! @file
@brief 6×12フォント・クラス
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2016, 2017 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/R8C/blob/master/LICENSE
*/
//=====================================================================//
#include <cstdint>
namespace graphics {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief フォント・クラス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
class font6x12 {
static const uint8_t bitmap_[];
static const int8_t width_tbl_[];
public:
//-----------------------------------------------------------------//
/*!
@brief 文字の横幅
*/
//-----------------------------------------------------------------//
static const int8_t WIDTH = 6;
//-----------------------------------------------------------------//
/*!
@brief 文字の高さ
*/
//-----------------------------------------------------------------//
static const int8_t HEIGHT = 12;
//-----------------------------------------------------------------//
/*!
@brief 文字のビットマップを取得
@param[in] code 文字コード
@return 文字のビットマップ
*/
//-----------------------------------------------------------------//
static const uint8_t* get(uint8_t code)
{
return &bitmap_[(static_cast<uint16_t>(code) << 3) + static_cast<uint16_t>(code)];
}
//-----------------------------------------------------------------//
/*!
@brief プロポーショナル・フォント幅を取得
@param[in] code 文字コード
@return 文字幅
*/
//-----------------------------------------------------------------//
static int8_t get_width(uint8_t code)
{
if(code < 32 || code >= 128) return WIDTH;
else return width_tbl_[code - 32];
}
//-----------------------------------------------------------------//
/*!
@brief カーニングを取得
@param[in] code 文字コード
@return 文字幅
*/
//-----------------------------------------------------------------//
static int8_t get_kern(uint8_t code)
{
switch(code) {
case '!':
case '|':
case 'i':
case 'l':
return -1;
}
return 0;
}
};
}