changeset 5200:d8f1608ffe71

RT-32255 [mac only]
author Felipe Heidrich <felipe.heidrich@oracle.com>
date Fri, 27 Sep 2013 11:25:44 -0700
parents 4f279342c9b3
children 817ffac6c818
files modules/graphics/src/main/java/com/sun/javafx/font/CompositeStrike.java modules/graphics/src/main/java/com/sun/javafx/font/PrismFontStrike.java modules/graphics/src/main/java/com/sun/javafx/font/coretext/CFRange.java modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTFontFile.java modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTFontStrike.java modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTGlyph.java modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTGlyphLayout.java modules/graphics/src/main/java/com/sun/javafx/font/coretext/OS.java modules/graphics/src/main/java/com/sun/prism/sw/SWGraphics.java modules/graphics/src/main/native-font/coretext.c
diffstat 10 files changed, 107 insertions(+), 243 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/font/CompositeStrike.java	Fri Sep 27 09:40:26 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/CompositeStrike.java	Fri Sep 27 11:25:44 2013 -0700
@@ -197,11 +197,13 @@
         for (int i = 0; i < gl.getGlyphCount(); i++) {
             int glyphCode = gl.getGlyphCode(i);
             if (glyphCode != CharToGlyphMapper.INVISIBLE_GLYPH_ID) {
-                t.setTransform(transform);
                 Glyph glyph = getGlyph(glyphCode);
                 Shape gp = glyph.getShape();
-                t.translate(gl.getPosX(i), gl.getPosY(i));
-                p.append(gp.getPathIterator(t), false);
+                if (gp != null) {
+                    t.setTransform(transform);
+                    t.translate(gl.getPosX(i), gl.getPosY(i));
+                    p.append(gp.getPathIterator(t), false);
+                }
             }
         }
     }
--- a/modules/graphics/src/main/java/com/sun/javafx/font/PrismFontStrike.java	Fri Sep 27 09:40:26 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/PrismFontStrike.java	Fri Sep 27 11:25:44 2013 -0700
@@ -183,10 +183,12 @@
         for (int i = 0; i < gl.getGlyphCount(); i++) {
             int glyphCode = gl.getGlyphCode(i);
             if (glyphCode != CharToGlyphMapper.INVISIBLE_GLYPH_ID) {
-                t.setTransform(transform);
                 Shape gp = createGlyphOutline(glyphCode);
-                t.translate(gl.getPosX(i), gl.getPosY(i));
-                p.append(gp.getPathIterator(t), false);
+                if (gp != null) {
+                    t.setTransform(transform);
+                    t.translate(gl.getPosX(i), gl.getPosY(i));
+                    p.append(gp.getPathIterator(t), false);
+                }
             }
         }
     }
