Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/native/sun/font/AWTFont.m
38829 views
1
/*
2
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#ifdef MACOSX_NOTIOS // prevent merge conflicts
27
#import <JavaNativeFoundation/JavaNativeFoundation.h>
28
29
#import "java_awt_Font.h"
30
#import "sun_awt_PlatformFont.h"
31
#import "sun_awt_FontDescriptor.h"
32
#import "sun_font_CFont.h"
33
#import "sun_font_CFontManager.h"
34
35
#import "AWTFont.h"
36
#import "AWTStrike.h"
37
#import "CoreTextSupport.h"
38
39
@implementation AWTFont
40
41
- (id) initWithFont:(NSFont *)font {
42
self = [super init];
43
if (self) {
44
fFont = [font retain];
45
fNativeCGFont = CTFontCopyGraphicsFont((CTFontRef)font, NULL);
46
layoutTableCache = NULL;
47
}
48
return self;
49
}
50
51
static TTLayoutTableCache* newCFontLayoutTableCache() {
52
TTLayoutTableCache* ltc = calloc(1, sizeof(TTLayoutTableCache));
53
if (ltc) {
54
int i;
55
for(i=0;i<LAYOUTCACHE_ENTRIES;i++) {
56
ltc->entries[i].len = -1;
57
}
58
}
59
return ltc;
60
}
61
62
static void freeCFontLayoutTableCache(TTLayoutTableCache* ltc) {
63
if (ltc) {
64
int i;
65
for(i=0;i<LAYOUTCACHE_ENTRIES;i++) {
66
if(ltc->entries[i].ptr) free (ltc->entries[i].ptr);
67
}
68
if (ltc->kernPairs) free(ltc->kernPairs);
69
free(ltc);
70
}
71
}
72
73
- (void) dealloc {
74
[fFont release];
75
fFont = nil;
76
77
if (fNativeCGFont) {
78
CGFontRelease(fNativeCGFont);
79
fNativeCGFont = NULL;
80
if (layoutTableCache != NULL) {
81
freeCFontLayoutTableCache(layoutTableCache);
82
layoutTableCache = NULL;
83
}
84
}
85
86
[super dealloc];
87
}
88
89
- (void) finalize {
90
if (fNativeCGFont) {
91
CGFontRelease(fNativeCGFont);
92
fNativeCGFont = NULL;
93
}
94
if (layoutTableCache != NULL) {
95
freeCFontLayoutTableCache(layoutTableCache);
96
layoutTableCache = NULL;
97
}
98
[super finalize];
99
}
100
101
static NSString* uiName = nil;
102
static NSString* uiBoldName = nil;
103
104
+ (AWTFont *) awtFontForName:(NSString *)name
105
style:(int)style
106
{
107
// create font with family & size
108
NSFont *nsFont = nil;
109
110
if ((uiName != nil && [name isEqualTo:uiName]) ||
111
(uiBoldName != nil && [name isEqualTo:uiBoldName])) {
112
if (style & java_awt_Font_BOLD) {
113
nsFont = [NSFont boldSystemFontOfSize:1.0];
114
} else {
115
nsFont = [NSFont systemFontOfSize:1.0];
116
}
117
#ifdef DEBUG
118
NSLog(@"nsFont-name is : %@", nsFont.familyName);
119
NSLog(@"nsFont-family is : %@", nsFont.fontName);
120
NSLog(@"nsFont-desc-name is : %@", nsFont.fontDescriptor.postscriptName);
121
#endif
122
123
124
} else {
125
nsFont = [NSFont fontWithName:name size:1.0];
126
}
127
128
if (nsFont == nil) {
129
// if can't get font of that name, substitute system default font
130
nsFont = [NSFont fontWithName:@"Lucida Grande" size:1.0];
131
#ifdef DEBUG
132
NSLog(@"needed to substitute Lucida Grande for: %@", name);
133
#endif
134
}
135
136
// create an italic style (if one is installed)
137
if (style & java_awt_Font_ITALIC) {
138
nsFont = [[NSFontManager sharedFontManager] convertFont:nsFont toHaveTrait:NSItalicFontMask];
139
}
140
141
// create a bold style (if one is installed)
142
if (style & java_awt_Font_BOLD) {
143
nsFont = [[NSFontManager sharedFontManager] convertFont:nsFont toHaveTrait:NSBoldFontMask];
144
}
145
146
return [[[AWTFont alloc] initWithFont:nsFont] autorelease];
147
}
148
149
+ (NSFont *) nsFontForJavaFont:(jobject)javaFont env:(JNIEnv *)env {
150
if (javaFont == NULL) {
151
#ifdef DEBUG
152
NSLog(@"nil font");
153
#endif
154
return nil;
155
}
156
157
static JNF_CLASS_CACHE(jc_Font, "java/awt/Font");
158
159
// obtain the Font2D
160
static JNF_MEMBER_CACHE(jm_Font_getFont2D, jc_Font, "getFont2D", "()Lsun/font/Font2D;");
161
jobject font2d = JNFCallObjectMethod(env, javaFont, jm_Font_getFont2D);
162
if (font2d == NULL) {
163
#ifdef DEBUG
164
NSLog(@"nil font2d");
165
#endif
166
return nil;
167
}
168
169
// if it's not a CFont, it's likely one of TTF or OTF fonts
170
// from the Sun rendering loops
171
static JNF_CLASS_CACHE(jc_CFont, "sun/font/CFont");
172
if (!JNFIsInstanceOf(env, font2d, &jc_CFont)) {
173
#ifdef DEBUG
174
NSLog(@"font2d !instanceof CFont");
175
#endif
176
return nil;
177
}
178
179
static JNF_MEMBER_CACHE(jm_CFont_getFontStrike, jc_CFont, "getStrike", "(Ljava/awt/Font;)Lsun/font/FontStrike;");
180
jobject fontStrike = JNFCallObjectMethod(env, font2d, jm_CFont_getFontStrike, javaFont);
181
182
static JNF_CLASS_CACHE(jc_CStrike, "sun/font/CStrike");
183
if (!JNFIsInstanceOf(env, fontStrike, &jc_CStrike)) {
184
#ifdef DEBUG
185
NSLog(@"fontStrike !instanceof CStrike");
186
#endif
187
return nil;
188
}
189
190
static JNF_MEMBER_CACHE(jm_CStrike_nativeStrikePtr, jc_CStrike, "getNativeStrikePtr", "()J");
191
jlong awtStrikePtr = JNFCallLongMethod(env, fontStrike, jm_CStrike_nativeStrikePtr);
192
if (awtStrikePtr == 0L) {
193
#ifdef DEBUG
194
NSLog(@"nil nativeFontPtr from CFont");
195
#endif
196
return nil;
197
}
198
199
AWTStrike *strike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
200
201
return [NSFont fontWithName:[strike->fAWTFont->fFont fontName] matrix:(CGFloat *)(&(strike->fAltTx))];
202
}
203
204
@end
205
206
207
#pragma mark --- Font Discovery and Loading ---
208
209
static NSArray* sFilteredFonts = nil;
210
static NSDictionary* sFontFamilyTable = nil;
211
212
static NSString*
213
GetFamilyNameForFontName(NSString* fontname)
214
{
215
return [sFontFamilyTable objectForKey:fontname];
216
}
217
218
static void addFont(CTFontUIFontType uiType,
219
NSMutableArray *allFonts,
220
NSMutableDictionary* fontFamilyTable) {
221
222
CTFontRef font = CTFontCreateUIFontForLanguage(uiType, 0.0, NULL);
223
if (font == NULL) {
224
return;
225
}
226
CTFontDescriptorRef desc = CTFontCopyFontDescriptor(font);
227
if (desc == NULL) {
228
CFRelease(font);
229
return;
230
}
231
CFStringRef family = CTFontDescriptorCopyAttribute(desc, kCTFontFamilyNameAttribute);
232
if (family == NULL) {
233
CFRelease(desc);
234
CFRelease(font);
235
return;
236
}
237
CFStringRef name = CTFontDescriptorCopyAttribute(desc, kCTFontNameAttribute);
238
if (name == NULL) {
239
CFRelease(family);
240
CFRelease(desc);
241
CFRelease(font);
242
return;
243
}
244
if (uiType == kCTFontUIFontSystem) {
245
uiName = (NSString*)name;
246
}
247
if (uiType == kCTFontUIFontEmphasizedSystem) {
248
uiBoldName = (NSString*)name;
249
}
250
[allFonts addObject:name];
251
[fontFamilyTable setObject:family forKey:name];
252
#ifdef DEBUG
253
NSLog(@"name is : %@", (NSString*)name);
254
NSLog(@"family is : %@", (NSString*)family);
255
#endif
256
CFRelease(family);
257
CFRelease(name);
258
CFRelease(desc);
259
CFRelease(font);
260
}
261
262
static NSArray*
263
GetFilteredFonts()
264
{
265
if (sFilteredFonts == nil) {
266
NSFontManager *fontManager = [NSFontManager sharedFontManager];
267
NSUInteger fontCount = [[fontManager availableFonts] count];
268
269
NSMutableArray *allFonts = [[NSMutableArray alloc] initWithCapacity:fontCount];
270
NSMutableDictionary* fontFamilyTable = [[NSMutableDictionary alloc] initWithCapacity:fontCount];
271
NSArray *allFamilies = [fontManager availableFontFamilies];
272
273
NSUInteger familyCount = [allFamilies count];
274
275
NSUInteger familyIndex;
276
for (familyIndex = 0; familyIndex < familyCount; familyIndex++) {
277
NSString *family = [allFamilies objectAtIndex:familyIndex];
278
279
if ((family == nil) || [family characterAtIndex:0] == '.') {
280
continue;
281
}
282
283
NSArray *fontFaces = [fontManager availableMembersOfFontFamily:family];
284
NSUInteger faceCount = [fontFaces count];
285
286
NSUInteger faceIndex;
287
for (faceIndex = 0; faceIndex < faceCount; faceIndex++) {
288
NSString* face = [[fontFaces objectAtIndex:faceIndex] objectAtIndex:0];
289
if (face != nil) {
290
[allFonts addObject:face];
291
[fontFamilyTable setObject:family forKey:face];
292
}
293
}
294
}
295
296
/*
297
* JavaFX registers these fonts and so JDK needs to do so as well.
298
* If this isn't done we will have mis-matched rendering, since
299
* although these may include fonts that are enumerated normally
300
* they also demonstrably includes fonts that are not.
301
*/
302
addFont(kCTFontUIFontSystem, allFonts, fontFamilyTable);
303
addFont(kCTFontUIFontEmphasizedSystem, allFonts, fontFamilyTable);
304
305
sFilteredFonts = allFonts;
306
sFontFamilyTable = fontFamilyTable;
307
}
308
309
return sFilteredFonts;
310
}
311
312
#pragma mark --- sun.font.CFontManager JNI ---
313
314
static OSStatus CreateFSRef(FSRef *myFSRefPtr, NSString *inPath)
315
{
316
return FSPathMakeRef((UInt8 *)[inPath fileSystemRepresentation],
317
myFSRefPtr, NULL);
318
}
319
320
// /*
321
// * Class: sun_font_CFontManager
322
// * Method: loadFileFont
323
// * Signature: (Ljava/lang/String;)Lsun/font/Font2D;
324
// */
325
// JNIEXPORT /* sun.font.CFont */ jobject JNICALL
326
// Java_sun_font_CFontManager_loadFileFont
327
// (JNIEnv *env, jclass obj, jstring fontpath)
328
// {
329
// jobject result = NULL;
330
//
331
// JNF_COCOA_ENTER(env);
332
//
333
// NSString *nsFilePath = JNFJavaToNSString(env, fontpath);
334
// jstring javaFontName = NULL;
335
//
336
// //
337
// // Note: This API uses ATS and can therefore return Carbon error codes.
338
// // These codes can be found at:
339
// // http://developer.apple.com/techpubs/macosx/Carbon/Files/FileManager/File_Manager/ResultCodes/ResultCodes.html
340
// //
341
//
342
// FSRef iFile;
343
// OSStatus status = CreateFSRef(&iFile, nsFilePath);
344
//
345
// if (status == noErr) {
346
// ATSFontContainerRef oContainer;
347
// status = ATSFontActivateFromFileReference(&iFile, kATSFontContextLocal,
348
// kATSFontFormatUnspecified,
349
// NULL,
350
// kATSOptionFlagsUseDataFork,
351
// &oContainer);
352
// if (status == noErr) {
353
// ATSFontRef ioArray[1];
354
// ItemCount oCount;
355
// status = ATSFontFindFromContainer(oContainer,
356
// kATSOptionFlagsUseDataFork,
357
// 1, ioArray, &oCount);
358
//
359
// if (status == noErr) {
360
// CFStringRef oName;
361
// status = ATSFontGetPostScriptName(ioArray[0],
362
// kATSOptionFlagsUseDataFork,
363
// &oName);
364
// if (status == noErr) {
365
// javaFontName = JNFNSToJavaString(env, (NSString *)oName);
366
// CFRelease(oName);
367
// }
368
// }
369
// }
370
// }
371
//
372
// if (javaFontName != NULL) {
373
// // create the CFont!
374
// static JNF_CLASS_CACHE(sjc_CFont, "sun/font/CFont");
375
// static JNF_CTOR_CACHE(sjf_CFont_ctor,
376
// sjc_CFont, "(Ljava/lang/String;)V");
377
// result = JNFNewObject(env, sjf_CFont_ctor, javaFontName);
378
// }
379
//
380
// JNF_COCOA_EXIT(env);
381
//
382
// return result;
383
// }
384
385
/*
386
* Class: sun_font_CFontManager
387
* Method: loadNativeFonts
388
* Signature: ()V
389
*/
390
JNIEXPORT void JNICALL
391
Java_sun_font_CFontManager_loadNativeFonts
392
(JNIEnv *env, jobject jthis)
393
{
394
static JNF_CLASS_CACHE(jc_CFontManager,
395
"sun/font/CFontManager");
396
static JNF_MEMBER_CACHE(jm_registerFont, jc_CFontManager,
397
"registerFont",
398
"(Ljava/lang/String;Ljava/lang/String;)V");
399
400
jint num = 0;
401
402
JNF_COCOA_ENTER(env);
403
404
NSArray *filteredFonts = GetFilteredFonts();
405
num = (jint)[filteredFonts count];
406
407
jint i;
408
for (i = 0; i < num; i++) {
409
NSString *fontname = [filteredFonts objectAtIndex:i];
410
jobject jFontName = JNFNSToJavaString(env, fontname);
411
jobject jFontFamilyName =
412
JNFNSToJavaString(env, GetFamilyNameForFontName(fontname));
413
414
JNFCallVoidMethod(env, jthis,
415
jm_registerFont, jFontName, jFontFamilyName);
416
}
417
418
JNF_COCOA_EXIT(env);
419
}
420
421
/*
422
* Class: Java_sun_font_CFontManager_loadNativeDirFonts
423
* Method: loadNativeDirFonts
424
* Signature: (Ljava/lang/String;)V;
425
*/
426
JNIEXPORT void JNICALL
427
Java_sun_font_CFontManager_loadNativeDirFonts
428
(JNIEnv *env, jclass clz, jstring filename)
429
{
430
JNF_COCOA_ENTER(env);
431
432
NSString *nsFilePath = JNFJavaToNSString(env, filename);
433
434
FSRef iFile;
435
OSStatus status = CreateFSRef(&iFile, nsFilePath);
436
437
if (status == noErr) {
438
ATSFontContainerRef oContainer;
439
status = ATSFontActivateFromFileReference(&iFile, kATSFontContextLocal,
440
kATSFontFormatUnspecified,
441
NULL, kNilOptions,
442
&oContainer);
443
}
444
445
JNF_COCOA_EXIT(env);
446
}
447
448
#pragma mark --- sun.font.CFont JNI ---
449
450
/*
451
* Class: sun_font_CFont
452
* Method: getPlatformFontPtrNative
453
* Signature: (JI)[B
454
*/
455
JNIEXPORT jlong JNICALL
456
Java_sun_font_CFont_getCGFontPtrNative
457
(JNIEnv *env, jclass clazz,
458
jlong awtFontPtr)
459
{
460
AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
461
return (jlong)(awtFont->fNativeCGFont);
462
}
463
464
/*
465
* Class: sun_font_CFont
466
* Method: getLayoutTableCacheNative
467
* Signature: (J)J
468
*/
469
JNIEXPORT jlong JNICALL
470
Java_sun_font_CFont_getLayoutTableCacheNative
471
(JNIEnv *env, jclass clazz,
472
jlong awtFontPtr)
473
{
474
AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
475
if (awtFont->layoutTableCache == NULL) {
476
awtFont->layoutTableCache = newCFontLayoutTableCache();
477
}
478
return (jlong)(awtFont->layoutTableCache);
479
}
480
481
/*
482
* Class: sun_font_CFont
483
* Method: getTableBytesNative
484
* Signature: (JI)[B
485
*/
486
JNIEXPORT jbyteArray JNICALL
487
Java_sun_font_CFont_getTableBytesNative
488
(JNIEnv *env, jclass clazz,
489
jlong awtFontPtr, jint jtag)
490
{
491
jbyteArray jbytes = NULL;
492
JNF_COCOA_ENTER(env);
493
494
CTFontTableTag tag = (CTFontTableTag)jtag;
495
int i, found = 0;
496
AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
497
NSFont* nsFont = awtFont->fFont;
498
CTFontRef ctfont = (CTFontRef)nsFont;
499
CFArrayRef tagsArray =
500
CTFontCopyAvailableTables(ctfont, kCTFontTableOptionNoOptions);
501
CFIndex numTags = CFArrayGetCount(tagsArray);
502
for (i=0; i<numTags; i++) {
503
if (tag ==
504
(CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(tagsArray, i)) {
505
found = 1;
506
break;
507
}
508
}
509
CFRelease(tagsArray);
510
if (!found) {
511
return NULL;
512
}
513
CFDataRef table = CTFontCopyTable(ctfont, tag, kCTFontTableOptionNoOptions);
514
if (table == NULL) {
515
return NULL;
516
}
517
518
char *tableBytes = (char*)(CFDataGetBytePtr(table));
519
size_t tableLength = CFDataGetLength(table);
520
if (tableBytes == NULL || tableLength == 0) {
521
CFRelease(table);
522
return NULL;
523
}
524
525
jbytes = (*env)->NewByteArray(env, (jsize)tableLength);
526
if (jbytes == NULL) {
527
return NULL;
528
}
529
(*env)->SetByteArrayRegion(env, jbytes, 0,
530
(jsize)tableLength,
531
(jbyte*)tableBytes);
532
CFRelease(table);
533
534
JNF_COCOA_EXIT(env);
535
536
return jbytes;
537
}
538
539
/*
540
* Class: sun_font_CFont
541
* Method: initNativeFont
542
* Signature: (Ljava/lang/String;I)J
543
*/
544
JNIEXPORT jlong JNICALL
545
Java_sun_font_CFont_createNativeFont
546
(JNIEnv *env, jclass clazz,
547
jstring nativeFontName, jint style)
548
{
549
AWTFont *awtFont = nil;
550
551
JNF_COCOA_ENTER(env);
552
553
awtFont =
554
[AWTFont awtFontForName:JNFJavaToNSString(env, nativeFontName)
555
style:style]; // autoreleased
556
557
if (awtFont) {
558
CFRetain(awtFont); // GC
559
}
560
561
JNF_COCOA_EXIT(env);
562
563
return ptr_to_jlong(awtFont);
564
}
565
566
/*
567
* Class: sun_font_CFont
568
* Method: getWidthNative
569
* Signature: (J)F
570
*/
571
JNIEXPORT jfloat JNICALL
572
Java_sun_font_CFont_getWidthNative
573
(JNIEnv *env, jobject cfont, jlong awtFontPtr)
574
{
575
float widthVal;
576
JNF_COCOA_ENTER(env);
577
578
AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
579
NSFont* nsFont = awtFont->fFont;
580
NSFontDescriptor *fontDescriptor = nsFont.fontDescriptor;
581
NSDictionary *fontTraits = [fontDescriptor objectForKey : NSFontTraitsAttribute];
582
NSNumber *width = [fontTraits objectForKey : NSFontWidthTrait];
583
widthVal = (float)[width floatValue];
584
585
JNF_COCOA_EXIT(env);
586
return (jfloat)widthVal;
587
}
588
589
/*
590
* Class: sun_font_CFont
591
* Method: getWeightNative
592
* Signature: (J)F
593
*/
594
JNIEXPORT jfloat JNICALL
595
Java_sun_font_CFont_getWeightNative
596
(JNIEnv *env, jobject cfont, jlong awtFontPtr)
597
{
598
float weightVal;
599
JNF_COCOA_ENTER(env);
600
601
AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
602
NSFont* nsFont = awtFont->fFont;
603
NSFontDescriptor *fontDescriptor = nsFont.fontDescriptor;
604
NSDictionary *fontTraits = [fontDescriptor objectForKey : NSFontTraitsAttribute];
605
NSNumber *weight = [fontTraits objectForKey : NSFontWeightTrait];
606
weightVal = (float)[weight floatValue];
607
608
JNF_COCOA_EXIT(env);
609
return (jfloat)weightVal;
610
}
611
612
/*
613
* Class: sun_font_CFont
614
* Method: disposeNativeFont
615
* Signature: (J)V
616
*/
617
JNIEXPORT void JNICALL
618
Java_sun_font_CFont_disposeNativeFont
619
(JNIEnv *env, jclass clazz, jlong awtFontPtr)
620
{
621
JNF_COCOA_ENTER(env);
622
623
if (awtFontPtr) {
624
CFRelease((AWTFont *)jlong_to_ptr(awtFontPtr)); // GC
625
}
626
627
JNF_COCOA_EXIT(env);
628
}
629
630
631
#pragma mark --- Miscellaneous JNI ---
632
633
#ifndef HEADLESS
634
/*
635
* Class: sun_awt_PlatformFont
636
* Method: initIDs
637
* Signature: ()V
638
*/
639
JNIEXPORT void JNICALL
640
Java_sun_awt_PlatformFont_initIDs
641
(JNIEnv *env, jclass cls)
642
{
643
}
644
645
/*
646
* Class: sun_awt_FontDescriptor
647
* Method: initIDs
648
* Signature: ()V
649
*/
650
JNIEXPORT void JNICALL
651
Java_sun_awt_FontDescriptor_initIDs
652
(JNIEnv *env, jclass cls)
653
{
654
}
655
#endif
656
657
/*
658
* Class: sun_awt_FontDescriptor
659
* Method: initIDs
660
* Signature: ()V
661
*/
662
JNIEXPORT void JNICALL
663
Java_sun_font_CFont_getCascadeList
664
(JNIEnv *env, jclass cls, jlong awtFontPtr, jobject arrayListOfString)
665
{
666
jclass alc = (*env)->FindClass(env, "java/util/ArrayList");
667
if (alc == NULL) return;
668
jmethodID addMID = (*env)->GetMethodID(env, alc, "add", "(Ljava/lang/Object;)Z");
669
if (addMID == NULL) return;
670
671
CFIndex i;
672
AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
673
NSFont* nsFont = awtFont->fFont;
674
CTFontRef font = (CTFontRef)nsFont;
675
CFStringRef base = CTFontCopyFullName(font);
676
CFArrayRef codes = CFLocaleCopyISOLanguageCodes();
677
678
#ifdef DEBUG
679
NSLog(@"BaseFont is : %@", (NSString*)base);
680
#endif
681
CFArrayRef fds = CTFontCopyDefaultCascadeListForLanguages(font, codes);
682
CFIndex cnt = CFArrayGetCount(fds);
683
for (i=0; i<cnt; i++) {
684
CTFontDescriptorRef ref = CFArrayGetValueAtIndex(fds, i);
685
CFStringRef fontname =
686
CTFontDescriptorCopyAttribute(ref, kCTFontNameAttribute);
687
#ifdef DEBUG
688
NSLog(@"Font is : %@", (NSString*)fontname);
689
#endif
690
jstring jFontName = (jstring)JNFNSToJavaString(env, fontname);
691
(*env)->CallBooleanMethod(env, arrayListOfString, addMID, jFontName);
692
(*env)->DeleteLocalRef(env, jFontName);
693
}
694
}
695
#endif
696
697