src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m
Print this page
*** 33,51 ****
#import "AWTFont.h"
#import "AWTStrike.h"
#import "CoreTextSupport.h"
-
- #define DEBUG
-
@implementation AWTFont
! - (id) initWithFont:(NSFont *)font isFakeItalic:(BOOL)isFakeItalic {
self = [super init];
if (self) {
- fIsFakeItalic = isFakeItalic;
fFont = [font retain];
fNativeCGFont = CTFontCopyGraphicsFont((CTFontRef)font, NULL);
}
return self;
}
--- 33,47 ----
#import "AWTFont.h"
#import "AWTStrike.h"
#import "CoreTextSupport.h"
@implementation AWTFont
! - (id) initWithFont:(NSFont *)font {
self = [super init];
if (self) {
fFont = [font retain];
fNativeCGFont = CTFontCopyGraphicsFont((CTFontRef)font, NULL);
}
return self;
}
*** 70,80 ****
[super finalize];
}
+ (AWTFont *) awtFontForName:(NSString *)name
style:(int)style
- isFakeItalic:(BOOL)isFakeItalic
{
// create font with family & size
NSFont *nsFont = [NSFont fontWithName:name size:1.0];
if (nsFont == nil) {
--- 66,75 ----
*** 93,103 ****
// create a bold style (if one is installed)
if (style & java_awt_Font_BOLD) {
nsFont = [[NSFontManager sharedFontManager] convertFont:nsFont toHaveTrait:NSBoldFontMask];
}
! return [[[AWTFont alloc] initWithFont:nsFont isFakeItalic:isFakeItalic] autorelease];
}
+ (NSFont *) nsFontForJavaFont:(jobject)javaFont env:(JNIEnv *)env {
if (javaFont == NULL) {
#ifdef DEBUG
--- 88,98 ----
// create a bold style (if one is installed)
if (style & java_awt_Font_BOLD) {
nsFont = [[NSFontManager sharedFontManager] convertFont:nsFont toHaveTrait:NSBoldFontMask];
}
! return [[[AWTFont alloc] initWithFont:nsFont] autorelease];
}
+ (NSFont *) nsFontForJavaFont:(jobject)javaFont env:(JNIEnv *)env {
if (javaFont == NULL) {
#ifdef DEBUG
*** 352,371 ****
* Signature: (Ljava/lang/String;I)J
*/
JNIEXPORT jlong JNICALL
Java_sun_font_CFont_createNativeFont
(JNIEnv *env, jclass clazz,
! jstring nativeFontName, jint style, jboolean isFakeItalic)
{
AWTFont *awtFont = nil;
JNF_COCOA_ENTER(env);
awtFont =
[AWTFont awtFontForName:JNFJavaToNSString(env, nativeFontName)
! style:style
! isFakeItalic:isFakeItalic]; // autoreleased
if (awtFont) {
CFRetain(awtFont); // GC
}
--- 347,365 ----
* Signature: (Ljava/lang/String;I)J
*/
JNIEXPORT jlong JNICALL
Java_sun_font_CFont_createNativeFont
(JNIEnv *env, jclass clazz,
! jstring nativeFontName, jint style)
{
AWTFont *awtFont = nil;
JNF_COCOA_ENTER(env);
awtFont =
[AWTFont awtFontForName:JNFJavaToNSString(env, nativeFontName)
! style:style]; // autoreleased
if (awtFont) {
CFRetain(awtFont); // GC
}
*** 374,383 ****
--- 368,423 ----
return ptr_to_jlong(awtFont);
}
/*
* Class: sun_font_CFont
+ * Method: getWidthNative
+ * Signature: (J)F
+ */
+ JNIEXPORT jfloat JNICALL
+ Java_sun_font_CFont_getWidthNative
+ (JNIEnv *env, jobject cfont, jlong awtFontPtr)
+ {
+ float widthVal;
+ JNF_COCOA_ENTER(env);
+
+ AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
+ NSFont* nsFont = awtFont->fFont;
+ NSFontDescriptor *fontDescriptor = nsFont.fontDescriptor;
+ NSDictionary *fontTraits = [fontDescriptor objectForKey : NSFontTraitsAttribute];
+ NSNumber *width = [fontTraits objectForKey : NSFontWidthTrait];
+ widthVal = (float)[width floatValue];
+
+ JNF_COCOA_EXIT(env);
+ return (jfloat)widthVal;
+ }
+
+ /*
+ * Class: sun_font_CFont
+ * Method: getWeightNative
+ * Signature: (J)F
+ */
+ JNIEXPORT jfloat JNICALL
+ Java_sun_font_CFont_getWeightNative
+ (JNIEnv *env, jobject cfont, jlong awtFontPtr)
+ {
+ float weightVal;
+ JNF_COCOA_ENTER(env);
+
+ AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
+ NSFont* nsFont = awtFont->fFont;
+ NSFontDescriptor *fontDescriptor = nsFont.fontDescriptor;
+ NSDictionary *fontTraits = [fontDescriptor objectForKey : NSFontTraitsAttribute];
+ NSNumber *weight = [fontTraits objectForKey : NSFontWeightTrait];
+ weightVal = (float)[weight floatValue];
+
+ JNF_COCOA_EXIT(env);
+ return (jfloat)weightVal;
+ }
+
+ /*
+ * Class: sun_font_CFont
* Method: disposeNativeFont
* Signature: (J)V
*/
JNIEXPORT void JNICALL
Java_sun_font_CFont_disposeNativeFont