--- a/modules/graphics/src/main/java/com/sun/javafx/font/coretext/CFRange.java	Fri Sep 27 09:40:26 2013 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.javafx.font.coretext;
-
-class CFRange {
-    long location;
-    long length;
-}
--- a/modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTFontFile.java	Fri Sep 27 09:40:26 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTFontFile.java	Fri Sep 27 11:25:44 2013 -0700
@@ -48,19 +48,27 @@
     public static boolean registerFont(String fontfile) {
         if (fontfile == null) return false;
         long alloc = OS.kCFAllocatorDefault();
+        boolean result = false;
         long fileRef = OS.CFStringCreate(fontfile);
-        long urlRef = OS.CFURLCreateWithFileSystemPath(alloc, fileRef, OS.kCFURLPOSIXPathStyle, false);
-        int scope = OS.kCTFontManagerScopeProcess;
-        boolean result = OS.CTFontManagerRegisterFontsForURL(urlRef, scope, 0);
-        OS.CFRelease(fileRef);
-        OS.CFRelease(urlRef);
+        if (fileRef != 0) {
+            int pathStyle = OS.kCFURLPOSIXPathStyle;
+            long urlRef = OS.CFURLCreateWithFileSystemPath(alloc, fileRef, pathStyle, false);
+            if (urlRef != 0) {
+                int scope = OS.kCTFontManagerScopeProcess;
+                result = OS.CTFontManagerRegisterFontsForURL(urlRef, scope, 0);
+                OS.CFRelease(urlRef);
+            }
+            OS.CFRelease(fileRef);
+        }
         return result;
     }
 
     CGRect getBBox(int gc, float size) {
         CTFontStrike strike = (CTFontStrike)getStrike(size, BaseTransform.IDENTITY_TRANSFORM);
         long fontRef = strike.getFontRef();
+        if (fontRef == 0) return null;
         long pathRef = OS.CTFontCreatePathForGlyph(fontRef, (short)gc, tx);
+        if (pathRef == 0) return null;
         CGRect rect = OS.CGPathGetPathBoundingBox(pathRef);
         OS.CGPathRelease(pathRef);
         return rect;
@@ -69,7 +77,9 @@
     Path2D getGlyphOutline(int gc, float size) {
         CTFontStrike strike = (CTFontStrike)getStrike(size, BaseTransform.IDENTITY_TRANSFORM);
         long fontRef = strike.getFontRef();
+        if (fontRef == 0) return null;
         long pathRef = OS.CTFontCreatePathForGlyph(fontRef, (short)gc, tx);
+        if (pathRef == 0) return null;
         Path2D path = OS.CGPathApply(pathRef);
         OS.CGPathRelease(pathRef);
         return path;
@@ -80,6 +90,10 @@
         CTFontStrike strike = (CTFontStrike)getStrike(size,
                                                       BaseTransform.IDENTITY_TRANSFORM);
 
+        long fontRef = strike.getFontRef();
+        if (fontRef == 0) return null;
+        int[] bb = new int[4];
+
         /* For some reason CTFontGetBoundingRectsForGlyphs has poor performance.
          * The fix is to use the 'loca' and the 'glyf' tables to determine
          * the glyph bounding box (same as T2K). This implementation
@@ -87,8 +101,6 @@
          * In case it fails, or the font doesn't have a glyph table
          * (CFF fonts), then the bounds of the glyph outline is used instead.
          */
-        long fontRef = strike.getFontRef();
-        int[] bb = new int[4];
         if (!isCFF()) {
             short format = getIndexToLocFormat();
             if (OS.CTFontGetBoundingRectForGlyphUsingTables(fontRef, (short)gc, format, bb)) {
@@ -97,6 +109,7 @@
         }
         /* Note: not using tx here as the bounds need to be y up */
         long pathRef = OS.CTFontCreatePathForGlyph(fontRef, (short)gc, null);
+        if (pathRef == 0) return null;
         CGRect rect = OS.CGPathGetPathBoundingBox(pathRef);
         OS.CGPathRelease(pathRef);
         float scale = getUnitsPerEm() / size;
@@ -108,8 +121,8 @@
     }
 
     @Override
-    protected PrismFontStrike createStrike(float size, BaseTransform transform,
-                                           int aaMode, FontStrikeDesc desc) {
+    protected PrismFontStrike<CTFontFile> createStrike(float size,
+            BaseTransform transform, int aaMode, FontStrikeDesc desc) {
         return new CTFontStrike(this, size, transform, aaMode, desc);
     }
 
--- a/modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTFontStrike.java	Fri Sep 27 09:40:26 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTFontStrike.java	Fri Sep 27 11:25:44 2013 -0700
@@ -68,8 +68,15 @@
             }
         }
         long psNameRef = OS.CFStringCreate(fontResource.getPSName());
-        fontRef = OS.CTFontCreateWithName(psNameRef, size, matrix);
-        OS.CFRelease(psNameRef);
+        if (psNameRef != 0) {
+            fontRef = OS.CTFontCreateWithName(psNameRef, size, matrix);
+            OS.CFRelease(psNameRef);
+        }
+        if (fontRef == 0) {
+            if (PrismFontFactory.debugFonts) {
+                System.err.println("Failed to create CTFont for " + this);
+            }
+        }
 
         /* CoreText uses different precision for subpixel text according
          * to the font size. By observation, font sizes smaller than 12
--- a/modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTGlyph.java	Fri Sep 27 09:40:26 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTGlyph.java	Fri Sep 27 11:25:44 2013 -0700
@@ -64,6 +64,7 @@
     @Override public RectBounds getBBox() {
         /* IN T2k this is the bounds of the glyph path see GeneralPath.cpp */
         CGRect rect = strike.getBBox(glyphCode);
+        if (rect == null) return new RectBounds();
         return new RectBounds((float)rect.origin.x,
                               (float)rect.origin.y,
                               (float)(rect.origin.x + rect.size.width),
@@ -76,9 +77,10 @@
         if (strike.getSize() == 0) return;
 
         long fontRef = strike.getFontRef();
+        if (fontRef == 0) return;
         int orientation = OS.kCTFontOrientationDefault;
         CGSize size = new CGSize();
-        OS.CTFontGetAdvancesForGlyphs(fontRef, orientation, (short)glyphCode, size, 1);
+        OS.CTFontGetAdvancesForGlyphs(fontRef, orientation, (short)glyphCode, size);
         xAdvance = size.width;
         yAdvance = -size.height;   /*Inverted coordinates system */
 
@@ -153,6 +155,7 @@
         boolean cache = CACHE_CONTEXT & BITMAP_WIDTH >= w & BITMAP_HEIGHT >= h;
         long context = cache ? getCachedContext(lcdContext) :
                                createContext(lcdContext, w, h);
+        if (context == 0) return new byte[0];
 
         /* Fill background with white */
         OS.CGContextSetRGBFillColor(context, 1, 1, 1, 1);
@@ -175,7 +178,7 @@
 
         /* Draw the text with black */
         OS.CGContextSetRGBFillColor(context, 0, 0, 0, 1);
-        OS.CTFontDrawGlyphs(fontRef, (short)glyphCode, -drawX, -drawY, 1, context);
+        OS.CTFontDrawGlyphs(fontRef, (short)glyphCode, -drawX, -drawY, context);
 
         if (matrix != null) {
             OS.CGContextTranslateCTM(context, x, y);
--- a/modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTGlyphLayout.java	Fri Sep 27 09:40:26 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTGlyphLayout.java	Fri Sep 27 11:25:44 2013 -0700
@@ -40,26 +40,36 @@
         /* Use CoreText to analize the run */
         long alloc = OS.kCFAllocatorDefault();
         long textRef = OS.CFStringCreateWithCharacters(alloc, chars, start, length);
-        long attributes = OS.CFDictionaryCreateMutable(alloc, 4,
-                              OS.kCFTypeDictionaryKeyCallBacks(),
-                              OS.kCFTypeDictionaryValueCallBacks());
-        OS.CFDictionaryAddValue(attributes, OS.kCTFontAttributeName(), fontRef);
-        /* Note that by default CoreText will apply kerning depending on the font*/
-        long attString = OS.CFAttributedStringCreate(alloc, textRef, attributes);
-        long lineRef = OS.CTLineCreateWithAttributedString(attString);
-        OS.CFRelease(attributes);
-        OS.CFRelease(attString);
-        OS.CFRelease(textRef);
+        long lineRef = 0;
+        if (textRef != 0) {
+            long attributes = OS.CFDictionaryCreateMutable(alloc, 4,
+                                  OS.kCFTypeDictionaryKeyCallBacks(),
+                                  OS.kCFTypeDictionaryValueCallBacks());
+            if (attributes != 0) {
+                OS.CFDictionaryAddValue(attributes, OS.kCTFontAttributeName(), fontRef);
+                /* Note that by default CoreText will apply kerning depending on the font*/
+                long attString = OS.CFAttributedStringCreate(alloc, textRef, attributes);
+                if (attString != 0) {
+                    lineRef = OS.CTLineCreateWithAttributedString(attString);
+                    OS.CFRelease(attString);
+                }
+                OS.CFRelease(attributes);
+            }
+            OS.CFRelease(textRef);
+        }
         return lineRef;
     }
 
     private int getFontSlot(long runRef, CompositeFontResource fr, String name) {
         long runAttrs = OS.CTRunGetAttributes(runRef);
+        if (runAttrs == 0) return -1;
         long actualFont = OS.CFDictionaryGetValue(runAttrs, OS.kCTFontAttributeName());
+        if (actualFont == 0) return -1;
 
         /* Use the display name from the kCTFontDisplayNameAttribute attribute
          * instead of CTFontCopyDisplayName() to avoid localized names*/
         String fontName = OS.CTFontCopyAttributeDisplayName(actualFont);
+        if (fontName == null) return -1;
         int slot = 0;
         if (!fontName.equalsIgnoreCase(name)) {
             if (fr == null) return -1;
@@ -81,32 +91,37 @@
         float size = strike.getSize();
         String fontName = strike.getFontResource().getFullName();
         long fontRef = ((CTFontStrike)strike).getFontRef();
+        if (fontRef == 0) return;
         long lineRef = createCTLine(fontRef, text, run.getStart(), run.getLength());
+        if (lineRef == 0) return;
         long runs = OS.CTLineGetGlyphRuns(lineRef);
-        int glyphCount = (int)OS.CTLineGetGlyphCount(lineRef);
-        int[] glyphs = new int[glyphCount];
-        float[] positions = new float[glyphCount * 2 + 2];
-        int[] indices = new int[glyphCount];
-        long runCount = OS.CFArrayGetCount(runs);
-        int glyphStart = 0, posStart = 0, indicesStart = 0;
-        for (int i = 0; i < runCount; i++) {
-            long runRef = OS.CFArrayGetValueAtIndex(runs, i);
-            int slot = getFontSlot(runRef, composite, fontName) ;
-            if (slot != -1) {
-                glyphStart += OS.CTRunGetGlyphs(runRef, slot << 24, glyphStart, glyphs);
-            } else {
-                glyphStart += OS.CTRunGetGlyphCount(runRef);
+        if (runs != 0) {
+            int glyphCount = (int)OS.CTLineGetGlyphCount(lineRef);
+            int[] glyphs = new int[glyphCount];
+            float[] positions = new float[glyphCount * 2 + 2];
+            int[] indices = new int[glyphCount];
+            long runCount = OS.CFArrayGetCount(runs);
+            int glyphStart = 0, posStart = 0, indicesStart = 0;
+            for (int i = 0; i < runCount; i++) {
+                long runRef = OS.CFArrayGetValueAtIndex(runs, i);
+                if (runRef == 0) continue;
+                int slot = getFontSlot(runRef, composite, fontName) ;
+                if (slot != -1) {
+                    glyphStart += OS.CTRunGetGlyphs(runRef, slot << 24, glyphStart, glyphs);
+                } else {
+                    glyphStart += OS.CTRunGetGlyphCount(runRef);
+                }
+                if (size > 0) {
+                    posStart += OS.CTRunGetPositions(runRef, posStart, positions);
+                }
+                indicesStart += OS.CTRunGetStringIndices(runRef, indicesStart, indices);
+
             }
             if (size > 0) {
-                posStart += OS.CTRunGetPositions(runRef, posStart, positions);
+                positions[posStart] = (float)OS.CTLineGetTypographicBounds(lineRef);
             }
-            indicesStart += OS.CTRunGetStringIndices(runRef, indicesStart, indices);
-
+            run.shape(glyphCount, glyphs, positions, indices);
         }
-        if (size > 0) {
-            positions[posStart] = (float)OS.CTLineGetTypographicBounds(lineRef);
-        }
-        run.shape(glyphCount, glyphs, positions, indices);
         OS.CFRelease(lineRef);
     }
 }
--- a/modules/graphics/src/main/java/com/sun/javafx/font/coretext/OS.java	Fri Sep 27 09:40:26 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/coretext/OS.java	Fri Sep 27 11:25:44 2013 -0700
@@ -44,24 +44,12 @@
 
     static final int kCFURLPOSIXPathStyle = 0;
     static final int kCTFontOrientationDefault = 0;
-    static final int kCTFontManagerScopeNone = 0;
     static final int kCTFontManagerScopeProcess = 1;
-    static final int kCTFontManagerScopeSession = 3;
-    static final int kCTFontManagerScopeUser = 2;
-    static final int kCTRunStatusNoStatus = 0;
-    static final int kCTRunStatusNonMonotonic = 2;
-    static final int kCTRunStatusRightToLeft = 1;
     static final int kCGBitmapByteOrder32Big = 4 << 12;
     static final int kCGBitmapByteOrder32Little = 2 << 12;
     static final int kCGBitmapByteOrder32Host = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN ? kCGBitmapByteOrder32Little : kCGBitmapByteOrder32Big;
     static final int kCGImageAlphaPremultipliedFirst = 2;
     static final int kCGImageAlphaNone = 0;
-    static final int kCGImageAlphaOnly = 7;
-    static final int kCGPathElementAddCurveToPoint = 3;
-    static final int kCGPathElementAddLineToPoint = 1;
-    static final int kCGPathElementAddQuadCurveToPoint = 2;
-    static final int kCGPathElementCloseSubpath = 4;
-    static final int kCGPathElementMoveToPoint = 0;
 
     static final long CFStringCreate(String string) {
         char[] buffer = string.toCharArray();
@@ -70,23 +58,17 @@
     }
 
     /* Custom */
-    static final native byte[] CGBitmapContextGetData(long c);
     static final native byte[] CGBitmapContextGetData(long c, int width, int height, int bpp);
-    static final native void CGPointApplyAffineTransform(CGPoint point, CGAffineTransform t);
     static final native void CGRectApplyAffineTransform(CGRect rect, CGAffineTransform t);
-    static final native CGAffineTransform CGAffineTransformInvert(CGAffineTransform t);
     static final native Path2D CGPathApply(long path);
     static final native CGRect CGPathGetPathBoundingBox(long path);
     static final native long CFStringCreateWithCharacters(long alloc, char[] chars, long start, long numChars);
-    static final native String CTFontCopyDisplayName(long font);
     static final native String CTFontCopyAttributeDisplayName(long font);
-    static final native void CTFontDrawGlyphs(long font, short glyphs, double x, double y, long count, long context);
-    static final native double CTFontGetAdvancesForGlyphs(long font, int orientation, short glyphs, CGSize advances, long count);
-    static final native CGRect CTFontGetBoundingRectsForGlyphs(long font, int orientation, short glyphs, CGRect boundingRects, long count);
+    static final native void CTFontDrawGlyphs(long font, short glyphs, double x, double y, long context);
+    static final native double CTFontGetAdvancesForGlyphs(long font, int orientation, short glyphs, CGSize advances);
     static final native boolean CTFontGetBoundingRectForGlyphUsingTables(long font, short glyphs, short format, int[] retArr);
     static final native int CTRunGetGlyphs(long run, int slotMask, int start, int[] buffer);
     static final native int CTRunGetStringIndices(long run, int start, int[] buffer);
-    static final native CFRange CTRunGetStringRange(long run);
     static final native int CTRunGetPositions(long run, int start, float[] buffer);
 
     /* one to one */
@@ -125,6 +107,5 @@
     static final native double CTLineGetTypographicBounds(long line);
     static final native long CTRunGetGlyphCount(long run);
     static final native long CTRunGetAttributes(long run);
-    static final native int CTRunGetStatus(long run);
 
 }
--- a/modules/graphics/src/main/java/com/sun/prism/sw/SWGraphics.java	Fri Sep 27 09:40:26 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/prism/sw/SWGraphics.java	Fri Sep 27 11:25:44 2013 -0700
@@ -783,9 +783,12 @@
                 }
             }
         } else {
-            glyphTx.setTransform(tx);
-            glyphTx.deriveWithTranslation(x + gl.getPosX(idx), y + gl.getPosY(idx));
-            this.paintShapePaintAlreadySet(g.getShape(), null, glyphTx);
+            Shape shape = g.getShape();
+            if (shape != null) {
+                glyphTx.setTransform(tx);
+                glyphTx.deriveWithTranslation(x + gl.getPosX(idx), y + gl.getPosY(idx));
+                this.paintShapePaintAlreadySet(shape, null, glyphTx);
+            }
         }
     }
 
