20 #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
35 int ascii = 0, xOffset = 0, yOffset = 0, page = 0, first = 0, second = 0, kerning = 0;
37 int ascii, xOffset, yOffset, page, first, second, kerning;
40 const char* charLinePattern =
41 "char id=%d%[ ]x=%d%[ ]y=%d%[ ]width=%d%[ ]height=%d%[ ]xoffset=%d%[ ]yoffset=%d%[ "
42 "]xadvance=%d%[ ]page=%d%[ ]\n";
46 ifs.open(filename.c_str(), std::ios::in | std::ios::binary);
53 std::getline(ifs, line);
54 std::getline(ifs, line);
55 std::getline(ifs, line);
56 std::getline(ifs, line);
59 std::getline(ifs, line);
61 if (sscanf_s(line.c_str(), charLinePattern, &ascii, spaces, (
unsigned)_countof(spaces), &
_invalid_char.
x,
62 spaces, (
unsigned)_countof(spaces), &
_invalid_char.
y, spaces, (
unsigned)_countof(spaces),
64 (
unsigned)_countof(spaces), &xOffset, spaces, (
unsigned)_countof(spaces), &yOffset, spaces,
66 &page, spaces, (
unsigned)_countof(spaces)) != 18)
79 while (std::getline(ifs, line))
85 if (sscanf_s(line.c_str(), charLinePattern, &ascii, spaces, (
unsigned)_countof(spaces), &
c.x, spaces,
86 (
unsigned)_countof(spaces), &
c.y, spaces, (
unsigned)_countof(spaces), &
c.w, spaces,
87 (
unsigned)_countof(spaces), &
c.h, spaces, (
unsigned)_countof(spaces), &xOffset, spaces,
88 (
unsigned)_countof(spaces), &yOffset, spaces, (
unsigned)_countof(spaces), &
c.advance,
89 spaces, (
unsigned)_countof(spaces), &page, spaces, (
unsigned)_countof(spaces)) == 18)
93 if (sscanf_s(line.c_str(),
"kerning first=%d%[ ]second=%d%[ ]amount=%d%[ ]", &first, spaces,
94 (
unsigned)_countof(spaces), &second, spaces, (
unsigned)_countof(spaces), &kerning,
95 spaces, (
unsigned)_countof(spaces)))
98 if (sscanf(line.c_str(), charLinePattern, &ascii, spaces, &
c.x, spaces, &
c.y, spaces, &
c.w, spaces,
99 &
c.h, spaces, &xOffset, spaces, &yOffset, spaces, &
c.advance, spaces, &page, spaces) == 18)
103 if (sscanf(line.c_str(),
"kerning first=%d%[ ]second=%d%[ ]amount=%d%[ ]", &first, spaces, &second,
104 spaces, &kerning, spaces))
111 std::string tgaFilename = filename.substr(0, filename.find_last_of(
'.')) +
".tga";
112 ifs.open(tgaFilename.c_str(), std::ios::in | std::ios::binary);
119 ifs.seekg(12, std::ios::beg);
122 ifs.read((
char*)&
_sizeX, 2);
123 ifs.read((
char*)&
_sizeY, 2);
126 ifs.seekg(2, std::ios::cur);
130 _data =
new unsigned char[textureSize];
131 ifs.read((
char*)
_data, textureSize);
141 if (
c >= 0 &&
c < 256)
149 if (first >= 0 && first < 256 && second >= 0 && second < 256)
OGLFontChar _invalid_char
const int getKerning(unsigned char first, unsigned char second) const
std::vector< OGLFontChar > _char
virtual bool load(const std::string &filename)
const OGLFontChar & getChar(unsigned char c) const