src/macosx/native/sun/font/AWTStrike.m

Print this page


   1 /*
   2  * Copyright (c) 2011, 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


  48                  tx:(CGAffineTransform)tx
  49            invDevTx:(CGAffineTransform)invDevTx
  50               style:(JRSFontRenderingStyle)style
  51             aaStyle:(jint)aaStyle {
  52 
  53     self = [super init];
  54     if (self) {
  55         fAWTFont = [awtFont retain];
  56         fStyle = style;
  57         fAAStyle = aaStyle;
  58 
  59         fTx = tx; // composited glyph and device transform
  60 
  61         fAltTx = tx;
  62         fAltTx.b *= -1;
  63         fAltTx.d *= -1;
  64 
  65         invDevTx.b *= -1;
  66         invDevTx.c *= -1;
  67         fFontTx = CGAffineTransformConcat(CGAffineTransformConcat(tx, invDevTx), sInverseTX);

  68 
  69         // the "font size" is the square root of the determinant of the matrix
  70         fSize = sqrt(abs(fFontTx.a * fFontTx.d - fFontTx.b * fFontTx.c));
  71     }
  72     return self;
  73 }
  74 
  75 - (void) dealloc {
  76     [fAWTFont release];
  77     fAWTFont = nil;
  78 
  79     [super dealloc];
  80 }
  81 
  82 + (AWTStrike *) awtStrikeForFont:(AWTFont *)awtFont
  83                               tx:(CGAffineTransform)tx
  84                         invDevTx:(CGAffineTransform)invDevTx
  85                            style:(JRSFontRenderingStyle)style
  86                          aaStyle:(jint)aaStyle {
  87 


 131         CGAffineTransformMake(txPtr[0], txPtr[1], txPtr[2],
 132                               txPtr[3], txPtr[4], txPtr[5]);
 133     tx = CGAffineTransformConcat(sInverseTX, tx);
 134 
 135     (*env)->ReleasePrimitiveArrayCritical(env, txArray, txPtr, JNI_ABORT);
 136 
 137     return tx;
 138 }
 139 
 140 /*
 141  * Class:     sun_font_CStrike
 142  * Method:    getNativeGlyphAdvance
 143  * Signature: (JI)F
 144  */
 145 JNIEXPORT jfloat JNICALL
 146 Java_sun_font_CStrike_getNativeGlyphAdvance
 147     (JNIEnv *env, jclass clazz, jlong awtStrikePtr, jint glyphCode)
 148 {
 149     CGSize advance;
 150 JNF_COCOA_ENTER(env);
 151     AWTFont *awtFont = ((AWTStrike *)jlong_to_ptr(awtStrikePtr))->fAWTFont;

 152 
 153     // negative glyph codes are really unicodes, which were placed there by the mapper
 154     // to indicate we should use CoreText to substitute the character
 155     CGGlyph glyph;
 156     const CTFontRef fallback = CTS_CopyCTFallbackFontAndGlyphForJavaGlyphCode(awtFont, glyphCode, &glyph);
 157     CTFontGetAdvancesForGlyphs(fallback, kCTFontDefaultOrientation, &glyph, &advance, 1);
 158     CFRelease(fallback);




 159 
 160 JNF_COCOA_EXIT(env);
 161     return advance.width;
 162 }
 163 
 164 /*
 165  * Class:     sun_font_CStrike
 166  * Method:    getNativeGlyphImageBounds
 167  * Signature: (JJILjava/awt/geom/Rectangle2D/Float;DD)V
 168  */
 169 JNIEXPORT void JNICALL
 170 Java_sun_font_CStrike_getNativeGlyphImageBounds
 171     (JNIEnv *env, jclass clazz,
 172      jlong awtStrikePtr, jint glyphCode,
 173      jobject result /*Rectangle*/, jdouble x, jdouble y)
 174 {
 175 JNF_COCOA_ENTER(env);
 176 
 177     AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
 178     AWTFont *awtFont = awtStrike->fAWTFont;


   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


  48                  tx:(CGAffineTransform)tx
  49            invDevTx:(CGAffineTransform)invDevTx
  50               style:(JRSFontRenderingStyle)style
  51             aaStyle:(jint)aaStyle {
  52 
  53     self = [super init];
  54     if (self) {
  55         fAWTFont = [awtFont retain];
  56         fStyle = style;
  57         fAAStyle = aaStyle;
  58 
  59         fTx = tx; // composited glyph and device transform
  60 
  61         fAltTx = tx;
  62         fAltTx.b *= -1;
  63         fAltTx.d *= -1;
  64 
  65         invDevTx.b *= -1;
  66         invDevTx.c *= -1;
  67         fFontTx = CGAffineTransformConcat(CGAffineTransformConcat(tx, invDevTx), sInverseTX);
  68         fDevTx = CGAffineTransformInvert(invDevTx);
  69 
  70         // the "font size" is the square root of the determinant of the matrix
  71         fSize = sqrt(abs(fFontTx.a * fFontTx.d - fFontTx.b * fFontTx.c));
  72     }
  73     return self;
  74 }
  75 
  76 - (void) dealloc {
  77     [fAWTFont release];
  78     fAWTFont = nil;
  79 
  80     [super dealloc];
  81 }
  82 
  83 + (AWTStrike *) awtStrikeForFont:(AWTFont *)awtFont
  84                               tx:(CGAffineTransform)tx
  85                         invDevTx:(CGAffineTransform)invDevTx
  86                            style:(JRSFontRenderingStyle)style
  87                          aaStyle:(jint)aaStyle {
  88 


 132         CGAffineTransformMake(txPtr[0], txPtr[1], txPtr[2],
 133                               txPtr[3], txPtr[4], txPtr[5]);
 134     tx = CGAffineTransformConcat(sInverseTX, tx);
 135 
 136     (*env)->ReleasePrimitiveArrayCritical(env, txArray, txPtr, JNI_ABORT);
 137 
 138     return tx;
 139 }
 140 
 141 /*
 142  * Class:     sun_font_CStrike
 143  * Method:    getNativeGlyphAdvance
 144  * Signature: (JI)F
 145  */
 146 JNIEXPORT jfloat JNICALL
 147 Java_sun_font_CStrike_getNativeGlyphAdvance
 148     (JNIEnv *env, jclass clazz, jlong awtStrikePtr, jint glyphCode)
 149 {
 150     CGSize advance;
 151 JNF_COCOA_ENTER(env);
 152     AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
 153     AWTFont *awtFont = awtStrike->fAWTFont;
 154 
 155     // negative glyph codes are really unicodes, which were placed there by the mapper
 156     // to indicate we should use CoreText to substitute the character
 157     CGGlyph glyph;
 158     const CTFontRef fallback = CTS_CopyCTFallbackFontAndGlyphForJavaGlyphCode(awtFont, glyphCode, &glyph);
 159     CTFontGetAdvancesForGlyphs(fallback, kCTFontDefaultOrientation, &glyph, &advance, 1);
 160     CFRelease(fallback);
 161     advance = CGSizeApplyAffineTransform(advance, awtStrike->fFontTx);
 162     if (!JRSFontStyleUsesFractionalMetrics(awtStrike->fStyle)) {
 163         advance.width = round(advance.width);
 164     }
 165 
 166 JNF_COCOA_EXIT(env);
 167     return advance.width;
 168 }
 169 
 170 /*
 171  * Class:     sun_font_CStrike
 172  * Method:    getNativeGlyphImageBounds
 173  * Signature: (JJILjava/awt/geom/Rectangle2D/Float;DD)V
 174  */
 175 JNIEXPORT void JNICALL
 176 Java_sun_font_CStrike_getNativeGlyphImageBounds
 177     (JNIEnv *env, jclass clazz,
 178      jlong awtStrikePtr, jint glyphCode,
 179      jobject result /*Rectangle*/, jdouble x, jdouble y)
 180 {
 181 JNF_COCOA_ENTER(env);
 182 
 183     AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
 184     AWTFont *awtFont = awtStrike->fAWTFont;