GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
 * shoes/ruby.c: adding `font` method for loading external fonts into the 
 shoes app (uses native APIs: fontconfig, win32, ATSUI.)
why (author)
Sun Oct 05 22:58:36 -0700 2008
commit  7af37aa35d15f47c5ce3bb5ff4f09e2870666db5
tree    4bba034ed90bc5193d890f44598e1b8422f1764c
parent  48432feca63f305f32cd26f4e2710ab6023effc0
...
17
18
19
 
20
21
22
...
17
18
19
20
21
22
23
0
@@ -17,6 +17,7 @@
0
 #define SHOES_IMAGE_DOWNLOAD 42
0
 #define SHOES_MAX_MESSAGE 100
0
 
0
+VALUE shoes_load_font(const char *);
0
 void shoes_native_init();
0
 void shoes_native_cleanup(shoes_world_t *world);
0
 void shoes_native_quit();
...
487
488
489
 
 
 
 
 
 
 
 
 
490
491
492
...
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
0
@@ -487,6 +487,15 @@ create_help_menu(NSMenu *main)
0
     [menuHelp release];
0
 }
0
 
0
+int
0
+shoes_load_font(const char *filename)
0
+{
0
+ ATSFontContainerRef o;
0
+ if (ATSFontActivateFromFileReference(file, kATSFontContextLocal, kATSFontFormatUnspecified,
0
+ NULL, kATSOptionFlagsDefault, &o) != noErr) return Qnil;
0
+ return rb_ary_new();
0
+}
0
+
0
 void shoes_native_init()
0
 {
0
   INIT;
...
9
10
11
 
12
13
14
...
19
20
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
23
24
...
9
10
11
12
13
14
15
...
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
0
@@ -9,6 +9,7 @@
0
 #include "shoes/native.h"
0
 #include "shoes/internal.h"
0
 
0
+#include <fontconfig/fontconfig.h>
0
 #include <curl/curl.h>
0
 
0
 #define GTK_CHILD(child, ptr) \
0
@@ -19,6 +20,30 @@
0
 
0
 #define SHOES_GTK_INVISIBLE_CHAR (gunichar)0x2022
0
 
0
+VALUE
0
+shoes_load_font(const char *filename)
0
+{
0
+ int i = 0;
0
+ VALUE ary = rb_ary_new();
0
+ FcConfig *fc = FcConfigGetCurrent();
0
+ FcFontSet *fonts = FcFontSetCreate();
0
+ if (!FcFileScan(fonts, NULL, NULL, NULL, filename, FcTrue))
0
+ return Qnil;
0
+ for (i = 0; i < fonts->nfont; i++)
0
+ {
0
+ FcValue val;
0
+ FcPattern *p = fonts->fonts[i];
0
+ if (FcPatternGet(p, FC_FAMILY, 0, &val) == FcResultMatch)
0
+ rb_ary_push(ary, rb_str_new2(val.u.s));
0
+ }
0
+ FcFontSetDestroy(fonts);
0
+
0
+ if (!FcConfigAppFontAddFile(fc, filename))
0
+ return Qnil;
0
+
0
+ return rb_funcall(ary, rb_intern("uniq"), 0);
0
+}
0
+
0
 void shoes_native_init()
0
 {
0
   curl_global_init(CURL_GLOBAL_ALL);
...
54
55
56
 
 
 
 
 
 
 
 
57
58
59
...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
0
@@ -54,6 +54,14 @@ shoes_win32_cmdvector(const char *cmdline, char ***argv)
0
   return rb_w32_cmdvector(cmdline, argv);
0
 }
0
 
0
+int
0
+shoes_load_font(const char *filename)
0
+{
0
+ int fonts = AddFontResourceEx(filename, FR_PRIVATE, 0);
0
+ if (!fonts) return Qnil;
0
+ return rb_ary_new();
0
+}
0
+
0
 void shoes_native_init()
0
 {
0
   INITCOMMONCONTROLSEX InitCtrlEx;
...
4002
4003
4004
 
 
 
 
 
 
 
4005
4006
4007
...
4731
4732
4733
 
4734
...
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
...
4738
4739
4740
4741
4742
0
@@ -4002,6 +4002,13 @@ shoes_log(VALUE self)
0
   return shoes_world->msgs;
0
 }
0
 
0
+VALUE
0
+shoes_font(VALUE self, VALUE path)
0
+{
0
+ StringValue(path);
0
+ return shoes_load_font(RSTRING_PTR(path));
0
+}
0
+
0
 //
0
 // Defines a redirecting function which applies the element or transformation
0
 // to the currently active canvas. This is used in place of the old instance_eval
0
@@ -4731,4 +4738,5 @@ shoes_ruby_init()
0
   rb_define_method(rb_mKernel, "ask_open_folder", CASTHOOK(shoes_dialog_open_folder), 0);
0
   rb_define_method(rb_mKernel, "ask_save_folder", CASTHOOK(shoes_dialog_save_folder), 0);
0
   rb_define_method(rb_mKernel, "download_and_wait", CASTHOOK(shoes_download_non_threaded), 1);
0
+ rb_define_method(rb_mKernel, "font", CASTHOOK(shoes_font), 1);
0
 }

Comments

    No one has commented yet.