Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m
41152 views
/*1* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#import "JNIUtilities.h"2627#import "AWTFont.h"28#import "CoreTextSupport.h"2930#import "sun_font_CCharToGlyphMapper.h"3132/*33* Class: sun_font_CCharToGlyphMapper34* Method: countGlyphs35* Signature: (J)I36*/37JNIEXPORT jint JNICALL38Java_sun_font_CCharToGlyphMapper_countGlyphs39(JNIEnv *env, jclass clazz, jlong awtFontPtr)40{41jint numGlyphs = 0;4243JNI_COCOA_ENTER(env);4445AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);46numGlyphs = [awtFont->fFont numberOfGlyphs];4748JNI_COCOA_EXIT(env);4950return numGlyphs;51}5253static inline void54GetGlyphsFromUnicodes(JNIEnv *env, AWTFont *awtFont,55jint count, UniChar *unicodes,56CGGlyph *cgGlyphs, jintArray glyphs)57{58jint *glyphCodeInts = (*env)->GetPrimitiveArrayCritical(env, glyphs, 0);5960CTS_GetGlyphsAsIntsForCharacters(awtFont, unicodes,61cgGlyphs, glyphCodeInts, count);6263// Do not use JNI_COMMIT, as that will not free the buffer copy64// when +ProtectJavaHeap is on.65(*env)->ReleasePrimitiveArrayCritical(env, glyphs, glyphCodeInts, 0);66}6768static inline void69AllocateGlyphBuffer(JNIEnv *env, AWTFont *awtFont,70jint count, UniChar *unicodes, jintArray glyphs)71{72if (count < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) {73CGGlyph cgGlyphs[count];74GetGlyphsFromUnicodes(env, awtFont, count, unicodes, cgGlyphs, glyphs);75} else {76CGGlyph *cgGlyphs = (CGGlyph *)malloc(count * sizeof(CGGlyph));77GetGlyphsFromUnicodes(env, awtFont, count, unicodes, cgGlyphs, glyphs);78free(cgGlyphs);79}80}8182/*83* Class: sun_font_CCharToGlyphMapper84* Method: nativeCharsToGlyphs85* Signature: (JI[C[I)V86*/87JNIEXPORT void JNICALL88Java_sun_font_CCharToGlyphMapper_nativeCharsToGlyphs89(JNIEnv *env, jclass clazz,90jlong awtFontPtr, jint count, jcharArray unicodes, jintArray glyphs)91{92JNI_COCOA_ENTER(env);9394AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);9596// check the array size97jint len = (*env)->GetArrayLength(env, glyphs);98if (len < count) {99count = len;100}101102jchar *unicodesAsChars =103(*env)->GetPrimitiveArrayCritical(env, unicodes, NULL);104105if (unicodesAsChars != NULL) {106AllocateGlyphBuffer(env, awtFont, count,107(UniChar *)unicodesAsChars, glyphs);108109(*env)->ReleasePrimitiveArrayCritical(env, unicodes,110unicodesAsChars, JNI_ABORT);111}112113JNI_COCOA_EXIT(env);114}115116117