allegro4r 0.0.1-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +59 -0
  3. data/README.txt +94 -0
  4. data/examples/exdbuf.rb +58 -0
  5. data/examples/exfixed.rb +46 -0
  6. data/examples/exflame.rb +200 -0
  7. data/examples/exflip.rb +87 -0
  8. data/examples/exfont.rb +70 -0
  9. data/examples/exhello.rb +46 -0
  10. data/examples/exjoy.rb +206 -0
  11. data/examples/exkeys.rb +216 -0
  12. data/examples/exmem.rb +50 -0
  13. data/examples/exmidi.rb +97 -0
  14. data/examples/exmouse.rb +149 -0
  15. data/examples/expal.rb +70 -0
  16. data/examples/expat.rb +62 -0
  17. data/examples/exsample.rb +89 -0
  18. data/examples/extimer.rb +84 -0
  19. data/examples/unifont.dat +0 -0
  20. data/ext/a4r_API_BITMAP.c +27 -0
  21. data/ext/a4r_API_DIGI_DRIVER.c +14 -0
  22. data/ext/a4r_API_GFX_DRIVER.c +14 -0
  23. data/ext/a4r_API_JOYSTICK_AXIS_INFO.c +53 -0
  24. data/ext/a4r_API_JOYSTICK_BUTTON_INFO.c +27 -0
  25. data/ext/a4r_API_JOYSTICK_DRIVER.c +14 -0
  26. data/ext/a4r_API_JOYSTICK_INFO.c +84 -0
  27. data/ext/a4r_API_JOYSTICK_STICK_INFO.c +62 -0
  28. data/ext/a4r_API_KEYBOARD_DRIVER.c +14 -0
  29. data/ext/a4r_API_MIDI_DRIVER.c +14 -0
  30. data/ext/a4r_API_MOUSE_DRIVER.c +14 -0
  31. data/ext/a4r_API_PALETTE.c +63 -0
  32. data/ext/a4r_API_RGB.c +118 -0
  33. data/ext/a4r_API_TIMER_DRIVER.c +14 -0
  34. data/ext/a4r_API_bitmap_objects.c +310 -0
  35. data/ext/a4r_API_blitting_and_sprites.c +86 -0
  36. data/ext/a4r_API_digital_sample_routines.c +83 -0
  37. data/ext/a4r_API_direct_access_to_video_memory.c +102 -0
  38. data/ext/a4r_API_drawing_primitives.c +114 -0
  39. data/ext/a4r_API_file_and_compression_routines.c +27 -0
  40. data/ext/a4r_API_fixed_point_math_routines.c +98 -0
  41. data/ext/a4r_API_fonts.c +147 -0
  42. data/ext/a4r_API_graphics_modes.c +155 -0
  43. data/ext/a4r_API_joystick_routines.c +213 -0
  44. data/ext/a4r_API_keyboard_routines.c +420 -0
  45. data/ext/a4r_API_misc.c +133 -0
  46. data/ext/a4r_API_mouse_routines.c +220 -0
  47. data/ext/a4r_API_music_routines_midi.c +147 -0
  48. data/ext/a4r_API_palette_routines.c +112 -0
  49. data/ext/a4r_API_sound_init_routines.c +29 -0
  50. data/ext/a4r_API_text_output.c +178 -0
  51. data/ext/a4r_API_timer_routines.c +250 -0
  52. data/ext/a4r_API_transparency_and_patterned_drawing.c +87 -0
  53. data/ext/a4r_API_truecolor_pixel_formats.c +44 -0
  54. data/ext/a4r_API_unicode_routines.c +53 -0
  55. data/ext/a4r_API_using_allegro.c +98 -0
  56. data/ext/allegro4r.c +866 -0
  57. data/ext/allegro4r.h +311 -0
  58. data/ext/allegro4r.so +0 -0
  59. data/ext/extconf.rb +11 -0
  60. metadata +113 -0