--- a/modules/graphics/src/main/native-font/coretext.c	Fri Sep 27 09:40:26 2013 -0700
+++ b/modules/graphics/src/main/native-font/coretext.c	Fri Sep 27 11:25:44 2013 -0700
@@ -104,50 +104,6 @@
     return lpObject;
 }
 
-typedef struct CFRange_FID_CACHE {
-    int cached;
-    jclass clazz;
-    jfieldID location, length;
-    jmethodID init;
-} CFRange_FID_CACHE;
-
-CFRange_FID_CACHE CFRangeFc;
-
-void cacheCFRangeFields(JNIEnv *env)
-{
-    if (CFRangeFc.cached) return;
-    jclass tmpClass = (*env)->FindClass(env, "com/sun/javafx/font/coretext/CFRange");
-    CFRangeFc.clazz =  (jclass)(*env)->NewGlobalRef(env, tmpClass);
-    CFRangeFc.location = (*env)->GetFieldID(env, CFRangeFc.clazz, "location", "J");
-    CFRangeFc.length = (*env)->GetFieldID(env, CFRangeFc.clazz, "length", "J");
-    CFRangeFc.init = (*env)->GetMethodID(env, CFRangeFc.clazz, "<init>", "()V");
-    CFRangeFc.cached = 1;
-}
-
-CFRange *getCFRangeFields(JNIEnv *env, jobject lpObject, CFRange *lpStruct)
-{
-    if (!CFRangeFc.cached) cacheCFRangeFields(env);
-    lpStruct->location = (*env)->GetLongField(env, lpObject, CFRangeFc.location);
-    lpStruct->length = (*env)->GetLongField(env, lpObject, CFRangeFc.length);
-    return lpStruct;
-}
-
-void setCFRangeFields(JNIEnv *env, jobject lpObject, CFRange *lpStruct)
-{
-    if (!CFRangeFc.cached) cacheCFRangeFields(env);
-    (*env)->SetLongField(env, lpObject, CFRangeFc.location, (jlong)lpStruct->location);
-    (*env)->SetLongField(env, lpObject, CFRangeFc.length, (jlong)lpStruct->length);
-}
-
-jobject newCFRange(JNIEnv *env, CFRange *lpStruct)
-{
-    jobject lpObject = NULL;
-    if (!CFRangeFc.cached) cacheCFRangeFields(env);
-    lpObject = (*env)->NewObject(env, CFRangeFc.clazz, CFRangeFc.init);
-    if (lpObject && lpStruct) setCFRangeFields(env, lpObject, lpStruct);
-    return lpObject;
-}
-
 typedef struct CGPoint_FID_CACHE {
     int cached;
     jclass clazz;
@@ -525,12 +481,6 @@
     return (jlong)CTRunGetGlyphCount((CTRunRef)arg0);
 }
 
