gosu 0.13.3 → 0.14.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gosu/Audio.hpp +15 -11
- data/Gosu/Font.hpp +24 -20
- data/Gosu/Fwd.hpp +1 -1
- data/Gosu/Graphics.hpp +8 -9
- data/Gosu/ImageData.hpp +1 -1
- data/Gosu/Input.hpp +1 -1
- data/Gosu/Math.hpp +0 -18
- data/Gosu/Text.hpp +22 -30
- data/Gosu/TextInput.hpp +13 -0
- data/Gosu/Utility.hpp +2 -0
- data/Gosu/Window.hpp +3 -3
- data/README.md +3 -4
- data/ext/gosu/extconf.rb +7 -9
- data/lib/gosu/swig_patches.rb +1 -4
- data/rdoc/gosu.rb +34 -9
- data/src/Audio.cpp +6 -6
- data/src/AudioImpl.cpp +2 -2
- data/src/Bitmap.cpp +1 -2
- data/src/BitmapIO.cpp +21 -2
- data/src/BlockAllocator.cpp +1 -1
- data/src/Channel.cpp +7 -1
- data/src/ClipRectStack.hpp +4 -1
- data/src/Color.cpp +2 -1
- data/src/DirectoriesWin.cpp +1 -1
- data/src/DrawOp.hpp +8 -4
- data/src/DrawOpQueue.hpp +13 -24
- data/src/FileUnix.cpp +3 -1
- data/src/Font.cpp +92 -96
- data/src/GosuGLView.cpp +59 -31
- data/src/GosuGLView.hpp +14 -0
- data/src/GosuViewController.cpp +21 -21
- data/src/{GosuViewController.h → GosuViewController.hpp} +2 -4
- data/src/Graphics.cpp +71 -38
- data/src/GraphicsImpl.hpp +12 -29
- data/src/Image.cpp +5 -7
- data/src/Input.cpp +7 -5
- data/src/InputUIKit.cpp +19 -37
- data/src/Macro.cpp +10 -2
- data/src/MarkupParser.cpp +241 -0
- data/src/MarkupParser.hpp +61 -0
- data/src/Math.cpp +1 -1
- data/src/OffScreenTarget.cpp +99 -0
- data/src/OffScreenTarget.hpp +23 -0
- data/src/OggFile.hpp +10 -0
- data/src/RenderState.hpp +0 -2
- data/src/Resolution.cpp +2 -2
- data/src/RubyGosu.cxx +457 -244
- data/src/TexChunk.cpp +8 -6
- data/src/Text.cpp +58 -345
- data/src/TextBuilder.cpp +138 -0
- data/src/TextBuilder.hpp +55 -0
- data/src/TextInput.cpp +27 -10
- data/src/Texture.cpp +22 -17
- data/src/Texture.hpp +19 -20
- data/src/TimingApple.cpp +5 -7
- data/src/TimingUnix.cpp +1 -4
- data/src/TimingWin.cpp +4 -1
- data/src/TrueTypeFont.cpp +282 -0
- data/src/TrueTypeFont.hpp +66 -0
- data/src/TrueTypeFontApple.cpp +65 -0
- data/src/TrueTypeFontUnix.cpp +91 -0
- data/src/TrueTypeFontWin.cpp +82 -0
- data/src/Utility.cpp +40 -0
- data/src/Window.cpp +7 -6
- data/src/WindowUIKit.cpp +9 -4
- data/src/stb_truetype.h +4589 -0
- data/src/utf8proc.c +755 -0
- data/src/utf8proc.h +699 -0
- data/src/utf8proc_data.h +14386 -0
- metadata +23 -16
- data/src/FormattedString.cpp +0 -237
- data/src/FormattedString.hpp +0 -47
- data/src/GosuAppDelegate.cpp +0 -30
- data/src/GosuAppDelegate.h +0 -8
- data/src/GosuGLView.h +0 -8
- data/src/TextApple.cpp +0 -212
- data/src/TextTTFWin.cpp +0 -197
- data/src/TextUnix.cpp +0 -280
- data/src/TextWin.cpp +0 -191
data/src/TextTTFWin.cpp
DELETED
@@ -1,197 +0,0 @@
|
|
1
|
-
#include <Gosu/Platform.hpp>
|
2
|
-
#if defined(GOSU_IS_WIN)
|
3
|
-
|
4
|
-
#include <Gosu/IO.hpp>
|
5
|
-
#include <Gosu/Utility.hpp>
|
6
|
-
#include <cassert>
|
7
|
-
#include <cstdio>
|
8
|
-
#include <windows.h>
|
9
|
-
|
10
|
-
// Adapted from http://www.codeproject.com/KB/GDI/xfont.aspx.
|
11
|
-
// Kudos to Philip Patrick and Hans Dietrich!
|
12
|
-
|
13
|
-
struct FONT_PROPERTIES_ANSI
|
14
|
-
{
|
15
|
-
char csName[1024];
|
16
|
-
char csCopyright[1024];
|
17
|
-
char csTrademark[1024];
|
18
|
-
char csFamily[1024];
|
19
|
-
};
|
20
|
-
struct TT_OFFSET_TABLE
|
21
|
-
{
|
22
|
-
USHORT uMajorVersion;
|
23
|
-
USHORT uMinorVersion;
|
24
|
-
USHORT uNumOfTables;
|
25
|
-
USHORT uSearchRange;
|
26
|
-
USHORT uEntrySelector;
|
27
|
-
USHORT uRangeShift;
|
28
|
-
};
|
29
|
-
struct TT_TABLE_DIRECTORY
|
30
|
-
{
|
31
|
-
char szTag[4]; //table name
|
32
|
-
ULONG uCheckSum; //Check sum
|
33
|
-
ULONG uOffset; //Offset from beginning of file
|
34
|
-
ULONG uLength; //length of the table in bytes
|
35
|
-
};
|
36
|
-
struct TT_NAME_TABLE_HEADER
|
37
|
-
{
|
38
|
-
USHORT uFSelector; //format selector. Always 0
|
39
|
-
USHORT uNRCount; //Name Records count
|
40
|
-
USHORT uStorageOffset; //Offset for strings storage, from start of the table
|
41
|
-
};
|
42
|
-
struct TT_NAME_RECORD
|
43
|
-
{
|
44
|
-
USHORT uPlatformID;
|
45
|
-
USHORT uEncodingID;
|
46
|
-
USHORT uLanguageID;
|
47
|
-
USHORT uNameID;
|
48
|
-
USHORT uStringLength;
|
49
|
-
USHORT uStringOffset; //from start of storage area
|
50
|
-
};
|
51
|
-
|
52
|
-
#define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
|
53
|
-
#define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
|
54
|
-
|
55
|
-
#define _T(x) x
|
56
|
-
#define TRACE printf
|
57
|
-
|
58
|
-
namespace Gosu
|
59
|
-
{
|
60
|
-
std::string get_name_from_ttf_file(const std::string& filename)
|
61
|
-
{
|
62
|
-
FONT_PROPERTIES_ANSI fp;
|
63
|
-
FONT_PROPERTIES_ANSI * lpFontProps = &fp;
|
64
|
-
memset(lpFontProps, 0, sizeof(FONT_PROPERTIES_ANSI));
|
65
|
-
|
66
|
-
Buffer buffer;
|
67
|
-
load_file(buffer, filename);
|
68
|
-
|
69
|
-
// get the file size
|
70
|
-
DWORD dwFileSize = buffer.size();
|
71
|
-
LPBYTE lpMapAddress = (LPBYTE) buffer.data();
|
72
|
-
|
73
|
-
BOOL bRetVal = FALSE;
|
74
|
-
int index = 0;
|
75
|
-
|
76
|
-
TT_OFFSET_TABLE ttOffsetTable;
|
77
|
-
memcpy(&ttOffsetTable, &lpMapAddress[index], sizeof(TT_OFFSET_TABLE));
|
78
|
-
index += sizeof(TT_OFFSET_TABLE);
|
79
|
-
|
80
|
-
ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
|
81
|
-
ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
|
82
|
-
ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
|
83
|
-
|
84
|
-
//check is this is a true type font and the version is 1.0
|
85
|
-
if (ttOffsetTable.uMajorVersion != 1 || ttOffsetTable.uMinorVersion != 0) {
|
86
|
-
throw std::runtime_error("Only version 1.0 of the TTF file format is supported");
|
87
|
-
}
|
88
|
-
|
89
|
-
TT_TABLE_DIRECTORY tblDir;
|
90
|
-
memset(&tblDir, 0, sizeof(TT_TABLE_DIRECTORY));
|
91
|
-
BOOL bFound = FALSE;
|
92
|
-
char szTemp[4096];
|
93
|
-
memset(szTemp, 0, sizeof(szTemp));
|
94
|
-
|
95
|
-
for (int i = 0; i< ttOffsetTable.uNumOfTables; i++)
|
96
|
-
{
|
97
|
-
memcpy(&tblDir, &lpMapAddress[index], sizeof(TT_TABLE_DIRECTORY));
|
98
|
-
index += sizeof(TT_TABLE_DIRECTORY);
|
99
|
-
|
100
|
-
strncpy(szTemp, tblDir.szTag, 4);
|
101
|
-
if (stricmp(szTemp, "name") == 0)
|
102
|
-
{
|
103
|
-
bFound = TRUE;
|
104
|
-
tblDir.uLength = SWAPLONG(tblDir.uLength);
|
105
|
-
tblDir.uOffset = SWAPLONG(tblDir.uOffset);
|
106
|
-
break;
|
107
|
-
}
|
108
|
-
else if (szTemp[0] == 0)
|
109
|
-
{
|
110
|
-
break;
|
111
|
-
}
|
112
|
-
}
|
113
|
-
|
114
|
-
if (bFound)
|
115
|
-
{
|
116
|
-
index = tblDir.uOffset;
|
117
|
-
|
118
|
-
TT_NAME_TABLE_HEADER ttNTHeader;
|
119
|
-
memcpy(&ttNTHeader, &lpMapAddress[index], sizeof(TT_NAME_TABLE_HEADER));
|
120
|
-
index += sizeof(TT_NAME_TABLE_HEADER);
|
121
|
-
|
122
|
-
ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
|
123
|
-
ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
|
124
|
-
TT_NAME_RECORD ttRecord;
|
125
|
-
bFound = FALSE;
|
126
|
-
|
127
|
-
for (int i = 0;
|
128
|
-
i < ttNTHeader.uNRCount &&
|
129
|
-
(lpFontProps->csCopyright[0] == 0 ||
|
130
|
-
lpFontProps->csName[0] == 0 ||
|
131
|
-
lpFontProps->csTrademark[0] == 0 ||
|
132
|
-
lpFontProps->csFamily[0] == 0);
|
133
|
-
i++)
|
134
|
-
{
|
135
|
-
memcpy(&ttRecord, &lpMapAddress[index], sizeof(TT_NAME_RECORD));
|
136
|
-
index += sizeof(TT_NAME_RECORD);
|
137
|
-
|
138
|
-
ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
|
139
|
-
ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
|
140
|
-
ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
|
141
|
-
|
142
|
-
if (ttRecord.uNameID == 1 || ttRecord.uNameID == 0 || ttRecord.uNameID == 7)
|
143
|
-
{
|
144
|
-
int nPos = index;
|
145
|
-
|
146
|
-
index = tblDir.uOffset + ttRecord.uStringOffset + ttNTHeader.uStorageOffset;
|
147
|
-
|
148
|
-
memset(szTemp, 0, sizeof(szTemp));
|
149
|
-
|
150
|
-
memcpy(szTemp, &lpMapAddress[index], ttRecord.uStringLength);
|
151
|
-
index += ttRecord.uStringLength;
|
152
|
-
|
153
|
-
if (szTemp[0] != 0)
|
154
|
-
{
|
155
|
-
assert (strlen(szTemp) < sizeof(lpFontProps->csName));
|
156
|
-
|
157
|
-
switch (ttRecord.uNameID)
|
158
|
-
{
|
159
|
-
case 0:
|
160
|
-
if (lpFontProps->csCopyright[0] == 0)
|
161
|
-
strncpy(lpFontProps->csCopyright, szTemp,
|
162
|
-
sizeof(lpFontProps->csCopyright)-1);
|
163
|
-
break;
|
164
|
-
|
165
|
-
case 1:
|
166
|
-
if (lpFontProps->csFamily[0] == 0)
|
167
|
-
strncpy(lpFontProps->csFamily, szTemp,
|
168
|
-
sizeof(lpFontProps->csFamily)-1);
|
169
|
-
bRetVal = TRUE;
|
170
|
-
break;
|
171
|
-
|
172
|
-
case 4:
|
173
|
-
if (lpFontProps->csName[0] == 0)
|
174
|
-
strncpy(lpFontProps->csName, szTemp,
|
175
|
-
sizeof(lpFontProps->csName)-1);
|
176
|
-
break;
|
177
|
-
|
178
|
-
case 7:
|
179
|
-
if (lpFontProps->csTrademark[0] == 0)
|
180
|
-
strncpy(lpFontProps->csTrademark, szTemp,
|
181
|
-
sizeof(lpFontProps->csTrademark)-1);
|
182
|
-
break;
|
183
|
-
|
184
|
-
default:
|
185
|
-
break;
|
186
|
-
}
|
187
|
-
}
|
188
|
-
index = nPos;
|
189
|
-
}
|
190
|
-
}
|
191
|
-
}
|
192
|
-
|
193
|
-
return lpFontProps->csName[0] ? lpFontProps->csName : lpFontProps->csFamily;
|
194
|
-
}
|
195
|
-
}
|
196
|
-
|
197
|
-
#endif
|
data/src/TextUnix.cpp
DELETED
@@ -1,280 +0,0 @@
|
|
1
|
-
#include <Gosu/Platform.hpp>
|
2
|
-
#if defined(GOSU_IS_X)
|
3
|
-
|
4
|
-
#include <Gosu/Text.hpp>
|
5
|
-
#include <Gosu/Bitmap.hpp>
|
6
|
-
#include <Gosu/Utility.hpp>
|
7
|
-
|
8
|
-
#include <SDL_ttf.h>
|
9
|
-
#include <glib.h>
|
10
|
-
#include <pango/pango.h>
|
11
|
-
#include <pango/pangoft2.h>
|
12
|
-
|
13
|
-
#include <cstring>
|
14
|
-
#include <stdexcept>
|
15
|
-
#include <string>
|
16
|
-
|
17
|
-
std::string Gosu::default_font_name()
|
18
|
-
{
|
19
|
-
return "sans";
|
20
|
-
}
|
21
|
-
|
22
|
-
namespace Gosu
|
23
|
-
{
|
24
|
-
// Used for system fonts
|
25
|
-
// Adapted from original version by Jan Lücker
|
26
|
-
class PangoRenderer
|
27
|
-
{
|
28
|
-
PangoRenderer(const PangoRenderer&);
|
29
|
-
PangoRenderer& operator=(const PangoRenderer&);
|
30
|
-
|
31
|
-
int width, height;
|
32
|
-
|
33
|
-
PangoContext* context;
|
34
|
-
PangoLayout* layout;
|
35
|
-
PangoFontDescription* font_description;
|
36
|
-
PangoAttribute* attr;
|
37
|
-
PangoAttrList* attr_list;
|
38
|
-
|
39
|
-
public:
|
40
|
-
PangoRenderer()
|
41
|
-
{
|
42
|
-
font_description = NULL;
|
43
|
-
attr = NULL;
|
44
|
-
attr_list = NULL;
|
45
|
-
}
|
46
|
-
|
47
|
-
~PangoRenderer()
|
48
|
-
{
|
49
|
-
g_object_unref(context);
|
50
|
-
g_object_unref(layout);
|
51
|
-
|
52
|
-
if (font_description) {
|
53
|
-
pango_font_description_free(font_description);
|
54
|
-
}
|
55
|
-
|
56
|
-
if (attr) {
|
57
|
-
pango_attribute_destroy(attr);
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
unsigned text_width(const std::string& text, const std::string& font_face,
|
62
|
-
unsigned font_height, unsigned font_flags)
|
63
|
-
{
|
64
|
-
g_type_init();
|
65
|
-
|
66
|
-
int dpi_x = 100, dpi_y = 100;
|
67
|
-
|
68
|
-
context = pango_ft2_get_context(dpi_x, dpi_y);
|
69
|
-
|
70
|
-
pango_context_set_language(context, pango_language_from_string("en_US"));
|
71
|
-
PangoDirection init_dir = PANGO_DIRECTION_LTR;
|
72
|
-
pango_context_set_base_dir(context, init_dir);
|
73
|
-
|
74
|
-
font_description = pango_font_description_new();
|
75
|
-
|
76
|
-
pango_font_description_set_family(font_description, g_strdup(font_face.c_str()));
|
77
|
-
pango_font_description_set_style(font_description,
|
78
|
-
(font_flags & FF_ITALIC) ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
|
79
|
-
pango_font_description_set_variant(font_description, PANGO_VARIANT_NORMAL);
|
80
|
-
pango_font_description_set_weight(font_description,
|
81
|
-
(font_flags & FF_BOLD) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
|
82
|
-
pango_font_description_set_stretch(font_description, PANGO_STRETCH_NORMAL);
|
83
|
-
int init_scale = int(font_height / 2.0 + 0.5);
|
84
|
-
pango_font_description_set_size(font_description, init_scale * PANGO_SCALE);
|
85
|
-
|
86
|
-
pango_context_set_font_description(context, font_description);
|
87
|
-
|
88
|
-
layout = pango_layout_new(context);
|
89
|
-
|
90
|
-
if (font_flags & FF_UNDERLINE) {
|
91
|
-
attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
|
92
|
-
attr->start_index = 0;
|
93
|
-
attr->end_index = text.length();
|
94
|
-
attr_list = pango_attr_list_new();
|
95
|
-
pango_attr_list_insert(attr_list, attr);
|
96
|
-
pango_layout_set_attributes(layout, attr_list);
|
97
|
-
pango_attr_list_unref(attr_list);
|
98
|
-
}
|
99
|
-
|
100
|
-
pango_layout_set_text(layout, text.c_str(), -1);
|
101
|
-
|
102
|
-
PangoDirection base_dir = pango_context_get_base_dir(context);
|
103
|
-
pango_layout_set_alignment(layout,
|
104
|
-
base_dir == PANGO_DIRECTION_LTR ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT);
|
105
|
-
|
106
|
-
pango_layout_set_width(layout, -1);
|
107
|
-
|
108
|
-
PangoRectangle logical_rect;
|
109
|
-
|
110
|
-
pango_layout_get_pixel_extents(layout, NULL, &logical_rect);
|
111
|
-
height = logical_rect.height;
|
112
|
-
width = logical_rect.width;
|
113
|
-
|
114
|
-
return width;
|
115
|
-
}
|
116
|
-
|
117
|
-
void draw_text(Bitmap& bitmap, const std::string& text, int x, int y, Color c,
|
118
|
-
const std::string& font_face, unsigned font_height, unsigned font_flags)
|
119
|
-
{
|
120
|
-
text_width(text, font_face, font_height, font_flags);
|
121
|
-
|
122
|
-
FT_Bitmap ft_bitmap;
|
123
|
-
|
124
|
-
guchar* buf = new guchar[width * height];
|
125
|
-
std::fill(buf, buf + width * height, 0x00);
|
126
|
-
|
127
|
-
ft_bitmap.rows = height;
|
128
|
-
ft_bitmap.width = width;
|
129
|
-
ft_bitmap.pitch = ft_bitmap.width;
|
130
|
-
ft_bitmap.buffer = buf;
|
131
|
-
ft_bitmap.num_grays = 256;
|
132
|
-
ft_bitmap.pixel_mode = ft_pixel_mode_grays;
|
133
|
-
|
134
|
-
int x_start = 0;
|
135
|
-
pango_ft2_render_layout(&ft_bitmap, layout, x_start, 0);
|
136
|
-
|
137
|
-
int min_height = std::min<int>(height, font_height);
|
138
|
-
|
139
|
-
for (int y2 = 0; y2 < min_height; y2++) {
|
140
|
-
if (y + y2 < 0 || y + y2 >= bitmap.height()) break;
|
141
|
-
|
142
|
-
for (int x2 = 0; x2 < width; x2++) {
|
143
|
-
if (x + x2 < 0 || x + x2 >= bitmap.width()) break;
|
144
|
-
unsigned val = ft_bitmap.buffer[y2 * width + x2];
|
145
|
-
Color color = multiply(c, Gosu::Color(val, 255, 255, 255));
|
146
|
-
bitmap.set_pixel(x2 + x, y2 + y, color);
|
147
|
-
}
|
148
|
-
}
|
149
|
-
|
150
|
-
delete[] buf;
|
151
|
-
}
|
152
|
-
};
|
153
|
-
|
154
|
-
// Used for custom TTF files
|
155
|
-
// Adapted from custom_font class by José Tomás Tocino García (TheOm3ga)
|
156
|
-
class SDLTTFRenderer
|
157
|
-
{
|
158
|
-
SDLTTFRenderer(const SDLTTFRenderer&) = delete;
|
159
|
-
SDLTTFRenderer& operator=(const SDLTTFRenderer&) = delete;
|
160
|
-
SDLTTFRenderer(SDLTTFRenderer&&) = delete;
|
161
|
-
SDLTTFRenderer& operator=(SDLTTFRenderer&&) = delete;
|
162
|
-
|
163
|
-
TTF_Font* font;
|
164
|
-
|
165
|
-
class SDLSurface
|
166
|
-
{
|
167
|
-
SDLSurface(const SDLSurface&);
|
168
|
-
SDLSurface& operator=(const SDLSurface&);
|
169
|
-
|
170
|
-
SDL_Surface* surface;
|
171
|
-
|
172
|
-
public:
|
173
|
-
SDLSurface(TTF_Font* font, const std::string& text, Gosu::Color c)
|
174
|
-
{
|
175
|
-
// This is intentionally re-ordered to BGR. This way, the surface pixels do not
|
176
|
-
// have to be converted from RGB to BGR later in the process.
|
177
|
-
SDL_Color color = { c.blue(), c.green(), c.red() };
|
178
|
-
surface = TTF_RenderUTF8_Blended(font, text.c_str(), color);
|
179
|
-
if (!surface) {
|
180
|
-
throw std::runtime_error("Could not render text: " + text);
|
181
|
-
}
|
182
|
-
}
|
183
|
-
|
184
|
-
~SDLSurface()
|
185
|
-
{
|
186
|
-
SDL_FreeSurface(surface);
|
187
|
-
}
|
188
|
-
|
189
|
-
unsigned height() const
|
190
|
-
{
|
191
|
-
return surface->h;
|
192
|
-
}
|
193
|
-
|
194
|
-
unsigned width() const
|
195
|
-
{
|
196
|
-
return surface->w;
|
197
|
-
}
|
198
|
-
|
199
|
-
const void* data() const
|
200
|
-
{
|
201
|
-
return surface->pixels;
|
202
|
-
}
|
203
|
-
};
|
204
|
-
|
205
|
-
public:
|
206
|
-
SDLTTFRenderer(const std::string& font_name, unsigned font_height)
|
207
|
-
{
|
208
|
-
static int init_result = TTF_Init();
|
209
|
-
if (init_result < 0) {
|
210
|
-
throw std::runtime_error("Could not initialize SDL_TTF");
|
211
|
-
}
|
212
|
-
|
213
|
-
// Try to open the font at the given path
|
214
|
-
font = TTF_OpenFont(font_name.c_str(), font_height);
|
215
|
-
if (!font) {
|
216
|
-
throw std::runtime_error("Could not open TTF file " + font_name);
|
217
|
-
}
|
218
|
-
|
219
|
-
// Re-open with scaled height so that ascenders/descenders fit
|
220
|
-
int too_large_height = TTF_FontHeight(font);
|
221
|
-
int real_height = font_height * font_height / too_large_height;
|
222
|
-
TTF_CloseFont(font);
|
223
|
-
font = TTF_OpenFont(font_name.c_str(), real_height);
|
224
|
-
if (!font) {
|
225
|
-
throw std::runtime_error("Could not open TTF file " + font_name);
|
226
|
-
}
|
227
|
-
}
|
228
|
-
|
229
|
-
~SDLTTFRenderer()
|
230
|
-
{
|
231
|
-
TTF_CloseFont(font);
|
232
|
-
}
|
233
|
-
|
234
|
-
unsigned text_width(const std::string& text)
|
235
|
-
{
|
236
|
-
return SDLSurface(font, text, 0xffffff).width();
|
237
|
-
}
|
238
|
-
|
239
|
-
void draw_text(Bitmap& bmp, const std::string& text, int x, int y, Gosu::Color c)
|
240
|
-
{
|
241
|
-
SDLSurface surf(font, text, c);
|
242
|
-
Gosu::Bitmap temp;
|
243
|
-
temp.resize(surf.width(), surf.height());
|
244
|
-
std::memcpy(temp.data(), surf.data(), temp.width() * temp.height() * 4);
|
245
|
-
bmp.insert(temp, x, y);
|
246
|
-
}
|
247
|
-
};
|
248
|
-
}
|
249
|
-
|
250
|
-
unsigned Gosu::text_width(const std::string& text, const std::string& font_name,
|
251
|
-
unsigned font_height, unsigned font_flags)
|
252
|
-
{
|
253
|
-
if (text.find_first_of("\r\n") != text.npos) {
|
254
|
-
throw std::invalid_argument("the argument to text_width cannot contain line breaks");
|
255
|
-
}
|
256
|
-
|
257
|
-
if (font_name.find("/") == font_name.npos) {
|
258
|
-
return PangoRenderer().text_width(text, font_name, font_height, font_flags);
|
259
|
-
}
|
260
|
-
else {
|
261
|
-
return SDLTTFRenderer(font_name, font_height).text_width(text);
|
262
|
-
}
|
263
|
-
}
|
264
|
-
|
265
|
-
void Gosu::draw_text(Bitmap& bitmap, const std::string& text, int x, int y, Color c,
|
266
|
-
const std::string& font_name, unsigned font_height, unsigned font_flags)
|
267
|
-
{
|
268
|
-
if (text.find_first_of("\r\n") != text.npos) {
|
269
|
-
throw std::invalid_argument("the argument to draw_text cannot contain line breaks");
|
270
|
-
}
|
271
|
-
|
272
|
-
if (font_name.find("/") == font_name.npos) {
|
273
|
-
PangoRenderer().draw_text(bitmap, text, x, y, c, font_name, font_height, font_flags);
|
274
|
-
}
|
275
|
-
else {
|
276
|
-
SDLTTFRenderer(font_name, font_height).draw_text(bitmap, text, x, y, c);
|
277
|
-
}
|
278
|
-
}
|
279
|
-
|
280
|
-
#endif
|