0N/A/*
0N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A */
0N/A
0N/A#import <JavaNativeFoundation/JavaNativeFoundation.h>
0N/A
0N/A#import "AWTFont.h"
0N/A#import "CoreTextSupport.h"
0N/A
0N/A#import "sun_font_CCharToGlyphMapper.h"
0N/A
0N/A/*
0N/A * Class: sun_font_CCharToGlyphMapper
0N/A * Method: countGlyphs
0N/A * Signature: (J)I
0N/A */
0N/AJNIEXPORT jint JNICALL
0N/AJava_sun_font_CCharToGlyphMapper_countGlyphs
0N/A (JNIEnv *env, jclass clazz, jlong awtFontPtr)
0N/A{
0N/A jint numGlyphs = 0;
0N/A
0N/AJNF_COCOA_ENTER(env);
0N/A
0N/A AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
0N/A numGlyphs = [awtFont->fFont numberOfGlyphs];
0N/A
0N/AJNF_COCOA_EXIT(env);
0N/A
0N/A return numGlyphs;
0N/A}
0N/A
0N/Astatic inline void
0N/AGetGlyphsFromUnicodes(JNIEnv *env, AWTFont *awtFont,
0N/A jint count, UniChar *unicodes,
0N/A CGGlyph *cgGlyphs, jintArray glyphs)
0N/A{
0N/A jint *glyphCodeInts = (*env)->GetPrimitiveArrayCritical(env, glyphs, 0);
0N/A
0N/A CTS_GetGlyphsAsIntsForCharacters(awtFont, unicodes,
0N/A cgGlyphs, glyphCodeInts, count);
0N/A
0N/A // Do not use JNI_COMMIT, as that will not free the buffer copy
0N/A // when +ProtectJavaHeap is on.
0N/A (*env)->ReleasePrimitiveArrayCritical(env, glyphs, glyphCodeInts, 0);
0N/A}
0N/A
0N/Astatic inline void
0N/AAllocateGlyphBuffer(JNIEnv *env, AWTFont *awtFont,
0N/A jint count, UniChar *unicodes, jintArray glyphs)
0N/A{
0N/A if (count < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) {
0N/A CGGlyph cgGlyphs[count];
0N/A GetGlyphsFromUnicodes(env, awtFont, count, unicodes, cgGlyphs, glyphs);
0N/A } else {
0N/A CGGlyph *cgGlyphs = (CGGlyph *)malloc(count * sizeof(CGGlyph));
0N/A GetGlyphsFromUnicodes(env, awtFont, count, unicodes, cgGlyphs, glyphs);
0N/A free(cgGlyphs);
0N/A }
0N/A}
0N/A
0N/A/*
0N/A * Class: sun_font_CCharToGlyphMapper
0N/A * Method: nativeCharsToGlyphs
0N/A * Signature: (JI[C[I)V
0N/A */
0N/AJNIEXPORT void JNICALL
0N/AJava_sun_font_CCharToGlyphMapper_nativeCharsToGlyphs
0N/A (JNIEnv *env, jclass clazz,
0N/A jlong awtFontPtr, jint count, jcharArray unicodes, jintArray glyphs)
0N/A{
0N/AJNF_COCOA_ENTER(env);
0N/A
0N/A AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr);
0N/A
0N/A // check the array size
0N/A jint len = (*env)->GetArrayLength(env, glyphs);
0N/A if (len < count) {
0N/A count = len;
0N/A }
0N/A
0N/A jchar *unicodesAsChars =
0N/A (*env)->GetPrimitiveArrayCritical(env, unicodes, NULL);
0N/A
0N/A AllocateGlyphBuffer(env, awtFont, count, (UniChar *)unicodesAsChars, glyphs);
0N/A
0N/A (*env)->ReleasePrimitiveArrayCritical(env, unicodes,
0N/A unicodesAsChars, JNI_ABORT);
0N/A
0N/AJNF_COCOA_EXIT(env);
0N/A}
0N/A