-JNIEXPORT jint JNICALL OS_NATIVE(CTRunGetStatus)
-    (JNIEnv *env, jclass that, jlong arg0)
-{
-    return (jint)CTRunGetStatus((CTRunRef)arg0);
-}
-
 JNIEXPORT jlong JNICALL OS_NATIVE(CTRunGetAttributes)
     (JNIEnv *env, jclass that, jlong arg0)
 {
@@ -619,20 +569,11 @@
     return i;
 }
 
-JNIEXPORT jobject JNICALL OS_NATIVE(CTRunGetStringRange)
-    (JNIEnv *env, jclass that, jlong arg0)
-{
-    CTRunRef run = (CTRunRef)arg0;
-    CFRange result = CTRunGetStringRange(run);
-    return newCFRange(env, &result);
-}
-
 JNIEXPORT jstring JNICALL OS_NATIVE(CTFontCopyAttributeDisplayName)
     (JNIEnv *env, jclass that, jlong arg0)
 {
     CFStringRef stringRef = CTFontCopyAttribute((CTFontRef)arg0, kCTFontDisplayNameAttribute);
-
-    /* Copied from MacFontFinder#createJavaString */
+    if (stringRef == NULL) return NULL;
     CFIndex length = CFStringGetLength(stringRef);
     UniChar buffer[length];
     CFStringGetCharacters(stringRef, CFRangeMake(0, length), buffer);
@@ -640,36 +581,7 @@
     return (*env)->NewString(env, (jchar *)buffer, length);
 }
 
