< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m

Print this page




  49 - (void) dealloc {
  50     [fFont release];
  51     fFont = nil;
  52 
  53     if (fNativeCGFont) {
  54         CGFontRelease(fNativeCGFont);
  55     fNativeCGFont = NULL;
  56     }
  57 
  58     [super dealloc];
  59 }
  60 
  61 - (void) finalize {
  62     if (fNativeCGFont) {
  63         CGFontRelease(fNativeCGFont);
  64     fNativeCGFont = NULL;
  65     }
  66     [super finalize];
  67 }
  68 



  69 + (AWTFont *) awtFontForName:(NSString *)name
  70                        style:(int)style
  71 {
  72     // create font with family & size
  73     NSFont *nsFont = [NSFont fontWithName:name size:1.0];


















  74 
  75     if (nsFont == nil) {
  76         // if can't get font of that name, substitute system default font
  77         nsFont = [NSFont fontWithName:@"Lucida Grande" size:1.0];
  78 #ifdef DEBUG
  79         NSLog(@"needed to substitute Lucida Grande for: %@", name);
  80 #endif
  81     }
  82 
  83     // create an italic style (if one is installed)
  84     if (style & java_awt_Font_ITALIC) {
  85         nsFont = [[NSFontManager sharedFontManager] convertFont:nsFont toHaveTrait:NSItalicFontMask];
  86     }
  87 
  88     // create a bold style (if one is installed)
  89     if (style & java_awt_Font_BOLD) {
  90         nsFont = [[NSFontManager sharedFontManager] convertFont:nsFont toHaveTrait:NSBoldFontMask];
  91     }
  92 
  93     return [[[AWTFont alloc] initWithFont:nsFont] autorelease];


 171             return;
 172         }
 173         CTFontDescriptorRef desc = CTFontCopyFontDescriptor(font);
 174         if (desc == NULL) {
 175             CFRelease(font);
 176             return;
 177         }
 178         CFStringRef family = CTFontDescriptorCopyAttribute(desc, kCTFontFamilyNameAttribute);
 179         if (family == NULL) {
 180             CFRelease(desc);
 181             CFRelease(font);
 182             return;
 183         }
 184         CFStringRef name = CTFontDescriptorCopyAttribute(desc, kCTFontNameAttribute);
 185         if (name == NULL) {
 186             CFRelease(family);
 187             CFRelease(desc);
 188             CFRelease(font);
 189             return;
 190         }






 191         [allFonts addObject:name];
 192         [fontFamilyTable setObject:family forKey:name];
 193 #ifdef DEBUG
 194         NSLog(@"name is : %@", (NSString*)name);
 195         NSLog(@"family is : %@", (NSString*)family);
 196 #endif
 197         CFRelease(family);
 198         CFRelease(name);
 199         CFRelease(desc);
 200         CFRelease(font);
 201 }
 202  
 203 static NSArray*
 204 GetFilteredFonts()
 205 {
 206     if (sFilteredFonts == nil) {
 207         NSFontManager *fontManager = [NSFontManager sharedFontManager];
 208         NSUInteger fontCount = [[fontManager availableFonts] count];
 209 
 210         NSMutableArray *allFonts = [[NSMutableArray alloc] initWithCapacity:fontCount];


 225             NSUInteger faceCount = [fontFaces count];
 226 
 227             NSUInteger faceIndex;
 228             for (faceIndex = 0; faceIndex < faceCount; faceIndex++) {
 229                 NSString* face = [[fontFaces objectAtIndex:faceIndex] objectAtIndex:0];
 230                 if (face != nil) {
 231                     [allFonts addObject:face];
 232                     [fontFamilyTable setObject:family forKey:face];
 233                 }
 234             }
 235         }
 236 
 237         /*
 238          * JavaFX registers these fonts and so JDK needs to do so as well.
 239          * If this isn't done we will have mis-matched rendering, since
 240          * although these may include fonts that are enumerated normally
 241          * they also demonstrably includes fonts that are not.
 242          */
 243         addFont(kCTFontUIFontSystem, allFonts, fontFamilyTable);
 244         addFont(kCTFontUIFontEmphasizedSystem, allFonts, fontFamilyTable);
 245         addFont(kCTFontUIFontUserFixedPitch, allFonts, fontFamilyTable);
 246 
 247         sFilteredFonts = allFonts;
 248         sFontFamilyTable = fontFamilyTable;
 249     }
 250 
 251     return sFilteredFonts;
 252 }
 253 
 254 #pragma mark --- sun.font.CFontManager JNI ---
 255 
 256 static OSStatus CreateFSRef(FSRef *myFSRefPtr, NSString *inPath)
 257 {
 258     return FSPathMakeRef((UInt8 *)[inPath fileSystemRepresentation],
 259                          myFSRefPtr, NULL);
 260 }
 261 
 262 // /*
 263 //  * Class:     sun_font_CFontManager
 264 //  * Method:    loadFileFont
 265 //  * Signature: (Ljava/lang/String;)Lsun/font/Font2D;




  49 - (void) dealloc {
  50     [fFont release];
  51     fFont = nil;
  52 
  53     if (fNativeCGFont) {
  54         CGFontRelease(fNativeCGFont);
  55     fNativeCGFont = NULL;
  56     }
  57 
  58     [super dealloc];
  59 }
  60 
  61 - (void) finalize {
  62     if (fNativeCGFont) {
  63         CGFontRelease(fNativeCGFont);
  64     fNativeCGFont = NULL;
  65     }
  66     [super finalize];
  67 }
  68 
  69 static NSString* uiName = nil;
  70 static NSString* uiBoldName = nil;
  71 
  72 + (AWTFont *) awtFontForName:(NSString *)name
  73                        style:(int)style
  74 {
  75     // create font with family & size
  76     NSFont *nsFont = nil;
  77 
  78     if ((uiName != nil && [name isEqualTo:uiName]) ||
  79         (uiBoldName != nil && [name isEqualTo:uiBoldName])) {
  80         if (style & java_awt_Font_BOLD) {
  81             nsFont = [NSFont boldSystemFontOfSize:1.0];
  82         } else {
  83             nsFont = [NSFont systemFontOfSize:1.0];
  84         }
  85 #ifdef DEBUG
  86         NSLog(@"nsFont-name is : %@", nsFont.familyName);
  87         NSLog(@"nsFont-family is : %@", nsFont.fontName);
  88         NSLog(@"nsFont-desc-name is : %@", nsFont.fontDescriptor.postscriptName);
  89 #endif
  90         
  91        
  92     } else {
  93            nsFont = [NSFont fontWithName:name size:1.0];
  94     }
  95 
  96     if (nsFont == nil) {
  97         // if can't get font of that name, substitute system default font
  98         nsFont = [NSFont fontWithName:@"Lucida Grande" size:1.0];
  99 #ifdef DEBUG
 100         NSLog(@"needed to substitute Lucida Grande for: %@", name);
 101 #endif
 102     }
 103 
 104     // create an italic style (if one is installed)
 105     if (style & java_awt_Font_ITALIC) {
 106         nsFont = [[NSFontManager sharedFontManager] convertFont:nsFont toHaveTrait:NSItalicFontMask];
 107     }
 108 
 109     // create a bold style (if one is installed)
 110     if (style & java_awt_Font_BOLD) {
 111         nsFont = [[NSFontManager sharedFontManager] convertFont:nsFont toHaveTrait:NSBoldFontMask];
 112     }
 113 
 114     return [[[AWTFont alloc] initWithFont:nsFont] autorelease];


 192             return;
 193         }
 194         CTFontDescriptorRef desc = CTFontCopyFontDescriptor(font);
 195         if (desc == NULL) {
 196             CFRelease(font);
 197             return;
 198         }
 199         CFStringRef family = CTFontDescriptorCopyAttribute(desc, kCTFontFamilyNameAttribute);
 200         if (family == NULL) {
 201             CFRelease(desc);
 202             CFRelease(font);
 203             return;
 204         }
 205         CFStringRef name = CTFontDescriptorCopyAttribute(desc, kCTFontNameAttribute);
 206         if (name == NULL) {
 207             CFRelease(family);
 208             CFRelease(desc);
 209             CFRelease(font);
 210             return;
 211         }
 212         if (uiType == kCTFontUIFontSystem) {
 213             uiName = (NSString*)name;
 214         }
 215         if (uiType == kCTFontUIFontEmphasizedSystem) {
 216             uiBoldName = (NSString*)name;
 217         }
 218         [allFonts addObject:name];
 219         [fontFamilyTable setObject:family forKey:name];
 220 #ifdef DEBUG
 221         NSLog(@"name is : %@", (NSString*)name);
 222         NSLog(@"family is : %@", (NSString*)family);
 223 #endif
 224         CFRelease(family);
 225         CFRelease(name);
 226         CFRelease(desc);
 227         CFRelease(font);
 228 }
 229  
 230 static NSArray*
 231 GetFilteredFonts()
 232 {
 233     if (sFilteredFonts == nil) {
 234         NSFontManager *fontManager = [NSFontManager sharedFontManager];
 235         NSUInteger fontCount = [[fontManager availableFonts] count];
 236 
 237         NSMutableArray *allFonts = [[NSMutableArray alloc] initWithCapacity:fontCount];


 252             NSUInteger faceCount = [fontFaces count];
 253 
 254             NSUInteger faceIndex;
 255             for (faceIndex = 0; faceIndex < faceCount; faceIndex++) {
 256                 NSString* face = [[fontFaces objectAtIndex:faceIndex] objectAtIndex:0];
 257                 if (face != nil) {
 258                     [allFonts addObject:face];
 259                     [fontFamilyTable setObject:family forKey:face];
 260                 }
 261             }
 262         }
 263 
 264         /*
 265          * JavaFX registers these fonts and so JDK needs to do so as well.
 266          * If this isn't done we will have mis-matched rendering, since
 267          * although these may include fonts that are enumerated normally
 268          * they also demonstrably includes fonts that are not.
 269          */
 270         addFont(kCTFontUIFontSystem, allFonts, fontFamilyTable);
 271         addFont(kCTFontUIFontEmphasizedSystem, allFonts, fontFamilyTable);

 272 
 273         sFilteredFonts = allFonts;
 274         sFontFamilyTable = fontFamilyTable;
 275     }
 276 
 277     return sFilteredFonts;
 278 }
 279 
 280 #pragma mark --- sun.font.CFontManager JNI ---
 281 
 282 static OSStatus CreateFSRef(FSRef *myFSRefPtr, NSString *inPath)
 283 {
 284     return FSPathMakeRef((UInt8 *)[inPath fileSystemRepresentation],
 285                          myFSRefPtr, NULL);
 286 }
 287 
 288 // /*
 289 //  * Class:     sun_font_CFontManager
 290 //  * Method:    loadFileFont
 291 //  * Signature: (Ljava/lang/String;)Lsun/font/Font2D;


< prev index next >