@@ -0,0 +1,83 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * load_sample(filename) -> a_sample
6
+ *
7
+ * Loads a sample from a file, supporting both mono and stereo WAV and mono VOC
8
+ * files, in 8 or 16-bit formats, as well as formats handled by functions
9
+ * registered using register_sample_file_type. Example:
10
+ * sample = load_sample(user_input)
11
+ * abort_on_error("Couldn't load sample!") if sample.nil?
12
+ *
13
+ * Return value: Returns a reference to the SAMPLE or nil on error. Remember to
14
+ * free this sample later to avoid memory leaks.
15
+ */
16
+ VALUE a4r_API_load_sample(VALUE self, VALUE filename)
17
+ {
18
+ SAMPLE *s = load_sample(StringValuePtr(filename));
19
+ if (s == NULL)
20
+ return Qnil;
21
+
22
+ VALUE obj = Data_Wrap_Struct(cAPI_SAMPLE, 0, 0, s);
23
+ return obj;
24
+ }
25
+
26
+ /*
27
+ * call-seq:
28
+ * destroy_sample(spl) -> nil
29
+ *
30
+ * Destroys a sample structure when you are done with it. It is safe to call
31
+ * this even when the sample might be playing, because it checks and will kill
32
+ * it off if it is active. Use this to avoid memory leaks in your program.
33
+ */
34
+ VALUE a4r_API_destroy_sample(VALUE self, VALUE spl)
35
+ {
36
+ SAMPLE *s;
37
+ Data_Get_Struct(spl, SAMPLE, s);
38
+ destroy_sample(s);
39
+ return Qnil;
40
+ }
41
+
42
+ /*
43
+ * call-seq:
44
+ * play_sample(spl, vol, pan, freq, loop) -> int
45
+ *
46
+ * Triggers a sample at the specified volume, pan position, and frequency. The
47
+ * parameters 'vol' and 'pan' range from 0 (min/left) to 255 (max/right).
48
+ * Frequency is relative rather than absolute: 1000 represents the frequency
49
+ * that the sample was recorded at, 2000 is twice this, etc. If 'loop' is true,
50
+ * the sample will repeat until you call stop_sample, and can be manipulated
51
+ * while it is playing by calling adjust_sample. Example:
52
+ * # Scream from the left speaker, twice the freq.
53
+ * sound = play_sample(scream, 255, 0, 2000, false)
54
+ *
55
+ * Return value: Returns the voice number that was allocated for the sample or
56
+ * negative if no voices were available.
57
+ */
58
+ VALUE a4r_API_play_sample(VALUE self, VALUE spl, VALUE vol, VALUE pan, VALUE freq, VALUE loop)
59
+ {
60
+ SAMPLE *s;
61
+ Data_Get_Struct(spl, SAMPLE, s);
62
+ return INT2FIX(play_sample(s, FIX2INT(vol), FIX2INT(pan), FIX2INT(freq), RTEST(loop)));
63
+ }
64
+
65
+ /*
66
+ * call-seq:
67
+ * adjust_sample(spl, vol, pan, freq, loop) -> nil
68
+ *
69
+ * Alters the parameters of a sample while it is playing (useful for
70
+ * manipulating looped sounds). You can alter the volume, pan, and frequency,
71
+ * and can also clear the loop flag, which will stop the sample when it next
72
+ * reaches the end of its loop. The values of the parameters are just like those
73
+ * of play_sample. If there are several copies of the same sample playing, this
74
+ * will adjust the first one it comes across. If the sample is not playing it
75
+ * has no effect.
76
+ */
77
+ VALUE a4r_API_adjust_sample(VALUE self, VALUE spl, VALUE vol, VALUE pan, VALUE freq, VALUE loop)
78
+ {
79
+ SAMPLE *s;
80
+ Data_Get_Struct(spl, SAMPLE, s);
81
+ adjust_sample(s, FIX2INT(vol), FIX2INT(pan), FIX2INT(freq), RTEST(loop));
82
+ return Qnil;
83
+ }
@@ -0,0 +1,102 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * bmp_select(bmp) -> nil
6
+ *
7
+ */
8
+ VALUE a4r_API_bmp_select(VALUE self, VALUE bmp)
9
+ {
10
+ BITMAP *bitmap;
11
+ Data_Get_Struct(bmp, BITMAP, bitmap);
12
+ bmp_select(bmp);
13
+ return Qnil;
14
+ }
15
+
16
+ /*
17
+ * call-seq:
18
+ * bmp_read8(addr) -> str
19
+ *
20
+ */
21
+ VALUE a4r_API_bmp_read8(VALUE self, VALUE addr)
22
+ {
23
+ return rb_str_new((char*)&(bmp_read8(NUM2ULONG(addr))), sizeof(uint8_t));
24
+ }
25
+
26
+ /*
27
+ * call-seq:
28
+ * bmp_read32(addr) -> str
29
+ *
30
+ */
31
+ VALUE a4r_API_bmp_read32(VALUE self, VALUE addr)
32
+ {
33
+ return rb_str_new((char*)&(bmp_read32(NUM2ULONG(addr))), sizeof(uint32_t));
34
+ }
35
+
36
+ /*
37
+ * call-seq:
38
+ * bmp_write8(addr, c) -> nil
39
+ *
40
+ */
41
+ VALUE a4r_API_bmp_write8(VALUE self, VALUE addr, VALUE c)
42
+ {
43
+ bmp_write8(NUM2ULONG(addr), *((uint8_t*)StringValuePtr(c)));
44
+ return Qnil;
45
+ }
46
+
47
+ /*
48
+ * call-seq:
49
+ * bmp_write32(addr, c) -> nil
50
+ *
51
+ */
52
+ VALUE a4r_API_bmp_write32(VALUE self, VALUE addr, VALUE c)
53
+ {
54
+ bmp_write32(NUM2ULONG(addr), *((uint32_t*)StringValuePtr(c)));
55
+ return Qnil;
56
+ }
57
+
58
+ /*
59
+ * call-seq:
60
+ * bmp_write_line(bmp, line) -> num
61
+ *
62
+ * Selects the line of a bitmap that you are going to draw onto.
63
+ *
64
+ * Return value: Returns the address of the selected line for writing.
65
+ */
66
+ VALUE a4r_API_bmp_write_line(VALUE self, VALUE bmp, VALUE line)
67
+ {
68
+ BITMAP *bitmap;
69
+ Data_Get_Struct(bmp, BITMAP, bitmap);
70
+ return ULONG2NUM(bmp_write_line(bitmap, FIX2INT(line)));
71
+ }
72
+
73
+ /*
74
+ * call-seq:
75
+ * bmp_read_line(bmp, line) -> num
76
+ *
77
+ * Selects the line of a bitmap that you are going to read from.
78
+ *
79
+ * Return value: Returns the address of the selected line for reading.
80
+ */
81
+ VALUE a4r_API_bmp_read_line(VALUE self, VALUE bmp, VALUE line)
82
+ {
83
+ BITMAP *bitmap;
84
+ Data_Get_Struct(bmp, BITMAP, bitmap);
85
+ return ULONG2NUM(bmp_read_line(bitmap, FIX2INT(line)));
86
+ }
87
+
88
+ /*
89
+ * call-seq:
90
+ * bmp_unwrite_line(bmp, line) -> nil
91
+ *
92
+ * Releases the bitmap memory after you are finished with it. You only need to
93
+ * call this once at the end of a drawing operation, even if you have called
94
+ * bmp_write_line or bmp_read_line several times before it.
95
+ */
96
+ VALUE a4r_API_bmp_unwrite_line(VALUE self, VALUE bmp)
97
+ {
98
+ BITMAP *bitmap;
99
+ Data_Get_Struct(bmp, BITMAP, bitmap);
100
+ bmp_unwrite_line(bitmap);
101
+ return Qnil;
102
+ }
@@ -0,0 +1,114 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * clear_bitmap(bitmap) -> nil
6
+ *
7
+ * Clears the bitmap to color 0.
8
+ */
9
+ VALUE a4r_API_clear_bitmap(VALUE self, VALUE bitmap)
10
+ {
11
+ BITMAP *bmp;
12
+ Data_Get_Struct(bitmap, BITMAP, bmp);
13
+ clear_bitmap(bmp);
14
+ return Qnil;
15
+ }
16
+
17
+ /*
18
+ * call-seq:
19
+ * clear_to_color(bitmap, color) -> nil
20
+ *
21
+ * Clears the bitmap to the specified color. Example:
22
+ * # Clear the screen to red.
23
+ * clear_to_color(bmp, makecol(255, 0, 0))
24
+ */
25
+ VALUE a4r_API_clear_to_color(VALUE self, VALUE bitmap, VALUE color)
26
+ {
27
+ BITMAP *bmp;
28
+ Data_Get_Struct(bitmap, BITMAP, bmp);
29
+ clear_to_color(bmp, FIX2INT(color));
30
+ return Qnil;
31
+ }
32
+
33
+ /*
34
+ * call-seq:
35
+ * putpixel(bmp, x, y, color) -> nil
36
+ *
37
+ * Writes a pixel to the specified position in the bitmap, using the current
38
+ * drawing mode and the bitmap's clipping rectangle. Example:
39
+ * putpixel(screen, 10, 30, some_color)
40
+ */
41
+ VALUE a4r_API_putpixel(VALUE self, VALUE bmp, VALUE x, VALUE y, VALUE color)
42
+ {
43
+ BITMAP *bitmap;
44
+ Data_Get_Struct(bmp, BITMAP, bitmap);
45
+ putpixel(bitmap, FIX2INT(x), FIX2INT(y), FIX2INT(color));
46
+ return Qnil;
47
+ }
48
+
49
+ /*
50
+ * call-seq:
51
+ * getpixel(bmp, x, y) -> int
52
+ *
53
+ * Reads a pixel from point (x, y) in the bitmap.
54
+ *
55
+ * Return value: Returns -1 if the point lies outside the bitmap (ignoring the
56
+ * clipping rectangle), otherwise the value of the pixel in the color format of
57
+ * the bitmap.
58
+ *
59
+ * Warning: -1 is also a valid value for pixels contained in 32-bit bitmaps with
60
+ * alpha channel (when R,G,B,A are all equal to 255) so you can't use the test
61
+ * against -1 as a predicate for such bitmaps. In this cases, the only reliable
62
+ * predicate is is_inside_bitmap.
63
+ *
64
+ * To extract the individual color components, use the getr / getg / getb /
65
+ * geta family of functions.
66
+ */
67
+ VALUE a4r_API_getpixel(VALUE self, VALUE bmp, VALUE x, VALUE y)
68
+ {
69
+ BITMAP *bitmap;
70
+ Data_Get_Struct(bmp, BITMAP, bitmap);
71
+ return INT2FIX(getpixel(bitmap, FIX2INT(x), FIX2INT(y)));
72
+ }
73
+
74
+ /*
75
+ * call-seq:
76
+ * rectfill(bmp, x1, y1, x2, y2, color) -> nil
77
+ *
78
+ * Draws a solid, filled rectangle with the two points as its opposite corners.
79
+ */
80
+ VALUE a4r_API_rectfill(VALUE self, VALUE bmp, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE color)
81
+ {
82
+ BITMAP *bitmap;
83
+ Data_Get_Struct(bmp, BITMAP, bitmap);
84
+ rectfill(bitmap, FIX2INT(x1), FIX2INT(y1), FIX2INT(x2), FIX2INT(y2), FIX2INT(color));
85
+ return Qnil;
86
+ }
87
+
88
+ /*
89
+ * call-seq:
90
+ * circle(bmp, x, y, radius, color) -> nil
91
+ *
92
+ * Draws a circle with the specified centre and radius.
93
+ */
94
+ VALUE a4r_API_circle(VALUE self, VALUE bmp, VALUE x, VALUE y, VALUE radius, VALUE color)
95
+ {
96
+ BITMAP *bitmap;
97
+ Data_Get_Struct(bmp, BITMAP, bitmap);
98
+ circle(bitmap, FIX2INT(x), FIX2INT(y), FIX2INT(radius), FIX2INT(color));
99
+ return Qnil;
100
+ }
101
+
102
+ /*
103
+ * call-seq:
104
+ * circlefill(bmp, x, y, radius, color) -> nil
105
+ *
106
+ * Draws a filled circle with the specified centre and radius.
107
+ */
108
+ VALUE a4r_API_circlefill(VALUE self, VALUE bmp, VALUE x, VALUE y, VALUE radius, VALUE color)
109
+ {
110
+ BITMAP *bitmap;
111
+ Data_Get_Struct(bmp, BITMAP, bitmap);
112
+ circlefill(bitmap, FIX2INT(x), FIX2INT(y), FIX2INT(radius), FIX2INT(color));
113
+ return Qnil;
114
+ }
@@ -0,0 +1,27 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * get_filename(path) -> str
6
+ *
7
+ * Finds out the filename portion of a completely specified file path. Both '\'
8
+ * and '/' are recognized as directory separators under DOS and Windows.
9
+ * However, only '/' is recognized as directory separator under other platforms.
10
+ * Example:
11
+ * name = get_executable_name
12
+ * allegro_message("Running '%s'\n" % get_filename(name))
13
+ *
14
+ * Note that Allegro won't perform any IO operations during the verification.
15
+ * This means that if you have '/a/path/like/this/', which doesn't have a
16
+ * filename, the function will return an empty string. However, if you have
17
+ * '/a/path/like/this', Allegro will return 'this', even if it is a valid
18
+ * directory.
19
+ *
20
+ * Return value: Returns a string with the filename, or the beginning of 'path'
21
+ * if no valid filename is found (eg. you are processing a path with backslashes
22
+ * under Unix).
23
+ */
24
+ VALUE a4r_API_get_filename(VALUE self, VALUE path)
25
+ {
26
+ return rb_str_new2(get_filename(StringValuePtr(path)));
27
+ }
@@ -0,0 +1,98 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * itofix(x) -> num
6
+ *
7
+ * Converts an integer to fixed point. This is the same thing as x<<16. Remember
8
+ * that overflows (trying to convert an integer greater than 32767) and
9
+ * underflows (trying to convert an integer lesser than -32768) are not detected
10
+ * even in debug builds! The values simply "wrap around". Example:
11
+ * # This conversion is OK.
12
+ * number = itofix(100)
13
+ * ASSERT(fixtoi(number) == 100)
14
+ * number = itofix(64000)
15
+ * # This check will fail in debug builds.
16
+ * ASSERT(fixtoi(number) == 64000)
17
+ *
18
+ * Return value: Returns the value of the integer converted to fixed point
19
+ * ignoring overflows.
20
+ */
21
+ VALUE a4r_API_itofix(VALUE self, VALUE x)
22
+ {
23
+ return LONG2NUM(itofix(FIX2INT(x)));
24
+ }
25
+
26
+ /*
27
+ * call-seq:
28
+ * ftofix(x) -> num
29
+ *
30
+ * Converts a floating point value to fixed point. Unlike itofix, this function
31
+ * clamps values which could overflow the type conversion, setting 'errno' to
32
+ * ERANGE in the process if this happens. Example:
33
+ * number = itofix(-40000)
34
+ * ASSERT(fixfloor(number) == -32768)
35
+ * number = itofix(64000)
36
+ * ASSERT(fixfloor(number) == 32767)
37
+ * ASSERT(errno == 0) # This will fail.
38
+ *
39
+ * Return value: Returns the value of the floating point value converted to
40
+ * fixed point clamping overflows (and setting 'errno').
41
+ */
42
+ VALUE a4r_API_ftofix(VALUE self, VALUE x)
43
+ {
44
+ return LONG2NUM(ftofix(NUM2DBL(x)));
45
+ }
46
+
47
+ /*
48
+ * call-seq:
49
+ * fixtof(x) -> float
50
+ *
51
+ * Converts fixed point to floating point. Example:
52
+ * # This will put 33.33333 into 'result'.
53
+ * result = fixtof(itofix(100) / 3)
54
+ * # This will put 16.66666 into 'result'.
55
+ * result = fixtof(itofix(100) / 6)
56
+ */
57
+ VALUE a4r_API_fixtof(VALUE self, VALUE x)
58
+ {
59
+ return rb_float_new(fixtof(NUM2LONG(x)));
60
+ }
61
+
62
+ /*
63
+ * call-seq:
64
+ * fixmul(x, y) -> float
65
+ *
66
+ * A fixed point value can be multiplied or divided by an integer with the
67
+ * normal '*' and '/' operators. To multiply two fixed point values, though, you
68
+ * must use this function.
69
+ *
70
+ * If an overflow occurs, 'errno' will be set and the maximum possible value
71
+ * will be returned, but 'errno' is not cleared if the operation is successful.
72
+ * This means that if you are going to test for overflow you should set
73
+ * 'errno=0' before calling fixmul. Example
74
+ * # This will put 30000 into 'result'.
75
+ * result = fixmul(itofix(10), itofix(3000))
76
+ * # But this overflows, and sets 'errno'.
77
+ * result = fixmul(itofix(100), itofix(3000))
78
+ * ASSERT(errno == 0)
79
+ *
80
+ * Return value: Returns the clamped result of multiplying 'x' by 'y', setting
81
+ * 'errno' to ERANGE if there was an overflow.
82
+ */
83
+ VALUE a4r_API_fixmul(VALUE self, VALUE x, VALUE y)
84
+ {
85
+ return rb_float_new(fixmul(NUM2LONG(x), NUM2LONG(y)));
86
+ }
87
+
88
+ /*
89
+ * call-seq:
90
+ * fixsqrt(x) -> float
91
+ *
92
+ * This finds out the non negative square root of 'x'. If 'x' is negative,
93
+ * 'errno' is set to EDOM and the function returns zero.
94
+ */
95
+ VALUE a4r_API_fixsqrt(VALUE self, VALUE x)
96
+ {
97
+ return rb_float_new(fixsqrt(NUM2LONG(x)));
98
+ }
@@ -0,0 +1,147 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * load_font(filename, pal, param) -> a_fnt or nil
6
+ *
7
+ * Loads a font from a file. At present, this supports loading fonts from a GRX
8
+ * format .fnt file, a 8x8 or 8x16 BIOS format .fnt file, a datafile or any
9
+ * bitmap format that can be loaded by load_bitmap.
10
+ *
11
+ * If the font contains palette information, then the palette is returned in the
12
+ * second parameter, which should be an array of 256 RGB structures (a PALETTE).
13
+ * The pal argument may be nil. In this case, the palette data, if present, is
14
+ * simply not returned.
15
+ *
16
+ * The third parameter can be used to pass specific information to a custom
17
+ * loader routine. Normally, you can just leave this as nil. Note that another
18
+ * way of loading fonts is embedding them into a datafile and using the datafile
19
+ * related functions.
20
+ *
21
+ * Example:
22
+ * myfont = load_font("my_font.pcx", palette, nil)
23
+ * abort_on_error("Couldn't load font!") if myfont.nil?
24
+ * ...
25
+ * textout_centre_ex(screen, myfont, "This is my own pretty font!",
26
+ * SCREEN_W / 2, SCREEN_H / 2, white, black)
27
+ * ...
28
+ * destroy_font(myfont)
29
+ *
30
+ * Returns a reference to the font or nil on error. Remember that you are
31
+ * responsible for destroying the font when you are finished with it to avoid
32
+ * memory leaks.
33
+ */
34
+ VALUE a4r_API_load_font(VALUE self, VALUE filename, VALUE pal, VALUE param)
35
+ {
36
+ PALETTE *palette;
37
+ RGB *rgb;
38
+ if (pal == Qnil)
39
+ rgb = NULL;
40
+ else
41
+ {
42
+ Data_Get_Struct(pal, PALETTE, palette);
43
+ rgb = *palette;
44
+ }
45
+
46
+ void *p;
47
+ if (param == Qnil)
48
+ p = NULL;
49
+ else
50
+ p = StringValuePtr(param);
51
+
52
+ FONT *font = load_font(StringValuePtr(filename), rgb, p);
53
+ if (font == NULL)
54
+ return Qnil;
55
+
56
+ VALUE obj = Data_Wrap_Struct(cAPI_FONT, 0, 0, font);
57
+ return obj;
58
+ }
59
+
60
+ /*
61
+ * call-seq:
62
+ * destroy_font(f) -> nil
63
+ *
64
+ * Frees the memory being used by a font structure. Don't use this on the
65
+ * default global Allegro font or any text routines using it could crash. You
66
+ * should use this only on fonts you have loaded manually after you are done
67
+ * with them, to prevent memory leaks in your program.
68
+ */
69
+ VALUE a4r_API_destroy_font(VALUE self, VALUE f)
70
+ {
71
+ FONT *font;
72
+ Data_Get_Struct(f, FONT, font);
73
+ destroy_font(font);
74
+ return Qnil;
75
+ }
76
+
77
+ /*
78
+ * call-seq:
79
+ * extract_font_range(f, begin, end) -> a_fnt or nil
80
+ *
81
+ * This function extracts a character range from a font and returns a new font
82
+ * that contains only the range of characters selected by this function. You can
83
+ * pass -1 for either the lower or upper bound if you want to select all
84
+ * characters from the start or to the end of the font. Example:
85
+ * # Create a font of only capital letters
86
+ * capitals = extract_font_range(myfont, ?A, ?Z)
87
+ *
88
+ * # Create a copy of the font
89
+ * fontcopy = extract_font_range(myfont, -1, -1)
90
+ * ...
91
+ * destroy_font(capitals)
92
+ * destroy_font(fontcopy)
93
+ *
94
+ * Returns a reference to the new font or nil on error. Remember that you are
95
+ * responsible for destroying the font when you are finished with it to avoid
96
+ * memory leaks.
97
+ */
98
+ VALUE a4r_API_extract_font_range(VALUE self, VALUE f, VALUE begin, VALUE end)
99
+ {
100
+ FONT *from, *to;
101
+ Data_Get_Struct(f, FONT, from);
102
+ to = extract_font_range(from, FIX2INT(begin), FIX2INT(end));
103
+ if (to == NULL)
104
+ return Qnil;
105
+ VALUE obj = Data_Wrap_Struct(cAPI_FONT, 0, 0, to);
106
+ return obj;
107
+ }
108
+
109
+ /*
110
+ * call-seq:
111
+ * merge_fonts(f1, f2) -> a_fnt or nil
112
+ *
113
+ * This function merges the character ranges from two fonts and returns a new
114
+ * font containing all characters in the old fonts. In general, you cannot merge
115
+ * fonts of different types (eg, TrueType fonts and bitmapped fonts), but as a
116
+ * special case, this function can promote a monochrome bitmapped font to a
117
+ * color font and merge those. Example:
118
+ * # Create a font that contains the capatials from
119
+ * # the fancy font but other characters from myfont
120
+ * lower_range = extract_font_range(myfont, -1, ?A - 1)
121
+ * upper_range = extract_font_range(myfont, ?Z + 1, -1)
122
+ * capitals = extract_font_range(myfancy_font, ?A, ?Z)
123
+ *
124
+ * tempfont = merge_fonts(lower_range, capitals)
125
+ * combined_font = merge_fonts(tempfont, upper_range);
126
+ *
127
+ * # Clean up temporary fonts
128
+ * destroy_font(lower_range)
129
+ * destroy_font(upper_range)
130
+ * destroy_font(capitals)
131
+ * destroy_font(tempfont)
132
+ *
133
+ * Returns a reference to the new font or nil on error. Remember that you are
134
+ * responsible for destroying the font when you are finished with it to avoid
135
+ * memory leaks.
136
+ */
137
+ VALUE a4r_API_merge_fonts(VALUE self, VALUE f1, VALUE f2)
138
+ {
139
+ FONT *font1, *font2, *ret;
140
+ Data_Get_Struct(f1, FONT, font1);
141
+ Data_Get_Struct(f2, FONT, font2);
142
+ ret = merge_fonts(font1, font2);
143
+ if (ret == NULL)
144
+ return Qnil;
145
+ VALUE obj = Data_Wrap_Struct(cAPI_FONT, 0, 0, ret);
146
+ return obj;
147
+ }