-JNIEXPORT jstring JNICALL OS_NATIVE(CTFontCopyDisplayName)
-    (JNIEnv *env, jclass that, jlong arg0)
-{
-    CFStringRef stringRef = CTFontCopyDisplayName((CTFontRef)arg0);
-
-    /* Copied from MacFontFinder#createJavaString */
-    CFIndex length = CFStringGetLength(stringRef);
-    UniChar buffer[length];
-    CFStringGetCharacters(stringRef, CFRangeMake(0, length), buffer);
-    CFRelease(stringRef);
-    return (*env)->NewString(env, (jchar *)buffer, length);
-}
-
-JNIEXPORT jbyteArray JNICALL OS_NATIVE(CGBitmapContextGetData__J)
-    (JNIEnv *env, jclass that, jlong arg0)
-{
-    jbyteArray result = NULL;
-    CGContextRef context = (CGContextRef)arg0;
-    void* data = CGBitmapContextGetData(context);
-    if (data) {
-        size_t size = CGBitmapContextGetBytesPerRow(context) * CGBitmapContextGetHeight(context);
-        result = (*env)->NewByteArray(env, size);
-        if (result) {
-            (*env)->SetByteArrayRegion(env, result, 0, size, data);
-        }
-    }
-    return result;
-}
-
-JNIEXPORT jbyteArray JNICALL OS_NATIVE(CGBitmapContextGetData__JIII)
+JNIEXPORT jbyteArray JNICALL OS_NATIVE(CGBitmapContextGetData)
     (JNIEnv *env, jclass that, jlong arg0, jint dstWidth, jint dstHeight, jint bpp)
 {
     jbyteArray result = NULL;
@@ -679,7 +591,9 @@
     if (srcData) {
         /* Use one byte per pixel for grayscale */
         size_t srcWidth = CGBitmapContextGetWidth(context);
+        if (srcWidth < dstWidth) return NULL;
         size_t srcHeight =  CGBitmapContextGetHeight(context);
+        if (srcHeight < dstHeight) return NULL;
         size_t srcBytesPerRow = CGBitmapContextGetBytesPerRow(context);
         size_t srcStep = CGBitmapContextGetBitsPerPixel(context) / 8;
         int srcOffset = (srcHeight - dstHeight) * srcBytesPerRow;
@@ -695,7 +609,7 @@
         for (y = 0; y < dstHeight; y++) {
             for (x = 0, sx = 0; x < dstWidth; x++, dstOffset += dstStep, sx += srcStep) {
                 if (dstStep == 1) {
-                    /* BGRA or Gray to Gray*/
+                    /* BGRA or Gray to Gray */
                     data[dstOffset] = 0xFF - srcData[srcOffset + sx];
                 } else {
                     /* BGRA to RGB */
@@ -715,20 +629,6 @@
     return result;
 }
 
-JNIEXPORT void JNICALL OS_NATIVE(CGPointApplyAffineTransform)
-    (JNIEnv *env, jclass that, jobject arg0, jobject arg1)
-{
-    CGPoint _arg0, *lparg0=NULL;
-    CGAffineTransform _arg1, *lparg1=NULL;
-    if (arg0) if ((lparg0 = getCGPointFields(env, arg0, &_arg0)) == NULL) goto fail;
-    if (arg1) if ((lparg1 = getCGAffineTransformFields(env, arg1, &_arg1)) == NULL) goto fail;
-    _arg0 = CGPointApplyAffineTransform(*lparg0, *lparg1);
-fail:
-    /* In Only */
-//    if (arg1 && lparg1) setCGAffineTransformFields(env, arg1, lparg1);
-    if (arg0 && lparg0) setCGPointFields(env, arg0, lparg0);
-}
-
 JNIEXPORT void JNICALL OS_NATIVE(CGRectApplyAffineTransform)
     (JNIEnv *env, jclass that, jobject arg0, jobject arg1)
 {
@@ -744,28 +644,12 @@
 }
 
 JNIEXPORT void JNICALL OS_NATIVE(CTFontDrawGlyphs)
-    (JNIEnv *env, jclass that, jlong arg0, jshort arg1, jdouble arg2, jdouble arg3, jlong arg4, jlong arg5)
+    (JNIEnv *env, jclass that, jlong arg0, jshort arg1, jdouble arg2, jdouble arg3, jlong contextRef)
 {
     /* Custom: only takes one glyph at the time */
     CGGlyph glyphs[] = {arg1};
     CGPoint pos[] = {CGPointMake(arg2, arg3)};
-    CTFontDrawGlyphs((CTFontRef)arg0, glyphs, pos, 1, (CGContextRef)arg5);
-}
-
-JNIEXPORT jobject JNICALL OS_NATIVE(CTFontGetBoundingRectsForGlyphs)
-    (JNIEnv *env, jclass that, jlong arg1, jint arg2, jshort arg3, jobject arg4, jlong arg5)
-{
-    /* Custom: only takes one glyph at the time */
-    jobject rc = NULL;
-    CGRect result;
-    CGGlyph glyphs[] = {arg3};
-    CGRect _arg4, *lparg4=NULL;
-    if (arg4) if ((lparg4 = getCGRectFields(env, arg4, &_arg4)) == NULL) goto fail;
-    result = CTFontGetBoundingRectsForGlyphs((CTFontRef)arg1, (CTFontOrientation)arg2, glyphs, lparg4, 1);
-    rc = newCGRect(env, &result);
-fail:
-    if (arg4 && lparg4) setCGRectFields(env, arg4, &_arg4);
-    return rc;
+    CTFontDrawGlyphs((CTFontRef)arg0, glyphs, pos, 1, (CGContextRef)contextRef);
 }
 
 JNIEXPORT jboolean JNICALL OS_NATIVE(CTFontGetBoundingRectForGlyphUsingTables)
@@ -831,7 +715,7 @@
 }
 
 JNIEXPORT jdouble JNICALL OS_NATIVE(CTFontGetAdvancesForGlyphs)
-    (JNIEnv *env, jclass that, jlong arg0, jint arg1, jshort arg2, jobject arg3, jlong arg4)
+    (JNIEnv *env, jclass that, jlong arg0, jint arg1, jshort arg2, jobject arg3)
 {
     /* Custom: only takes one glyph at the time */
     jdouble rc = 0;
@@ -851,21 +735,6 @@
     return newCGRect(env, &result);
 }
 
-JNIEXPORT jobject JNICALL OS_NATIVE(CGAffineTransformInvert)
-    (JNIEnv *env, jclass that, jobject arg0)
-{
-    jobject rc = NULL;
-    CGAffineTransform result;
-    CGAffineTransform _arg0, *lparg0=NULL;
-    if (arg0) if ((lparg0 = getCGAffineTransformFields(env, arg0, &_arg0)) == NULL) goto fail;
-    result = CGAffineTransformInvert(*lparg0);
-    rc = newCGAffineTransform(env, &result);
-fail:
-    /* In Only */
-//    if (arg0 && lparg0) setCGAffineTransformFields(env, arg0, lparg0);
-    return rc;
-}
-
 /***********************************************/
 /*                Glyph Outline                */
 /***********************************************/