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/native/cocoa.m: read the family names from the font file.
why (author)
Sun Oct 05 23:55:17 -0700 2008
commit  26ea246df394d9689806bc3a50713b3790416db9
tree    f685269c24d471310b3790d652c2c41fbf60860c
parent  e685aabb283258e6f47a9b88cd273680c70a59e5
...
493
494
495
 
 
 
496
497
498
499
500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
502
503
504
505
506
 
507
508
509
...
493
494
495
496
497
498
499
500
501
502
 
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
 
 
 
 
529
530
531
532
0
@@ -493,17 +493,40 @@ shoes_load_font(const char *filename)
0
   FSRef fsRef;
0
   FSSpec fsSpec;
0
   Boolean isDir;
0
+ VALUE families = Qnil;
0
+ ATSFontContainerRef ref;
0
+ NSString *fontName;
0
   FSPathMakeRef(filename, &fsRef, &isDir);
0
   if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL) == noErr)
0
   {
0
     ATSFontActivateFromFileSpecification(&fsSpec, kATSFontContextLocal, kATSFontFormatUnspecified,
0
- NULL, kATSOptionFlagsDefault, NULL);
0
+ NULL, kATSOptionFlagsDefault, &ref);
0
+ if (ref != NULL)
0
+ {
0
+ int i = 0;
0
+ ItemCount count = 0;
0
+ ATSFontRef *fonts;
0
+ ATSFontFindFromContainer(ref, kATSOptionFlagsDefault, 0, NULL, &count);
0
+ families = rb_ary_new();
0
+ if (count > 0)
0
+ {
0
+ fonts = SHOE_ALLOC_N(ATSFontRef, count);
0
+ ATSFontFindFromContainer(ref, kATSOptionFlagsDefault, count, fonts, &count);
0
+ for (i = 0; i < count; i++)
0
+ {
0
+ fontName = NULL;
0
+ ATSFontGetName(fonts[i], kATSOptionFlagsDefault, &fontName);
0
+ if (fontName != NULL)
0
+ {
0
+ rb_ary_push(families, rb_str_new2([fontName UTF8String]));
0
+ }
0
+ }
0
+ SHOE_FREE(fonts);
0
+ }
0
+ }
0
   }
0
 
0
- // ATSFontContainerRef o;
0
- // if (ATSFontActivateFromFileReference(file, kATSFontContextLocal, kATSFontFormatUnspecified,
0
- // NULL, kATSOptionFlagsDefault, &o) != noErr) return Qnil;
0
- return rb_ary_new();
0
+ return families;
0
 }
0
 
0
 void shoes_native_init()

Comments

    No one has commented yet.