rays 0.1.11 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/camera.cpp +88 -0
- data/.doc/ext/rays/color.cpp +223 -45
- data/.doc/ext/rays/color_space.cpp +146 -46
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +69 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +14 -8
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +187 -292
- data/.doc/ext/rays/point.cpp +96 -77
- data/.doc/ext/rays/polygon.cpp +313 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +167 -0
- data/.doc/ext/rays/rays.cpp +103 -12
- data/.doc/ext/rays/shader.cpp +83 -9
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +24 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/camera.cpp +94 -0
- data/ext/rays/color.cpp +231 -51
- data/ext/rays/color_space.cpp +149 -47
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +2 -3
- data/ext/rays/font.cpp +74 -24
- data/ext/rays/image.cpp +28 -40
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +14 -8
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +203 -298
- data/ext/rays/point.cpp +105 -81
- data/ext/rays/polygon.cpp +329 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +176 -0
- data/ext/rays/rays.cpp +103 -13
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/camera.h +49 -0
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +15 -10
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +36 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +12 -18
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +89 -93
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +198 -0
- data/include/rays/polyline.h +71 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/camera.h +41 -0
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/rays.h +8 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +7 -2
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/camera.rb +21 -0
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +3 -7
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +78 -93
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +58 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +52 -34
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +172 -98
- data/src/image.h +25 -0
- data/src/ios/bitmap.h +21 -0
- data/src/ios/bitmap.mm +129 -110
- data/src/ios/camera.mm +236 -0
- data/src/ios/font.mm +50 -62
- data/src/ios/helper.h +2 -2
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.h +21 -0
- data/src/osx/bitmap.mm +129 -110
- data/src/osx/camera.mm +236 -0
- data/src/osx/font.mm +49 -62
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +845 -671
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1266 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +160 -0
- data/src/polyline.h +69 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_font.rb +5 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +157 -51
- data/test/test_painter_shape.rb +102 -0
- data/test/test_point.rb +29 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +171 -0
- data/test/test_shader.rb +9 -9
- metadata +102 -70
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
data/src/color_space.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "
|
1
|
+
#include "color_space.h"
|
2
2
|
|
3
3
|
|
4
4
|
#include <assert.h>
|
@@ -13,13 +13,15 @@ namespace Rays
|
|
13
13
|
enum
|
14
14
|
{
|
15
15
|
|
16
|
-
|
16
|
+
FIRST = GRAY_8, LAST = ABGR_float,
|
17
17
|
|
18
|
-
|
18
|
+
GRAY_FIRST = GRAY_8, GRAY_LAST = GRAY_float,
|
19
19
|
|
20
|
-
|
20
|
+
ALPHA_FIRST = ALPHA_8, ALPHA_LAST = ALPHA_float,
|
21
21
|
|
22
|
-
|
22
|
+
RGB_FIRST = RGB_888, RGB_LAST = ABGR_float,
|
23
|
+
|
24
|
+
RGB_FLOAT_FIRST = RGB_float, RGB_FLOAT_LAST = ABGR_float,
|
23
25
|
|
24
26
|
};
|
25
27
|
|
@@ -45,12 +47,15 @@ namespace Rays
|
|
45
47
|
{
|
46
48
|
static const int BPPS[] =
|
47
49
|
{
|
48
|
-
0,
|
49
|
-
8, 16, 24, 32, 32,
|
50
|
-
8,
|
51
|
-
|
50
|
+
0, // UNKNOWN
|
51
|
+
8, 16, 24, 32, 32, // GRAY
|
52
|
+
8, 16, 24, 32, 32, // ALPHA
|
53
|
+
8, 8, 8, 8, 8, // RGB(A),
|
54
|
+
8, 8, 8, 8, 8, // BGR(A)
|
55
|
+
32, 32, 32, // RGB(A) float
|
56
|
+
32, 32, 32, // BGR(A) float
|
52
57
|
};
|
53
|
-
if (type_ < 0 ||
|
58
|
+
if (type_ < 0 || COLORSPACE_MAX <= type_) return BPPS[COLORSPACE_UNKNOWN];
|
54
59
|
return BPPS[type_];
|
55
60
|
}
|
56
61
|
|
@@ -67,12 +72,13 @@ namespace Rays
|
|
67
72
|
{
|
68
73
|
0, // UNKNOWN
|
69
74
|
8, 16, 24, 32, 32, // GRAY
|
75
|
+
8, 16, 24, 32, 32, // ALPHA
|
70
76
|
24, 32, 32, 32, 32, // RGB(A)
|
71
77
|
24, 32, 32, 32, 32, // BGR(A)
|
72
78
|
96, 128, 128, // RGB(A) float
|
73
79
|
96, 128, 128, // BGR(A) float
|
74
80
|
};
|
75
|
-
if (type_ < 0 ||
|
81
|
+
if (type_ < 0 || COLORSPACE_MAX <= type_) return BPPS[COLORSPACE_UNKNOWN];
|
76
82
|
return BPPS[type_];
|
77
83
|
}
|
78
84
|
|
@@ -91,7 +97,13 @@ namespace Rays
|
|
91
97
|
bool
|
92
98
|
ColorSpace::is_gray () const
|
93
99
|
{
|
94
|
-
return GRAY_FIRST
|
100
|
+
return GRAY_FIRST <= (int) type_ && (int) type_ <= GRAY_LAST;
|
101
|
+
}
|
102
|
+
|
103
|
+
bool
|
104
|
+
ColorSpace::is_alpha () const
|
105
|
+
{
|
106
|
+
return ALPHA_FIRST <= (int) type_ && (int) type_ <= ALPHA_LAST;
|
95
107
|
}
|
96
108
|
|
97
109
|
bool
|
@@ -114,14 +126,15 @@ namespace Rays
|
|
114
126
|
ColorSpace::is_float () const
|
115
127
|
{
|
116
128
|
return
|
117
|
-
type_ == GRAY_float ||
|
118
|
-
(
|
129
|
+
type_ == GRAY_float || type_ == ALPHA_float ||
|
130
|
+
(RGB_FLOAT_FIRST <= (int) type_ && (int) type_ <= RGB_FLOAT_LAST);
|
119
131
|
}
|
120
132
|
|
121
133
|
bool
|
122
134
|
ColorSpace::has_alpha () const
|
123
135
|
{
|
124
136
|
return
|
137
|
+
(ALPHA_FIRST <= type_ && type_ <= ALPHA_LAST) ||
|
125
138
|
type_ == RGBA_8888 || type_ == ARGB_8888 ||
|
126
139
|
type_ == BGRA_8888 || type_ == ABGR_8888 ||
|
127
140
|
type_ == RGBA_float || type_ == ARGB_float ||
|
@@ -170,51 +183,56 @@ namespace Rays
|
|
170
183
|
return premult;
|
171
184
|
}
|
172
185
|
|
186
|
+
ColorSpace::operator bool () const
|
187
|
+
{
|
188
|
+
return FIRST <= (int) type_ && (int) type_ <= LAST;
|
189
|
+
}
|
190
|
+
|
191
|
+
bool
|
192
|
+
ColorSpace::operator ! () const
|
193
|
+
{
|
194
|
+
return !operator bool();
|
195
|
+
}
|
196
|
+
|
197
|
+
|
173
198
|
void
|
174
|
-
|
199
|
+
ColorSpace_get_gl_format_and_type (
|
200
|
+
GLenum* format, GLenum* type, const ColorSpace& cs)
|
175
201
|
{
|
176
202
|
if (!format && !type)
|
177
203
|
argument_error(__FILE__, __LINE__);
|
178
204
|
|
179
|
-
if (
|
205
|
+
if (!cs)
|
180
206
|
invalid_state_error(__FILE__, __LINE__);
|
181
207
|
|
182
208
|
if (format)
|
183
209
|
{
|
184
|
-
if (is_rgb())
|
210
|
+
if (cs.is_rgb()) *format = cs.has_alpha() ? GL_RGBA : GL_RGB;
|
185
211
|
#ifndef IOS
|
186
|
-
else if (is_bgr())
|
212
|
+
else if (cs.is_bgr()) *format = cs.has_alpha() ? GL_BGRA : GL_BGR;
|
187
213
|
#endif
|
188
|
-
else if (is_gray())
|
189
|
-
else
|
214
|
+
else if (cs.is_gray()) *format = GL_LUMINANCE;
|
215
|
+
else if (cs.is_alpha()) *format = GL_ALPHA;
|
216
|
+
else
|
217
|
+
rays_error(__FILE__, __LINE__, "invalid color space.");
|
190
218
|
}
|
191
219
|
|
192
220
|
if (type)
|
193
221
|
{
|
194
|
-
if (is_float())
|
222
|
+
if (cs.is_float())
|
195
223
|
*type = GL_FLOAT;
|
196
|
-
else switch (bpc())
|
224
|
+
else switch (cs.bpc())
|
197
225
|
{
|
198
226
|
case 8: *type = GL_UNSIGNED_BYTE; break;
|
199
227
|
case 16: *type = GL_UNSIGNED_SHORT; break;
|
200
228
|
#ifndef IOS
|
201
229
|
case 32: *type = GL_UNSIGNED_INT; break;
|
202
230
|
#endif
|
203
|
-
default:
|
231
|
+
default:
|
232
|
+
rays_error(__FILE__, __LINE__, "invalid bpc.");
|
204
233
|
}
|
205
234
|
}
|
206
235
|
}
|
207
236
|
|
208
|
-
ColorSpace::operator bool () const
|
209
|
-
{
|
210
|
-
return FIRST <= (int) type_ && (int) type_ <= LAST;
|
211
|
-
}
|
212
|
-
|
213
|
-
bool
|
214
|
-
ColorSpace::operator ! () const
|
215
|
-
{
|
216
|
-
return !operator bool();
|
217
|
-
}
|
218
|
-
|
219
237
|
|
220
238
|
}// Rays
|
data/src/color_space.h
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_SRC_COLOR_SPACE_H__
|
4
|
+
#define __RAYS_SRC_COLOR_SPACE_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rays/color_space.h>
|
8
|
+
#include "opengl.h"
|
9
|
+
|
10
|
+
|
11
|
+
namespace Rays
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
void ColorSpace_get_gl_format_and_type (
|
16
|
+
GLenum* format, GLenum* type, const ColorSpace& cs);
|
17
|
+
|
18
|
+
|
19
|
+
}// Rays
|
20
|
+
|
21
|
+
|
22
|
+
#endif//EOH
|
data/src/coord.cpp
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
#include "coord.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <xot/string.h>
|
5
|
+
#include "rays/exception.h"
|
6
|
+
|
7
|
+
|
8
|
+
namespace Rays
|
9
|
+
{
|
10
|
+
|
11
|
+
|
12
|
+
Coord2&
|
13
|
+
Coord2::reset (coord value)
|
14
|
+
{
|
15
|
+
return reset(value, value);
|
16
|
+
}
|
17
|
+
|
18
|
+
Coord2&
|
19
|
+
Coord2::reset (coord x, coord y)
|
20
|
+
{
|
21
|
+
this->x = x;
|
22
|
+
this->y = y;
|
23
|
+
return *this;
|
24
|
+
}
|
25
|
+
|
26
|
+
size_t
|
27
|
+
Coord2::size () const
|
28
|
+
{
|
29
|
+
return SIZE;
|
30
|
+
}
|
31
|
+
|
32
|
+
String
|
33
|
+
Coord2::inspect () const
|
34
|
+
{
|
35
|
+
return Xot::stringf("x=%f y=%f", x, y);
|
36
|
+
}
|
37
|
+
|
38
|
+
coord&
|
39
|
+
Coord2::operator [] (size_t index)
|
40
|
+
{
|
41
|
+
if (index >= 2)
|
42
|
+
argument_error(__FILE__, __LINE__);
|
43
|
+
|
44
|
+
return array[index];
|
45
|
+
}
|
46
|
+
|
47
|
+
const coord&
|
48
|
+
Coord2::operator [] (size_t index) const
|
49
|
+
{
|
50
|
+
return const_cast<Coord2*>(this)->operator[](index);
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
Coord3&
|
55
|
+
Coord3::operator = (const Coord2& rhs)
|
56
|
+
{
|
57
|
+
x = rhs.x;
|
58
|
+
y = rhs.y;
|
59
|
+
z = 0;
|
60
|
+
return *this;
|
61
|
+
}
|
62
|
+
|
63
|
+
Coord3&
|
64
|
+
Coord3::reset (coord value)
|
65
|
+
{
|
66
|
+
return reset(value, value);
|
67
|
+
}
|
68
|
+
|
69
|
+
Coord3&
|
70
|
+
Coord3::reset (coord x, coord y, coord z)
|
71
|
+
{
|
72
|
+
this->x = x;
|
73
|
+
this->y = y;
|
74
|
+
this->z = z;
|
75
|
+
return *this;
|
76
|
+
}
|
77
|
+
|
78
|
+
size_t
|
79
|
+
Coord3::size () const
|
80
|
+
{
|
81
|
+
return SIZE;
|
82
|
+
}
|
83
|
+
|
84
|
+
String
|
85
|
+
Coord3::inspect () const
|
86
|
+
{
|
87
|
+
return Xot::stringf("x=%f y=%f z=%f", x, y, z);
|
88
|
+
}
|
89
|
+
|
90
|
+
coord&
|
91
|
+
Coord3::operator [] (size_t index)
|
92
|
+
{
|
93
|
+
if (index >= 3)
|
94
|
+
argument_error(__FILE__, __LINE__);
|
95
|
+
|
96
|
+
return array[index];
|
97
|
+
}
|
98
|
+
|
99
|
+
const coord&
|
100
|
+
Coord3::operator [] (size_t index) const
|
101
|
+
{
|
102
|
+
return const_cast<Coord3*>(this)->operator[](index);
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
Coord4&
|
107
|
+
Coord4::operator = (const Coord2& rhs)
|
108
|
+
{
|
109
|
+
x = rhs.x;
|
110
|
+
y = rhs.y;
|
111
|
+
z = 0;
|
112
|
+
w = 1;
|
113
|
+
return *this;
|
114
|
+
}
|
115
|
+
|
116
|
+
Coord4&
|
117
|
+
Coord4::operator = (const Coord3& rhs)
|
118
|
+
{
|
119
|
+
x = rhs.x;
|
120
|
+
y = rhs.y;
|
121
|
+
z = rhs.z;
|
122
|
+
w = 1;
|
123
|
+
return *this;
|
124
|
+
}
|
125
|
+
|
126
|
+
Coord4&
|
127
|
+
Coord4::reset (coord value)
|
128
|
+
{
|
129
|
+
return reset(value, value, value);
|
130
|
+
}
|
131
|
+
|
132
|
+
Coord4&
|
133
|
+
Coord4::reset (coord x, coord y, coord z, coord w)
|
134
|
+
{
|
135
|
+
this->x = x;
|
136
|
+
this->y = y;
|
137
|
+
this->z = z;
|
138
|
+
this->w = w;
|
139
|
+
return *this;
|
140
|
+
}
|
141
|
+
|
142
|
+
size_t
|
143
|
+
Coord4::size () const
|
144
|
+
{
|
145
|
+
return SIZE;
|
146
|
+
}
|
147
|
+
|
148
|
+
String
|
149
|
+
Coord4::inspect () const
|
150
|
+
{
|
151
|
+
return Xot::stringf("x=%f y=%f z=%f w=%f", x, y, z, w);
|
152
|
+
}
|
153
|
+
|
154
|
+
coord&
|
155
|
+
Coord4::operator [] (size_t index)
|
156
|
+
{
|
157
|
+
if (index >= 4)
|
158
|
+
argument_error(__FILE__, __LINE__);
|
159
|
+
|
160
|
+
return array[index];
|
161
|
+
}
|
162
|
+
|
163
|
+
const coord&
|
164
|
+
Coord4::operator [] (size_t index) const
|
165
|
+
{
|
166
|
+
return const_cast<Coord4*>(this)->operator[](index);
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
}// Rays
|
data/src/coord.h
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_SRC_COORD_H__
|
4
|
+
#define __RAYS_SRC_COORD_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <glm/vec2.hpp>
|
8
|
+
#include <glm/vec3.hpp>
|
9
|
+
#include <rays/coord.h>
|
10
|
+
|
11
|
+
|
12
|
+
namespace Rays
|
13
|
+
{
|
14
|
+
|
15
|
+
|
16
|
+
typedef glm::tvec3<coord, glm::defaultp> Vec3;
|
17
|
+
|
18
|
+
typedef glm::tvec4<coord, glm::defaultp> Vec4;
|
19
|
+
|
20
|
+
|
21
|
+
inline Vec3& to_glm ( Coord3& val) {return *( Vec3*) &val;}
|
22
|
+
|
23
|
+
inline const Vec3& to_glm (const Coord3& val) {return *(const Vec3*) &val;}
|
24
|
+
|
25
|
+
template <typename T>
|
26
|
+
inline T& to_rays ( Vec3& val) {return *( T*) &val;}
|
27
|
+
|
28
|
+
template <typename T>
|
29
|
+
inline const T& to_rays (const Vec3& val) {return *(const T*) &val;}
|
30
|
+
|
31
|
+
|
32
|
+
}// Rays
|
33
|
+
|
34
|
+
|
35
|
+
#endif//EOH
|
data/src/font.cpp
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
#include "font.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <assert.h>
|
5
|
+
|
6
|
+
|
7
|
+
namespace Rays
|
8
|
+
{
|
9
|
+
|
10
|
+
|
11
|
+
struct Font::Data
|
12
|
+
{
|
13
|
+
|
14
|
+
RawFont rawfont;
|
15
|
+
|
16
|
+
mutable RawFont rawfont_for_pixel_density;
|
17
|
+
|
18
|
+
mutable float for_pixel_density = 1;
|
19
|
+
|
20
|
+
const RawFont& get_raw (float pixel_density) const
|
21
|
+
{
|
22
|
+
assert(pixel_density > 0);
|
23
|
+
|
24
|
+
if (!rawfont || pixel_density == 1)
|
25
|
+
return rawfont;
|
26
|
+
|
27
|
+
if (pixel_density != for_pixel_density)
|
28
|
+
{
|
29
|
+
rawfont_for_pixel_density =
|
30
|
+
RawFont(rawfont.name(), rawfont.size() * pixel_density);
|
31
|
+
for_pixel_density = pixel_density;
|
32
|
+
}
|
33
|
+
|
34
|
+
return rawfont_for_pixel_density;
|
35
|
+
}
|
36
|
+
|
37
|
+
};// Font::Data
|
38
|
+
|
39
|
+
|
40
|
+
const Font&
|
41
|
+
default_font ()
|
42
|
+
{
|
43
|
+
static const Font FONT(NULL);
|
44
|
+
return FONT;
|
45
|
+
}
|
46
|
+
|
47
|
+
const RawFont&
|
48
|
+
Font_get_raw (const Font& font, float pixel_density)
|
49
|
+
{
|
50
|
+
return font.self->get_raw(pixel_density);
|
51
|
+
}
|
52
|
+
|
53
|
+
coord
|
54
|
+
Font_get_width (const Font& font, float pixel_density, const char* str)
|
55
|
+
{
|
56
|
+
return Font_get_raw(font, pixel_density).get_width(str);
|
57
|
+
}
|
58
|
+
|
59
|
+
coord
|
60
|
+
Font_get_height (
|
61
|
+
const Font& font, float pixel_density,
|
62
|
+
coord* ascent, coord* descent, coord* leading)
|
63
|
+
{
|
64
|
+
return Font_get_raw(font, pixel_density)
|
65
|
+
.get_height(ascent, descent, leading);
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
Font::Font ()
|
70
|
+
{
|
71
|
+
}
|
72
|
+
|
73
|
+
Font::Font (const char* name, coord size)
|
74
|
+
{
|
75
|
+
self->rawfont = RawFont(name, size);
|
76
|
+
}
|
77
|
+
|
78
|
+
Font::~Font ()
|
79
|
+
{
|
80
|
+
}
|
81
|
+
|
82
|
+
String
|
83
|
+
Font::name () const
|
84
|
+
{
|
85
|
+
return self->rawfont.name();
|
86
|
+
}
|
87
|
+
|
88
|
+
coord
|
89
|
+
Font::size () const
|
90
|
+
{
|
91
|
+
return self->rawfont.size();
|
92
|
+
}
|
93
|
+
|
94
|
+
coord
|
95
|
+
Font::get_width (const char* str) const
|
96
|
+
{
|
97
|
+
return self->rawfont.get_width(str);
|
98
|
+
}
|
99
|
+
|
100
|
+
coord
|
101
|
+
Font::get_height (coord* ascent, coord* descent, coord* leading) const
|
102
|
+
{
|
103
|
+
return self->rawfont.get_height(ascent, descent, leading);
|
104
|
+
}
|
105
|
+
|
106
|
+
Font::operator bool () const
|
107
|
+
{
|
108
|
+
return !!self->rawfont;
|
109
|
+
}
|
110
|
+
|
111
|
+
bool
|
112
|
+
Font::operator ! () const
|
113
|
+
{
|
114
|
+
return !operator bool();
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
}// Rays
|